<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 25, 2015 at 10:50 AM, Bataev, Alexey <span dir="ltr"><<a href="mailto:a.bataev@hotmail.com" target="_blank">a.bataev@hotmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Guys, talking about implicitly captured variables we have to deal with 2 locations: 1) point of real capturing (it is the point of '=' or '&' symbols in lambda capture-list);</blockquote><div><br></div><div>I'm not sure that's "the point of real capturing" if it's an implicit capture - nature of it being implicit is that there is no point where the variable is explicitly captured.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> 2) a point of first use of variable inside lambda's body.<br>
When we're talking about diagnostic for implicitly captured variables we have to deal with the second point, not the first one, because of usability.</blockquote><div><br>That's what I'm trying to understand - why is (2) relevant for diagnostic usability, but not for debugger usability?<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> I don't think that the "diagnostic consumer" would be happy to see a message like "unnamed variable cannot be implicitly captured in a lambda expression" pointing to '=' or '&'. Here we have to emit the diagnostic at the point of the very first use of the variable we're going to capture to make diagnostic more user-friendly. But actual point of capturing is still a point, where we have '=' or '&' symbols in capture-list.<span class=""><br>
<br>
Best regards,<br>
Alexey Bataev<br>
=============<br>
Software Engineer<br>
Intel Compiler Team<br>
<br>
</span><a href="tel:25.08.2015%2019" value="+12508201519" target="_blank">25.08.2015 19</a>:00, Eric Christopher пишет:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
<br>
Yeah. I can't see a difference here being useful, and more likely harmful.<br>
<br>
<br></span><span class="">
On Tue, Aug 25, 2015, 8:48 AM David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a> <mailto:<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>>> wrote:<br>
<br>
    On Tue, Aug 25, 2015 at 8:44 AM, Bataev, Alexey<br></span><span class="">
    <<a href="mailto:a.bataev@hotmail.com" target="_blank">a.bataev@hotmail.com</a> <mailto:<a href="mailto:a.bataev@hotmail.com" target="_blank">a.bataev@hotmail.com</a>>> wrote:<br>
<br>
        Debug info points to the real place where it is captured,<br>
        while diagnostics points to the first use of implicitly<br>
        captured variable.<br>
<br>
<br>
    Right, but I'm trying to understand the justification for why<br>
    that's the right thing to do. Why the debug info user would want a<br>
    different experience than the compiler diagnostic consumer would want.<br>
<br>
<br>
    - David<br>
<br>
<br>
<br>
        Best regards,<br>
        Alexey Bataev<br>
        =============<br>
        Software Engineer<br>
        Intel Compiler Team<br>
<br></span>
        <a href="tel:25.08.2015%2018" value="+12508201518" target="_blank">25.08.2015 18</a> <tel:25.08.2015%2018>:22, David Blaikie пишет:<span class=""><br>
<br>
<br>
<br>
            On Tue, Aug 25, 2015 at 8:18 AM, Bataev, Alexey<br>
            <<a href="mailto:a.bataev@hotmail.com" target="_blank">a.bataev@hotmail.com</a> <mailto:<a href="mailto:a.bataev@hotmail.com" target="_blank">a.bataev@hotmail.com</a>><br></span>
            <mailto:<a href="mailto:a.bataev@hotmail.com" target="_blank">a.bataev@hotmail.com</a><div><div class="h5"><br>
            <mailto:<a href="mailto:a.bataev@hotmail.com" target="_blank">a.bataev@hotmail.com</a>>>> wrote:<br>
<br>
                I though about this. I think it will be more<br>
            convenient for user<br>
                to see the diagnostic on the first use of the variable<br>
            rather than<br>
                on '=' or '&' symbol.<br>
<br>
<br>
            Why the difference between the diagnostic & the debug<br>
            info, then?<br>
<br>
<br>
                Best regards,<br>
                Alexey Bataev<br>
                =============<br>
                Software Engineer<br>
                Intel Compiler Team<br>
<br>
            <a href="tel:25.08.2015%2018" value="+12508201518" target="_blank">25.08.2015 18</a> <tel:25.08.2015%2018><br>
            <tel:25.08.2015%2018>:07, David Blaikie пишет:<br>
<br>
<br>
<br>
                    On Tue, Aug 18, 2015 at 9:05 PM, Alexey Bataev via<br>
            cfe-commits<br>
                    <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
            <mailto:<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>><br>
                    <mailto:<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
            <mailto:<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>>><br>
                    <mailto:<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
            <mailto:<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>><br>
<br>
                    <mailto:<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
            <mailto:<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>>>>> wrote:<br>
<br>
                        ABataev created this revision.<br>
                        ABataev added reviewers: echristo, rjmccall,<br>
            rsmith.<br>
                        ABataev added a subscriber: cfe-commits.<br>
<br>
                        When variables are implicitly captured in<br>
            lambdas, debug info<br>
                        generated for captured variables points to<br>
            location where<br>
                    they are<br>
                        used first.  This patch makes debug info to<br>
            point to capture<br>
                        default location.<br>
<br>
<br>
                    Not sure if this is the right tradeoff, or if it<br>
            is, perhaps<br>
                    we should reconsider how our diagnostics work too?<br>
<br>
                    Currently if you, say, capture a variable by value<br>
            and that<br>
                    variable doesn't have an accessible copy ctor, the<br>
            diagnostic<br>
                    points to the first use. Should we change that too?<br>
<br>
<br>
            <a href="http://reviews.llvm.org/D12134" rel="noreferrer" target="_blank">http://reviews.llvm.org/D12134</a><br>
