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

Friedman, Eli via cfe-dev cfe-dev at lists.llvm.org
Tue Nov 22 12:44:38 PST 2016


On 11/22/2016 12:18 AM, Paulo Matos wrote:
>
> On 21/11/16 19:23, Friedman, Eli wrote:
>>> 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.
>>
> That's correct but that's not the problem. It works ok for sizeof (vla)
> and for typeof (vla) but not for sizeof (typeof (vla)). Note that
> TransformToPotentiallyEvaluated is called for typeof (the inner
> expression) and this function only actually does the transformation is
> the sizeof (...) context is marked as PotentiallyEvaluated, which is not
> in trunk.
>
> I submitted a patch for review that fixes the issue (but causes others)
> that mark the sizeof context as PotentiallyEvaluated, however this needs
> changing.
>
> If you have any suggestions on how to go about fixing this, I am all ears.
>

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.)

-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