Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Preprocessor / has_c_attribute.c
blob3332571d758c84f8ef63aa65175b238cc61b0373
1 // RUN: %clang_cc1 -std=c11 -E -P %s -o - | FileCheck %s
2 // RUN: %clang_cc1 -std=c2x -E -P %s -o - | FileCheck %s
4 #define C2x(x) x: __has_c_attribute(x)
6 // CHECK: fallthrough: 201910L
7 C2x(fallthrough)
9 // CHECK: __nodiscard__: 202003L
10 C2x(__nodiscard__)
12 // CHECK: warn_unused_result: 0
13 C2x(warn_unused_result)
15 // CHECK: gnu::warn_unused_result: 1
16 C2x(gnu::warn_unused_result)
18 // CHECK: clang::warn_unused_result: 0
19 C2x(clang::warn_unused_result)
21 // CHECK: selectany: 0
22 C2x(selectany); // Known attribute not supported in C mode
24 // CHECK: frobble: 0
25 C2x(frobble) // Unknown attribute
27 // CHECK: frobble::frobble: 0
28 C2x(frobble::frobble) // Unknown vendor namespace
30 // CHECK: clang::annotate: 1
31 C2x(clang::annotate)
33 // CHECK: deprecated: 201904L
34 C2x(deprecated)
36 // CHECK: maybe_unused: 202106L
37 C2x(maybe_unused)
39 // CHECK: __gnu__::warn_unused_result: 1
40 C2x(__gnu__::warn_unused_result)
42 // CHECK: gnu::__warn_unused_result__: 1
43 C2x(gnu::__warn_unused_result__)
45 // Test that macro expansion of the builtin argument works.
46 #define C clang
47 #define L likely
48 #define CL clang::likely
49 #define N nodiscard
51 #if __has_c_attribute(N)
52 int has_nodiscard;
53 #endif
54 // CHECK: int has_nodiscard;
56 #if __has_c_attribute(C::L)
57 int has_clang_likely_1;
58 #endif
59 // CHECK: int has_clang_likely_1;
61 #if __has_c_attribute(clang::L)
62 int has_clang_likely_2;
63 #endif
64 // CHECK: int has_clang_likely_2;
66 #if __has_c_attribute(C::likely)
67 int has_clang_likely_3;
68 #endif
69 // CHECK: int has_clang_likely_3;
71 #if __has_c_attribute(CL)
72 int has_clang_likely_4;
73 #endif
74 // CHECK: int has_clang_likely_4;
76 #define FUNCLIKE1(x) clang::x
77 #if __has_c_attribute(FUNCLIKE1(likely))
78 int funclike_1;
79 #endif
80 // CHECK: int funclike_1;
82 #define FUNCLIKE2(x) _Clang::x
83 #if __has_c_attribute(FUNCLIKE2(likely))
84 int funclike_2;
85 #endif
86 // CHECK: int funclike_2;