[PATCH] D108686: [clang] Don't generate warn-stack-size when the warning is ignored

Yi Kong via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 25 00:01:14 PDT 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rG5fc4828aa6c6: [clang] Don't generate warn-stack-size when the warning is ignored (authored by kongyi).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D108686?vs=368560&id=368564#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108686/new/

https://reviews.llvm.org/D108686

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/Misc/backend-stack-frame-diagnostics-attributes.cpp


Index: clang/test/Misc/backend-stack-frame-diagnostics-attributes.cpp
===================================================================
--- /dev/null
+++ clang/test/Misc/backend-stack-frame-diagnostics-attributes.cpp
@@ -0,0 +1,24 @@
+// Test the warn-stack-size function attribute is not generated when -Wframe-larger-than is ignored
+// through pragma.
+
+// RUN: %clang_cc1 -fwarn-stack-size=70 -emit-llvm -o - %s | FileCheck %s
+// CHECK: "warn-stack-size"="70"
+
+// RUN: %clang_cc1 -DIGNORED -fwarn-stack-size=70 -emit-llvm -o - %s | FileCheck %s --check-prefix=IGNORED
+// IGNORED-NOT: "warn-stack-size"="70"
+
+extern void doIt(char *);
+
+#ifdef IGNORED
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wframe-larger-than"
+#endif
+
+void frameSizeAttr() {
+  char buffer[80];
+  doIt(buffer);
+}
+
+#ifdef IGNORED
+#pragma GCC diagnostic pop
+#endif
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1049,7 +1049,8 @@
     Fn->addFnAttr("packed-stack");
   }
 
-  if (CGM.getCodeGenOpts().WarnStackSize != UINT_MAX)
+  if (CGM.getCodeGenOpts().WarnStackSize != UINT_MAX &&
+      !CGM.getDiags().isIgnored(diag::warn_fe_backend_frame_larger_than, Loc))
     Fn->addFnAttr("warn-stack-size",
                   std::to_string(CGM.getCodeGenOpts().WarnStackSize));
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108686.368564.patch
Type: text/x-patch
Size: 1442 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210825/6b3736c5/attachment.bin>


More information about the cfe-commits mailing list