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.
11 { dg-options "-O2 -Wno-array-bounds -fno-tree-vectorize" } */
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). */
19 extern char a5
[5]; // { dg-message "at offset 5 into destination object 'a5' of size 5" "note" }
21 void max_a3_a5 (int i
)
26 /* The relational expression below is invalid and should be diagnosed
27 by its own warning independently of -Wstringop-overflow. */
33 d
[5] = 0; // { dg-warning "writing 1 byte into a region of size 0" }
37 // Same as above but with the larger array as the first MAX_EXPR operand.
39 extern char b6
[6]; // { dg-message "at offset 6 into destination object 'b6' of size 6" "note" }
41 void max_b6_b4 (int i
)
50 d
[6] = 0; // { dg-warning "writing 1 byte into a region of size 0" }
55 char a3
[3]; // { dg-message "at offset 3 into destination object 'a3' of size 3" "pr??????" { xfail *-*-* } }
56 char a5
[5]; // { dg-message "at offset 5 into destination object 'a5' of size 5" "note" }
59 void max_A3_A5 (int i
, struct A3_5
*pa3_5
)
61 char *p
= pa3_5
->a3
+ i
;
62 char *q
= pa3_5
->a5
+ i
;
66 d
[3] = 0; // { dg-warning "writing 1 byte into a region of size 0" "pr??????" { xfail *-*-* } }
68 d
[5] = 0; // { dg-warning "writing 1 byte into a region of size 0" }
75 char b6
[6]; // { dg-message "at offset 6 into destination object 'b6' of size 6" "note" }
78 void max_B6_B4 (int i
, struct B4_B6
*pb4_b6
)
80 char *p
= pb4_b6
->b6
+ i
;
81 char *q
= pb4_b6
->b4
+ i
;
87 d
[6] = 0; // { dg-warning "writing 1 byte into a region of size 0" }