[PATCH] D83688: [Bitcode] Avoid duplicating linker option when upgrading
Steven Wu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 13 10:05:16 PDT 2020
steven_wu updated this revision to Diff 277470.
steven_wu added a comment.
Add comments in the tests.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D83688/new/
https://reviews.llvm.org/D83688
Files:
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/test/Bitcode/Inputs/linker-options.bc
llvm/test/Bitcode/upgrade-linker-options-2.ll
Index: llvm/test/Bitcode/upgrade-linker-options-2.ll
===================================================================
--- /dev/null
+++ llvm/test/Bitcode/upgrade-linker-options-2.ll
@@ -0,0 +1,12 @@
+;; Test upgrade linker option doesn't create duplicated linker options.
+;; Inputs is generated from IR and checked in as bitcode as it will get rejected by verifier.
+;; define void @test() {
+;; ret void
+;; }
+;; !llvm.module.flags = !{!0}
+;; !0 = !{i32 6, !"Linker Options", !1}
+;; !1 = !{!2}
+;; !2 = !{!"-framework", !"Foundation"}
+
+; RUN: llvm-dis %S/Inputs/linker-options.bc -o - | FileCheck %s
+; CHECK: !llvm.linker.options = !{!2}
Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
===================================================================
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -2965,12 +2965,15 @@
}
// Upgrade "Linker Options" module flag to "llvm.linker.options" module-level
- // metadata.
- if (Metadata *Val = TheModule->getModuleFlag("Linker Options")) {
- NamedMDNode *LinkerOpts =
- TheModule->getOrInsertNamedMetadata("llvm.linker.options");
- for (const MDOperand &MDOptions : cast<MDNode>(Val)->operands())
- LinkerOpts->addOperand(cast<MDNode>(MDOptions));
+ // metadata. Only upgrade if the new option doesn't exist to avoid upgrade
+ // multiple times.
+ if (!TheModule->getNamedMetadata("llvm.linker.options")) {
+ if (Metadata *Val = TheModule->getModuleFlag("Linker Options")) {
+ NamedMDNode *LinkerOpts =
+ TheModule->getOrInsertNamedMetadata("llvm.linker.options");
+ for (const MDOperand &MDOptions : cast<MDNode>(Val)->operands())
+ LinkerOpts->addOperand(cast<MDNode>(MDOptions));
+ }
}
DeferredMetadataInfo.clear();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83688.277470.patch
Type: text/x-patch
Size: 1797 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200713/39b816b2/attachment.bin>
More information about the llvm-commits
mailing list