[cfe-dev] Can't use sizeof ( typeof ( <vla> ))

Friedman, Eli via cfe-dev cfe-dev at lists.llvm.org
Mon Nov 21 10:23:19 PST 2016


On 11/18/2016 12:18 AM, Paulo Matos wrote:
>
> On 17/11/16 19:00, Friedman, Eli wrote:
>> On 11/17/2016 7:02 AM, Paulo Matos via cfe-dev wrote:
>>> The problem with this rationale is that it's not true in this case since
>>> you need to evaluate typeof (a), which can't be evaluated at compile
>>> time. Is it true that to fix this issue, we need to rethink how sizeof
>>> are evaluated?
>> sizeof() and typeof() with an operand of VLA type are already
>> special-cased; see Sema::TransformToPotentiallyEvaluated.
>>
> Actually sizeof does not seem to be special cased. Only Typeof which
> calls Sema::TransformToPotentiallyEvaluated through
> Sema::HandleExprEvaluationContextForTypeof. Special-casing works by
> making the typeof context evaluated if the previous context is evaluated:
> ExprResult Sema::TransformToPotentiallyEvaluated(Expr *E) {
>    assert(isUnevaluatedContext() &&
>           "Should only transform unevaluated expressions");
>    ExprEvalContexts.back().Context =
>        ExprEvalContexts[ExprEvalContexts.size()-2].Context;
>    if (isUnevaluatedContext())
>      return E;
>    return TransformToPE(*this).TransformExpr(E);
> }
>
>
> Unfortunately the previous context is a sizeof which is not evaluated
> and therefore leaves the typeof as unevaluated, hence the bug.
>
git grep shows that TransformToPotentiallyEvaluated has three callers; 
one for typeof, one for sizeof, and one for typeid.

-Eli

-- 
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project




More information about the cfe-dev mailing list