1*2d56fbf6SArthur Eubanks // REQUIRES: x86-registered-target
2*2d56fbf6SArthur Eubanks // RUN: %clang_cc1 -triple x86_64-linux-gnu -verify=expected,enabled -emit-codegen-only %s
3*2d56fbf6SArthur 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) {
26aa53785fSArthur Eubanks   foo(); // expected-error {{call to foo() declared with 'error' attribute: oh no foo}}
27aa53785fSArthur Eubanks   if (x())
28aa53785fSArthur Eubanks     bar(); // expected-error {{call to bar() declared with 'error' attribute: oh no bar}}
29aa53785fSArthur Eubanks 
30aa53785fSArthur Eubanks   quux();                     // enabled-warning {{call to quux() declared with 'warning' attribute: oh no quux}}
31aa53785fSArthur Eubanks   __compiletime_assert_455(); // expected-error {{call to __compiletime_assert_455() declared with 'error' attribute: demangle me}}
32aa53785fSArthur Eubanks   duplicate_errors();         // expected-error {{call to duplicate_errors() declared with 'error' attribute: two}}
33aa53785fSArthur Eubanks   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) {
48aa53785fSArthur Eubanks   foo(); // expected-error {{call to foo() declared with 'error' attribute: oh no foo}}
49aa53785fSArthur Eubanks   if (x())
50aa53785fSArthur Eubanks     bar(); // expected-error {{call to bar() declared with 'error' attribute: oh no bar}}
51aa53785fSArthur Eubanks   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++.
54aa53785fSArthur Eubanks   __compiletime_assert_455(); // expected-error {{call to __compiletime_assert_455() declared with 'error' attribute: demangle me}}
55aa53785fSArthur Eubanks   nocall<int>(42);            // expected-error {{call to int nocall<int>(int) declared with 'error' attribute: demangle me, too}}
56aa53785fSArthur Eubanks 
57aa53785fSArthur Eubanks   Widget W;
58aa53785fSArthur Eubanks   int w = W; // enabled-warning {{Widget::operator int() declared with 'warning' attribute: don't call me!}}
59aa53785fSArthur Eubanks }
60aa53785fSArthur Eubanks #endif
61