1 // RUN: %clang_cc1 -verify -fsyntax-only %s -Wno-c++17-extensions
2
3 int bar();
4
always_inline_fn(void)5 [[gnu::always_inline]] void always_inline_fn(void) {}
6 // expected-note@+1{{conflicting attribute is here}}
flatten_fn(void)7 [[gnu::flatten]] void flatten_fn(void) {}
8 // expected-note@+1{{conflicting attribute is here}}
noinline_fn(void)9 [[gnu::noinline]] void noinline_fn(void) {}
10
foo()11 void foo() {
12 [[clang::always_inline]] bar();
13 [[clang::always_inline(0)]] bar(); // expected-error {{'always_inline' attribute takes no arguments}}
14 int x;
15 [[clang::always_inline]] int i = bar(); // expected-warning {{'always_inline' attribute only applies to functions and statements}}
16 [[clang::always_inline]] x = 0; // expected-warning {{'always_inline' attribute is ignored because there exists no call expression inside the statement}}
17 [[clang::always_inline]] { asm("nop"); } // expected-warning {{'always_inline' attribute is ignored because there exists no call expression inside the statement}}
18 [[clang::always_inline]] label : x = 1; // expected-warning {{'always_inline' attribute only applies to functions and statements}}
19
20 [[clang::always_inline]] always_inline_fn();
21 [[clang::always_inline]] noinline_fn(); // expected-warning {{statement attribute 'always_inline' has higher precedence than function attribute 'noinline'}}
22 [[clang::always_inline]] flatten_fn(); // expected-warning {{statement attribute 'always_inline' has higher precedence than function attribute 'flatten'}}
23
24 [[gnu::always_inline]] bar(); // expected-warning {{attribute is ignored on this statement as it only applies to functions; use '[[clang::always_inline]]' on statements}}
25 __attribute__((always_inline)) bar(); // expected-warning {{attribute is ignored on this statement as it only applies to functions; use '[[clang::always_inline]]' on statements}}
26 }
27
28 [[clang::always_inline]] static int i = bar(); // expected-warning {{'always_inline' attribute only applies to functions and statements}}
29
30 // This used to crash the compiler.
31 template<int D>
foo(int x)32 int foo(int x) {
33 [[clang::always_inline]] return foo<D-1>(x + 1);
34 }
35
36 template<int D>
37 [[gnu::noinline]]
dependent(int x)38 int dependent(int x){ return x + D;} // #DEP
39 [[gnu::noinline]]
non_dependent(int x)40 int non_dependent(int x){return x;} // #NO_DEP
41
42 template<int D> [[gnu::noinline]]
baz(int x)43 int baz(int x) { // #BAZ
44 // expected-warning@+2{{statement attribute 'always_inline' has higher precedence than function attribute 'noinline'}}
45 // expected-note@#NO_DEP{{conflicting attribute is here}}
46 [[clang::always_inline]] non_dependent(x);
47 if constexpr (D>0) {
48 // expected-warning@+6{{statement attribute 'always_inline' has higher precedence than function attribute 'noinline'}}
49 // expected-note@#NO_DEP{{conflicting attribute is here}}
50 // expected-warning@+4 3{{statement attribute 'always_inline' has higher precedence than function attribute 'noinline'}}
51 // expected-note@#BAZ 3{{conflicting attribute is here}}
52 // expected-note@#BAZ_INST 3{{in instantiation}}
53 // expected-note@+1 3{{in instantiation}}
54 [[clang::always_inline]] return non_dependent(x), baz<D-1>(x + 1);
55 }
56 return x;
57 }
58
59 // We can't suppress if there is a variadic involved.
60 template<int ... D>
variadic_baz(int x)61 int variadic_baz(int x) {
62 // Diagnoses NO_DEP 2x, once during phase 1, the second during instantiation.
63 // Dianoses DEP 3x, once per variadic expansion.
64 // expected-warning@+5 2{{statement attribute 'always_inline' has higher precedence than function attribute 'noinline'}}
65 // expected-note@#NO_DEP 2{{conflicting attribute is here}}
66 // expected-warning@+3 3{{statement attribute 'always_inline' has higher precedence than function attribute 'noinline'}}
67 // expected-note@#DEP 3{{conflicting attribute is here}}
68 // expected-note@#VARIADIC_INST{{in instantiation}}
69 [[clang::always_inline]] return non_dependent(x) + (dependent<D>(x) + ...);
70 }
71
use()72 void use() {
73 baz<3>(0); // #BAZ_INST
74 variadic_baz<0, 1, 2>(0); // #VARIADIC_INST
75
76 }
77