about summary refs log tree commit diff homepage
path: root/lib/Module
diff options
context:
space:
mode:
authorMartin Nowack <m.nowack@imperial.ac.uk>2019-01-11 14:39:47 +0000
committerCristian Cadar <c.cadar@imperial.ac.uk>2019-03-19 15:37:46 +0000
commit2558d3e34b4e0a47a1fe224683604ddaec96f69c (patch)
treeaeaf940c46d047fa5e6622ee72c581c5326dd423 /lib/Module
parentf8a481b82a403641440f6fd0de9f50af127fceec (diff)
downloadklee-2558d3e34b4e0a47a1fe224683604ddaec96f69c.tar.gz
Use debugging information from newer LLVM versions
Diffstat (limited to 'lib/Module')
-rw-r--r--lib/Module/InstructionInfoTable.cpp30
-rw-r--r--lib/Module/IntrinsicCleaner.cpp3
-rw-r--r--lib/Module/KModule.cpp3
3 files changed, 34 insertions, 2 deletions
diff --git a/lib/Module/InstructionInfoTable.cpp b/lib/Module/InstructionInfoTable.cpp
index 4d6379de..a1896831 100644
--- a/lib/Module/InstructionInfoTable.cpp
+++ b/lib/Module/InstructionInfoTable.cpp
@@ -135,11 +135,28 @@ public:
 
   std::unique_ptr<FunctionInfo> getFunctionInfo(const llvm::Function &Func) {
     auto asmLine = lineTable.at(reinterpret_cast<std::uintptr_t>(&Func));
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
+#if LLVM_VERSION_CODE >= LLVM_VERSION(6, 0)
+    auto dsub = Func.getSubprogram();
+#else
+    auto dsub = llvm::getDISubprogram(&Func);
+#endif
+    if (dsub == nullptr)
+      return std::unique_ptr<FunctionInfo>(
+          new FunctionInfo(0, getInternedString(""), 0, asmLine));
+    auto path = getFullPath(dsub->getDirectory(), dsub->getFilename());
+    return std::unique_ptr<FunctionInfo>(
+        new FunctionInfo(0, getInternedString(path), dsub->getLine(), asmLine));
 
+#else
     // Acquire function debug information
+#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5)
     for (auto subIt = DIF.subprogram_begin(), subItE = DIF.subprogram_end();
          subIt != subItE; ++subIt) {
       llvm::DISubprogram SubProgram(*subIt);
+#else
+    for (const auto &SubProgram : DIF.subprograms()) {
+#endif
       if (SubProgram.getFunction() != &Func)
         continue;
 
@@ -152,12 +169,23 @@ public:
 
     return std::unique_ptr<FunctionInfo>(
         new FunctionInfo(0, getInternedString(""), 0, asmLine));
+#endif
   }
 
   std::unique_ptr<InstructionInfo>
   getInstructionInfo(const llvm::Instruction &Inst, const FunctionInfo &f) {
     auto asmLine = lineTable.at(reinterpret_cast<std::uintptr_t>(&Inst));
 
+#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
+    auto dl = Inst.getDebugLoc();
+    auto dil = dl.get();
+    if (dil != nullptr) {
+      auto full_path = getFullPath(dil->getDirectory(), dil->getFilename());
+
+      return std::unique_ptr<InstructionInfo>(new InstructionInfo(
+          0, getInternedString(full_path), dl.getLine(), dl.getCol(), asmLine));
+    }
+#else
     llvm::DebugLoc Loc(Inst.getDebugLoc());
     if (!Loc.isUnknown()) {
       llvm::DIScope Scope(Loc.getScope(module.getContext()));
@@ -166,7 +194,7 @@ public:
           new InstructionInfo(0, getInternedString(full_path), Loc.getLine(),
                               Loc.getCol(), asmLine));
     }
-
+#endif
     // If nothing found, use the surrounding function
     return std::unique_ptr<InstructionInfo>(
         new InstructionInfo(0, f.file, f.line, 0, asmLine));
diff --git a/lib/Module/IntrinsicCleaner.cpp b/lib/Module/IntrinsicCleaner.cpp
index ba8ebcc0..b757faa1 100644
--- a/lib/Module/IntrinsicCleaner.cpp
+++ b/lib/Module/IntrinsicCleaner.cpp
@@ -53,6 +53,9 @@ bool IntrinsicCleanerPass::runOnBasicBlock(BasicBlock &b, Module &M) {
     // increment now since deletion of instructions makes iterator invalid.
     ++i;
     if (ii) {
+      if (isa<DbgInfoIntrinsic>(ii))
+        continue;
+
       switch (ii->getIntrinsicID()) {
       case Intrinsic::vastart:
       case Intrinsic::vaend:
diff --git a/lib/Module/KModule.cpp b/lib/Module/KModule.cpp
index 9cd46798..f4b71208 100644
--- a/lib/Module/KModule.cpp
+++ b/lib/Module/KModule.cpp
@@ -427,7 +427,8 @@ static int getOperandNum(Value *v,
     return a->getArgNo();
 #if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
     // Metadata is no longer a Value
-  } else if (isa<BasicBlock>(v) || isa<InlineAsm>(v)) {
+  } else if (isa<BasicBlock>(v) || isa<InlineAsm>(v) ||
+             isa<MetadataAsValue>(v)) {
 #else
   } else if (isa<BasicBlock>(v) || isa<InlineAsm>(v) ||
              isa<MDNode>(v)) {