[PATCH] D12134: Improve debug info for implicitly captured vars in lambdas

Alexey Bataev via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 18 21:05:17 PDT 2015


ABataev created this revision.
ABataev added reviewers: echristo, rjmccall, rsmith.
ABataev added a subscriber: cfe-commits.

When variables are implicitly captured in lambdas, debug info generated for captured variables points to location where they are used first.  This patch makes debug info to point to capture default location.

http://reviews.llvm.org/D12134

Files:
  lib/Sema/SemaLambda.cpp
  test/CodeGenCXX/debug-lambda-expressions.cpp

Index: lib/Sema/SemaLambda.cpp
===================================================================
--- lib/Sema/SemaLambda.cpp
+++ lib/Sema/SemaLambda.cpp
@@ -1377,10 +1377,10 @@
 }
 
 static ExprResult performLambdaVarCaptureInitialization(
-    Sema &S, LambdaScopeInfo::Capture &Capture,
-    FieldDecl *Field,
+    Sema &S, LambdaScopeInfo::Capture &Capture, FieldDecl *Field,
     SmallVectorImpl<VarDecl *> &ArrayIndexVars,
-    SmallVectorImpl<unsigned> &ArrayIndexStarts) {
+    SmallVectorImpl<unsigned> &ArrayIndexStarts, bool ImplicitCapture,
+    SourceLocation CaptureDefaultLoc) {
   assert(Capture.isVariableCapture() && "not a variable capture");
 
   auto *Var = Capture.getVariable();
@@ -1399,7 +1399,10 @@
   //   An entity captured by a lambda-expression is odr-used (3.2) in
   //   the scope containing the lambda-expression.
   ExprResult RefResult = S.BuildDeclarationNameExpr(
-      CXXScopeSpec(), DeclarationNameInfo(Var->getDeclName(), Loc), Var);
+      CXXScopeSpec(),
+      DeclarationNameInfo(Var->getDeclName(),
+                          ImplicitCapture ? CaptureDefaultLoc : Loc),
+      Var);
   if (RefResult.isInvalid())
     return ExprError();
   Expr *Ref = RefResult.get();
@@ -1561,7 +1564,8 @@
       Expr *Init = From.getInitExpr();
       if (!Init) {
         auto InitResult = performLambdaVarCaptureInitialization(
-            *this, From, *CurField, ArrayIndexVars, ArrayIndexStarts);
+            *this, From, *CurField, ArrayIndexVars, ArrayIndexStarts,
+            CaptureDefault != LCD_None, CaptureDefaultLoc);
         if (InitResult.isInvalid())
           return ExprError();
         Init = InitResult.get();
Index: test/CodeGenCXX/debug-lambda-expressions.cpp
===================================================================
--- test/CodeGenCXX/debug-lambda-expressions.cpp
+++ test/CodeGenCXX/debug-lambda-expressions.cpp
@@ -14,6 +14,19 @@
 struct D { D(); D(const D&); int x; };
 int d(int x) { D y[10]; return [x,y] { return y[x].x; }(); }
 
+// CHECK-LABEL: foo
+int foo(int x) {
+// CHECK: [[X:%.+]] = alloca i32,
+// CHECK: call void @llvm.dbg.declare(
+// CHECK: [[X_REF:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* %{{.+}}, i32 0, i32 0, !dbg ![[DBG_FOO:[0-9]+]]
+// CHECK: [[X_VAL:%.+]] = load i32, i32* [[X]], align 4, !dbg ![[DBG_FOO]]
+// CHECK: store i32 [[X_VAL]], i32* [[X_REF]], align 4, !dbg ![[DBG_FOO]]
+// CHECK: call i32 @{{.+}}, !dbg ![[DBG_FOO]]
+  return [=] {
+    return x;
+  }();
+}
+
 // Randomness for file. -- 6
 // CHECK: [[FILE:.*]] = !DIFile(filename: "{{.*}}debug-lambda-expressions.cpp",
 
@@ -100,3 +113,5 @@
 // CHECK-SAME:                          line: [[VAR_LINE]],
 // CHECK-SAME:                          elements: ![[VAR_ARGS:[0-9]+]]
 // CHECK: ![[VAR_ARGS]] = !{!{{[0-9]+}}}
+
+// CHECK: [[DBG_FOO:![0-9]+]] = !DILocation(line: 25,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12134.32496.patch
Type: text/x-patch
Size: 2851 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150819/bc14b137/attachment-0001.bin>


More information about the cfe-commits mailing list