| 1 |
/* PR middle-end/92721 - checking ICE on attribute access redeclaration |
| 2 |
Test to verify the handling of attribute access combining multiple |
| 3 |
declarations of the same function. |
| 4 |
{ dg-do compile } |
| 5 |
{ dg-options "-O0 -Wall -ftrack-macro-expansion=0" } */ |
| 6 |
|
| 7 |
#define RO(...) __attribute__ ((access (read_only, __VA_ARGS__))) |
| 8 |
#define RW(...) __attribute__ ((access (read_write, __VA_ARGS__))) |
| 9 |
#define WO(...) __attribute__ ((access (write_only, __VA_ARGS__))) |
| 10 |
|
| 11 |
typedef __INT32_TYPE__ int32_t; |
| 12 |
|
| 13 |
void RO (1) RO (1) rop1_ror2 (const int32_t*, const int32_t&); |
| 14 |
void RO (1) RO (2) rop1_ror2 (const int32_t*, const int32_t&); |
| 15 |
void RO (2) RO (1) rop1_ror2 (const int32_t*, const int32_t&); |
| 16 |
void RO (2) RO (2) rop1_ror2 (const int32_t*, const int32_t&); |
| 17 |
|
| 18 |
void RW (1) RW (1) rdwrp1_rdwrr2 (int32_t*, int32_t&); |
| 19 |
void RW (1) RW (2) rdwrp1_rdwrr2 (int32_t*, int32_t&); |
| 20 |
void RW (2) RW (1) rdwrp1_rdwrr2 (int32_t*, int32_t&); |
| 21 |
void RW (2) RW (2) rdwrp1_rdwrr2 (int32_t*, int32_t&); |
| 22 |
|
| 23 |
void WO (1) WO (1) wop1_wor2 (int32_t*, int32_t&); |
| 24 |
void WO (1) WO (2) wop1_wor2 (int32_t*, int32_t&); |
| 25 |
void WO (2) WO (1) wop1_wor2 (int32_t*, int32_t&); |
| 26 |
void WO (2) WO (2) wop1_wor2 (int32_t*, int32_t&); |
| 27 |
|
| 28 |
|
| 29 |
// Verify that everything works even with no optimization. |
| 30 |
|
| 31 |
void call_rop1_ror2_O0 (void) |
| 32 |
{ |
| 33 |
const int32_t x[1] = { }; |
| 34 |
|
| 35 |
rop1_ror2 (x, x[0]); |
| 36 |
rop1_ror2 (x, x[1]); // { dg-warning "reading 4 bytes from a region of size 0" } |
| 37 |
rop1_ror2 (x + 1, x[0]); // { dg-warning "reading 4 bytes from a region of size 0" } |
| 38 |
} |
| 39 |
|
| 40 |
void call_rdwrp1_rdwrr2_O0 (void) |
| 41 |
{ |
| 42 |
int32_t x[1] = { }; |
| 43 |
|
| 44 |
rdwrp1_rdwrr2 (x, x[0]); |
| 45 |
rdwrp1_rdwrr2 (x, x[1]); // { dg-warning "accessing 4 bytes in a region of size 0" } |
| 46 |
rdwrp1_rdwrr2 (x + 1, x[0]); // { dg-warning "accessing 4 bytes in a region of size 0" } |
| 47 |
} |
| 48 |
|
| 49 |
void call_wop1_wor2_O0 (void) |
| 50 |
{ |
| 51 |
int32_t x[1]; |
| 52 |
|
| 53 |
wop1_wor2 (x, x[0]); |
| 54 |
wop1_wor2 (x, x[1]); // { dg-warning "writing 4 bytes into a region of size 0" } |
| 55 |
wop1_wor2 (x + 1, x[0]); // { dg-warning "writing 4 bytes into a region of size 0" } |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
// Verify that everything still works with -O1. |
| 60 |
|
| 61 |
#pragma GCC optimize "1" |
| 62 |
|
| 63 |
void call_rop1_ror2_O1 (void) |
| 64 |
{ |
| 65 |
const int32_t x[1] = { 1 }; |
| 66 |
const int32_t *p0 = x, &r0 = x[0]; |
| 67 |
const int32_t *p1 = (const int32_t*)((const char*)p0 + 1); |
| 68 |
const int32_t &r2 = *(const int32_t*)((const char*)p1 + 1); |
| 69 |
|
| 70 |
rop1_ror2 (x, x[0]); |
| 71 |
rop1_ror2 (x, x[1]); // { dg-warning "reading 4 bytes from a region of size 0" } |
| 72 |
rop1_ror2 (x + 1, x[0]); // { dg-warning "reading 4 bytes from a region of size 0" } |
| 73 |
|
| 74 |
rop1_ror2 (p0, r0); |
| 75 |
rop1_ror2 (p0, r2); // { dg-warning "reading 4 bytes from a region of size 2" } |
| 76 |
rop1_ror2 (p1, r0); // { dg-warning "reading 4 bytes from a region of size 3" } |
| 77 |
} |
| 78 |
|
| 79 |
void call_rdwrp1_rdwrr2_O1 (void) |
| 80 |
{ |
| 81 |
int32_t x[1] = { }; |
| 82 |
int32_t *p0 = x, &r0 = x[0]; |
| 83 |
int32_t *p1 = (int32_t*)((char*)p0 + 1); |
| 84 |
int32_t &r2 = *(int32_t*)((char*)p1 + 1); |
| 85 |
|
| 86 |
rdwrp1_rdwrr2 (x, x[0]); |
| 87 |
rdwrp1_rdwrr2 (x, x[1]); // { dg-warning "accessing 4 bytes in a region of size 0" } |
| 88 |
rdwrp1_rdwrr2 (x + 1, x[0]); // { dg-warning "accessing 4 bytes in a region of size 0" } |
| 89 |
|
| 90 |
rdwrp1_rdwrr2 (p0, r0); |
| 91 |
rdwrp1_rdwrr2 (p0, r2); // { dg-warning "accessing 4 bytes in a region of size 2" } |
| 92 |
rdwrp1_rdwrr2 (p1, r0); // { dg-warning "accessing 4 bytes in a region of size 3" } |
| 93 |
} |
| 94 |
|
| 95 |
void call_wop1_wor2_O1 (void) |
| 96 |
{ |
| 97 |
int32_t x[1]; |
| 98 |
int32_t *p0 = x, &r0 = x[0]; |
| 99 |
int32_t *p1 = (int32_t*)((char*)p0 + 1); |
| 100 |
int32_t &r2 = *(int32_t*)((char*)p1 + 1); |
| 101 |
|
| 102 |
wop1_wor2 (x, x[0]); |
| 103 |
wop1_wor2 (x, x[1]); // { dg-warning "writing 4 bytes into a region of size 0" } |
| 104 |
wop1_wor2 (x + 1, x[0]); // { dg-warning "writing 4 bytes into a region of size 0" } |
| 105 |
|
| 106 |
wop1_wor2 (p0, r0); |
| 107 |
wop1_wor2 (p0, r2); // { dg-warning "writing 4 bytes into a region of size 2" } |
| 108 |
wop1_wor2 (p1, r0); // { dg-warning "writing 4 bytes into a region of size 3" } |
| 109 |
} |