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

Paulo Matos via cfe-dev cfe-dev at lists.llvm.org
Thu Dec 1 02:13:50 PST 2016



On 22/11/16 21:44, Friedman, Eli wrote:
> 
> The way it should work is that there are three calls to
> TransformToPotentiallyEvaluated: the first time, we're calling on the
> typeof, and it's unevaluated.  The second time, we're calling it on the
> sizeof(), and it's potentially evaluated.  The third time is a recursive
> call: in the process of transforming the sizeof(), we make a new
> typeof() expression, and call TransformToPotentiallyEvaluated on that;
> at that point, it should be potentially-evaluated.  (Yes, this is
> terribly inefficient, but it's a rare situation anyway.)
> 

Apologies, only just managed to get back on this. I assume you're
suggesting a solution, not how it's implemented.

Currently there are two calls in SemaExpr.cpp and one in SemaExprCXX,cpp.

The two in SemaExpr.cpp are:

* in CreateUnaryExprOrTypeTraitExpr:

it happens when Expr is a Sizeof and argument is VLA.


* in HandleExprEvaluationContextforTypeof:

it checks if argument is vla and if so, transforms it to VLA if context
of typeof is PotentiallyEvaluated.

The one in SemaExprCXX.cpp is:

* in BuildCXXTypeId:

it is called when building a C++ Typeid.

Unfortunately for an expression in C like `sizeof(typeof(foo))` where
foo is a VLA, a context is created when parsing the sizeof which is
unevaluated and once typeof is parsed, it calls
HandleExprEvaluationContextforTypeof which since argument is vla, tries
to transform the context. However the context of typeof is unevaluated
so nothing changes.

Going back to what you said, there's currently no recursive call to
handle this. Was your message a suggestion for implementation?

I was going to implement it through extending the context types to add
UnevaluatedSizeof and detect this throughout the parser.

-- 
Paulo Matos



More information about the cfe-dev mailing list