[cfe-commits] [PATCH] Catching large array sizes

Aaron Ballman aaron at aaronballman.com
Sun Jul 22 13:13:17 PDT 2012


On Sun, Jul 22, 2012 at 2:41 PM, Abramo Bagnara
<abramo.bagnara at gmail.com> wrote:
> Il 22/07/2012 20:50, Aaron Ballman ha scritto:
>> This patch is to address PR13271 -- the problem comes from declaring
>> an array that's "too large" within a structure, and then attempting to
>> take the sizeof that structure.  We have an assert in
>> ASTContext::getTypeInfoImpl about the size of constant arrays, but the
>> problem is that this is called when attempting to get the sizeof a
>> structure.  We've already reported the issue to the user about the
>> array being too large by this point, and so the assert triggers.
>>
>> I'm not convinced the assert is required here, so I've removed it in
>> this patch.  However, I'm also not convinced the assert is invalid and
>> am open to suggestions as to other ways to handle the error.
>
> The assertion is needed because unfortunately type size are currently
> evaluated in bits (and not in bytes) inside an uint64_t.
>
> This means that perfectly valid sizeof >= 1 << 61 are not evaluatable
> and clang silently produced invalid code. The assertion was introduced
> to avoid that.
>
> The proper fix should be to make clang able to evaluate correctly type
> size in bytes also when it is >= 1 << 61.

That makes sense (and thank you for the backstory).  I'll give this
some more thought before diving back in.

~Aaron



More information about the cfe-commits mailing list