LowerBitSets: Give names to aliases of unnamed bitset element objects.
authorPeter Collingbourne <peter@pcc.me.uk>
Fri, 12 Jun 2015 03:25:05 +0000 (03:25 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Fri, 12 Jun 2015 03:25:05 +0000 (03:25 +0000)
It is valid for globals to be unnamed, but aliases must have a name. To avoid
creating invalid IR, we need to assign names to any aliases we create that
point to unnamed objects that have been moved into combined globals.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239590 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/LowerBitSets.cpp
test/Transforms/LowerBitSets/unnamed.ll [new file with mode: 0644]

index bffeebb..dec583b 100644 (file)
@@ -556,8 +556,9 @@ void LowerBitSets::buildBitSetsFromGlobals(
     } else {
       GlobalAlias *GAlias =
           GlobalAlias::create(Globals[I]->getType(), Globals[I]->getLinkage(),
-                              "", CombinedGlobalElemPtr, M);
-      GAlias->takeName(Globals[I]);
+                              "data", CombinedGlobalElemPtr, M);
+      if (Globals[I]->hasName())
+        GAlias->takeName(Globals[I]);
       Globals[I]->replaceAllUsesWith(GAlias);
     }
     Globals[I]->eraseFromParent();
diff --git a/test/Transforms/LowerBitSets/unnamed.ll b/test/Transforms/LowerBitSets/unnamed.ll
new file mode 100644 (file)
index 0000000..5ff0453
--- /dev/null
@@ -0,0 +1,19 @@
+; RUN: opt -S -lowerbitsets < %s | FileCheck %s
+
+target datalayout = "e-p:32:32"
+
+; CHECK: @data ={{.*}} alias
+@0 = constant i32 1
+@1 = constant [2 x i32] [i32 2, i32 3]
+
+!0 = !{!"bitset1", i32* @0, i32 0}
+!1 = !{!"bitset1", [2 x i32]* @1, i32 4}
+
+!llvm.bitsets = !{ !0, !1 }
+
+declare i1 @llvm.bitset.test(i8* %ptr, metadata %bitset) nounwind readnone
+
+define i1 @foo(i8* %p) {
+  %x = call i1 @llvm.bitset.test(i8* %p, metadata !"bitset1")
+  ret i1 %x
+}