Skip to content

Commit a500a43

Browse files
committed
[CodeGen][AMDGPU] Fix ICE for static initializer IR generation
Differential Revision: https://reviews.llvm.org/D92782
1 parent 956034c commit a500a43

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

clang/lib/CodeGen/CGDecl.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,12 +353,11 @@ CodeGenFunction::AddInitializerToStaticVarDecl(const VarDecl &D,
353353
if (GV->getValueType() != Init->getType()) {
354354
llvm::GlobalVariable *OldGV = GV;
355355

356-
GV = new llvm::GlobalVariable(CGM.getModule(), Init->getType(),
357-
OldGV->isConstant(),
358-
OldGV->getLinkage(), Init, "",
359-
/*InsertBefore*/ OldGV,
360-
OldGV->getThreadLocalMode(),
361-
CGM.getContext().getTargetAddressSpace(D.getType()));
356+
GV = new llvm::GlobalVariable(
357+
CGM.getModule(), Init->getType(), OldGV->isConstant(),
358+
OldGV->getLinkage(), Init, "",
359+
/*InsertBefore*/ OldGV, OldGV->getThreadLocalMode(),
360+
OldGV->getType()->getPointerAddressSpace());
362361
GV->setVisibility(OldGV->getVisibility());
363362
GV->setDSOLocal(OldGV->isDSOLocal());
364363
GV->setComdat(OldGV->getComdat());

clang/test/CodeGen/address-space.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,14 @@ void __attribute__((address_space(1)))*
5959
void_ptr_arithmetic_test(void __attribute__((address_space(1))) *arg) {
6060
return arg + 4;
6161
}
62+
63+
// CHECK-LABEL: define i32* @test5(
64+
const unsigned *test5() {
65+
// Intentionally leave a part of an array uninitialized. This triggers a
66+
// different code path contrary to a fully initialized array.
67+
// CHECK: ret i32* getelementptr inbounds ([256 x i32]
68+
static const unsigned bars[256] = {
69+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
70+
11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
71+
return &bars[0];
72+
}

0 commit comments

Comments
 (0)