about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
-rw-r--r--lib/Core/Executor.cpp7
-rw-r--r--lib/Core/StatsTracker.cpp40
-rw-r--r--lib/Module/InstructionInfoTable.cpp30
-rw-r--r--lib/Module/IntrinsicCleaner.cpp3
-rw-r--r--lib/Module/KModule.cpp3
5 files changed, 59 insertions, 24 deletions
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
index cd0f6078..82fe2356 100644
--- a/lib/Core/Executor.cpp
+++ b/lib/Core/Executor.cpp
@@ -597,7 +597,7 @@ void Executor::initializeGlobalObject(ExecutionState &state, ObjectState *os,
     for (unsigned i=0, e=cds->getNumElements(); i != e; ++i)
       initializeGlobalObject(state, os, cds->getElementAsConstant(i),
                              offset + i*elementSize);
-  } else if (!isa<UndefValue>(c)) {
+  } else if (!isa<UndefValue>(c) && !isa<MetadataAsValue>(c)) {
     unsigned StoreBits = targetData->getTypeStoreSizeInBits(c->getType());
     ref<ConstantExpr> C = evalConstant(c);
 
@@ -1329,6 +1329,8 @@ void Executor::executeCall(ExecutionState &state,
                            Function *f,
                            std::vector< ref<Expr> > &arguments) {
   Instruction *i = ki->inst;
+  if (i && isa<DbgInfoIntrinsic>(i))
+    return;
   if (f && f->isDeclaration()) {
     switch(f->getIntrinsicID()) {
     case Intrinsic::not_intrinsic:
@@ -1909,6 +1911,9 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
 
   case Instruction::Invoke:
   case Instruction::Call: {
+    // Ignore debug intrinsic calls
+    if (isa<DbgInfoIntrinsic>(i))
+      break;
     CallSite cs(i);
 
     unsigned numArgs = cs.arg_size();
diff --git a/lib/Core/StatsTracker.cpp b/lib/Core/StatsTracker.cpp
index 67553ad0..c0e3264d 100644
--- a/lib/Core/StatsTracker.cpp
+++ b/lib/Core/StatsTracker.cpp
@@ -546,7 +546,7 @@ void StatsTracker::writeIStats() {
       // KCachegrind can create two entries for the function, one with an
       // unnamed file and one without.
       Function *fn = &*fnIt;
-      const InstructionInfo &ii = executor.kmodule->infos->getFunctionInfo(fn);
+      const FunctionInfo &ii = executor.kmodule->infos->getFunctionInfo(*fn);
       if (ii.file != sourceFile) {
         of << "fl=" << ii.file << "\n";
         sourceFile = ii.file;
@@ -558,7 +558,7 @@ void StatsTracker::writeIStats() {
         for (BasicBlock::iterator it = bbIt->begin(), ie = bbIt->end(); 
              it != ie; ++it) {
           Instruction *instr = &*it;
-          const InstructionInfo &ii = executor.kmodule->infos->getInfo(instr);
+          const InstructionInfo &ii = executor.kmodule->infos->getInfo(*instr);
           unsigned index = ii.id;
           if (ii.file!=sourceFile) {
             of << "fl=" << ii.file << "\n";
@@ -575,14 +575,13 @@ void StatsTracker::writeIStats() {
               (isa<CallInst>(instr) || isa<InvokeInst>(instr))) {
             CallSiteSummaryTable::iterator it = callSiteStats.find(instr);
             if (it!=callSiteStats.end()) {
-              for (std::map<llvm::Function*, CallSiteInfo>::iterator
-                     fit = it->second.begin(), fie = it->second.end(); 
+              for (auto fit = it->second.begin(), fie = it->second.end();
                    fit != fie; ++fit) {
-                Function *f = fit->first;
+                const Function *f = fit->first;
                 CallSiteInfo &csi = fit->second;
-                const InstructionInfo &fii = 
-                  executor.kmodule->infos->getFunctionInfo(f);
-  
+                const FunctionInfo &fii =
+                    executor.kmodule->infos->getFunctionInfo(*f);
+
                 if (fii.file!="" && fii.file!=sourceFile)
                   of << "cfl=" << fii.file << "\n";
                 of << "cfn=" << f->getName().str() << "\n";
@@ -746,7 +745,7 @@ void StatsTracker::computeReachableUncovered() {
              it != ie; ++it) {
           Instruction *inst = &*it;
           instructions.push_back(inst);
-          unsigned id = infos.getInfo(inst).id;
+          unsigned id = infos.getInfo(*inst).id;
           sm.setIndexedValue(stats::minDistToReturn, 
                              id, 
                              isa<ReturnInst>(inst)
@@ -761,8 +760,8 @@ void StatsTracker::computeReachableUncovered() {
     bool changed;
     do {
       changed = false;
-      for (std::vector<Instruction*>::iterator it = instructions.begin(),
-             ie = instructions.end(); it != ie; ++it) {
+      for (auto it = instructions.begin(), ie = instructions.end(); it != ie;
+           ++it) {
         Instruction *inst = *it;
         unsigned bestThrough = 0;
 
@@ -782,13 +781,13 @@ void StatsTracker::computeReachableUncovered() {
         }
        
         if (bestThrough) {
-          unsigned id = infos.getInfo(*it).id;
+          unsigned id = infos.getInfo(*(*it)).id;
           uint64_t best, cur = best = sm.getIndexedValue(stats::minDistToReturn, id);
           std::vector<Instruction*> succs = getSuccs(*it);
           for (std::vector<Instruction*>::iterator it2 = succs.begin(),
                  ie = succs.end(); it2 != ie; ++it2) {
             uint64_t dist = sm.getIndexedValue(stats::minDistToReturn,
-                                               infos.getInfo(*it2).id);
+                                               infos.getInfo(*(*it2)).id);
             if (dist) {
               uint64_t val = bestThrough + dist;
               if (best==0 || val<best)
@@ -824,7 +823,7 @@ void StatsTracker::computeReachableUncovered() {
       for (BasicBlock::iterator it = bbIt->begin(), ie = bbIt->end(); 
            it != ie; ++it) {
         Instruction *inst = &*it;
-        unsigned id = infos.getInfo(inst).id;
+        unsigned id = infos.getInfo(*inst).id;
         instructions.push_back(inst);
         sm.setIndexedValue(stats::minDistToUncovered, 
                            id, 
@@ -842,8 +841,8 @@ void StatsTracker::computeReachableUncovered() {
     for (std::vector<Instruction*>::iterator it = instructions.begin(),
            ie = instructions.end(); it != ie; ++it) {
       Instruction *inst = *it;
-      uint64_t best, cur = best = sm.getIndexedValue(stats::minDistToUncovered, 
-                                                     infos.getInfo(inst).id);
+      uint64_t best, cur = best = sm.getIndexedValue(stats::minDistToUncovered,
+                                                     infos.getInfo(*inst).id);
       unsigned bestThrough = 0;
       
       if (isa<CallInst>(inst) || isa<InvokeInst>(inst)) {
@@ -858,8 +857,8 @@ void StatsTracker::computeReachableUncovered() {
           }
 
           if (!(*fnIt)->isDeclaration()) {
-            uint64_t calleeDist = sm.getIndexedValue(stats::minDistToUncovered,
-                                                     infos.getFunctionInfo(*fnIt).id);
+            uint64_t calleeDist = sm.getIndexedValue(
+                stats::minDistToUncovered, infos.getFunctionInfo(*(*fnIt)).id);
             if (calleeDist) {
               calleeDist = 1+calleeDist; // count instruction itself
               if (best==0 || calleeDist<best)
@@ -876,7 +875,7 @@ void StatsTracker::computeReachableUncovered() {
         for (std::vector<Instruction*>::iterator it2 = succs.begin(),
                ie = succs.end(); it2 != ie; ++it2) {
           uint64_t dist = sm.getIndexedValue(stats::minDistToUncovered,
-                                             infos.getInfo(*it2).id);
+                                             infos.getInfo(*(*it2)).id);
           if (dist) {
             uint64_t val = bestThrough + dist;
             if (best==0 || val<best)
@@ -886,8 +885,7 @@ void StatsTracker::computeReachableUncovered() {
       }
 
       if (best != cur) {
-        sm.setIndexedValue(stats::minDistToUncovered, 
-                           infos.getInfo(inst).id, 
+        sm.setIndexedValue(stats::minDistToUncovered, infos.getInfo(*inst).id,
                            best);
         changed = true;
       }
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)) {