| 1 |
// RUN: %clang_analyze_cc1 -triple x86_64-pc-linux-gnu -analyzer-checker=core,alpha.core -std=gnu99 -analyzer-config suppress-dereferences-from-any-address-space=false -verify=x86-nosuppress,common %s |
| 2 |
// RUN: %clang_analyze_cc1 -triple x86_64-pc-linux-gnu -analyzer-checker=core,alpha.core -std=gnu99 -verify=x86-suppress,common %s |
| 3 |
// RUN: %clang_analyze_cc1 -triple arm-pc-linux-gnu -analyzer-checker=core,alpha.core -std=gnu99 -analyzer-config suppress-dereferences-from-any-address-space=false -verify=other-nosuppress,common %s |
| 4 |
// RUN: %clang_analyze_cc1 -triple arm-pc-linux-gnu -analyzer-checker=core,alpha.core -std=gnu99 -verify=other-suppress,common %s |
| 5 |
|
| 6 |
#define AS_ATTRIBUTE(_X) volatile __attribute__((address_space(_X))) |
| 7 |
|
| 8 |
#define _get_base() ((void * AS_ATTRIBUTE(256) *)0) |
| 9 |
|
| 10 |
void* test_address_space_array(unsigned long slot) { |
| 11 |
return _get_base()[slot]; // other-nosuppress-warning{{Dereference}} |
| 12 |
} |
| 13 |
|
| 14 |
void test_address_space_condition(int AS_ATTRIBUTE(257) *cpu_data) { |
| 15 |
if (cpu_data == 0) { |
| 16 |
*cpu_data = 3; // other-nosuppress-warning{{Dereference}} |
| 17 |
} |
| 18 |
} |
| 19 |
|
| 20 |
struct X { int member; }; |
| 21 |
int test_address_space_member(void) { |
| 22 |
struct X AS_ATTRIBUTE(258) *data = (struct X AS_ATTRIBUTE(258) *)0UL; |
| 23 |
int ret; |
| 24 |
ret = data->member; // other-nosuppress-warning{{Dereference}} |
| 25 |
return ret; |
| 26 |
} |
| 27 |
|
| 28 |
void test_other_address_space_condition(int AS_ATTRIBUTE(259) *cpu_data) { |
| 29 |
if (cpu_data == 0) { |
| 30 |
*cpu_data = 3; // other-nosuppress-warning{{Dereference}} \ |
| 31 |
// x86-nosuppress-warning{{Dereference}} |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
void test_no_address_space_condition(int *cpu_data) { |
| 36 |
if (cpu_data == 0) { |
| 37 |
*cpu_data = 3; // common-warning{{Dereference}} |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
#define _fixed_get_base() ((void * AS_ATTRIBUTE(256) *)2) |
| 42 |
|
| 43 |
void* fixed_test_address_space_array(unsigned long slot) { |
| 44 |
return _fixed_get_base()[slot]; // other-nosuppress-warning{{Dereference}} |
| 45 |
} |
| 46 |
|
| 47 |
void fixed_test_address_space_condition(int AS_ATTRIBUTE(257) *cpu_data) { |
| 48 |
if (cpu_data == (int AS_ATTRIBUTE(257) *)2) { |
| 49 |
*cpu_data = 3; // other-nosuppress-warning{{Dereference}} |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
int fixed_test_address_space_member(void) { |
| 54 |
struct X AS_ATTRIBUTE(258) *data = (struct X AS_ATTRIBUTE(258) *)2UL; |
| 55 |
int ret; |
| 56 |
ret = data->member; // other-nosuppress-warning{{Dereference}} |
| 57 |
return ret; |
| 58 |
} |
| 59 |
|
| 60 |
void fixed_test_other_address_space_condition(int AS_ATTRIBUTE(259) *cpu_data) { |
| 61 |
if (cpu_data == (int AS_ATTRIBUTE(259) *)2) { |
| 62 |
*cpu_data = 3; // other-nosuppress-warning{{Dereference}} \ |
| 63 |
// x86-nosuppress-warning{{Dereference}} |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
void fixed_test_no_address_space_condition(int *cpu_data) { |
| 68 |
if (cpu_data == (int *)2) { |
| 69 |
*cpu_data = 3; // common-warning{{Dereference}} |
| 70 |
} |
| 71 |
} |