Fix PR23045.
authorRafael Espindola <rafael.espindola@gmail.com>
Mon, 30 Mar 2015 21:36:43 +0000 (21:36 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Mon, 30 Mar 2015 21:36:43 +0000 (21:36 +0000)
Keep a note in the materializer that we are stripping debug info so that
user doing a lazy read of the module don't hit outdated formats.

Thanks to Duncan for suggesting the fix.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233603 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/DebugInfo.h
include/llvm/IR/GVMaterializer.h
lib/Bitcode/Reader/BitcodeReader.cpp
lib/IR/DebugInfo.cpp
tools/gold/gold-plugin.cpp
tools/llvm-link/llvm-link.cpp

index 25198328bf546a2e70784351539962538572ce56..4aca3455c0572a3a5af7c277ff46162dcaa6b8d8 100644 (file)
@@ -1376,6 +1376,7 @@ DITypeIdentifierMap generateDITypeIdentifierMap(const NamedMDNode *CU_Nodes);
 /// metadata for debugging. We also remove debug locations for instructions.
 /// Return true if module is modified.
 bool StripDebugInfo(Module &M);
 /// metadata for debugging. We also remove debug locations for instructions.
 /// Return true if module is modified.
 bool StripDebugInfo(Module &M);
+bool stripDebugInfo(Function &F);
 
 /// \brief Return Debug Info Metadata Version by checking module flags.
 unsigned getDebugMetadataVersionFromModule(const Module &M);
 
 /// \brief Return Debug Info Metadata Version by checking module flags.
 unsigned getDebugMetadataVersionFromModule(const Module &M);
index ae2f2e1aefbed5f4e26e4e711baf053812c6e237..779f2e0181842985eba3fee002d16e9a2eb56117 100644 (file)
@@ -54,6 +54,7 @@ public:
   virtual std::error_code MaterializeModule(Module *M) = 0;
 
   virtual std::error_code materializeMetadata() = 0;
   virtual std::error_code MaterializeModule(Module *M) = 0;
 
   virtual std::error_code materializeMetadata() = 0;
+  virtual void setStripDebugInfo() = 0;
 
   virtual std::vector<StructType *> getIdentifiedStructTypes() const = 0;
 };
 
   virtual std::vector<StructType *> getIdentifiedStructTypes() const = 0;
 };
index 84753ffd181f9ad7dabb55aa335def34751b97a6..274b982283cdc5d7b9db88410a770fa826628339 100644 (file)
@@ -16,6 +16,7 @@
 #include "llvm/Bitcode/LLVMBitCodes.h"
 #include "llvm/IR/AutoUpgrade.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/Bitcode/LLVMBitCodes.h"
 #include "llvm/IR/AutoUpgrade.h"
 #include "llvm/IR/Constants.h"
+#include "llvm/IR/DebugInfo.h"
 #include "llvm/IR/DebugInfoMetadata.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/DiagnosticPrinter.h"
 #include "llvm/IR/DebugInfoMetadata.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/DiagnosticPrinter.h"
@@ -218,6 +219,8 @@ class BitcodeReader : public GVMaterializer {
   /// True if any Metadata block has been materialized.
   bool IsMetadataMaterialized;
 
   /// True if any Metadata block has been materialized.
   bool IsMetadataMaterialized;
 
+  bool StripDebugInfo = false;
+
 public:
   std::error_code Error(BitcodeError E, const Twine &Message);
   std::error_code Error(BitcodeError E);
 public:
   std::error_code Error(BitcodeError E, const Twine &Message);
   std::error_code Error(BitcodeError E);
@@ -255,6 +258,8 @@ public:
   /// Materialize any deferred Metadata block.
   std::error_code materializeMetadata() override;
 
   /// Materialize any deferred Metadata block.
   std::error_code materializeMetadata() override;
 
+  void setStripDebugInfo() override;
+
 private:
   std::vector<StructType *> IdentifiedStructTypes;
   StructType *createIdentifiedStructType(LLVMContext &Context, StringRef Name);
 private:
   std::vector<StructType *> IdentifiedStructTypes;
   StructType *createIdentifiedStructType(LLVMContext &Context, StringRef Name);
@@ -2609,6 +2614,10 @@ std::error_code BitcodeReader::materializeMetadata() {
   return std::error_code();
 }
 
   return std::error_code();
 }
 
+void BitcodeReader::setStripDebugInfo() {
+  StripDebugInfo = true;
+}
+
 /// RememberAndSkipFunctionBody - When we see the block for a function body,
 /// remember where it is and then skip it.  This lets us lazily deserialize the
 /// functions.
 /// RememberAndSkipFunctionBody - When we see the block for a function body,
 /// remember where it is and then skip it.  This lets us lazily deserialize the
 /// functions.
