<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Jul 21, 2014 at 10:58 PM, 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">Richard, yes, I understood that. We have troubles in CodeGen in this case. Yes, I can call getSizeExpr() for VariableArrayType, by it is impossible to get llvm::Value* for the expression returned by getSizeExpr() in lambda operator(). </blockquote>
<div><br></div><div>You can do this in exactly the same way you do it in your current patch; see attached patch for example.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
This value is calculated in parent function for lambda expr and we have to pass it somehow to lambda. Passing VariableArrayType* does not allow us to get an access to this value.<br>
We must not recalculate the value of expression from getSizeExpr(), we must use the value, calculated in parent function. That's why it is not enough just to pass VariableArrayType*, also we need to pass llvm::Value* for getSizeExpr(), calculated in parent function.<div class="">
<br>
<br>
Best regards,<br>
Alexey Bataev<br>
=============<br>
Software Engineer<br>
Intel Compiler Team<br>
<br></div>
22 Июль 2014 г. 9:41:43, 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:14 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, I don't think this is possible. If we storing<br>
    VariableLengthArray* on FieldDecl, then in Lambda operator we can<br></div>
    access VariableLengthArray->__<u></u>getSizeExpr(). But! We won't be able<div class=""><br>
    to get the llvm::Value* for this<br></div>
    VariableLengthArray->__<u></u>getSizeExpr(), calculated in another<div class=""><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*, llvm::Value*><br>
    VLASizeMap[n+m]=value; VLASizeMap stores pre-calculated 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()), llvm::DenseMap<const<div class=""><br>
    Expr*, llvm::Value*> VLASizeMap[n+m]=????? - llvm::Value* for<br>
    'n+m' is not captured here, we don't have an access to 'value',<br>
    calculated in CodeGenFunction(foo) for expression 'n+m'.<br>
<br>
    To solve this problem we can try to capture 2 fields instead - one<br>
    for VariableLengthArray*, and another one for llvm::Value*<br></div>
    calculated for VariableLengthArray->__<u></u>getSizeExpr().<div class=""><br>
<br>
<br>
I'm sorry, I still think we're miscommunicating. What I'm suggesting<br>
is a mechanical transformation: store the VariableArrayType* 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></div>
        <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>><div class="">
<br>
        wrote:<br>
<br>
            Updated version after last review. Unfortunately, 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 capture this<br>
        type,<br>
            not VariableLengthArray *. I have to pass actual value of<br>
        SizeExpr<br>
            to the Lambda in this field, because it is defined only in<br>
        calling<br>
            function and in Lambda it can be received only in one of<br>
        captured<br>
            fields.<br>
<br>
<br>
        I don't understand what you're saying. What I'm suggesting is<br>
        storing<br>
        the VariableLengthArray* in the InitializerOrBitWidth 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>
              include/clang/AST/__<u></u>LambdaCapture.h<br>
              include/clang/Basic/__<u></u>DiagnosticSemaKinds.td<div class=""><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>
</blockquote>
</blockquote></div><br></div></div>