Skip to content

Commit 2823e70

Browse files
authored
[Backport to 14] Don't add initializer to local variables with external linkage. (#2644)
If a variable is external, it will be defined during linking, the translator should not do it. Signed-off-by: Marcos Maronas <[email protected]>
1 parent f238450 commit 2823e70

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/SPIRV/SPIRVReader.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1573,7 +1573,8 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
15731573
else if (LinkageTy == GlobalValue::CommonLinkage)
15741574
// In LLVM, variables with common linkage type must be initialized to 0.
15751575
Initializer = Constant::getNullValue(Ty);
1576-
else if (BS == SPIRVStorageClassKind::StorageClassWorkgroup)
1576+
else if (BS == SPIRVStorageClassKind::StorageClassWorkgroup &&
1577+
LinkageTy != GlobalValue::ExternalLinkage)
15771578
Initializer = dyn_cast<Constant>(UndefValue::get(Ty));
15781579
else if ((LinkageTy != GlobalValue::ExternalLinkage) &&
15791580
(BS == SPIRVStorageClassKind::StorageClassCrossWorkgroup))

test/local_var_keeps_external.ll

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 -opaque-pointers
2+
; RUN: llvm-spirv %t.bc -o %t.spv -opaque-pointers
3+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc -opaque-pointers
4+
; RUN: llvm-dis %t.rev.bc -o %t.rev.ll -opaque-pointers
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)