<div dir="ltr">As mentioned in the bug, I /think/ the right thing to do here is to change the preferred location of the CXXMemberCallExpr so that we improve diagnostics as well. Any place where the preferred location of an expression and the debug location of an expression are differing I'd really like a pretty deep discussion of why those two uses cases should differ.<br><br>Eg, where this location turns up in diagnostics:<br><br><pre style="color:rgb(0,0,0)">blaikie@blaikie-linux:~/dev$ cat loc.cpp
struct foo {
  const foo *x() const;
  void y();
};

void f(const foo *g) {
  g->x()->y();
  g->x()->x()->y();
}
blaikie@blaikie-linux:~/dev$ clang++-tot loc.cpp -fsyntax-only
loc.cpp:7:3: error: member function 'y' not viable: 'this' argument has type 'const foo', but function is not marked const
  g->x()->y();
  ^~~~~~
...
loc.cpp:8:3: error: member function 'y' not viable: 'this' argument has type 'const foo', but function is not marked const
  g->x()->x()->y();
  ^~~~~~~~~~~
...

It seems like pointing to the 'y' in both these cases would be an improvement? The source range highlighting the 'this' part of the expression is certainly helpful, but could still be confusing if the functions had more similar/the same name, etc.</pre><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 28, 2016 at 8:42 PM, Hal Finkel via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">hfinkel created this revision.<br>
hfinkel added reviewers: rsmith, aprantl, dexonsmith, dblaikie, echristo.<br>
hfinkel added a subscriber: cfe-commits.<br>
Herald added subscribers: joker.eph, mcrosier.<br>
<br>
We currently generate debug info for member calls in the context of the call expression. For member calls, this has an odd effect, which becomes especially obvious when generating source locations for optimizer-feedback remarks regarding inlining.<br>
<br>
Given this:<br>
<br>
  $ cat -n /tmp/i.cpp<br>
     1  void ext();<br>
     2<br>
     3  struct Bar {<br>
     4    void bar() { ext(); }<br>
     5  };<br>
     6<br>
     7  struct Foo {<br>
     8    Bar *b;<br>
     9<br>
    10    Bar *foo() { return b; }<br>
    11  };<br>
    12<br>
    13  void test(Foo *f) {<br>
    14    f->foo()->bar();<br>
    15  }<br>
<br>
  $ clang -g /tmp/i.cpp -S -emit-llvm -o -<br>
<br>
  define void @_Z4testP3Foo(%struct.Foo* %f) #0 !dbg !6 {<br>
    ...<br>
    %call = call %struct.Bar* @_ZN3Foo3fooEv(%struct.Foo* %0), !dbg !27<br>
    call void @_ZN3Bar3barEv(%struct.Bar* %call), !dbg !28<br>
    ...<br>
  !27 = !DILocation(line: 14, column: 3, scope: !6)<br>
  !28 = !DILocation(line: 14, column: 3, scope: !29)<br>
<br>
but we want instead for the calls to point to the callee expressions (foo() and bar() in this case). With this change, that's what happens.<br>
<br>
Fixes PR27567.<br>
<br>
<a href="http://reviews.llvm.org/D19708" rel="noreferrer" target="_blank">http://reviews.llvm.org/D19708</a><br>
<br>
Files:<br>
  lib/CodeGen/CGExprCXX.cpp<br>
  test/CodeGenCXX/debug-info-member-call.cpp<br>
<br>
Index: test/CodeGenCXX/debug-info-member-call.cpp<br>
===================================================================<br>
--- /dev/null<br>
+++ test/CodeGenCXX/debug-info-member-call.cpp<br>
@@ -0,0 +1,24 @@<br>
+// RUN: %clang_cc1 -triple x86_64-unknown_unknown -emit-llvm -debug-info-kind=standalone -dwarf-column-info %s -o - | FileCheck %s<br>
+void ext();<br>
+<br>
+struct Bar {<br>
+  void bar() { ext(); }<br>
+};<br>
+<br>
+struct Foo {<br>
+  Bar *b;<br>
+<br>
+  Bar *foo() { return b; }<br>
+};<br>
+<br>
+void test(Foo *f) {<br>
+  f->foo()->bar();<br>
+}<br>
+<br>
+// CHECK-LABEL: @_Z4testP3Foo<br>
+// CHECK: call {{.*}} @_ZN3Foo3fooEv{{.*}}, !dbg ![[CALL1LOC:.*]]<br>
+// CHECK: call void @_ZN3Bar3barEv{{.*}}, !dbg ![[CALL2LOC:.*]]<br>
+<br>
+// CHECK: ![[CALL1LOC]] = !DILocation(line: [[LINE:[0-9]+]], column: 6,<br>
+// CHECK: ![[CALL2LOC]] = !DILocation(line: [[LINE]], column: 13,<br>
+<br>
Index: lib/CodeGen/CGExprCXX.cpp<br>
===================================================================<br>
--- lib/CodeGen/CGExprCXX.cpp<br>
+++ lib/CodeGen/CGExprCXX.cpp<br>
@@ -107,6 +107,10 @@<br>
                                               ReturnValueSlot ReturnValue) {<br>
   const Expr *callee = CE->getCallee()->IgnoreParens();<br>
<br>
+  // The debug information for the call instruction should point to the callee<br>
+  // expression.<br>
+  ApplyDebugLocation DL(*this, callee);<br>
+<br>
   if (isa<BinaryOperator>(callee))<br>
     return EmitCXXMemberPointerCallExpr(CE, ReturnValue);<br>
<br>
<br>
<br>
<br>_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div><br></div>