| 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" } */ |
| 7 |
|
| 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" } |
| 13 |
|
| 14 |
void min_a3_a5 (int i) |
| 15 |
{ |
| 16 |
char *p = a3 + i; |
| 17 |
char *q = a5 + i; |
| 18 |
|
| 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; |
| 22 |
|
| 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 } } } |
| 25 |
} |
| 26 |
|
| 27 |
|
| 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" } |
| 31 |
|
| 32 |
void min_b6_b4 (int i) |
| 33 |
{ |
| 34 |
char *p = b6 + i; |
| 35 |
char *q = b4 + i; |
| 36 |
char *d = p < q ? p : q; |
| 37 |
|
| 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 } } } |
| 40 |
} |
| 41 |
|
| 42 |
|
| 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 } } } |
| 46 |
|
| 47 |
void min_p_c7 (char *p, int i) |
| 48 |
{ |
| 49 |
char *q = c7 + i; |
| 50 |
char *d = p < q ? p : q; |
| 51 |
|
| 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 } } } |
| 54 |
} |
| 55 |
|
| 56 |
|
| 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 } } } |
| 60 |
|
| 61 |
void min_d8_p (char *q, int i) |
| 62 |
{ |
| 63 |
char *p = d8 + i; |
| 64 |
char *d = p < q ? p : q; |
| 65 |
|
| 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 } } } |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
struct A3_5 |
| 72 |
{ |
| 73 |
char a3[3]; |
| 74 |
char a5[5]; // { dg-message "at offset 5 into destination object 'a5' of size 5" "note" } |
| 75 |
}; |
| 76 |
|
| 77 |
void min_A3_A5 (int i, struct A3_5 *pa3_5) |
| 78 |
{ |
| 79 |
char *p = pa3_5->a3 + i; |
| 80 |
char *q = pa3_5->a5 + i; |
| 81 |
|
| 82 |
char *d = p < q ? p : q; |
| 83 |
|
| 84 |
// d[4] = 0; |
| 85 |
d[5] = 0; // { dg-warning "writing 1 byte into a region of size 0" } |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
struct B4_B6 |
| 90 |
{ |
| 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 } } } |
| 93 |
}; |
| 94 |
|
| 95 |
void min_B6_B4 (int i, struct B4_B6 *pb4_b6) |
| 96 |
{ |
| 97 |
char *p = pb4_b6->b6 + i; |
| 98 |
char *q = pb4_b6->b4 + i; |
| 99 |
char *d = p < q ? p : q; |
| 100 |
|
| 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 } } } |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
struct C7 |
| 107 |
{ |
| 108 |
char c7[7]; // { dg-message "at offset 7 into destination object 'c7' of size 7" "note" { xfail { vect_slp_v2qi_store_unalign } } } |
| 109 |
}; |
| 110 |
|
| 111 |
void min_p_C7 (char *p, int i, struct C7 *pc7) |
| 112 |
{ |
| 113 |
char *q = pc7->c7 + i; |
| 114 |
char *d = p < q ? p : q; |
| 115 |
|
| 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 } } } |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
struct D8 |
| 122 |
{ |
| 123 |
char d8[8]; // { dg-message "at offset 8 into destination object 'd8' of size 8" "note" { xfail { vect_slp_v2qi_store_unalign } } } |
| 124 |
}; |
| 125 |
|
| 126 |
void min_D8_p (char *q, int i, struct D8 *pd8) |
| 127 |
{ |
| 128 |
char *p = pd8->d8 + i; |
| 129 |
char *d = p < q ? p : q; |
| 130 |
|
| 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 } } } |
| 133 |
} |