xref: /llvm-project/clang/test/Frontend/backend-attribute-error-warning.cpp (revision e588d23a91fd28cd4218995a33c2a46fe721ff62)
12d56fbf6SArthur Eubanks // REQUIRES: x86-registered-target
22d56fbf6SArthur Eubanks // RUN: %clang_cc1 -triple x86_64-linux-gnu -verify=expected,enabled -emit-codegen-only %s
32d56fbf6SArthur Eubanks // RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -emit-codegen-only -Wno-attribute-warning %s
4aa53785fSArthur Eubanks 
5aa53785fSArthur Eubanks __attribute__((error("oh no foo"))) void foo(void);
6aa53785fSArthur Eubanks 
7aa53785fSArthur Eubanks __attribute__((error("oh no bar"))) void bar(void);
8aa53785fSArthur Eubanks 
x(void)9aa53785fSArthur Eubanks int x(void) {
10aa53785fSArthur Eubanks   return 8 % 2 == 1;
11aa53785fSArthur Eubanks }
12aa53785fSArthur Eubanks 
13aa53785fSArthur Eubanks __attribute__((warning("oh no quux"))) void quux(void);
14aa53785fSArthur Eubanks 
15aa53785fSArthur Eubanks __attribute__((error("demangle me"))) void __compiletime_assert_455(void);
16aa53785fSArthur Eubanks 
17aa53785fSArthur Eubanks __attribute__((error("one"), error("two"))) // expected-warning {{attribute 'error' is already applied with different arguments}}
18aa53785fSArthur Eubanks void                                        // expected-note@-1 {{previous attribute is here}}
19aa53785fSArthur Eubanks duplicate_errors(void);
20aa53785fSArthur Eubanks 
21aa53785fSArthur Eubanks __attribute__((warning("one"), warning("two"))) // expected-warning {{attribute 'warning' is already applied with different arguments}}
22aa53785fSArthur Eubanks void                                            // expected-note@-1 {{previous attribute is here}}
23aa53785fSArthur Eubanks duplicate_warnings(void);
24aa53785fSArthur Eubanks 
baz(void)25aa53785fSArthur Eubanks void baz(void) {
26*e588d23aSFangrui Song   foo(); // expected-error {{call to 'foo()' declared with 'error' attribute: oh no foo}}
27aa53785fSArthur Eubanks   if (x())
28*e588d23aSFangrui Song     bar(); // expected-error {{call to 'bar()' declared with 'error' attribute: oh no bar}}
29aa53785fSArthur Eubanks 
30*e588d23aSFangrui Song   quux();                     // enabled-warning {{call to 'quux()' declared with 'warning' attribute: oh no quux}}
31*e588d23aSFangrui Song   __compiletime_assert_455(); // expected-error {{call to '__compiletime_assert_455()' declared with 'error' attribute: demangle me}}
32*e588d23aSFangrui Song   duplicate_errors();         // expected-error {{call to 'duplicate_errors()' declared with 'error' attribute: two}}
33*e588d23aSFangrui Song   duplicate_warnings();       // enabled-warning {{call to 'duplicate_warnings()' declared with 'warning' attribute: two}}
34aa53785fSArthur Eubanks }
35aa53785fSArthur Eubanks 
36aa53785fSArthur Eubanks #ifdef __cplusplus
37aa53785fSArthur Eubanks template <typename T>
38aa53785fSArthur Eubanks __attribute__((error("demangle me, too")))
39aa53785fSArthur Eubanks T
40aa53785fSArthur Eubanks nocall(T t);
41aa53785fSArthur Eubanks 
42aa53785fSArthur Eubanks struct Widget {
43aa53785fSArthur Eubanks   __attribute__((warning("don't call me!")))
operator intWidget44aa53785fSArthur Eubanks   operator int() { return 42; }
45aa53785fSArthur Eubanks };
46aa53785fSArthur Eubanks 
baz_cpp(void)47aa53785fSArthur Eubanks void baz_cpp(void) {
48*e588d23aSFangrui Song   foo(); // expected-error {{call to 'foo()' declared with 'error' attribute: oh no foo}}
49aa53785fSArthur Eubanks   if (x())
50*e588d23aSFangrui Song     bar(); // expected-error {{call to 'bar()' declared with 'error' attribute: oh no bar}}
51*e588d23aSFangrui Song   quux();  // enabled-warning {{call to 'quux()' declared with 'warning' attribute: oh no quux}}
52aa53785fSArthur Eubanks 
53aa53785fSArthur Eubanks   // Test that we demangle correctly in the diagnostic for C++.
54*e588d23aSFangrui Song   __compiletime_assert_455(); // expected-error {{call to '__compiletime_assert_455()' declared with 'error' attribute: demangle me}}
55*e588d23aSFangrui Song   nocall<int>(42);            // expected-error {{call to 'int nocall<int>(int)' declared with 'error' attribute: demangle me, too}}
56aa53785fSArthur Eubanks 
57aa53785fSArthur Eubanks   Widget W;
58*e588d23aSFangrui Song   int w = W; // enabled-warning {{call to 'Widget::operator int()' declared with 'warning' attribute: don't call me!}}
59aa53785fSArthur Eubanks }
60aa53785fSArthur Eubanks #endif
61