<div dir="ltr">Thanks! <div>At least the simple test case works now. </div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Dec 8, 2014 at 4:32 PM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: dblaikie<br>
Date: Mon Dec  8 18:32:22 2014<br>
New Revision: 223726<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=223726&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=223726&view=rev</a><br>
Log:<br>
DebugInfo: Correctly identify the location of C++ member initializer list elements<br>
<br>
This particularly helps the fidelity of ASan reports (which can occur<br>
even in these examples - if, for example, one uses placement new over a<br>
buffer of insufficient size - now ASan will correctly identify which<br>
member's initialization went over the end of the buffer).<br>
<br>
This doesn't cover all types of members - more coming.<br>
<br>
Modified:<br>
    cfe/trunk/lib/CodeGen/CGClass.cpp<br>
    cfe/trunk/lib/CodeGen/CGDecl.cpp<br>
    cfe/trunk/lib/CodeGen/CGExpr.cpp<br>
    cfe/trunk/lib/CodeGen/CodeGenFunction.h<br>
    cfe/trunk/test/CodeGenCXX/debug-info-line.cpp<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGClass.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=223726&r1=223725&r2=223726&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=223726&r1=223725&r2=223726&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Mon Dec  8 18:32:22 2014<br>
@@ -597,17 +597,19 @@ static void EmitMemberInitializer(CodeGe<br>
   ArrayRef<VarDecl *> ArrayIndexes;<br>
   if (MemberInit->getNumArrayIndices())<br>
     ArrayIndexes = MemberInit->getArrayIndexes();<br>
-  CGF.EmitInitializerForField(Field, LHS, MemberInit->getInit(), ArrayIndexes);<br>
+  CGF.EmitInitializerForField(Field, LHS, MemberInit->getInit(), ArrayIndexes,<br>
+                              MemberInit->getMemberLocation());<br>
 }<br>
<br>
-void CodeGenFunction::EmitInitializerForField(FieldDecl *Field,<br>
-                                              LValue LHS, Expr *Init,<br>
-                                             ArrayRef<VarDecl *> ArrayIndexes) {<br>
+void CodeGenFunction::EmitInitializerForField(FieldDecl *Field, LValue LHS,<br>
+                                              Expr *Init,<br>
+                                              ArrayRef<VarDecl *> ArrayIndexes,<br>
+                                              SourceLocation DbgLoc) {<br>
   QualType FieldType = Field->getType();<br>
   switch (getEvaluationKind(FieldType)) {<br>
   case TEK_Scalar:<br>
     if (LHS.isSimple()) {<br>
-      EmitExprAsInit(Init, Field, LHS, false);<br>
+      EmitExprAsInit(Init, Field, LHS, false, DbgLoc);<br>
     } else {<br>
       RValue RHS = RValue::get(EmitScalarExpr(Init));<br>
       EmitStoreThroughLValue(RHS, LHS);<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=223726&r1=223725&r2=223726&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=223726&r1=223725&r2=223726&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Mon Dec  8 18:32:22 2014<br>
@@ -596,16 +596,15 @@ static void drillIntoBlockVariable(CodeG<br>
   lvalue.setAddress(CGF.BuildBlockByrefAddress(lvalue.getAddress(), var));<br>
 }<br>
<br>
-void CodeGenFunction::EmitScalarInit(const Expr *init,<br>
-                                     const ValueDecl *D,<br>
-                                     LValue lvalue,<br>
-                                     bool capturedByInit) {<br>
+void CodeGenFunction::EmitScalarInit(const Expr *init, const ValueDecl *D,<br>
+                                     LValue lvalue, bool capturedByInit,<br>
+                                     SourceLocation DbgLoc) {<br>
   Qualifiers::ObjCLifetime lifetime = lvalue.getObjCLifetime();<br>
   if (!lifetime) {<br>
     llvm::Value *value = EmitScalarExpr(init);<br>
     if (capturedByInit)<br>
       drillIntoBlockVariable(*this, lvalue, cast<VarDecl>(D));<br>
-    EmitStoreThroughLValue(RValue::get(value), lvalue, true);<br>
+    EmitStoreThroughLValue(RValue::get(value), lvalue, true, DbgLoc);<br>
     return;<br>
   }<br>
<br>
@@ -1192,22 +1191,21 @@ void CodeGenFunction::EmitAutoVarInit(co<br>
 /// \param alignment the alignment of the address<br>
 /// \param capturedByInit true if the variable is a __block variable<br>
 ///   whose address is potentially changed by the initializer<br>
-void CodeGenFunction::EmitExprAsInit(const Expr *init,<br>
-                                     const ValueDecl *D,<br>
-                                     LValue lvalue,<br>
-                                     bool capturedByInit) {<br>
+void CodeGenFunction::EmitExprAsInit(const Expr *init, const ValueDecl *D,<br>
+                                     LValue lvalue, bool capturedByInit,<br>
+                                     SourceLocation DbgLoc) {<br>
   QualType type = D->getType();<br>
<br>
   if (type->isReferenceType()) {<br>
     RValue rvalue = EmitReferenceBindingToExpr(init);<br>
     if (capturedByInit)<br>
       drillIntoBlockVariable(*this, lvalue, cast<VarDecl>(D));<br>
-    EmitStoreThroughLValue(rvalue, lvalue, true);<br>
+    EmitStoreThroughLValue(rvalue, lvalue, true, DbgLoc);<br>
     return;<br>
   }<br>
   switch (getEvaluationKind(type)) {<br>
   case TEK_Scalar:<br>
-    EmitScalarInit(init, D, lvalue, capturedByInit);<br>
+    EmitScalarInit(init, D, lvalue, capturedByInit, DbgLoc);<br>
     return;<br>
   case TEK_Complex: {<br>
     ComplexPairTy complex = EmitComplexExpr(init);<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=223726&r1=223725&r2=223726&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=223726&r1=223725&r2=223726&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Mon Dec  8 18:32:22 2014<br>
@@ -1437,7 +1437,11 @@ RValue CodeGenFunction::EmitLoadOfGlobal<br>
 /// lvalue, where both are guaranteed to the have the same type, and that type<br>
 /// is 'Ty'.<br>
 void CodeGenFunction::EmitStoreThroughLValue(RValue Src, LValue Dst,<br>
-                                             bool isInit) {<br>
+                                             bool isInit,<br>
+                                             SourceLocation DbgLoc) {<br>
+  if (auto *DI = getDebugInfo())<br>
+    DI->EmitLocation(Builder, DbgLoc);<br>
+<br>
   if (!Dst.isSimple()) {<br>
     if (Dst.isVectorElt()) {<br>
       // Read/modify/write the vector, inserting the new element.<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=223726&r1=223725&r2=223726&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=223726&r1=223725&r2=223726&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)<br>
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Mon Dec  8 18:32:22 2014<br>
@@ -1299,7 +1299,8 @@ public:<br>
                         FunctionArgList &Args);<br>
<br>
   void EmitInitializerForField(FieldDecl *Field, LValue LHS, Expr *Init,<br>
-                               ArrayRef<VarDecl *> ArrayIndexes);<br>
+                               ArrayRef<VarDecl *> ArrayIndexes,<br>
+                               SourceLocation DbgLoc = SourceLocation());<br>
<br>
   /// InitializeVTablePointer - Initialize the vtable pointer of the given<br>
   /// subobject.<br>
@@ -1543,8 +1544,9 @@ public:<br>
<br>
   /// EmitExprAsInit - Emits the code necessary to initialize a<br>
   /// location in memory with the given initializer.<br>
-  void EmitExprAsInit(const Expr *init, const ValueDecl *D,<br>
-                      LValue lvalue, bool capturedByInit);<br>
+  void EmitExprAsInit(const Expr *init, const ValueDecl *D, LValue lvalue,<br>
+                      bool capturedByInit,<br>
+                      SourceLocation DbgLoc = SourceLocation());<br>
<br>
   /// hasVolatileMember - returns true if aggregate type has a volatile<br>
   /// member.<br>
@@ -1830,8 +1832,9 @@ public:<br>
   /// This function can be called with a null (unreachable) insert point.<br>
   void EmitVarDecl(const VarDecl &D);<br>
<br>
-  void EmitScalarInit(const Expr *init, const ValueDecl *D,<br>
-                      LValue lvalue, bool capturedByInit);<br>
+  void EmitScalarInit(const Expr *init, const ValueDecl *D, LValue lvalue,<br>
+                      bool capturedByInit,<br>
+                      SourceLocation DbgLoc = SourceLocation());<br>
   void EmitScalarInit(llvm::Value *init, LValue lvalue);<br>
<br>
   typedef void SpecialInitFn(CodeGenFunction &Init, const VarDecl &D,<br>
@@ -2150,7 +2153,8 @@ public:<br>
   /// EmitStoreThroughLValue - Store the specified rvalue into the specified<br>
   /// lvalue, where both are guaranteed to the have the same type, and that type<br>
   /// is 'Ty'.<br>
-  void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit=false);<br>
+  void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit = false,<br>
+                              SourceLocation DbgLoc = SourceLocation());<br>
   void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst);<br>
   void EmitStoreThroughGlobalRegLValue(RValue Src, LValue Dst);<br>
<br>
<br>
Modified: cfe/trunk/test/CodeGenCXX/debug-info-line.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-line.cpp?rev=223726&r1=223725&r2=223726&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-line.cpp?rev=223726&r1=223725&r2=223726&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenCXX/debug-info-line.cpp (original)<br>
+++ cfe/trunk/test/CodeGenCXX/debug-info-line.cpp Mon Dec  8 18:32:22 2014<br>
@@ -1,26 +1,33 @@<br>
 // RUN: %clang_cc1 -g -std=c++11 -S -emit-llvm %s -o - | FileCheck %s<br>
<br>
-int src(); int* sink();<br>
+int &src(); int* sink();<br>
<br>
 void f1() {<br>
 #line 100<br>
   * // The store for the assignment should be attributed to the start of the<br>
     // assignment expression here, regardless of the location of subexpressions.<br>
-  (<br>
-  sink<br>
-  (<br>
-  )<br>
-  +<br>
-  3<br>
-  )<br>
-  =<br>
-  src<br>
-  (<br>
-  )<br>
-  +<br>
-  42<br>
-  ;<br>
-  // CHECK: store {{.*}}, !dbg [[DBG1:!.*]]<br>
+  sink() = src();<br>
+  // CHECK: store {{.*}}, !dbg [[DBG_F1:!.*]]<br>
 }<br>
<br>
-// CHECK: [[DBG1]] = metadata !{i32 100, {{.*}}<br>
+struct foo {<br>
+  int i;<br>
+  int &j;<br>
+  foo();<br>
+};<br>
+<br>
+foo::foo()<br>
+  :<br>
+#line 200<br>
+    i<br>
+    (src()),<br>
+    j<br>
+    (src())<br>
+    // CHECK: store i32 {{.*}} !dbg [[DBG_FOO_VALUE:!.*]]<br>
+    // CHECK: store i32* {{.*}} !dbg [[DBG_FOO_REF:!.*]]<br>
+{<br>
+}<br>
+<br>
+// CHECK: [[DBG_F1]] = metadata !{i32 100,<br>
+// CHECK: [[DBG_FOO_VALUE]] = metadata !{i32 200,<br>
+// CHECK: [[DBG_FOO_REF]] = metadata !{i32 202,<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>