Skip to content

Commit e7bfe86

Browse files
vmaksimosys-ce-bb
authored andcommitted
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 Original commit: KhronosGroup/SPIRV-LLVM-Translator@e099f77cc6d02b9
1 parent d0c3bea commit e7bfe86

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

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

3818-
Type *ResType = PointerType::get(GV->getContext(),
3819-
GV->getType()->getPointerAddressSpace());
3818+
Type *ResType = PointerType::get(
3819+
GV->getContext(), M->getDataLayout().getDefaultGlobalsAddressSpace());
38203820
Constant *C = ConstantExpr::getPointerBitCastOrAddrSpaceCast(GV, ResType);
38213821

38223822
Type *Int8PtrTyPrivate = PointerType::get(*Context, SPIRAS_Private);
@@ -3875,8 +3875,8 @@ void SPIRVToLLVM::transUserSemantic(SPIRV::SPIRVFunction *Fun) {
38753875
GS->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
38763876
GS->setSection("llvm.metadata");
38773877

3878-
Type *ResType = PointerType::get(V->getContext(),
3879-
V->getType()->getPointerAddressSpace());
3878+
Type *ResType = PointerType::get(
3879+
V->getContext(), M->getDataLayout().getDefaultGlobalsAddressSpace());
38803880
Constant *C =
38813881
ConstantExpr::getPointerBitCastOrAddrSpaceCast(TransFun, ResType);
38823882

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)