blob: 6556e7bf1df09128599317541d3a4d2c0be7b637 [file] [log] [blame]
Kostya Serebryany71efba02012-01-24 19:25:38 +00001// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
Richard Smithd6396a62012-11-05 22:21:05 +00002// RUN: %clang_cc1 -emit-llvm -o - %s -fsanitize=address | FileCheck -check-prefix ASAN %s
Will Dietz4f45bc02013-01-18 11:30:38 +00003// RUN: echo "src:%s" > %t
4// RUN: %clang_cc1 -emit-llvm -o - %s -fsanitize=address -fsanitize-blacklist=%t | FileCheck %s
Kostya Serebryany71efba02012-01-24 19:25:38 +00005
6// The address_safety attribute should be attached to functions
7// when AddressSanitizer is enabled, unless no_address_safety_analysis attribute
8// is present.
9
10// CHECK-NOT: NoAddressSafety1{{.*}} address_safety
11// ASAN-NOT: NoAddressSafety1{{.*}} address_safety
12__attribute__((no_address_safety_analysis))
13int NoAddressSafety1(int *a) { return *a; }
14
15// CHECK-NOT: NoAddressSafety2{{.*}} address_safety
16// ASAN-NOT: NoAddressSafety2{{.*}} address_safety
17__attribute__((no_address_safety_analysis))
18int NoAddressSafety2(int *a);
19int NoAddressSafety2(int *a) { return *a; }
20
21// CHECK-NOT: AddressSafetyOk{{.*}} address_safety
22// ASAN: AddressSafetyOk{{.*}} address_safety
23int AddressSafetyOk(int *a) { return *a; }
24
25// CHECK-NOT: TemplateNoAddressSafety{{.*}} address_safety
26// ASAN-NOT: TemplateNoAddressSafety{{.*}} address_safety
27template<int i>
28__attribute__((no_address_safety_analysis))
29int TemplateNoAddressSafety() { return i; }
30
31// CHECK-NOT: TemplateAddressSafetyOk{{.*}} address_safety
32// ASAN: TemplateAddressSafetyOk{{.*}} address_safety
33template<int i>
34int TemplateAddressSafetyOk() { return i; }
35
36int force_instance = TemplateAddressSafetyOk<42>()
37 + TemplateNoAddressSafety<42>();
Kostya Serebryanyb9d2b3b2012-06-26 08:56:33 +000038
39// Check that __cxx_global_var_init* get the address_safety attribute.
40int global1 = 0;
41int global2 = *(int*)((char*)&global1+1);
42// CHECK-NOT: @__cxx_global_var_init{{.*}}address_safety
43// ASAN: @__cxx_global_var_init{{.*}}address_safety