Skip to content

Commit e099f77

Browse files
authored
Fix addrspace generation in reverse translation for global annotations (#2656)
This change fixes the assertion: Assertion `C->getType() == Ty->getElementType() && "Wrong type in array element initializer"' failed
1 parent 88e546a commit e099f77

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

lib/SPIRV/SPIRVReader.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3838,8 +3838,8 @@ void SPIRVToLLVM::transIntelFPGADecorations(SPIRVValue *BV, Value *V) {
38383838
GS->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
38393839
GS->setSection("llvm.metadata");
38403840

3841-
Type *ResType = PointerType::get(GV->getContext(),
3842-
GV->getType()->getPointerAddressSpace());
3841+
Type *ResType = PointerType::get(
3842+
GV->getContext(), M->getDataLayout().getDefaultGlobalsAddressSpace());
38433843
Constant *C = ConstantExpr::getPointerBitCastOrAddrSpaceCast(GV, ResType);
38443844

38453845
Type *Int8PtrTyPrivate = PointerType::get(*Context, SPIRAS_Private);
@@ -3898,8 +3898,8 @@ void SPIRVToLLVM::transUserSemantic(SPIRV::SPIRVFunction *Fun) {
38983898
GS->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
38993899
GS->setSection("llvm.metadata");
39003900

3901-
Type *ResType = PointerType::get(V->getContext(),
3902-
V->getType()->getPointerAddressSpace());
3901+
Type *ResType = PointerType::get(
3902+
V->getContext(), M->getDataLayout().getDefaultGlobalsAddressSpace());
39033903
Constant *C =
39043904
ConstantExpr::getPointerBitCastOrAddrSpaceCast(TransFun, ResType);
39053905

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
; This test checks that we don't face an assertion during the reverse translation:
2+
; Assertion `C->getType() == Ty->getElementType() && "Wrong type in array element initializer"' failed
3+
; It also verifies that all the different address spaces were casted to the "common" one.
4+
5+
; RUN: llvm-as %s -o %t.bc
6+
; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_INTEL_fpga_memory_attributes
7+
; RUN: spirv-val %t.spv
8+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
9+
; RUN: llvm-dis %t.rev.bc
10+
; RUN: FileCheck < %t.rev.ll %s
11+
12+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
13+
target triple = "spir64-unknown-unknown"
14+
15+
%class.test = type { %"class.test_private" }
16+
%"class.test_private" = type { i16 }
17+
18+
; CHECK: @llvm.global.annotations = appending global [2 x { ptr, ptr, ptr, i32, ptr }] [{ ptr, ptr, ptr, i32, ptr } { ptr addrspacecast (ptr addrspace(1) @samples to ptr), ptr @0, ptr undef, i32 undef, ptr undef }, { ptr, ptr, ptr, i32, ptr } { ptr addrspacecast (ptr addrspace(2) @foo to ptr), ptr @1, ptr undef, i32 undef, ptr undef }]
19+
20+
@llvm.global.annotations = addrspace(1) global [2 x { ptr addrspace(1), ptr addrspace(1), ptr addrspace(1), i32, ptr addrspace(1) }] [ { ptr addrspace(1), ptr addrspace(1), ptr addrspace(1), i32, ptr addrspace(1) } { ptr addrspace(1) @samples, ptr addrspace(1) @.str, ptr addrspace(1) null, i32 92, ptr addrspace(1) null }, { ptr addrspace(1), ptr addrspace(1), ptr addrspace(1), i32, ptr addrspace(1) } { ptr addrspace(1) addrspacecast (ptr addrspace(2) @foo to ptr addrspace(1)), ptr addrspace(1) @.str.2, ptr addrspace(1) null, i32 30, ptr addrspace(1) null }]
21+
@samples = external addrspace(1) global { [64 x %class.test] }
22+
@foo = dso_local addrspace(2) constant i32 1, align 4
23+
@.str = addrspace(1) constant [13 x i8] c"{register:1}\00"
24+
@.str.2 = addrspace(1) constant [13 x i8] c"{register:0}\00"

0 commit comments

Comments
 (0)