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