libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / Wstringop-overflow-76.c
blobd5cf8662c439a068cabba249d49fa1b14aea6cb0
1 /* Verify warnings and notes for MAX_EXPRs involving either pointers
2 to distinct objects or one to a known object and the other to
3 an unknown one. Unlike for the same object, for unrelated objects
4 the expected warnings and notes are the same as for MIN_EXPR: when
5 the order of the objects in the address space cannot be determined
6 the larger of them is assumed to be used. (This is different for
7 distinct struct members where the order is given.)
8 The relational expressions are strictly invalid but that should be
9 diagnosed by a separate warning.
10 { dg-do compile }
11 { dg-options "-O2 -Wno-array-bounds" } */
13 #define MAX(p, q) ((p) > (q) ? (p) : (q))
15 /* Verify that even for MAX_EXPR and like for MIN_EXPR, the note points
16 to the larger of the two objects and mentions the offset into it
17 (although the offset might be better included in the warning). */
18 extern char a3[3];
19 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" }
21 void max_a3_a5 (int i)
23 char *p = a3 + i;
24 char *q = a5 + i;
26 /* The relational expression below is invalid and should be diagnosed
27 by its own warning independently of -Wstringop-overflow. */
28 char *d = MAX (p, q);
30 d[2] = 0; // { dg-warning "writing 4 bytes into a region of size 3" "pr102706" { target { vect_slp_v4qi_store_unalign } } }
31 d[3] = 0;
32 d[4] = 0;
33 d[5] = 0; // { dg-warning "writing 1 byte into a region of size 0" "pr102706" { xfail { vect_slp_v4qi_store_unalign } } }
37 // Same as above but with the larger array as the first MAX_EXPR operand.
38 extern char b4[4];
39 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" }
41 void max_b6_b4 (int i)
43 char *p = b6 + i;
44 char *q = b4 + i;
45 char *d = MAX (p, q);
47 d[3] = 0; // { dg-warning "writing 4 bytes into a region of size 3" "pr102706" { target { vect_slp_v4qi_store_unalign } } }
48 d[4] = 0;
49 d[5] = 0;
50 d[6] = 0; // { dg-warning "writing 1 byte into a region of size 0" "pr102706" { xfail { vect_slp_v4qi_store_unalign } } }
54 /* Same as above but with the first MAX_EXPR operand pointing to an unknown
55 object. */
56 extern char c7[7]; // { dg-message "at offset 7 into destination object 'c7' of size 7" "note" { xfail { vect_slp_v2qi_store_unalign } } }
58 void max_p_c7 (char *p, int i)
60 char *q = c7 + i;
61 char *d = MAX (p, q);
63 d[6] = 0; // { dg-warning "writing 2 bytes into a region of size 1" "" { target { vect_slp_v2qi_store_unalign } } }
64 d[7] = 0; // { dg-warning "writing 1 byte into a region of size 0" "" { xfail { vect_slp_v2qi_store_unalign } } }
68 /* Same as above but with the second MIN_EXPR operand pointing to an unknown
69 object. */
70 extern char d8[8]; // { dg-message "at offset 8 into destination object 'd8' of size 8" "note" { xfail { vect_slp_v2qi_store_unalign } } }
72 void max_d8_p (char *q, int i)
74 char *p = d8 + i;
75 char *d = MAX (p, q);
77 d[7] = 0; // { dg-warning "writing 2 bytes into a region of size 1" "" { target { vect_slp_v2qi_store_unalign } } }
78 d[8] = 0; // { dg-warning "writing 1 byte into a region of size 0" "" { xfail { vect_slp_v2qi_store_unalign } } }
82 struct A3_5
84 char a3[3]; // { dg-message "at offset 3 into destination object 'a3' of size 3" "pr??????" { xfail *-*-* } }
85 // refer to pr102697 for xfail
86 char a5[5]; // { dg-message "at offset 5 into destination object 'a5' of size 5" "note" { xfail { vect_slp_v4qi_store_unalign } } }
89 void max_A3_A5 (int i, struct A3_5 *pa3_5)
91 char *p = pa3_5->a3 + i;
92 char *q = pa3_5->a5 + i;
94 char *d = MAX (p, q);
96 d[2] = 0;
97 d[3] = 0; // { dg-warning "writing 1 byte into a region of size 0" "pr??????" { xfail *-*-* } }
98 d[4] = 0;
99 d[5] = 0; // { dg-warning "writing 1 byte into a region of size 0" "pr102697" { xfail { vect_slp_v4qi_store_unalign } } }
103 struct B4_B6
105 char b4[4];
106 // refer to pr102697 for xfail
107 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" { xfail { vect_slp_v4qi_store_unalign } } }
110 void max_B6_B4 (int i, struct B4_B6 *pb4_b6)
112 char *p = pb4_b6->b6 + i;
113 char *q = pb4_b6->b4 + i;
114 char *d = MAX (p, q);
116 d[3] = 0;
117 d[4] = 0;
118 d[5] = 0;
119 d[6] = 0; // { dg-warning "writing 1 byte into a region of size 0" "pr102697" { xfail { vect_slp_v4qi_store_unalign } } }
123 struct C7
125 char c7[7]; // { dg-message "at offset 7 into destination object 'c7' of size 7" "note" { xfail { vect_slp_v2qi_store_unalign } } }
128 void max_p_C7 (char *p, int i, struct C7 *pc7)
130 char *q = pc7->c7 + i;
131 char *d = MAX (p, q);
133 d[6] = 0;
134 d[7] = 0; // { dg-warning "writing 1 byte into a region of size 0" "" { xfail { vect_slp_v2qi_store_unalign } } }
138 struct D8
140 char d8[8]; // { dg-message "at offset 8 into destination object 'd8' of size 8" "note" { xfail { vect_slp_v2qi_store_unalign } } }
143 void max_D8_p (char *q, int i, struct D8 *pd8)
145 char *p = pd8->d8 + i;
146 char *d = MAX (p, q);
148 d[7] = 0;
149 d[8] = 0; // { dg-warning "writing 1 byte into a region of size 0" "" { xfail { vect_slp_v2qi_store_unalign } } }