diff options
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/IR/DebugInfo.cpp | 34 | 
1 files changed, 13 insertions, 21 deletions
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp index e8c62961eba..18ec7cdfdba 100644 --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -247,8 +247,20 @@ bool llvm::stripDebugInfo(Function &F) {      Changed = true;      F.setSubprogram(nullptr);    } + +  Function *Declare = F.getParent()->getFunction("llvm.dbg.declare"); +  Function *DbgVal = F.getParent()->getFunction("llvm.dbg.value");    for (BasicBlock &BB : F) { -    for (Instruction &I : BB) { +    for (auto II = BB.begin(), End = BB.end(); II != End;) { +      Instruction &I = *II++; // We may delete the instruction, increment now. +      // Remove all of the calls to the debugger intrinsics, and remove them +      // from the module. +      CallInst *CI = dyn_cast<CallInst>(&I); +      if (CI && (CI->getCalledFunction() == Declare || +                 CI->getCalledFunction() == DbgVal)) { +        CI->eraseFromParent(); +        Changed = true; +      }        if (I.getDebugLoc()) {          Changed = true;          I.setDebugLoc(DebugLoc()); @@ -261,26 +273,6 @@ bool llvm::stripDebugInfo(Function &F) {  bool llvm::StripDebugInfo(Module &M) {    bool Changed = false; -  // Remove all of the calls to the debugger intrinsics, and remove them from -  // the module. -  if (Function *Declare = M.getFunction("llvm.dbg.declare")) { -    while (!Declare->use_empty()) { -      CallInst *CI = cast<CallInst>(Declare->user_back()); -      CI->eraseFromParent(); -    } -    Declare->eraseFromParent(); -    Changed = true; -  } - -  if (Function *DbgVal = M.getFunction("llvm.dbg.value")) { -    while (!DbgVal->use_empty()) { -      CallInst *CI = cast<CallInst>(DbgVal->user_back()); -      CI->eraseFromParent(); -    } -    DbgVal->eraseFromParent(); -    Changed = true; -  } -    for (Module::named_metadata_iterator NMI = M.named_metadata_begin(),           NME = M.named_metadata_end(); NMI != NME;) {      NamedMDNode *NMD = &*NMI;  | 