<br>
                        Files:<br>
                          lib/Sema/SemaLambda.cpp<br>
            test/CodeGenCXX/debug-lambda-expressions.cpp<br>
<br>
                        Index: lib/Sema/SemaLambda.cpp<br>
            ===================================================================<br>
                        --- lib/Sema/SemaLambda.cpp<br>
                        +++ lib/Sema/SemaLambda.cpp<br>
                        @@ -1377,10 +1377,10 @@<br>
                         }<br>
<br>
                         static ExprResult<br>
            performLambdaVarCaptureInitialization(<br>
                        -    Sema &S, LambdaScopeInfo::Capture &Capture,<br>
                        -    FieldDecl *Field,<br>
                        +    Sema &S, LambdaScopeInfo::Capture<br>
            &Capture, FieldDecl<br>
                    *Field,<br>
                             SmallVectorImpl<VarDecl *> &ArrayIndexVars,<br>
                        -    SmallVectorImpl<unsigned><br>
            &ArrayIndexStarts) {<br>
                        +    SmallVectorImpl<unsigned><br>
            &ArrayIndexStarts, bool<br>
                        ImplicitCapture,<br>
                        +    SourceLocation CaptureDefaultLoc) {<br>
             assert(Capture.isVariableCapture() && "not a variable<br>
                    capture");<br>
<br>
                           auto *Var = Capture.getVariable();<br>
                        @@ -1399,7 +1399,10 @@<br>
                           //   An entity captured by a<br>
            lambda-expression is<br>
                    odr-used (3.2) in<br>
                           //   the scope containing the<br>
            lambda-expression.<br>
                           ExprResult RefResult =<br>
            S.BuildDeclarationNameExpr(<br>
                        -      CXXScopeSpec(),<br>
            DeclarationNameInfo(Var->getDeclName(),<br>
                        Loc), Var);<br>
                        +      CXXScopeSpec(),<br>
                        + DeclarationNameInfo(Var->getDeclName(),<br>
                        + ImplicitCapture ?<br>
                    CaptureDefaultLoc : Loc),<br>
                        +      Var);<br>
                           if (RefResult.isInvalid())<br>
                             return ExprError();<br>
                           Expr *Ref = RefResult.get();<br>
                        @@ -1561,7 +1564,8 @@<br>
                               Expr *Init = From.getInitExpr();<br>
                               if (!Init) {<br>
                                 auto InitResult =<br>
                    performLambdaVarCaptureInitialization(<br>
                        -            *this, From, *CurField,<br>
            ArrayIndexVars,<br>
                        ArrayIndexStarts);<br>
                        +            *this, From, *CurField,<br>
            ArrayIndexVars,<br>
                    ArrayIndexStarts,<br>
                        +            CaptureDefault != LCD_None,<br>
            CaptureDefaultLoc);<br>
                                 if (InitResult.isInvalid())<br>
                                   return ExprError();<br>
                                 Init = InitResult.get();<br>
                        Index:<br>
            test/CodeGenCXX/debug-lambda-expressions.cpp<br>
            ===================================================================<br>
                        --- test/CodeGenCXX/debug-lambda-expressions.cpp<br>
                        +++ test/CodeGenCXX/debug-lambda-expressions.cpp<br>
                        @@ -14,6 +14,19 @@<br>
                         struct D { D(); D(const D&); int x; };<br>
                         int d(int x) { D y[10]; return [x,y] { return<br>
            y[x].x; }(); }<br>
<br>
                        +// CHECK-LABEL: foo<br>
                        +int foo(int x) {<br>
                        +// CHECK: [[X:%.+]] = alloca i32,<br>
                        +// CHECK: call void @llvm.dbg.declare(<br>
                        +// CHECK: [[X_REF:%.+]] = getelementptr<br>
            inbounds %{{.+}},<br>
                        %{{.+}}* %{{.+}}, i32 0, i32 0, !dbg<br>
            ![[DBG_FOO:[0-9]+]]<br>
                        +// CHECK: [[X_VAL:%.+]] = load i32, i32*<br>
            [[X]], align 4, !dbg<br>
                        ![[DBG_FOO]]<br>
                        +// CHECK: store i32 [[X_VAL]], i32*<br>
            [[X_REF]], align 4, !dbg<br>
                        ![[DBG_FOO]]<br>
                        +// CHECK: call i32 @{{.+}}, !dbg ![[DBG_FOO]]<br>
                        +  return [=] {<br>
                        +    return x;<br>
                        +  }();<br>
                        +}<br>
                        +<br>
                         // Randomness for file. -- 6<br>
                         // CHECK: [[FILE:.*]] = !DIFile(filename:<br>
            "{{.*}}debug-lambda-expressions.cpp",<br>
<br>
                        @@ -100,3 +113,5 @@<br>
                         // CHECK-SAME:     line: [[VAR_LINE]],<br>
                         // CHECK-SAME: elements:<br>
                        ![[VAR_ARGS:[0-9]+]]<br>
                         // CHECK: ![[VAR_ARGS]] = !{!{{[0-9]+}}}<br>
                        +<br>
                        +// CHECK: [[DBG_FOO:![0-9]+]] =<br>
            !DILocation(line: 25,<br>
<br>
<br>
<br>
            _______________________________________________<br>
                        cfe-commits mailing list<br>
            <a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
            <mailto:<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>><br>
            <mailto:<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
            <mailto:<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>>><br>
                    <mailto:<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
            <mailto:<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>><br>
                    <mailto:<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br></div></div>
            <mailto:<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">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>
<br>
<br>
<br>
<br>
</blockquote>
<br>
</blockquote></div><br></div></div>