| 1 |
/* { dg-do compile } |
| 2 |
{ dg-options "-O0" } |
| 3 |
This testcase checks that warn_compare_distinct_pointer_types is enabled by |
| 4 |
default. */ |
| 5 |
|
| 6 |
typedef __INT32_TYPE__ __u32; |
| 7 |
|
| 8 |
struct xdp_md |
| 9 |
{ |
| 10 |
char *data; |
| 11 |
char *data_meta; |
| 12 |
}; |
| 13 |
|
| 14 |
int xdp_context (struct xdp_md *xdp) |
| 15 |
{ |
| 16 |
void *data = (void *)(__INTPTR_TYPE__)xdp->data; |
| 17 |
__u32 *metadata = (void *)(__INTPTR_TYPE__)xdp->data_meta; |
| 18 |
__u32 ret; |
| 19 |
|
| 20 |
if (metadata + 1 > data) /* { dg-warning "comparison of distinct pointer types" } */ |
| 21 |
return 1; |
| 22 |
if (metadata + 1 >= data) /* { dg-warning "comparison of distinct pointer types" } */ |
| 23 |
return 2; |
| 24 |
if (metadata + 1 < data) /* { dg-warning "comparison of distinct pointer types" } */ |
| 25 |
return 3; |
| 26 |
if (metadata + 1 <= data) /* { dg-warning "comparison of distinct pointer types" } */ |
| 27 |
return 4; |
| 28 |
/* Note that it is ok to check for equality or inequality betewen void |
| 29 |
pointers and any other non-function pointers. */ |
| 30 |
if ((int*) (metadata + 1) == (long*) data) /* { dg-warning "comparison of distinct pointer types" } */ |
| 31 |
return 5; |
| 32 |
if ((int*) metadata + 1 != (long*) data) /* { dg-warning "comparison of distinct pointer types" } */ |
| 33 |
return 5; |
| 34 |
|
| 35 |
return 1; |
| 36 |
} |