[PATCH] D14818: llvm-link option and test for recent metadata mapping bug

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 20 16:38:18 PST 2015


This revision was automatically updated to reflect the committed changes.
Closed by commit rL253740: llvm-link option and test for recent metadata mapping bug (authored by tejohnson).

Changed prior to commit:
  http://reviews.llvm.org/D14818?vs=40648&id=40848#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D14818

Files:
  llvm/trunk/test/Linker/only-needed-named-metadata.ll
  llvm/trunk/tools/llvm-link/llvm-link.cpp

Index: llvm/trunk/test/Linker/only-needed-named-metadata.ll
===================================================================
--- llvm/trunk/test/Linker/only-needed-named-metadata.ll
+++ llvm/trunk/test/Linker/only-needed-named-metadata.ll
@@ -26,6 +26,11 @@
 ; ONLYNEEDED-NOT:@analias
 ; ONLYNEEDED-NOT:@globalfunc2()
 
+; Test -only-needed link with the modules preserved instead of freeing to
+; catch any cross-module references to metadata, which the bitcode writer
+; will assert on.
+; RUN: llvm-link -preserve-modules -o %t3.bc -only-needed %t2.bc %t.bc
+
 @X = global i32 5
 @U = global i32 6
 @U_linkonce = linkonce_odr hidden global i32 6
Index: llvm/trunk/tools/llvm-link/llvm-link.cpp
===================================================================
--- llvm/trunk/tools/llvm-link/llvm-link.cpp
+++ llvm/trunk/tools/llvm-link/llvm-link.cpp
@@ -89,6 +89,10 @@
 SuppressWarnings("suppress-warnings", cl::desc("Suppress all linking warnings"),
                  cl::init(false));
 
+static cl::opt<bool>
+    PreserveModules("preserve-modules",
+                    cl::desc("Preserve linked modules for testing"));
+
 static cl::opt<bool> PreserveBitcodeUseListOrder(
     "preserve-bc-uselistorder",
     cl::desc("Preserve use-list order when writing LLVM bitcode."),
@@ -259,6 +263,15 @@
       return false;
     // All linker flags apply to linking of subsequent files.
     ApplicableFlags = Flags;
+
+    // If requested for testing, preserve modules by releasing them from
+    // the unique_ptr before the are freed. This can help catch any
+    // cross-module references from e.g. unneeded metadata references
+    // that aren't properly set to null but instead mapped to the source
+    // module version. The bitcode writer will assert if it finds any such
+    // cross-module references.
+    if (PreserveModules)
+      M.release();
   }
 
   return true;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14818.40848.patch
Type: text/x-patch
Size: 1889 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151121/ceddc75d/attachment.bin>


More information about the llvm-commits mailing list