]> granicus.if.org Git - clang/commitdiff
[CGDebugInfo] Modify the preferred expression location for member calls.
authorHal Finkel <hfinkel@anl.gov>
Wed, 25 May 2016 22:08:27 +0000 (22:08 +0000)
committerHal Finkel <hfinkel@anl.gov>
Wed, 25 May 2016 22:08:27 +0000 (22:08 +0000)
If the callee has a valid location (not all do), then use that. Otherwise, fall
back to the starting location. This makes sure that the debug info for calls
points to the call (not the start of the expression providing the object on
which the member function is being called).

For example, given this:

  f->foo()->bar();

we don't want both calls to point to the 'f', but rather to the 'foo()' and
the 'bar()'.

Fixes PR27567.

Differential Revision: http://reviews.llvm.org/D19708

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@270775 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/ExprCXX.h
test/CodeGenCXX/debug-info-member-call.cpp [new file with mode: 0644]

index f4f653f4bb62a40dd7c14639b30b5046bde32311..41b6758bdc71076f3f3d484afc1850558f86d8cc 100644 (file)
@@ -143,6 +143,14 @@ public:
   /// FIXME: Returns 0 for member pointer call exprs.
   CXXRecordDecl *getRecordDecl() const;
 
+  SourceLocation getExprLoc() const LLVM_READONLY {
+    SourceLocation CLoc = getCallee()->getExprLoc();
+    if (CLoc.isValid())
+      return CLoc;
+
+    return getLocStart();
+  }
+
   static bool classof(const Stmt *T) {
     return T->getStmtClass() == CXXMemberCallExprClass;
   }
diff --git a/test/CodeGenCXX/debug-info-member-call.cpp b/test/CodeGenCXX/debug-info-member-call.cpp
new file mode 100644 (file)
index 0000000..3b5adb8
--- /dev/null
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -triple x86_64-unknown_unknown -emit-llvm -debug-info-kind=standalone -dwarf-column-info %s -o - | FileCheck %s
+void ext();
+
+struct Bar {
+  void bar() { ext(); }
+};
+
+struct Foo {
+  Bar *b;
+
+  Bar *foo() { return b; }
+};
+
+void test(Foo *f) {
+  f->foo()->bar();
+}
+
+// CHECK-LABEL: @_Z4testP3Foo
+// CHECK: call {{.*}} @_ZN3Foo3fooEv{{.*}}, !dbg ![[CALL1LOC:.*]]
+// CHECK: call void @_ZN3Bar3barEv{{.*}}, !dbg ![[CALL2LOC:.*]]
+
+// CHECK: ![[CALL1LOC]] = !DILocation(line: [[LINE:[0-9]+]], column: 6,
+// CHECK: ![[CALL2LOC]] = !DILocation(line: [[LINE]], column: 13,
+