72 lines · c
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 %s2// RUN: %clang_analyze_cc1 -triple x86_64-pc-linux-gnu -analyzer-checker=core,alpha.core -std=gnu99 -verify=x86-suppress,common %s3// 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 %s4// RUN: %clang_analyze_cc1 -triple arm-pc-linux-gnu -analyzer-checker=core,alpha.core -std=gnu99 -verify=other-suppress,common %s5 6#define AS_ATTRIBUTE(_X) volatile __attribute__((address_space(_X)))7 8#define _get_base() ((void * AS_ATTRIBUTE(256) *)0)9 10void* test_address_space_array(unsigned long slot) {11 return _get_base()[slot]; // other-nosuppress-warning{{Dereference}}12}13 14void 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 20struct X { int member; };21int 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 28void 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 35void 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 43void* fixed_test_address_space_array(unsigned long slot) {44 return _fixed_get_base()[slot]; // other-nosuppress-warning{{Dereference}}45}46 47void 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 53int 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 60void 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 67void fixed_test_no_address_space_condition(int *cpu_data) {68 if (cpu_data == (int *)2) {69 *cpu_data = 3; // common-warning{{Dereference}}70 }71}72