diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/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)); 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 --- /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