Author: Fangrui Song
Date: 2021-06-22T11:20:49-07:00
New Revision: 948016228fdfb647ad7bcc978fde173504e3df82

URL: 
https://github.com/llvm/llvm-project/commit/948016228fdfb647ad7bcc978fde173504e3df82
DIFF: 
https://github.com/llvm/llvm-project/commit/948016228fdfb647ad7bcc978fde173504e3df82.diff

LOG: Improve clang -Wframe-larger-than= diagnostic

Match the style in D104667.

This commit is for non-LTO diagnostics, while D104667 is for LTO and llc 
diagnostics.

Added: 
    

Modified: 
    clang/include/clang/Basic/DiagnosticFrontendKinds.td
    clang/lib/CodeGen/CodeGenAction.cpp
    clang/test/Frontend/backend-diagnostic.c
    clang/test/Misc/backend-stack-frame-diagnostics-fallback.cpp
    clang/test/Misc/backend-stack-frame-diagnostics.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index e68058dd19b5b..0f4ccec385506 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -25,7 +25,7 @@ def note_fe_source_mgr : Note<"%0">, CatSourceMgr;
 def err_fe_cannot_link_module : Error<"cannot link module '%0': %1">,
   DefaultFatal;
 
-def warn_fe_frame_larger_than : Warning<"stack frame size of %0 bytes in %q1">,
+def warn_fe_frame_larger_than : Warning<"stack frame size (%0) exceeds limit 
(%1) in %q2">,
     BackendInfo, InGroup<BackendFrameLargerThan>;
 def warn_fe_backend_frame_larger_than: Warning<"%0">,
     BackendInfo, InGroup<BackendFrameLargerThan>;

diff  --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 02dcea2865058..b30bd11edbadb 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -571,7 +571,9 @@ BackendConsumer::StackSizeDiagHandler(const 
llvm::DiagnosticInfoStackSize &D) {
     // FIXME: Shouldn't need to truncate to uint32_t
     Diags.Report(ND->getASTContext().getFullLoc(ND->getLocation()),
                  diag::warn_fe_frame_larger_than)
-      << static_cast<uint32_t>(D.getStackSize()) << 
Decl::castToDeclContext(ND);
+        << static_cast<uint32_t>(D.getStackSize())
+        << static_cast<uint32_t>(D.getStackLimit())
+        << Decl::castToDeclContext(ND);
     return true;
   }
 

diff  --git a/clang/test/Frontend/backend-diagnostic.c 
b/clang/test/Frontend/backend-diagnostic.c
index 01029d7f83d66..695158cdd186e 100644
--- a/clang/test/Frontend/backend-diagnostic.c
+++ b/clang/test/Frontend/backend-diagnostic.c
@@ -15,9 +15,9 @@
 
 extern void doIt(char *);
 
-// REGULAR: warning: stack frame size of {{[0-9]+}} bytes in function 
'stackSizeWarning'
-// PROMOTE: error: stack frame size of {{[0-9]+}} bytes in function 
'stackSizeWarning'
-// IGNORE-NOT: stack frame size of {{[0-9]+}} bytes in function 
'stackSizeWarning'
+// REGULAR: warning: stack frame size ([[#]]) exceeds limit ([[#]]) in 
function 'stackSizeWarning'
+// PROMOTE: error: stack frame size ([[#]]) exceeds limit ([[#]]) in function 
'stackSizeWarning'
+// IGNORE-NOT: stack frame size ([[#]]) exceeds limit ([[#]]) in function 
'stackSizeWarning'
 void stackSizeWarning() {
   char buffer[80];
   doIt(buffer);

diff  --git a/clang/test/Misc/backend-stack-frame-diagnostics-fallback.cpp 
b/clang/test/Misc/backend-stack-frame-diagnostics-fallback.cpp
index d28d54b0e8a2d..79c6ba9b23f6d 100644
--- a/clang/test/Misc/backend-stack-frame-diagnostics-fallback.cpp
+++ b/clang/test/Misc/backend-stack-frame-diagnostics-fallback.cpp
@@ -12,7 +12,7 @@ namespace frameSizeThunkWarning {
     virtual void f();
   };
 
-  // CHECK: warning: stack frame size of {{[0-9]+}} bytes in function 
'frameSizeThunkWarning::B::f'
+  // CHECK: warning: stack frame size ([[#]]) exceeds limit ([[#]]) in 
function 'frameSizeThunkWarning::B::f'
   // CHECK: warning: stack frame size ([[#]]) exceeds limit in function 
'_ZTv0_n12_N21frameSizeThunkWarning1B1fEv'
   void B::f() {
     volatile int x = 0; // Ensure there is stack usage.

diff  --git a/clang/test/Misc/backend-stack-frame-diagnostics.cpp 
b/clang/test/Misc/backend-stack-frame-diagnostics.cpp
index b02e7f4c471d5..f0ceac00ea357 100644
--- a/clang/test/Misc/backend-stack-frame-diagnostics.cpp
+++ b/clang/test/Misc/backend-stack-frame-diagnostics.cpp
@@ -26,7 +26,7 @@ void frameSizeWarning(int, int) {}
 
 void frameSizeWarning();
 
-void frameSizeWarning() { // expected-warning-re {{stack frame size of 
{{[0-9]+}} bytes in function 'frameSizeWarning'}}
+void frameSizeWarning() { // expected-warning-re {{stack frame size 
({{[0-9]+}}) exceeds limit ({{[0-9]+}}) in function 'frameSizeWarning'}}
   char buffer[80];
   doIt(buffer);
 }
@@ -45,7 +45,7 @@ void frameSizeWarningIgnored() {
 
 void frameSizeLocalClassWarning() {
   struct S {
-    S() { // expected-warning-re {{stack frame size of {{[0-9]+}} bytes in 
function 'frameSizeLocalClassWarning()::S::S'}}
+    S() { // expected-warning-re {{stack frame size ({{[0-9]+}}) exceeds limit 
({{[0-9]+}}) in function 'frameSizeLocalClassWarning()::S::S'}}
       char buffer[80];
       doIt(buffer);
     }
@@ -55,7 +55,7 @@ void frameSizeLocalClassWarning() {
 
 void frameSizeLambdaWarning() {
   auto fn =
-      []() { // expected-warning-re {{stack frame size of {{[0-9]+}} bytes in 
lambda expression}}
+      []() { // expected-warning-re {{stack frame size ({{[0-9]+}}) exceeds 
limit ({{[0-9]+}}) in lambda expression}}
     char buffer[80];
     doIt(buffer);
   };
@@ -64,7 +64,7 @@ void frameSizeLambdaWarning() {
 
 void frameSizeBlocksWarning() {
   auto fn =
-      ^() { // expected-warning-re {{stack frame size of {{[0-9]+}} bytes in 
block literal}}
+      ^() { // expected-warning-re {{stack frame size ({{[0-9]+}}) exceeds 
limit ({{[0-9]+}}) in block literal}}
     char buffer[80];
     doIt(buffer);
   };


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to