https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92378
Bug ID: 92378
Summary: missing -Warray-bounds warning
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: tangyixuan at mail dot dlut.edu.cn
Target Milestone: ---
Hi, I have two questions for the following:
1. Array a[3] is out of bound, there is no warnings compiled with -ftree-vrp
-Warray-bounds=1. When compiled with -Wall with O1/O2/O3, there is an
uninitialized warning.
2. The column is not precise for the uninitialized variant 'a[3]'.
$: cat s.c
#include <stdio.h>
int main()
{
int a[1]={0};
printf("%d", a[3]);
}
$: gcc-trunk -O2 -c -ftree-vrp -Warray-bounds=1 s.c
no warnings here.
$: gcc-trunk -O0 -c -Wall s.c
no warnings here.
$: gcc-trunk -O2 -c -Wall s.c
s.c: In function ‘main’:
s.c:5:3: warning: ‘a[3]’ is used uninitialized in this function
[-Wuninitialized]
5 | printf("%d", a[3]);
| ^~~~~~~~~~~~~~~~~~
$: clang -Weverything -c s.c
s.c:5:16: warning: array index 3 is past the end of the array (which contains 1
element) [-Warray-bounds]
printf("%d", a[3]);
^ ~
s.c:4:3: note: array 'a' declared here
int a[1]={0};
^
1 warning generated.