]> granicus.if.org Git - clang/commitdiff
DebugInfo: Emit the correct location for initialization of a complex variable
authorDavid Blaikie <dblaikie@gmail.com>
Tue, 9 Dec 2014 20:52:24 +0000 (20:52 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Tue, 9 Dec 2014 20:52:24 +0000 (20:52 +0000)
Especially useful for sanitizer reports.

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

lib/CodeGen/CGClass.cpp
lib/CodeGen/CGExprComplex.cpp
lib/CodeGen/CodeGenFunction.h
test/CodeGenCXX/debug-info-line.cpp

index dfd980f6e8626278130c38c03ff18b046d2772b6..5ffab603ac83084d7a2c6cea3e12e57eb8691df4 100644 (file)
@@ -616,7 +616,7 @@ void CodeGenFunction::EmitInitializerForField(FieldDecl *Field, LValue LHS,
     }
     break;
   case TEK_Complex:
-    EmitComplexExprIntoLValue(Init, LHS, /*isInit*/ true);
+    EmitComplexExprIntoLValue(Init, LHS, /*isInit*/ true, DbgLoc);
     break;
   case TEK_Aggregate: {
     llvm::Value *ArrayIndexVar = nullptr;
index 6b7826eef5d1a5dd86bd4b820ac24e441cf35919..f3493bfbbe3ceb0217a21d98ed19f3e159994c09 100644 (file)
@@ -81,7 +81,8 @@ public:
 
   /// EmitStoreOfComplex - Store the specified real/imag parts into the
   /// specified value pointer.
-  void EmitStoreOfComplex(ComplexPairTy Val, LValue LV, bool isInit);
+  void EmitStoreOfComplex(ComplexPairTy Val, LValue LV, bool isInit,
+                          SourceLocation DbgLoc = SourceLocation());
 
   /// EmitComplexToComplexCast - Emit a cast from complex value Val to DestType.
   ComplexPairTy EmitComplexToComplexCast(ComplexPairTy Val, QualType SrcType,
@@ -333,9 +334,12 @@ ComplexPairTy ComplexExprEmitter::EmitLoadOfLValue(LValue lvalue,
 
 /// EmitStoreOfComplex - Store the specified real/imag parts into the
 /// specified value pointer.
-void ComplexExprEmitter::EmitStoreOfComplex(ComplexPairTy Val,
-                                            LValue lvalue,
-                                            bool isInit) {
+void ComplexExprEmitter::EmitStoreOfComplex(ComplexPairTy Val, LValue lvalue,
+                                            bool isInit,
+                                            SourceLocation DbgLoc) {
+  if (auto *DI = CGF.getDebugInfo())
+    DI->EmitLocation(CGF.Builder, DbgLoc);
+
   if (lvalue.getType()->isAtomicType())
     return CGF.EmitAtomicStore(RValue::getComplex(Val), lvalue, isInit);
 
@@ -910,6 +914,7 @@ LValue ComplexExprEmitter::EmitBinAssignLValue(const BinaryOperator *E,
   LValue LHS = CGF.EmitLValue(E->getLHS());
 
   // Store the result value into the LHS lvalue.
+  // FIXME
   EmitStoreOfComplex(Val, LHS, /*isInit*/ false);
 
   return LHS;
@@ -1038,18 +1043,19 @@ ComplexPairTy CodeGenFunction::EmitComplexExpr(const Expr *E, bool IgnoreReal,
 }
 
 void CodeGenFunction::EmitComplexExprIntoLValue(const Expr *E, LValue dest,
-                                                bool isInit) {
+                                                bool isInit,
+                                                SourceLocation DbgLoc) {
   assert(E && getComplexType(E->getType()) &&
          "Invalid complex expression to emit");
   ComplexExprEmitter Emitter(*this);
   ComplexPairTy Val = Emitter.Visit(const_cast<Expr*>(E));
-  Emitter.EmitStoreOfComplex(Val, dest, isInit);
+  Emitter.EmitStoreOfComplex(Val, dest, isInit, DbgLoc);
 }
 
 /// EmitStoreOfComplex - Store a complex number into the specified l-value.
 void CodeGenFunction::EmitStoreOfComplex(ComplexPairTy V, LValue dest,
-                                         bool isInit) {
-  ComplexExprEmitter(*this).EmitStoreOfComplex(V, dest, isInit);
+                                         bool isInit, SourceLocation DbgLoc) {
+  ComplexExprEmitter(*this).EmitStoreOfComplex(V, dest, isInit, DbgLoc);
 }
 
 /// EmitLoadOfComplex - Load a complex number from the specified address.
index 98527b2b15062e8d3ffe56f018a29c499e4cc373..a80a199512eadf28c2e8659b5413cf73872737ee 100644 (file)
@@ -2524,10 +2524,12 @@ public:
 
   /// EmitComplexExprIntoLValue - Emit the given expression of complex
   /// type and place its result into the specified l-value.
-  void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit);
+  void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit,
+                                 SourceLocation DbgLoc = SourceLocation());
 
   /// EmitStoreOfComplex - Store a complex number into the specified l-value.
-  void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit);
+  void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit,
+                          SourceLocation DbgLoc = SourceLocation());
 
   /// EmitLoadOfComplex - Load a complex number from the specified l-value.
   ComplexPairTy EmitLoadOfComplex(LValue src, SourceLocation loc);
index 00d626155b0298a121cb6f1d229279aed9b67696..8f4e080bdc0bb34bff5cd3dca64c4c92bc4cffa1 100644 (file)
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 -g -std=c++11 -S -emit-llvm %s -o - | FileCheck %s
 
-int &src(); int* sink();
+int &src();
+int* sink();
+__complex float complex_src();
 
 void f1() {
 #line 100
@@ -13,6 +15,7 @@ void f1() {
 struct foo {
   int i;
   int &j;
+  __complex float k;
   foo();
 };
 
@@ -21,13 +24,17 @@ foo::foo()
 #line 200
     i
     (src()),
-    j
-    (src())
     // CHECK: store i32 {{.*}} !dbg [[DBG_FOO_VALUE:!.*]]
+    j
+    (src()),
     // CHECK: store i32* {{.*}} !dbg [[DBG_FOO_REF:!.*]]
+    k
+    (complex_src())
+    // CHECK: store float {{.*}} !dbg [[DBG_FOO_COMPLEX:!.*]]
 {
 }
 
 // CHECK: [[DBG_F1]] = metadata !{i32 100,
 // CHECK: [[DBG_FOO_VALUE]] = metadata !{i32 200,
-// CHECK: [[DBG_FOO_REF]] = metadata !{i32 202,
+// CHECK: [[DBG_FOO_REF]] = metadata !{i32 203,
+// CHECK: [[DBG_FOO_COMPLEX]] = metadata !{i32 206,