On 05/30/2018 05:18 PM, Jeff Law wrote:
On 05/18/2018 05:58 PM, Martin Sebor wrote:
The -Walloc-size-larger-than= option is supposed make it possible
to disable the warning by specifying a limit that's larger than
the default of PTRDIFF_MAX (the handler for the option argument
gets around the INT_MAX maximum for numeric arguments by accepting
suffixes like MB or GB). Unfortunately, a silly typo in the handler
prevents this from working correctly, and because there is no
-Wno-alloc-size-larger-than option it's impossible to suppress
unwanted instances of this warning.
The attached patch removes these shortcomings by:
1) fixing the typo,
2) letting the argument handler accept excessively large arguments
(> ULLONG_MAX) and treat them as infinite,
3) adding -Wno-alloc-size-larger-than option to disable the warning
The patch also issues a warning for invalid arguments (they either
reset the limit to zero or leave it at PTRDIFF_MAX otherwise).
I'm looking for approval to commit this patch to trunk and all
release branches that support the option (8 and 7).
For trunk, as the next step, I'd like to generalize the argument
handler and move it where other similar options (for example,
-Wlarger-than, -Walloca-larger-than, -Wframe-larger-than, and
-Wstack-usage) can make use of it.
Martin
gcc-82063.diff
PR c/82063 - issues with arguments enabled by -Wall
gcc/c-family/ChangeLog:
PR c/82063
* c.opt (-Wno-alloc-size-larger-than): New option.
gcc/ChangeLog:
PR c/82063
* calls.c (alloc_max_size): Correct a logic error/typo.
Treat excessive arguments as infinite. Warn for invalid arguments.
gcc/testsuite/ChangeLog:
PR c/82063
* gcc.dg/Walloc-size-larger-than-1.c: New test.
* gcc.dg/Walloc-size-larger-than-10.c: New test.
* gcc.dg/Walloc-size-larger-than-11.c: New test.
* gcc.dg/Walloc-size-larger-than-12.c: New test.
* gcc.dg/Walloc-size-larger-than-13.c: New test.
* gcc.dg/Walloc-size-larger-than-14.c: New test.
* gcc.dg/Walloc-size-larger-than-15.c: New test.
* gcc.dg/Walloc-size-larger-than-16.c: New test.
* gcc.dg/Walloc-size-larger-than-17.c: New test.
* gcc.dg/Walloc-size-larger-than-2.c: New test.
* gcc.dg/Walloc-size-larger-than-3.c: New test.
* gcc.dg/Walloc-size-larger-than-4.c: New test.
* gcc.dg/Walloc-size-larger-than-5.c: New test.
* gcc.dg/Walloc-size-larger-than-6.c: New test.
* gcc.dg/Walloc-size-larger-than-7.c: New test.
* gcc.dg/Walloc-size-larger-than-8.c: New test.
* gcc.dg/Walloc-size-larger-than-9.c: New test.
* gcc.dg/Walloc-size-larger-than.c: New test.
OK for the trunk. Not sure this is really a regression, so it'd need
Richi or Jakub to approve for the release branches.
I also updated the manual and committed r261030 to trunk.
Without the patch false positives the new warning sometimes
(if rarely) issues cannot be suppressed. The particular false
positive that prompted me to fix this is due to C++ front end
bug 82063, and there's nothing the implementation of the warning
can do to avoid it.
Richi and/or Jakub, can you please review the patch and let me
know if it's suitable for the release branches?
Martin