xref: /aosp_15_r20/external/clang/test/SemaCXX/attr-no-sanitize.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
2*67e74705SXin Li // RUN: not %clang_cc1 -std=c++11 -ast-dump %s | FileCheck --check-prefix=DUMP %s
3*67e74705SXin Li // RUN: not %clang_cc1 -std=c++11 -ast-print %s | FileCheck --check-prefix=PRINT %s
4*67e74705SXin Li 
5*67e74705SXin Li int v1 __attribute__((no_sanitize("address"))); // expected-error{{'no_sanitize' attribute only applies to functions and methods}}
6*67e74705SXin Li 
7*67e74705SXin Li int f1() __attribute__((no_sanitize)); // expected-error{{'no_sanitize' attribute takes at least 1 argument}}
8*67e74705SXin Li 
9*67e74705SXin Li int f2() __attribute__((no_sanitize(1))); // expected-error{{'no_sanitize' attribute requires a string}}
10*67e74705SXin Li 
11*67e74705SXin Li // DUMP-LABEL: FunctionDecl {{.*}} f3
12*67e74705SXin Li // DUMP: NoSanitizeAttr {{.*}} address
13*67e74705SXin Li // PRINT: int f3() __attribute__((no_sanitize("address")))
14*67e74705SXin Li int f3() __attribute__((no_sanitize("address")));
15*67e74705SXin Li 
16*67e74705SXin Li // DUMP-LABEL: FunctionDecl {{.*}} f4
17*67e74705SXin Li // DUMP: NoSanitizeAttr {{.*}} thread
18*67e74705SXin Li // PRINT: int f4() {{\[\[}}clang::no_sanitize("thread")]]
19*67e74705SXin Li [[clang::no_sanitize("thread")]] int f4();
20*67e74705SXin Li 
21*67e74705SXin Li // DUMP-LABEL: FunctionDecl {{.*}} f5
22*67e74705SXin Li // DUMP: NoSanitizeAttr {{.*}} address thread
23*67e74705SXin Li // PRINT: int f5() __attribute__((no_sanitize("address", "thread")))
24*67e74705SXin Li int f5() __attribute__((no_sanitize("address", "thread")));
25*67e74705SXin Li 
26*67e74705SXin Li // DUMP-LABEL: FunctionDecl {{.*}} f6
27*67e74705SXin Li // DUMP: NoSanitizeAttr {{.*}} unknown
28*67e74705SXin Li // PRINT: int f6() __attribute__((no_sanitize("unknown")))
29*67e74705SXin Li int f6() __attribute__((no_sanitize("unknown"))); // expected-warning{{unknown sanitizer 'unknown' ignored}}
30