[PATCH] handle constant size VLAs in -Warray-bounds (PR 82608, 92333)

Jeff Law law@redhat.com
Tue Nov 5 04:35:00 GMT 2019


On 11/4/19 8:26 PM, Martin Sebor wrote:
> -Warray-bounds doesn't yet have the logic to detect out-of-bounds
> indices into dynamically allocated arrays like VLAs because it
> doesn't track allocation calls.  But the warning could detect
> such errors in accesses to VLAs with constant sizes even without
> such tracking.
> 
> The attached patch adds this capability.  Testing the warning
> revealed that the names and locations of VLAs with constant sizes
> are unavailable, making the warnings less useful than they could
> be otherwise.  So the other part of the patch also arranges for
> the arrays backing the constant size VLAs to have names that
> reflect those of the VLAs, and the same location.
> 
> Tested on x86_64-linux.
> 
> Martin
> 
> gcc-92333.diff
> 
> PR middle-end/92333 - missing variable name referencing VLA in warnings
> PR middle-end/82608 - missing -Warray-bounds on an out-of-bounds VLA index
> 
> gcc/testsuite/ChangeLog:
> 
> 	PR middle-end/92333
> 	PR middle-end/82608
> 	* gcc.dg/Warray-bounds-53.c: New test.
> 
> gcc/ChangeLog:
> 
> 	PR middle-end/92333
> 	PR middle-end/82608
> 	* tree-vrp.c (vrp_prop::check_array_ref): Handle VLAs with constant
> 	size.
> 	* tree-ssa-ccp.c (fold_builtin_alloca_with_align): Use a meaninful
> 	name and location for a temporary variable.
OK
jeff



More information about the Gcc-patches mailing list