[llvm] r212776 - Reapply "DebugInfo: Ensure that all debug location scope chains from instructions within a function, lead to the function itself."

David Blaikie dblaikie at gmail.com
Thu Jul 10 15:59:39 PDT 2014


Author: dblaikie
Date: Thu Jul 10 17:59:39 2014
New Revision: 212776

URL: http://llvm.org/viewvc/llvm-project?rev=212776&view=rev
Log:
Reapply "DebugInfo: Ensure that all debug location scope chains from instructions within a function, lead to the function itself."

Committed in r212205 and reverted in r212226 due to msan self-hosting
failure, I believe I've got that fixed by r212761 to Clang.

Original commit message:

"Originally committed in r211723, reverted in r211724 due to failure
cases found and fixed (ArgumentPromotion: r211872, Inlining: r212065),
committed again in r212085 and reverted again in r212089 after fixing
some other cases, such as debug info subprogram lists not keeping track
of the function they represent (r212128) and then short-circuiting
things like LiveDebugVariables that build LexicalScopes for functions
that might not have full debug info.

And again, I believe the invariant actually holds for some reasonable
amount of code (but I'll keep an eye on the buildbots and see what
happens... ).

Original commit message:

PR20038: DebugInfo: Inlined call sites where the caller has debug info
but the call itself has no debug location.

This situation does bad things when inlined, so I've fixed Clang not to
produce inlinable call sites without locations when the caller has debug
info (in the one case where I could find that this occurred). This
updates the PR20038 test case to be what clang now produces, and readds
the assertion that had to be removed due to this bug.

I've also beefed up the debug info verifier to help diagnose these
issues in the future, and I hope to add checks to the inliner to just
assert-fail if it encounters this situation. If, in the future, we
decide we have to cope with this situation, the right thing to do is
probably to just remove all the DebugLocs from the inlined
instructions."

Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
    llvm/trunk/lib/CodeGen/LexicalScopes.cpp
    llvm/trunk/lib/IR/DebugInfo.cpp

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=212776&r1=212775&r2=212776&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Thu Jul 10 17:59:39 2014
@@ -788,8 +788,7 @@ void DwarfDebug::finishVariableDefinitio
   for (const auto &Var : ConcreteVariables) {
     DIE *VariableDie = Var->getDIE();
     // FIXME: There shouldn't be any variables without DIEs.
-    if (!VariableDie)
-      continue;
+    assert(VariableDie);
     // FIXME: Consider the time-space tradeoff of just storing the unit pointer
     // in the ConcreteVariables list, rather than looking it up again here.
     // DIE::getUnit isn't simple - it walks parent pointers, etc.

Modified: llvm/trunk/lib/CodeGen/LexicalScopes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LexicalScopes.cpp?rev=212776&r1=212775&r2=212776&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LexicalScopes.cpp (original)
+++ llvm/trunk/lib/CodeGen/LexicalScopes.cpp Thu Jul 10 17:59:39 2014
@@ -137,6 +137,8 @@ LexicalScope *LexicalScopes::findLexical
 /// getOrCreateLexicalScope - Find lexical scope for the given DebugLoc. If
 /// not available then create new lexical scope.
 LexicalScope *LexicalScopes::getOrCreateLexicalScope(DebugLoc DL) {
+  if (DL.isUnknown())
+    return nullptr;
   MDNode *Scope = nullptr;
   MDNode *InlinedAt = nullptr;
   DL.getScopeAndInlinedAt(Scope, InlinedAt, MF->getFunction()->getContext());
@@ -172,9 +174,12 @@ LexicalScope *LexicalScopes::getOrCreate
                               std::make_tuple(Parent, DIDescriptor(Scope),
                                               nullptr, false)).first;
 
-  if (!Parent && DIDescriptor(Scope).isSubprogram() &&
-      DISubprogram(Scope).describes(MF->getFunction()))
+  if (!Parent) {
+    assert(DIDescriptor(Scope).isSubprogram());
+    assert(DISubprogram(Scope).describes(MF->getFunction()));
+    assert(!CurrentFnLexicalScope);
     CurrentFnLexicalScope = &I->second;
+  }
 
   return &I->second;
 }

Modified: llvm/trunk/lib/IR/DebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfo.cpp?rev=212776&r1=212775&r2=212776&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DebugInfo.cpp (original)
+++ llvm/trunk/lib/IR/DebugInfo.cpp Thu Jul 10 17:59:39 2014
@@ -538,6 +538,32 @@ bool DISubprogram::Verify() const {
   if (isLValueReference() && isRValueReference())
     return false;
 
+  if (auto *F = getFunction()) {
+    LLVMContext &Ctxt = F->getContext();
+    for (auto &BB : *F) {
+      for (auto &I : BB) {
+        DebugLoc DL = I.getDebugLoc();
+        if (DL.isUnknown())
+          continue;
+
+        MDNode *Scope = nullptr;
+        MDNode *IA = nullptr;
+        // walk the inlined-at scopes
+        while (DL.getScopeAndInlinedAt(Scope, IA, F->getContext()), IA)
+          DL = DebugLoc::getFromDILocation(IA);
+        DL.getScopeAndInlinedAt(Scope, IA, Ctxt);
+        assert(!IA);
+        while (!DIDescriptor(Scope).isSubprogram()) {
+          DILexicalBlockFile D(Scope);
+          Scope = D.isLexicalBlockFile()
+                      ? D.getScope()
+                      : DebugLoc::getFromDILexicalBlock(Scope).getScope(Ctxt);
+        }
+        if (!DISubprogram(Scope).describes(F))
+          return false;
+      }
+    }
+  }
   return DbgNode->getNumOperands() == 20;
 }
 





More information about the llvm-commits mailing list