diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -2500,6 +2500,11 @@ def Wlarger_than_EQ : Joined<["-"], "Wlarger-than=">, Group; def Wlarger_than_ : Joined<["-"], "Wlarger-than-">, Alias; def Wframe_larger_than_EQ : Joined<["-"], "Wframe-larger-than=">, Group, Flags<[NoXarchOption]>; +def Wno_frame_larger_than_EQ : Joined<["-"], "Wnoframe-larger-than=">, Group, Flags<[NoXarchOption]>; +def Wstack_stack_usage_EQ : Joined<["-"], "Wstack-usage=">, Flags<[NoXarchOption]>, + Alias; +def Wno_stack_stack_usage_EQ : Joined<["-"], "Wno-stack-usage=">, Flags<[NoXarchOption]>, + Alias; def : Flag<["-"], "fterminated-vtables">, Alias; defm threadsafe_statics : BoolFOption<"threadsafe-statics", diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -4762,12 +4762,14 @@ D.Diag(diag::err_aix_default_altivec_abi); } - if (Arg *A = Args.getLastArg(options::OPT_Wframe_larger_than_EQ)) { - StringRef v = A->getValue(); - CmdArgs.push_back("-mllvm"); - CmdArgs.push_back(Args.MakeArgString("-warn-stack-size=" + v)); - A->claim(); - } + if (Args.hasFlag(options::OPT_Wframe_larger_than_EQ, + options::OPT_Wno_frame_larger_than_EQ, false)) + if (Arg *A = Args.getLastArg(options::OPT_Wframe_larger_than_EQ)) { + StringRef v = A->getValue(); + CmdArgs.push_back("-mllvm"); + CmdArgs.push_back(Args.MakeArgString("-warn-stack-size=" + v)); + A->claim(); + } if (!Args.hasFlag(options::OPT_fjump_tables, options::OPT_fno_jump_tables, true)) diff --git a/clang/test/Frontend/backend-stack-usage-diagnostic.c b/clang/test/Frontend/backend-stack-usage-diagnostic.c new file mode 100644 --- /dev/null +++ b/clang/test/Frontend/backend-stack-usage-diagnostic.c @@ -0,0 +1,21 @@ +// RUN: %clang -Wstack-usage=0 -o /dev/null -c %s 2> %t.err +// RUN: FileCheck < %t.err %s --check-prefix=WARN + +// RUN: %clang -Wstack-usage=0 -Wno-stack-usage= -o /dev/null -c %s 2> %t.err +// RUN: FileCheck < %t.err %s --check-prefix=IGNORE --allow-empty + +// RUN: %clang -Wstack-usage=0 -w -o /dev/null -c %s 2> %t.err +// RUN: FileCheck < %t.err %s --check-prefix=IGNORE --allow-empty + +// RUN: %clang -Wstack-usage=3 -o /dev/null -c %s 2> %t.err +// RUN: FileCheck < %t.err %s --check-prefix=WARN + +// RUN: %clang -Wstack-usage=100 -o /dev/null -c %s 2> %t.err +// RUN: FileCheck < %t.err %s --check-prefix=IGNORE --allow-empty + +// WARN: warning: stack frame size of {{[0-9]+}} bytes in function 'test_square' +// IGNORE-NOT: stack frame size of {{[0-9]+}} bytes in function 'test_square' +int test_square(int num) { + return num * num; +} +