<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Jul 22, 2014 at 12:30 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">Yes, we can do this. I wanted to do like this, but I thought it won't be accepted as a kind of a hack again. We're passing Type* as Expr*. I tried to avoid such reinterpret castings. But if this solution is acceptable, I'll rework the patch in a few minutes.</blockquote>
<div><br></div><div>Please change InitializerOrBitWidth to store a void* rather than casting the Type* to an Expr*. Other than that, I think this kind of approach is fine.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="">
Best regards,<br>
Alexey Bataev<br>
=============<br>
Software Engineer<br>
Intel Compiler Team<br>
<br></div>
22 Июль 2014 г. 10:58:11, Richard Smith писал:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">
On Mon, Jul 21, 2014 at 10:58 PM, Bataev, Alexey <<a href="mailto:a.bataev@hotmail.com" target="_blank">a.bataev@hotmail.com</a><br></div><div class="">
<mailto:<a href="mailto:a.bataev@hotmail.com" target="_blank">a.bataev@hotmail.com</a>>> wrote:<br>
<br>
    Richard, yes, I understood that. We have troubles in CodeGen in<br>
    this case. Yes, I can call getSizeExpr() for VariableArrayType, by<br>
    it is impossible to get llvm::Value* for the expression returned<br>
    by getSizeExpr() in lambda operator().<br>
<br>
<br>
You can do this in exactly the same way you do it in your current<br>
patch; see attached patch for example.<br>
<br>
    This value is calculated in parent function for lambda expr and we<br>
    have to pass it somehow to lambda. Passing VariableArrayType* does<br>
    not allow us to get an access to this value.<br>
    We must not recalculate the value of expression from<br>
    getSizeExpr(), we must use the value, calculated in parent<br>
    function. That's why it is not enough just to pass<br>
    VariableArrayType*, also we need to pass llvm::Value* for<br>
    getSizeExpr(), calculated in parent function.<br>
<br>
<br>
    Best regards,<br>
    Alexey Bataev<br>
    =============<br>
    Software Engineer<br>
    Intel Compiler Team<br>
<br>
    22 Июль 2014 г. 9:41:43, Richard Smith писал:<br>
<br>
        On Mon, Jul 21, 2014 at 10:14 PM, 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></div><div class="">
        <mailto:<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>>><u></u>><br>
        wrote:<br>
<br></div><div class="">
            Richard, I don't think this is possible. If we storing<br>
            VariableLengthArray* on FieldDecl, then in Lambda operator<br>
        we can<br></div>
            access VariableLengthArray->____<u></u>getSizeExpr(). But! We<div class=""><br>
        won't be able<br>
<br>
            to get the llvm::Value* for this<br></div>
            VariableLengthArray->____<u></u>getSizeExpr(), calculated in another<div class=""><br>
<br>
            function. We should pass this llvm::Value* as a member of<br>
            RecordDecl for LambdaExpr! Here is a scheme:<br>
<br>
            foo() {<br>
            int vla[n+m];<br>
            ....<br>
            some_lambda {vla....;}<br>
            ....<br>
            }<br>
<br>
            What we have in CodeGen for this example:<br>
            CodeGenFunction(foo), llvm::DenseMap<const Expr*,<br>
        llvm::Value*><br>
            VLASizeMap[n+m]=value; VLASizeMap stores pre-calculated<br>
        size of<br>
            each VLA.<br>
            {<br>
              FD->field_for_m+n_expr = (int [n+m]*)0;<br>
              CodeGenFunction CGF(some_lambda.operator(), FD);<br>
            }<br>
<br></div>
            CodeGenFunction(some_lambda.__<u></u>__operator()),<div class=""><br>
        llvm::DenseMap<const<br>
<br>
            Expr*, llvm::Value*> VLASizeMap[n+m]=????? - llvm::Value* for<br>
            'n+m' is not captured here, we don't have an access to<br>
        'value',<br>
            calculated in CodeGenFunction(foo) for expression 'n+m'.<br>
<br>
            To solve this problem we can try to capture 2 fields<br>
        instead - one<br>
            for VariableLengthArray*, and another one for llvm::Value*<br></div>
            calculated for VariableLengthArray->____<u></u>getSizeExpr().<div class=""><br>
<br>
<br>
<br>
        I'm sorry, I still think we're miscommunicating. What I'm<br>
        suggesting<br>
        is a mechanical transformation: store the VariableArrayType*<br>
        on the<br>
        FieldDecl, and then when you need the size expression that you're<br>
        currently storing there, call getSizeExpr() on the type.<br>
<br>
            Best regards,<br>
            Alexey Bataev<br>
            =============<br>
            Software Engineer<br>
            Intel Compiler Team<br>
<br>
            22 Июль 2014 г. 8:57:54, Richard Smith писал:<br>
<br>
                On Mon, Jul 21, 2014 at 5:43 AM, Alexey Bataev<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>
        <mailto:<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>
                <mailto:<a href="mailto:a.bataev@hotmail.com" target="_blank">a.bataev@hotmail.com</a><br>
        <mailto:<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></div>
        <mailto:<a href="mailto:a.bataev@hotmail.com" target="_blank">a.bataev@hotmail.com</a>>><u></u>>__><div><div class="h5"><br>
<br>
                wrote:<br>
<br>
                    Updated version after last review. Unfortunately,<br>
        I don't<br>
                think it<br>
                    is possible to pass captured expression as a<br>
                VariableLengthArray<br>
                    *. I have to capture expr of VariableLengthArray * and<br>
                then cast<br>
                    it to SizeExpr->getType() type to make lambda<br>
        capture this<br>
                type,<br>
                    not VariableLengthArray *. I have to pass actual<br>
        value of<br>
                SizeExpr<br>
                    to the Lambda in this field, because it is defined<br>
        only in<br>
                calling<br>
                    function and in Lambda it can be received only in<br>
        one of<br>
                captured<br>
                    fields.<br>
<br>
<br>
                I don't understand what you're saying. What I'm<br>
        suggesting is<br>
                storing<br>
                the VariableLengthArray* in the InitializerOrBitWidth<br>
        field on<br>
                FieldDecl, instead of storing the array bound there.<br>
<br>
        <a href="http://reviews.llvm.org/D4368" target="_blank">http://reviews.llvm.org/D4368</a><br>
<br>
                    Files:<br>
                      include/clang/AST/Decl.h<br></div></div>
                      include/clang/AST/____<u></u>LambdaCapture.h<br>
                      include/clang/Basic/____<u></u>DiagnosticSemaKinds.td<div class=""><br>
<br>
                      lib/AST/Decl.cpp<br>
                      lib/AST/Expr.cpp<br>
                      lib/AST/ExprCXX.cpp<br>
                      lib/AST/StmtPrinter.cpp<br>
                      lib/AST/StmtProfile.cpp<br>
                      lib/CodeGen/CGDebugInfo.cpp<br>
                      lib/CodeGen/CGExprCXX.cpp<br></div>
                      lib/CodeGen/CodeGenFunction.__<u></u>__cpp<br>
                      lib/Sema/SemaDecl.cpp<br>
                      lib/Sema/SemaExpr.cpp<br>
                      lib/Sema/TreeTransform.h<br>
                      test/CodeGenCXX/instantiate-__<u></u>__typeof-vla.cpp<br>
                      test/SemaTemplate/instantiate-<u></u>____typeof.cpp<br>
                      tools/libclang/IndexBody.cpp<br>
<br>
<br>
<br>
<br>
</blockquote>
</blockquote></div><br></div></div>