From ba74b27ed1ac9f0ea6cac2821bb87bebf102558d Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Fri, 12 Jun 2015 03:25:05 +0000 Subject: [PATCH] LowerBitSets: Give names to aliases of unnamed bitset element objects. 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 | 5 +++-- test/Transforms/LowerBitSets/unnamed.ll | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 test/Transforms/LowerBitSets/unnamed.ll diff --git a/lib/Transforms/IPO/LowerBitSets.cpp b/lib/Transforms/IPO/LowerBitSets.cpp index bffeebb6e2e..dec583b0e2d 100644 --- a/lib/Transforms/IPO/LowerBitSets.cpp +++ b/lib/Transforms/IPO/LowerBitSets.cpp @@ -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 index 00000000000..5ff0453391a --- /dev/null +++ b/test/Transforms/LowerBitSets/unnamed.ll @@ -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 +}