r227027 - DebugInfo: Use the preferred location rather than the start location for expression line info

David Blaikie dblaikie at gmail.com
Sat Jan 24 17:19:10 PST 2015


Author: dblaikie
Date: Sat Jan 24 19:19:10 2015
New Revision: 227027

URL: http://llvm.org/viewvc/llvm-project?rev=227027&view=rev
Log:
DebugInfo: Use the preferred location rather than the start location for expression line info

This causes things like assignment to refer to the '=' rather than the
LHS when attributing the store instruction, for example.

There were essentially 3 options for this:

* The beginning of an expression (this was the behavior prior to this
  commit). This meant that stepping through subexpressions would bounce
  around from subexpressions back to the start of the outer expression,
  etc. (eg: x + y + z would go x, y, x, z, x (the repeated 'x's would be
  where the actual addition occurred)).

* The end of an expression. This seems to be what GCC does /mostly/, and
  certainly this for function calls. This has the advantage that
  progress is always 'forwards' (never jumping backwards - except for
  independent subexpressions if they're evaluated in interesting orders,
  etc). "x + y + z" would go "x y z" with the additions occurring at y
  and z after the respective loads.
  The problem with this is that the user would still have to think
  fairly hard about precedence to realize which subexpression is being
  evaluated or which operator overload is being called in, say, an asan
  backtrace.

* The preferred location or 'exprloc'. In this case you get sort of what
  you'd expect, though it's a bit confusing in its own way due to going
  'backwards'. In this case the locations would be: "x y + z +" in
  lovely postfix arithmetic order. But this does mean that if the op+
  were an operator overload, say, and in a backtrace, the backtrace will
  point to the exact '+' that's being called, not to the end of one of
  its operands.

(actually the operator overload case doesn't work yet for other reasons,
but that's being fixed - but this at least gets scalar/complex
assignments and other plain operators right)

Modified:
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
    cfe/trunk/lib/CodeGen/CGDebugInfo.h
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/lib/CodeGen/CGExprAgg.cpp
    cfe/trunk/lib/CodeGen/CGExprCXX.cpp
    cfe/trunk/lib/CodeGen/CGExprComplex.cpp
    cfe/trunk/lib/CodeGen/CGExprScalar.cpp
    cfe/trunk/test/CodeGenCXX/debug-info-line.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=227027&r1=227026&r2=227027&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Sat Jan 24 19:19:10 2015
