Skip to content

Commit feaa59c

Browse files
maarquitos14sys-ce-bb
authored andcommitted
Don't add initializer to local variables with external linkage (#2637)
If a variable is external, it will be defined during linking, the translator should not do it. Signed-off-by: Marcos Maronas <[email protected]> Original commit: KhronosGroup/SPIRV-LLVM-Translator@19b7768fc6f4c01
1 parent e265f23 commit feaa59c

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1570,7 +1570,8 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
15701570
else if (LinkageTy == GlobalValue::CommonLinkage)
15711571
// In LLVM, variables with common linkage type must be initialized to 0.
15721572
Initializer = Constant::getNullValue(Ty);
1573-
else if (BS == SPIRVStorageClassKind::StorageClassWorkgroup)
1573+
else if (BS == SPIRVStorageClassKind::StorageClassWorkgroup &&
1574+
LinkageTy != GlobalValue::ExternalLinkage)
15741575
Initializer = dyn_cast<Constant>(UndefValue::get(Ty));
15751576
else if ((LinkageTy != GlobalValue::ExternalLinkage) &&
15761577
(BS == SPIRVStorageClassKind::StorageClassCrossWorkgroup))
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -o %t.spv
3+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
4+
; RUN: llvm-dis %t.rev.bc -o %t.rev.ll
5+
; RUN: FileCheck < %t.rev.ll %s --check-prefix CHECK-LLVM
6+
7+
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-G1"
8+
target triple = "spir64-unknown-unknown"
9+
@__LocalVar = external addrspace(3) global ptr addrspace(1)
10+
; CHECK-LLVM:@__LocalVar = external addrspace(3) global ptr addrspace(1)

0 commit comments

Comments
 (0)