xref: /minix3/external/bsd/llvm/dist/clang/test/Misc/backend-stack-frame-diagnostics.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // REQUIRES: x86-registered-target
2*0a6a1f1dSLionel Sambuc // RUN: %clang -target i386-apple-darwin -std=c++11 -fblocks -Wframe-larger-than=70 -Xclang -verify -o /dev/null -c %s
3*0a6a1f1dSLionel Sambuc // RUN: %clang -target i386-apple-darwin -std=c++11 -fblocks -Wframe-larger-than=70 -Xclang -verify -o /dev/null -c %s -DIS_SYSHEADER
4*0a6a1f1dSLionel Sambuc 
5*0a6a1f1dSLionel Sambuc // Test that:
6*0a6a1f1dSLionel Sambuc //  * The driver passes the option through to the backend.
7*0a6a1f1dSLionel Sambuc //  * The frontend diagnostic handler 'demangles' and resolves the correct function definition.
8*0a6a1f1dSLionel Sambuc 
9*0a6a1f1dSLionel Sambuc // Test that link invocations don't emit an "argument unused during compilation" diagnostic.
10*0a6a1f1dSLionel Sambuc // RUN: touch %t.o
11*0a6a1f1dSLionel Sambuc // RUN: %clang -Werror -Wframe-larger-than=0 %t.o -###  2>&1 | not grep ' error: '
12*0a6a1f1dSLionel Sambuc 
13*0a6a1f1dSLionel Sambuc // TODO: Support rich backend diagnostics for Objective-C methods.
14*0a6a1f1dSLionel Sambuc 
15*0a6a1f1dSLionel Sambuc // Backend diagnostics aren't suppressed in system headers because such results
16*0a6a1f1dSLionel Sambuc // are significant and actionable.
17*0a6a1f1dSLionel Sambuc #ifdef IS_HEADER
18*0a6a1f1dSLionel Sambuc 
19*0a6a1f1dSLionel Sambuc #ifdef IS_SYSHEADER
20*0a6a1f1dSLionel Sambuc #pragma clang system_header
21*0a6a1f1dSLionel Sambuc #endif
22*0a6a1f1dSLionel Sambuc 
23*0a6a1f1dSLionel Sambuc extern void doIt(char *);
24*0a6a1f1dSLionel Sambuc 
frameSizeWarning(int,int)25*0a6a1f1dSLionel Sambuc void frameSizeWarning(int, int) {}
26*0a6a1f1dSLionel Sambuc 
27*0a6a1f1dSLionel Sambuc void frameSizeWarning();
28*0a6a1f1dSLionel Sambuc 
frameSizeWarning()29*0a6a1f1dSLionel Sambuc void frameSizeWarning() { // expected-warning-re {{stack frame size of {{[0-9]+}} bytes in function 'frameSizeWarning'}}
30*0a6a1f1dSLionel Sambuc   char buffer[80];
31*0a6a1f1dSLionel Sambuc   doIt(buffer);
32*0a6a1f1dSLionel Sambuc }
33*0a6a1f1dSLionel Sambuc 
34*0a6a1f1dSLionel Sambuc void frameSizeWarning();
35*0a6a1f1dSLionel Sambuc 
frameSizeWarning(int)36*0a6a1f1dSLionel Sambuc void frameSizeWarning(int) {}
37*0a6a1f1dSLionel Sambuc 
38*0a6a1f1dSLionel Sambuc #pragma GCC diagnostic push
39*0a6a1f1dSLionel Sambuc #pragma GCC diagnostic ignored "-Wframe-larger-than="
frameSizeWarningIgnored()40*0a6a1f1dSLionel Sambuc void frameSizeWarningIgnored() {
41*0a6a1f1dSLionel Sambuc   char buffer[80];
42*0a6a1f1dSLionel Sambuc   doIt(buffer);
43*0a6a1f1dSLionel Sambuc }
44*0a6a1f1dSLionel Sambuc #pragma GCC diagnostic pop
45*0a6a1f1dSLionel Sambuc 
46*0a6a1f1dSLionel Sambuc #pragma GCC diagnostic push
47*0a6a1f1dSLionel Sambuc #ifndef IS_SYSHEADER
48*0a6a1f1dSLionel Sambuc // expected-warning@+2 {{unknown warning group '-Wframe-larger-than'}}
49*0a6a1f1dSLionel Sambuc #endif
50*0a6a1f1dSLionel Sambuc #pragma GCC diagnostic ignored "-Wframe-larger-than"
51*0a6a1f1dSLionel Sambuc #pragma GCC diagnostic pop
52*0a6a1f1dSLionel Sambuc 
frameSizeLocalClassWarning()53*0a6a1f1dSLionel Sambuc void frameSizeLocalClassWarning() {
54*0a6a1f1dSLionel Sambuc   struct S {
55*0a6a1f1dSLionel Sambuc     S() { // expected-warning-re {{stack frame size of {{[0-9]+}} bytes in function 'frameSizeLocalClassWarning()::S::S'}}
56*0a6a1f1dSLionel Sambuc       char buffer[80];
57*0a6a1f1dSLionel Sambuc       doIt(buffer);
58*0a6a1f1dSLionel Sambuc     }
59*0a6a1f1dSLionel Sambuc   };
60*0a6a1f1dSLionel Sambuc   S();
61*0a6a1f1dSLionel Sambuc }
62*0a6a1f1dSLionel Sambuc 
frameSizeLambdaWarning()63*0a6a1f1dSLionel Sambuc void frameSizeLambdaWarning() {
64*0a6a1f1dSLionel Sambuc   auto fn =
65*0a6a1f1dSLionel Sambuc       []() { // expected-warning-re {{stack frame size of {{[0-9]+}} bytes in lambda expression}}
66*0a6a1f1dSLionel Sambuc     char buffer[80];
67*0a6a1f1dSLionel Sambuc     doIt(buffer);
68*0a6a1f1dSLionel Sambuc   };
69*0a6a1f1dSLionel Sambuc   fn();
70*0a6a1f1dSLionel Sambuc }
71*0a6a1f1dSLionel Sambuc 
frameSizeBlocksWarning()72*0a6a1f1dSLionel Sambuc void frameSizeBlocksWarning() {
73*0a6a1f1dSLionel Sambuc   auto fn =
74*0a6a1f1dSLionel Sambuc       ^() { // expected-warning-re {{stack frame size of {{[0-9]+}} bytes in block literal}}
75*0a6a1f1dSLionel Sambuc     char buffer[80];
76*0a6a1f1dSLionel Sambuc     doIt(buffer);
77*0a6a1f1dSLionel Sambuc   };
78*0a6a1f1dSLionel Sambuc   fn();
79*0a6a1f1dSLionel Sambuc }
80*0a6a1f1dSLionel Sambuc 
81*0a6a1f1dSLionel Sambuc #else
82*0a6a1f1dSLionel Sambuc 
83*0a6a1f1dSLionel Sambuc #define IS_HEADER
84*0a6a1f1dSLionel Sambuc #include __FILE__
85*0a6a1f1dSLionel Sambuc #endif
86