@@ -65,6 +65,10 @@ ArtificialLocation::ArtificialLocation(C
 ApplyDebugLocation::ApplyDebugLocation(CodeGenFunction &CGF,
                                        SourceLocation TemporaryLocation)
     : CGF(CGF) {
+  init(TemporaryLocation);
+}
+
+void ApplyDebugLocation::init(SourceLocation TemporaryLocation) {
   if (auto *DI = CGF.getDebugInfo()) {
     OriginalLocation = CGF.Builder.getCurrentDebugLocation();
     if (TemporaryLocation.isInvalid())
@@ -74,6 +78,11 @@ ApplyDebugLocation::ApplyDebugLocation(C
   }
 }
 
+ApplyDebugLocation::ApplyDebugLocation(CodeGenFunction &CGF, const Expr *E)
+    : CGF(CGF) {
+  init(E->getExprLoc());
+}
+
 ApplyDebugLocation::ApplyDebugLocation(CodeGenFunction &CGF, llvm::DebugLoc Loc)
     : CGF(CGF) {
   if (CGF.getDebugInfo()) {

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=227027&r1=227026&r2=227027&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Sat Jan 24 19:19:10 2015
@@ -444,6 +444,9 @@ private:
 };
 
 class ApplyDebugLocation {
+private:
+  void init(SourceLocation TemporaryLocation);
+
 protected:
   llvm::DebugLoc OriginalLocation;
   CodeGenFunction &CGF;
@@ -451,6 +454,7 @@ protected:
 public:
   ApplyDebugLocation(CodeGenFunction &CGF,
                      SourceLocation TemporaryLocation = SourceLocation());
+  ApplyDebugLocation(CodeGenFunction &CGF, const Expr *E);
   ApplyDebugLocation(CodeGenFunction &CGF, llvm::DebugLoc Loc);
   ~ApplyDebugLocation();
 };

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=227027&r1=227026&r2=227027&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Sat Jan 24 19:19:10 2015
@@ -807,7 +807,7 @@ LValue CodeGenFunction::EmitCheckedLValu
 /// length type, this is not possible.
 ///
 LValue CodeGenFunction::EmitLValue(const Expr *E) {
-  ApplyDebugLocation DL(*this, E->getLocStart());
+  ApplyDebugLocation DL(*this, E);
   switch (E->getStmtClass()) {
   default: return EmitUnsupportedLValue(E, "l-value expression");
 
@@ -3060,7 +3060,7 @@ RValue CodeGenFunction::EmitRValueForFie
 
 RValue CodeGenFunction::EmitCallExpr(const CallExpr *E,
                                      ReturnValueSlot ReturnValue) {
-  ApplyDebugLocation DL(*this, E->getLocStart());
+  ApplyDebugLocation DL(*this, E);
 
   // Builtins never have block type.
   if (E->getCallee()->getType()->isBlockPointerType())

Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=227027&r1=227026&r2=227027&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Sat Jan 24 19:19:10 2015
@@ -99,7 +99,7 @@ public:
   //===--------------------------------------------------------------------===//
 
   void Visit(Expr *E) {
-    ApplyDebugLocation DL(CGF, E->getLocStart());
+    ApplyDebugLocation DL(CGF, E);
     StmtVisitor<AggExprEmitter>::Visit(E);
   }
 

Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=227027&r1=227026&r2=227027&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Sat Jan 24 19:19:10 2015
@@ -1016,7 +1016,7 @@ static void EmitNewInitializer(CodeGenFu
                                llvm::Value *NewPtr,
                                llvm::Value *NumElements,
                                llvm::Value *AllocSizeWithoutCookie) {
-  ApplyDebugLocation DL(CGF, E->getStartLoc());
+  ApplyDebugLocation DL(CGF, E);
   if (E->isArray())
     CGF.EmitNewArrayInitializer(E, ElementType, NewPtr, NumElements,
                                 AllocSizeWithoutCookie);

Modified: cfe/trunk/lib/CodeGen/CGExprComplex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprComplex.cpp?rev=227027&r1=227026&r2=227027&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprComplex.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprComplex.cpp Sat Jan 24 19:19:10 2015
@@ -95,7 +95,7 @@ public:
   //===--------------------------------------------------------------------===//
 
   ComplexPairTy Visit(Expr *E) {
-    ApplyDebugLocation DL(CGF, E->getLocStart());
+    ApplyDebugLocation DL(CGF, E);
     return StmtVisitor<ComplexExprEmitter, ComplexPairTy>::Visit(E);
   }
 

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=227027&r1=227026&r2=227027&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Sat Jan 24 19:19:10 2015
@@ -196,7 +196,7 @@ public:
   //===--------------------------------------------------------------------===//
 
   Value *Visit(Expr *E) {
-    ApplyDebugLocation DL(CGF, E->getLocStart());
+    ApplyDebugLocation DL(CGF, E);
     return StmtVisitor<ScalarExprEmitter, Value*>::Visit(E);
   }
 

Modified: cfe/trunk/test/CodeGenCXX/debug-info-line.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-line.cpp?rev=227027&r1=227026&r2=227027&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/debug-info-line.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info-line.cpp Sat Jan 24 19:19:10 2015
@@ -10,11 +10,11 @@ extern "C" __complex float *complex_sink
 
 // CHECK-LABEL: define
 void f1() {
-#line 100
-  * // The store for the assignment should be attributed to the start of the
-      // assignment expression here, regardless of the location of subexpressions.
-      sink() = src();
+  *sink()
   // CHECK: store {{.*}}, !dbg [[DBG_F1:!.*]]
+#line 100
+      = //
+      src();
 }
 
 struct foo {
@@ -38,16 +38,20 @@ foo::foo()
 
 // CHECK-LABEL: define {{.*}}f2{{.*}}
 void f2() {
+  // CHECK: store float {{.*}} !dbg [[DBG_F2:!.*]]
+  *complex_sink()
 #line 300
-  * // CHECK: store float {{.*}} !dbg [[DBG_F2:!.*]]
-      complex_sink() = complex_src();
+      = //
+      complex_src();
 }
 
 // CHECK-LABEL: define
 void f3() {
+  // CHECK: store float {{.*}} !dbg [[DBG_F3:!.*]]
+  *complex_sink()
 #line 400
-  * // CHECK: store float {{.*}} !dbg [[DBG_F3:!.*]]
-      complex_sink() += complex_src();
+      += //
+      complex_src();
 }
 
 // CHECK-LABEL: define





More information about the cfe-commits mailing list