]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/gcc.dg/Warray-bounds-63.c
Correct handling of variable offset minus constant in -Warray-bounds [PR100137]
[thirdparty/gcc.git] / gcc / testsuite / gcc.dg / Warray-bounds-63.c
CommitLineData
3f9a497d
MS
1/* PR middle-end/94195 - missing warning reading a smaller object via
2 an lvalue of a larger type
3 { dg-do compile }
28d3b78d
TV
4 { dg-options "-O2 -Wall" }
5 { dg-require-effective-target alloca } */
3f9a497d
MS
6
7typedef __INT16_TYPE__ int16_t;
8typedef __SIZE_TYPE__ size_t;
9
10void* alloca (size_t);
11
12void sink (void*);
13
14
15void byte_store_to_decl (void)
16{
a1108556 17 struct S6 { char a[6]; } s; // { dg-message "at offset 6 into object 's' of size 6" "note" }
3f9a497d
MS
18
19 char *p = (char*)&s;
20
21 p[0] = 0; p[1] = 1; p[2] = 2; p[3] = 3; p[4] = 4; p[5] = 5;
22 p[6] = 6; // { dg-warning "array subscript 6 is outside array bounds of 'struct S6\\\[1]" }
23
24 sink (&s);
25}
26
27
28void word_store_to_decl (void)
29{
a1108556 30 struct S6 { char a[6]; } s; // { dg-message "at offset 5 into object 's' of size 6" "note" }
3f9a497d
MS
31
32 char *p = (char*)&s;
33
34 int16_t *q = (int16_t*)(p + 1);
35
36 q[0] = 0; q[1] = 1;
37 q[2] = 2; // { dg-warning "array subscript 'int16_t {aka short int}\\\[2]' is partly outside array bounds of 'struct S6\\\[1]'" }
38
39 sink (&s);
40}
41
42
43void word_store_to_alloc (void)
44{
45 struct S6 { char a[6]; } *p;
a1108556 46 p = alloca (sizeof *p); // { dg-message "at offset 5 into object of size 6 allocated by 'alloca'" "note" }
3f9a497d
MS
47
48 int16_t *q = (int16_t*)((char*)p + 1);
49
50 q[0] = 0; q[1] = 1;
51 q[2] = 2; // { dg-warning "array subscript 'int16_t {aka short int}\\\[2]' is partly outside array bounds of 'unsigned char\\\[6]'" }
52
53 sink (p);
54}