GCC 8.1: alloc-size-larger-than warnings during operator new[]

Martin Sebor msebor@gmail.com
Mon May 14 02:00:00 GMT 2018


On 05/13/2018 02:32 PM, Paul Smith wrote:
> On Sun, 2018-05-13 at 15:53 -0400, Paul Smith wrote:
>> The first problem is that I have three instances (in a very large
>> codebase) where I'm seeing errors like this:
>>
>>   error: argument 1 value '18446744073709551615' exceeds maximum object
>> size 9223372036854775807 [-Werror=alloc-size-larger-than=]
>>
>> ...
>>
>> I can disable this warning
>
> Err... no I can't?  Isn't there some way to keep -Wall but disable
> -Walloc-size-larger-than?  -Wno-alloc-size-larger-than is unrecognized
> and -Walloc-size-larger-than=0 doesn't disable it...

It should be possible to disable the warning by specifying a large
enough size but GCC only accepts 32-bit integers as option arguments
and larger values wrap around.  (This is tracked in bug 71905.)

To work around this limitation the option accepts suffixes like KB,
GB, and TB but I don't think this works right (this is tracked in
bug 82063 that I was going to look into in GCC but forgot/didn't
get to).  The bug also discusses another problem with this option
(and some others like it) having to do with it being enabled by
default even though it's specified to be enabled by -Wall.

That said, false positives in this warning are due to optimizers
introducing and not eliminating calls with excessive arguments.
If you can reduce the false positive to a test case it should
(in theory) be possible to improve the pass that's responsible
for introducing the excessive size to avoid it.  Until then,
it should be possible to avoid the warning by asserting that
the argument is smaller than the limit (e.g., via something
like: if (n > SIZE_MAX / 2) abort ();)

Martin



More information about the Gcc-help mailing list