backend-stack-frame-diagnostics.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. // Test that:
  5. // * The driver passes the option through to the backend.
  6. // * The frontend diagnostic handler 'demangles' and resolves the correct function definition.
  7. // Test that link invocations don't emit an "argument unused during compilation" diagnostic.
  8. // RUN: touch %t.o
  9. // RUN: %clang -Werror -Wframe-larger-than=0 %t.o -### 2>&1 | not grep ' error: '
  10. // TODO: Support rich backend diagnostics for Objective-C methods.
  11. // Backend diagnostics aren't suppressed in system headers because such results
  12. // are significant and actionable.
  13. #ifdef IS_HEADER
  14. #ifdef IS_SYSHEADER
  15. #pragma clang system_header
  16. #endif
  17. extern void doIt(char *);
  18. void frameSizeWarning(int, int) {}
  19. void frameSizeWarning();
  20. void frameSizeWarning() { // expected-warning-re {{stack frame size of {{[0-9]+}} bytes in function 'frameSizeWarning'}}
  21. char buffer[80];
  22. doIt(buffer);
  23. }
  24. void frameSizeWarning();
  25. void frameSizeWarning(int) {}
  26. #pragma GCC diagnostic push
  27. #pragma GCC diagnostic ignored "-Wframe-larger-than="
  28. void frameSizeWarningIgnored() {
  29. char buffer[80];
  30. doIt(buffer);
  31. }
  32. #pragma GCC diagnostic pop
  33. #pragma GCC diagnostic push
  34. #ifndef IS_SYSHEADER
  35. // expected-warning@+2 {{unknown warning group '-Wframe-larger-than'}}
  36. #endif
  37. #pragma GCC diagnostic ignored "-Wframe-larger-than"
  38. #pragma GCC diagnostic pop
  39. void frameSizeLocalClassWarning() {
  40. struct S {
  41. S() { // expected-warning-re {{stack frame size of {{[0-9]+}} bytes in function 'frameSizeLocalClassWarning()::S::S'}}
  42. char buffer[80];
  43. doIt(buffer);
  44. }
  45. };
  46. S();
  47. }
  48. void frameSizeLambdaWarning() {
  49. auto fn =
  50. []() { // expected-warning-re {{stack frame size of {{[0-9]+}} bytes in lambda expression}}
  51. char buffer[80];
  52. doIt(buffer);
  53. };
  54. fn();
  55. }
  56. void frameSizeBlocksWarning() {
  57. auto fn =
  58. ^() { // expected-warning-re {{stack frame size of {{[0-9]+}} bytes in block literal}}
  59. char buffer[80];
  60. doIt(buffer);
  61. };
  62. fn();
  63. }
  64. #else
  65. #define IS_HEADER
  66. #include __FILE__
  67. #endif