[PATCH] D92782: [CodeGen][AMDGPU] Fix ICE for static initializer IR generation

Alexey Bader via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 7 12:19:56 PST 2020


bader created this revision.
bader added reviewers: rjmccall, yaxunl.
Herald added subscribers: ebevhan, t-tye, tpr, dstuttard, kzhuravl.
bader requested review of this revision.
Herald added subscribers: cfe-commits, wdng.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92782

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/test/CodeGen/address-space.c


Index: clang/test/CodeGen/address-space.c
===================================================================
--- clang/test/CodeGen/address-space.c
+++ clang/test/CodeGen/address-space.c
@@ -59,3 +59,14 @@
 void_ptr_arithmetic_test(void __attribute__((address_space(1))) *arg) {
     return arg + 4;
 }
+
+// CHECK-LABEL: define i32* @test5(
+const unsigned * test5() {
+  // Intentionally leave a part of an array uninitialized. This triggers a
+  // different code path contrary to a fully initialized array.
+  // CHECK: ret i32* getelementptr inbounds ([256 x i32]
+  static const unsigned bars[256] = {
+      0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
+      11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
+  return &bars[0];
+}
Index: clang/lib/CodeGen/CGDecl.cpp
===================================================================
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -353,12 +353,11 @@
   if (GV->getValueType() != Init->getType()) {
     llvm::GlobalVariable *OldGV = GV;
 
-    GV = new llvm::GlobalVariable(CGM.getModule(), Init->getType(),
-                                  OldGV->isConstant(),
-                                  OldGV->getLinkage(), Init, "",
-                                  /*InsertBefore*/ OldGV,
-                                  OldGV->getThreadLocalMode(),
-                           CGM.getContext().getTargetAddressSpace(D.getType()));
+    GV = new llvm::GlobalVariable(
+        CGM.getModule(), Init->getType(), OldGV->isConstant(),
+        OldGV->getLinkage(), Init, "",
+        /*InsertBefore*/ OldGV, OldGV->getThreadLocalMode(),
+        OldGV->getType()->getPointerAddressSpace());
     GV->setVisibility(OldGV->getVisibility());
     GV->setDSOLocal(OldGV->isDSOLocal());
     GV->setComdat(OldGV->getComdat());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92782.309988.patch
Type: text/x-patch
Size: 1785 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201207/75afeecb/attachment-0001.bin>


More information about the cfe-commits mailing list