Author: Yi Kong Date: 2021-08-25T14:58:45+08:00 New Revision: 5fc4828aa6c6df03bd98b1f066e85655383d0cce
URL: https://github.com/llvm/llvm-project/commit/5fc4828aa6c6df03bd98b1f066e85655383d0cce DIFF: https://github.com/llvm/llvm-project/commit/5fc4828aa6c6df03bd98b1f066e85655383d0cce.diff LOG: [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 Added: clang/test/Misc/backend-stack-frame-diagnostics-attributes.cpp Modified: clang/lib/CodeGen/CodeGenFunction.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index e3a66318c086c..a3c348051c675 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 0000000000000..c7d8a23023e9c --- /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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits