[PATCH] D83688: [Bitcode] Avoid duplicating linker option when upgrading

Steven Wu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 23 13:08:07 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rGac375c2fe316: [Bitcode] Avoid duplicating linker option when upgrading (authored by steven_wu).

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
@@ -2969,12 +2969,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.280238.patch
Type: text/x-patch
Size: 1797 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200723/23105fa7/attachment.bin>


More information about the llvm-commits mailing list