[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / Sema / no-builtin.cpp
blob1312d32e22b0b5f547515adfd6ebeef48621fedf
1 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s
3 /// Prevent use of all builtins.
4 void valid_attribute_all_1() __attribute__((no_builtin)) {}
5 void valid_attribute_all_2() __attribute__((no_builtin())) {}
7 /// Prevent use of specific builtins.
8 void valid_attribute_function() __attribute__((no_builtin("memcpy"))) {}
9 void valid_attribute_functions() __attribute__((no_builtin("memcpy"))) __attribute__((no_builtin("memcmp"))) {}
11 /// Many times the same builtin is fine.
12 void many_attribute_function_1() __attribute__((no_builtin)) __attribute__((no_builtin)) {}
13 void many_attribute_function_2() __attribute__((no_builtin("memcpy"))) __attribute__((no_builtin("memcpy"))) {}
14 void many_attribute_function_3() __attribute__((no_builtin("memcpy", "memcpy"))) {}
15 void many_attribute_function_4() __attribute__((no_builtin("memcpy", "memcpy"))) __attribute__((no_builtin("memcpy"))) {}
17 /// Invalid builtin name.
18 void invalid_builtin() __attribute__((no_builtin("not_a_builtin"))) {}
19 // expected-warning@-1 {{'not_a_builtin' is not a valid builtin name for 'no_builtin'}}
21 /// Can't use bare no_builtin with a named one.
22 void wildcard_and_functionname() __attribute__((no_builtin)) __attribute__((no_builtin("memcpy"))) {}
23 // expected-error@-1 {{empty 'no_builtin' cannot be composed with named ones}}
25 /// Can't attach attribute to a variable.
26 int __attribute__((no_builtin)) variable;
27 // expected-warning@-1 {{'no_builtin' attribute only applies to functions}}
29 /// Can't attach attribute to a declaration.
30 void nobuiltin_on_declaration() __attribute__((no_builtin));
31 // expected-error@-1 {{no_builtin attribute is permitted on definitions only}}
33 struct S {
34 /// Can't attach attribute to a defaulted function,
35 S()
36 __attribute__((no_builtin)) = default;
37 // expected-error@-1 {{no_builtin attribute has no effect on defaulted or deleted functions}}
39 /// Can't attach attribute to a deleted function,
40 S(const S &)
41 __attribute__((no_builtin)) = delete;
42 // expected-error@-1 {{no_builtin attribute has no effect on defaulted or deleted functions}}
44 void whatever() __attribute__((no_builtin("memcpy")));
45 // expected-error@-1 {{no_builtin attribute is permitted on definitions only}}
48 /// Can't attach attribute to an aliased function.
49 void alised_function() {}
50 void aliasing_function() __attribute__((no_builtin)) __attribute__((alias("alised_function")));
51 // expected-error@-1 {{no_builtin attribute is permitted on definitions only}}