77 lines · cpp
1// RUN: %clang_cc1 -verify -fsyntax-only %s -Wno-c++17-extensions2 3int bar();4 5[[gnu::always_inline]] void always_inline_fn(void) {}6// expected-note@+1{{conflicting attribute is here}}7[[gnu::flatten]] void flatten_fn(void) {}8// expected-note@+1{{conflicting attribute is here}}9[[gnu::noinline]] void noinline_fn(void) {}10 11void foo() {12 [[clang::always_inline]] bar();13 [[clang::always_inline(0)]] bar(); // expected-error {{'clang::always_inline' attribute takes no arguments}}14 int x;15 [[clang::always_inline]] int i = bar(); // expected-warning {{'clang::always_inline' attribute only applies to functions and statements}}16 [[clang::always_inline]] x = 0; // expected-warning {{'clang::always_inline' attribute is ignored because there exists no call expression inside the statement}}17 [[clang::always_inline]] { asm("nop"); } // expected-warning {{'clang::always_inline' attribute is ignored because there exists no call expression inside the statement}}18 [[clang::always_inline]] label : x = 1; // expected-warning {{'clang::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 'clang::always_inline' has higher precedence than function attribute 'noinline'}}22 [[clang::always_inline]] flatten_fn(); // expected-warning {{statement attribute 'clang::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 {{'clang::always_inline' attribute only applies to functions and statements}}29 30// This used to crash the compiler.31template<int D>32int foo(int x) {33 [[clang::always_inline]] return foo<D-1>(x + 1);34}35 36template<int D>37[[gnu::noinline]]38int dependent(int x){ return x + D;} // #DEP39[[gnu::noinline]]40int non_dependent(int x){return x;} // #NO_DEP41 42template<int D> [[gnu::noinline]]43int baz(int x) { // #BAZ44 // expected-warning@+2{{statement attribute 'clang::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 'clang::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 'clang::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.60template<int ... D>61int 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 'clang::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 'clang::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 72void use() {73 baz<3>(0); // #BAZ_INST74 variadic_baz<0, 1, 2>(0); // #VARIADIC_INST75 76}77