blob: 58a614729fa04e6616affb6a72c743c13ba522f2 [file] [log] [blame]
From 5fc4828aa6c6df03bd98b1f066e85655383d0cce Mon Sep 17 00:00:00 2001
From: Yi Kong <yikong@google.com>
Date: Tue, 24 Aug 2021 17:06:08 +0800
Subject: [PATCH] [clang] Don't generate warn-stack-size when the warning is
ignored
8ace12130526 introduced a regression for code that explicitly ignores the
-Wframe-larger-than= warning. Make sure we don't generate the
warn-stack-size attribute for that case.
Differential Revision: https://reviews.llvm.org/D108686
---
clang/lib/CodeGen/CodeGenFunction.cpp | 3 ++-
...end-stack-frame-diagnostics-attributes.cpp | 24 +++++++++++++++++++
2 files changed, 26 insertions(+), 1 deletion(-)
create mode 100644 clang/test/Misc/backend-stack-frame-diagnostics-attributes.cpp
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index e3a66318c086..a3c348051c67 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1049,7 +1049,8 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
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));
diff --git a/clang/test/Misc/backend-stack-frame-diagnostics-attributes.cpp b/clang/test/Misc/backend-stack-frame-diagnostics-attributes.cpp
new file mode 100644
index 000000000000..c7d8a23023e9
--- /dev/null
+++ b/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
--
2.33.0.rc2.250.ged5fa647cd-goog