[llvm] r240738 - [ASan] Use llvm::getDISubprogram() to get function entry debug location.

Alexey Samsonov vonosmas at gmail.com
Thu Jun 25 17:00:47 PDT 2015


Author: samsonov
Date: Thu Jun 25 19:00:47 2015
New Revision: 240738

URL: http://llvm.org/viewvc/llvm-project?rev=240738&view=rev
Log:
[ASan] Use llvm::getDISubprogram() to get function entry debug location.

It can be more robust than copying debug info from first non-alloca
instruction in the entry basic block. We use the same strategy in
coverage instrumentation.

Modified:
    llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Modified: llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp?rev=240738&r1=240737&r2=240738&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp Thu Jun 25 19:00:47 2015
@@ -1674,12 +1674,6 @@ void FunctionStackPoisoner::SetShadowToS
   }
 }
 
-static DebugLoc getFunctionEntryDebugLocation(Function &F) {
-  for (const auto &Inst : F.getEntryBlock())
-    if (!isa<AllocaInst>(Inst)) return Inst.getDebugLoc();
-  return DebugLoc();
-}
-
 PHINode *FunctionStackPoisoner::createPHI(IRBuilder<> &IRB, Value *Cond,
                                           Value *ValueIfTrue,
                                           Instruction *ThenTerm,
@@ -1732,7 +1726,9 @@ void FunctionStackPoisoner::poisonStack(
   if (AllocaVec.size() == 0) return;
 
   int StackMallocIdx = -1;
-  DebugLoc EntryDebugLocation = getFunctionEntryDebugLocation(F);
+  DebugLoc EntryDebugLocation;
+  if (auto SP = getDISubprogram(&F))
+    EntryDebugLocation = DebugLoc::get(SP->getScopeLine(), 0, SP);
 
   Instruction *InsBefore = AllocaVec[0];
   IRBuilder<> IRB(InsBefore);





More information about the llvm-commits mailing list