@@ -4305,6 +4314,9 @@ std::error_code BitcodeReader::materialize(GlobalValue *GV) {
     return EC;
   F->setIsMaterializable(false);
 
     return EC;
   F->setIsMaterializable(false);
 
+  if (StripDebugInfo)
+    stripDebugInfo(*F);
+
   // Upgrade any old intrinsic calls in the function.
   for (UpgradedIntrinsicMap::iterator I = UpgradedIntrinsics.begin(),
        E = UpgradedIntrinsics.end(); I != E; ++I) {
   // Upgrade any old intrinsic calls in the function.
   for (UpgradedIntrinsicMap::iterator I = UpgradedIntrinsics.begin(),
        E = UpgradedIntrinsics.end(); I != E; ++I) {
index d772583ba6ee6c85955ba86abd67d6874ae0e101..bc40907ba18ce66fa673bf89f79ad6d872065c59 100644 (file)
@@ -25,6 +25,7 @@
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Intrinsics.h"
+#include "llvm/IR/GVMaterializer.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/ValueHandle.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/ValueHandle.h"
 #include "llvm/Support/Debug.h"
@@ -945,6 +946,19 @@ template <> DITypeRef DIDescriptor::getFieldAs<DITypeRef>(unsigned Elt) const {
   return DITypeRef(cast_or_null<Metadata>(getField(DbgNode, Elt)));
 }
 
   return DITypeRef(cast_or_null<Metadata>(getField(DbgNode, Elt)));
 }
 
+bool llvm::stripDebugInfo(Function &F) {
+  bool Changed = false;
+  for (BasicBlock &BB : F) {
+    for (Instruction &I : BB) {
+      if (I.getDebugLoc()) {
+        Changed = true;
+        I.setDebugLoc(DebugLoc());
+      }
+    }
+  }
+  return Changed;
+}
+
 bool llvm::StripDebugInfo(Module &M) {
   bool Changed = false;
 
 bool llvm::StripDebugInfo(Module &M) {
   bool Changed = false;
 
@@ -978,16 +992,11 @@ bool llvm::StripDebugInfo(Module &M) {
     }
   }
 
     }
   }
 
-  for (Function &F : M) {
-    for (BasicBlock &BB : F) {
-      for (Instruction &I : BB) {
-        if (I.getDebugLoc()) {
-          Changed = true;
-          I.setDebugLoc(DebugLoc());
-        }
-      }
-    }
-  }
+  for (Function &F : M)
+    Changed |= stripDebugInfo(F);
+
+  if ( GVMaterializer *Materializer = M.getMaterializer())
+    Materializer->setStripDebugInfo();
 
   return Changed;
 }
 
   return Changed;
 }
index 16e5045bcb93fb611d99a603d35d6518cbf15773..93ce3bc0f446b2fbd1223dd3055b9f6252007fd0 100644 (file)
@@ -20,6 +20,7 @@
 #include "llvm/Bitcode/ReaderWriter.h"
 #include "llvm/CodeGen/Analysis.h"
 #include "llvm/CodeGen/CommandFlags.h"
 #include "llvm/Bitcode/ReaderWriter.h"
 #include "llvm/CodeGen/Analysis.h"
 #include "llvm/CodeGen/CommandFlags.h"
+#include "llvm/IR/AutoUpgrade.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DiagnosticInfo.h"
 #include "llvm/IR/DiagnosticPrinter.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DiagnosticInfo.h"
 #include "llvm/IR/DiagnosticPrinter.h"
@@ -602,11 +603,8 @@ getModuleForFile(LLVMContext &Context, claimed_file &F,
 
   Module &M = Obj.getModule();
 
 
   Module &M = Obj.getModule();
 
-  // Fixme (pr23045). We would like to upgrade the metadata with something like
-  //  Result->materializeMetadata();
-  //  UpgradeDebugInfo(*Result);
-  // but that fails to drop old debug info from function bodies.
-  M.materializeAllPermanently();
+  M.materializeMetadata();
+  UpgradeDebugInfo(M);
 
   SmallPtrSet<GlobalValue *, 8> Used;
   collectUsedGlobalVariables(M, Used, /*CompilerUsed*/ false);
 
   SmallPtrSet<GlobalValue *, 8> Used;
   collectUsedGlobalVariables(M, Used, /*CompilerUsed*/ false);
index a15855b392a45336031421ab9c2f5e6594cd450f..29c4c736b33b97b56fa92929d5664ddeec0056bf 100644 (file)
@@ -15,6 +15,7 @@
 #include "llvm/Linker/Linker.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Bitcode/ReaderWriter.h"
 #include "llvm/Linker/Linker.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Bitcode/ReaderWriter.h"
+#include "llvm/IR/AutoUpgrade.h"
 #include "llvm/IR/DiagnosticInfo.h"
 #include "llvm/IR/DiagnosticPrinter.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/DiagnosticInfo.h"
 #include "llvm/IR/DiagnosticPrinter.h"
 #include "llvm/IR/LLVMContext.h"
@@ -69,11 +70,8 @@ loadFile(const char *argv0, const std::string &FN, LLVMContext &Context) {
   if (!Result)
     Err.print(argv0, errs());
 
   if (!Result)
     Err.print(argv0, errs());
 
-  // Fixme (pr23045). We would like to upgrade the metadata with something like
-  //  Result->materializeMetadata();
-  //  UpgradeDebugInfo(*Result);
-  // but that fails to drop old debug info from function bodies.
-  Result->materializeAllPermanently();
+  Result->materializeMetadata();
+  UpgradeDebugInfo(*Result);
 
   return Result;
 }
 
   return Result;
 }