| 1 |
/* Verify that storing a bigger vector into smaller space is diagnosed. |
| 2 |
{ dg-do compile } |
| 3 |
{ dg-options "-O2" } */ |
| 4 |
|
| 5 |
typedef __INT16_TYPE__ int16_t; |
| 6 |
typedef __attribute__ ((__vector_size__ (32))) char C32; |
| 7 |
|
| 8 |
typedef __attribute__ ((__vector_size__ (64))) int16_t I16_64; |
| 9 |
|
| 10 |
void sink (void*); |
| 11 |
|
| 12 |
|
| 13 |
void nowarn_c32 (char c) |
| 14 |
{ |
| 15 |
extern char nowarn_a32[32]; |
| 16 |
|
| 17 |
void *p = nowarn_a32; |
| 18 |
*(C32*)p = (C32){ c }; |
| 19 |
sink (p); |
| 20 |
|
| 21 |
char a32[32]; |
| 22 |
p = a32; |
| 23 |
*(C32*)p = (C32){ c }; |
| 24 |
sink (p); |
| 25 |
} |
| 26 |
|
| 27 |
/* The tests below failed as a result of the hack for PR 96963. However, |
| 28 |
with -Wall, the invalid stores were diagnosed by -Warray-bounds which |
| 29 |
runs before vectorization and so doesn't need the hack. Now that |
| 30 |
-Warray-bounds has changed to use compute_objsize() the tests pass. */ |
| 31 |
|
| 32 |
void warn_c32 (char c) |
| 33 |
{ |
| 34 |
extern char warn_a32[32]; // { dg-message "at offset (32|1|17|29) into destination object 'warn_a32' of size 32" "pr97027" } |
| 35 |
|
| 36 |
void *p = warn_a32 + 1; |
| 37 |
*(C32*)p = (C32){ c }; // { dg-warning "writing (1 byte|16 bytes|32 bytes|4 bytes) into a region of size (0|15|31|3)" "pr97027" } |
| 38 |
|
| 39 |
/* Verify a local variable too. */ |
| 40 |
char a32[32]; |
| 41 |
p = a32 + 1; |
| 42 |
*(C32*)p = (C32){ c }; // { dg-warning "writing (1 byte|16 bytes|32 bytes|4 bytes) into a region of size (0|15|31|3)" "pr97027" } |
| 43 |
sink (p); |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
void nowarn_i16_64 (int16_t i) |
| 48 |
{ |
| 49 |
extern char nowarn_a64[64]; |
| 50 |
|
| 51 |
void *p = nowarn_a64; |
| 52 |
I16_64 *q = (I16_64*)p; |
| 53 |
*q = (I16_64){ i }; |
| 54 |
|
| 55 |
char a64[64]; |
| 56 |
q = (I16_64*)a64; |
| 57 |
*q = (I16_64){ i }; |
| 58 |
sink (q); |
| 59 |
} |
| 60 |
|
| 61 |
void warn_i16_64 (int16_t i) |
| 62 |
{ |
| 63 |
/* The IL below that's visible to the warning changes from one target to |
| 64 |
another. On some like aarch64 it's a single vector store, on others |
| 65 |
like x86_64 it's a series of BIT_FIELD_REFs. The overflow by |
| 66 |
the former is detected but the latter is not yet. */ |
| 67 |
|
| 68 |
extern char warn_a64[64]; // { dg-message "at offset (1|128) into destination object 'warn_a64' of size (63|64)" "pr97027 note" { xfail { ! { aarch64-*-* } } } } |
| 69 |
|
| 70 |
void *p = warn_a64 + 1; |
| 71 |
I16_64 *q = (I16_64*)p; |
| 72 |
*q = (I16_64){ i }; // { dg-warning "writing (1 byte|64 bytes) into a region of size (0|63)" "pr97027" { xfail { ! { aarch64-*-* } } } } |
| 73 |
|
| 74 |
char a64[64]; |
| 75 |
p = a64 + 1; |
| 76 |
q = (I16_64*)p; |
| 77 |
*q = (I16_64){ i }; // { dg-warning "writing (1 byte|64 bytes) into a region of size (0|63)" "pr97027" { xfail { ! { aarch64-*-* } } } } |
| 78 |
sink (p); |
| 79 |
} |