llvm.org GIT mirror llvm / e92934e
LowerBitSets: Ignore bitset entries that do not directly refer to a global. It is possible for a global to be substituted with another global of a different type or a different kind (i.e. an alias) at IR link time. One example of this scenario is when a Microsoft ABI vtable is substituted with an alias referring to a larger vtable containing an RTTI reference. This will cause the global to be RAUW'd with a possibly bitcasted reference to the other global. This will of course also affect any references to the global in bitset metadata. The right way to handle such metadata is simply to ignore it. This is sound because the linked module should contain another copy of the bitset entries as applied to the new global. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240866 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Collingbourne 4 years ago
2 changed file(s) with 26 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
270270 for (MDNode *Op : BitSetNM->operands()) {
271271 if (Op->getOperand(0) != BitSet || !Op->getOperand(1))
272272 continue;
273 auto OpGlobal = cast(
273 auto OpGlobal = dyn_cast(
274274 cast(Op->getOperand(1))->getValue());
275 if (!OpGlobal)
276 continue;
275277 uint64_t Offset =
276278 cast(cast(Op->getOperand(2))
277279 ->getValue())->getZExtValue();
620622 report_fatal_error("Bit set element must be a constant");
621623 auto OpGlobal = dyn_cast(OpConstMD->getValue());
622624 if (!OpGlobal)
623 report_fatal_error("Bit set element must refer to global");
625 continue;
624626
625627 auto OffsetConstMD = dyn_cast(Op->getOperand(2));
626628 if (!OffsetConstMD)
674676 if (I == BitSetIndices.end())
675677 continue;
676678
677 auto OpGlobal = cast(
679 auto OpGlobal = dyn_cast(
678680 cast(Op->getOperand(1))->getValue());
681 if (!OpGlobal)
682 continue;
679683 BitSetMembers[I->second].insert(GlobalIndices[OpGlobal]);
680684 }
681685 }
0 ; RUN: opt -S -lowerbitsets < %s | FileCheck %s
1
2 target datalayout = "e-p:32:32"
3
4 ; CHECK-NOT: @b = alias
5 @a = constant i32 1
6 @b = constant [2 x i32] [i32 2, i32 3]
7
8 !0 = !{!"bitset1", i32* @a, i32 0}
9 !1 = !{!"bitset1", i32* bitcast ([2 x i32]* @b to i32*), i32 0}
10
11 !llvm.bitsets = !{ !0, !1 }
12
13 declare i1 @llvm.bitset.test(i8* %ptr, metadata %bitset) nounwind readnone
14
15 define i1 @foo(i8* %p) {
16 %x = call i1 @llvm.bitset.test(i8* %p, metadata !"bitset1")
17 ret i1 %x
18 }