Skip analyzer strndup test on hppa*-*-hpux*
[official-gcc.git] / gcc / testsuite / gcc.dg / Wstringop-overflow-75.c
blob9f9c3a9c2a7ad6964468ea865e726c86ec7e6899
1 /* Verify warnings and notes for MIN_EXPRs involving either pointers
2 to distinct objects or one to a known object and the other to
3 an unknown one. The relational expressions are strictly invalid
4 but that should be diagnosed by a separate warning.
5 { dg-do compile }
6 { dg-options "-O2 -Wno-array-bounds" } */
8 /* Verify the note points to the larger of the two objects and mentions
9 the offset into it (although the offset might be better included in
10 the warning). */
11 extern char a3[3];
12 extern char a5[5]; // { dg-message "at offset \[^a-zA-Z\n\r\]*5\[^a-zA-Z0-9\]* into destination object 'a5' of size 5" "note" }
14 void min_a3_a5 (int i)
16 char *p = a3 + i;
17 char *q = a5 + i;
19 /* The relational expression below is invalid and should be diagnosed
20 by its own warning independently of -Wstringop-overflow. */
21 char *d = p < q ? p : q;
23 d[4] = 0; // { dg-warning "writing 2 bytes into a region of size 1" "" { target { vect_slp_v2qi_store_unalign } } }
24 d[5] = 0; // { dg-warning "writing 1 byte into a region of size 0" "" { xfail { vect_slp_v2qi_store_unalign } } }
28 // Same as above but with the larger array as the first MIN_EXPR operand.
29 extern char b4[4];
30 extern char b6[6]; // { dg-message "at offset \[^a-zA-Z\n\r\]*6\[^a-zA-Z0-9\]* into destination object 'b6' of size 6" "note" }
32 void min_b6_b4 (int i)
34 char *p = b6 + i;
35 char *q = b4 + i;
36 char *d = p < q ? p : q;
38 d[5] = 0; // { dg-warning "writing 2 bytes into a region of size 1" "" { target { vect_slp_v2qi_store_unalign } } }
39 d[6] = 0; // { dg-warning "writing 1 byte into a region of size 0" "" { xfail { vect_slp_v2qi_store_unalign } } }
43 /* Same as above but with the first MIN_EXPR operand pointing to an unknown
44 object. */
45 extern char c7[7]; // { dg-message "at offset 7 into destination object 'c7' of size 7" "note" { xfail { vect_slp_v2qi_store_unalign } } }
47 void min_p_c7 (char *p, int i)
49 char *q = c7 + i;
50 char *d = p < q ? p : q;
52 d[6] = 0; // { dg-warning "writing 2 bytes into a region of size 1" "" { target { vect_slp_v2qi_store_unalign } } }
53 d[7] = 0; // { dg-warning "writing 1 byte into a region of size 0" "" { xfail { vect_slp_v2qi_store_unalign } } }
57 /* Same as above but with the second MIN_EXPR operand pointing to an unknown
58 object. */
59 extern char d8[8]; // { dg-message "at offset 8 into destination object 'd8' of size 8" "note" { xfail { vect_slp_v2qi_store_unalign } } }
61 void min_d8_p (char *q, int i)
63 char *p = d8 + i;
64 char *d = p < q ? p : q;
66 d[7] = 0; // { dg-warning "writing 2 bytes into a region of size 1" "" { target { vect_slp_v2qi_store_unalign } } }
67 d[8] = 0; // { dg-warning "writing 1 byte into a region of size 0" "" { xfail { vect_slp_v2qi_store_unalign } } }
71 struct A3_5
73 char a3[3];
74 char a5[5]; // { dg-message "at offset 5 into destination object 'a5' of size 5" "note" }
77 void min_A3_A5 (int i, struct A3_5 *pa3_5)
79 char *p = pa3_5->a3 + i;
80 char *q = pa3_5->a5 + i;
82 char *d = p < q ? p : q;
84 // d[4] = 0;
85 d[5] = 0; // { dg-warning "writing 1 byte into a region of size 0" }
89 struct B4_B6
91 char b4[4];
92 char b6[6]; // { dg-message "at offset 6 into destination object 'b6' of size 6" "note" { xfail { vect_slp_v2qi_store_unalign } } }
95 void min_B6_B4 (int i, struct B4_B6 *pb4_b6)
97 char *p = pb4_b6->b6 + i;
98 char *q = pb4_b6->b4 + i;
99 char *d = p < q ? p : q;
101 d[5] = 0;
102 d[6] = 0; // { dg-warning "writing 1 byte into a region of size 0" "" { xfail { vect_slp_v2qi_store_unalign } } }
106 struct C7
108 char c7[7]; // { dg-message "at offset 7 into destination object 'c7' of size 7" "note" { xfail { vect_slp_v2qi_store_unalign } } }
111 void min_p_C7 (char *p, int i, struct C7 *pc7)
113 char *q = pc7->c7 + i;
114 char *d = p < q ? p : q;
116 d[6] = 0;
117 d[7] = 0; // { dg-warning "writing 1 byte into a region of size 0" "" { xfail { vect_slp_v2qi_store_unalign } } }
121 struct D8
123 char d8[8]; // { dg-message "at offset 8 into destination object 'd8' of size 8" "note" { xfail { vect_slp_v2qi_store_unalign } } }
126 void min_D8_p (char *q, int i, struct D8 *pd8)
128 char *p = pd8->d8 + i;
129 char *d = p < q ? p : q;
131 d[7] = 0;
132 d[8] = 0; // { dg-warning "writing 1 byte into a region of size 0" "" { xfail { vect_slp_v2qi_store_unalign } } }