[PATCH] D65312: ThinLTOBitcodeWriter: Include globals associated with type metadata globals in the merged module.
Peter Collingbourne via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 29 10:24:27 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL367242: ThinLTOBitcodeWriter: Include globals associated with type metadata globals in… (authored by pcc, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D65312?vs=211864&id=212194#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D65312/new/
https://reviews.llvm.org/D65312
Files:
llvm/trunk/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
llvm/trunk/test/Transforms/ThinLTOBitcodeWriter/associated.ll
Index: llvm/trunk/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
===================================================================
--- llvm/trunk/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
+++ llvm/trunk/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
@@ -218,10 +218,18 @@
promoteTypeIds(M, ModuleId);
- // Returns whether a global has attached type metadata. Such globals may
- // participate in CFI or whole-program devirtualization, so they need to
- // appear in the merged module instead of the thin LTO module.
+ // Returns whether a global or its associated global has attached type
+ // metadata. The former may participate in CFI or whole-program
+ // devirtualization, so they need to appear in the merged module instead of
+ // the thin LTO module. Similarly, globals that are associated with globals
+ // with type metadata need to appear in the merged module because they will
+ // reference the global's section directly.
auto HasTypeMetadata = [](const GlobalObject *GO) {
+ if (MDNode *MD = GO->getMetadata(LLVMContext::MD_associated))
+ if (auto *AssocVM = dyn_cast_or_null<ValueAsMetadata>(MD->getOperand(0)))
+ if (auto *AssocGO = dyn_cast<GlobalObject>(AssocVM->getValue()))
+ if (AssocGO->hasMetadata(LLVMContext::MD_type))
+ return true;
return GO->hasMetadata(LLVMContext::MD_type);
};
Index: llvm/trunk/test/Transforms/ThinLTOBitcodeWriter/associated.ll
===================================================================
--- llvm/trunk/test/Transforms/ThinLTOBitcodeWriter/associated.ll
+++ llvm/trunk/test/Transforms/ThinLTOBitcodeWriter/associated.ll
@@ -0,0 +1,14 @@
+; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t %s
+; RUN: llvm-modextract -b -n 0 -o - %t | llvm-dis | FileCheck --check-prefix=M0 %s
+; RUN: llvm-modextract -b -n 1 -o - %t | llvm-dis | FileCheck --check-prefix=M1 %s
+
+; M0: @g = external constant
+; M0-NOT: @assoc
+; M1: @g = constant i8 1
+; M1: @assoc = private constant i8 2
+
+ at g = constant i8 1, !type !0
+ at assoc = private constant i8 2, !associated !1
+
+!0 = !{i32 0, !"typeid"}
+!1 = !{i8* @g}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65312.212194.patch
Type: text/x-patch
Size: 2119 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190729/ab852811/attachment.bin>
More information about the llvm-commits
mailing list