diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td index 5122770316cd..e68058dd19b5 100644 --- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td @@ -26,9 +26,9 @@ def err_fe_cannot_link_module : Error<"cannot link module '%0': %1">, DefaultFatal; def warn_fe_frame_larger_than : Warning<"stack frame size of %0 bytes in %q1">, - BackendInfo, InGroup; + BackendInfo, InGroup; def warn_fe_backend_frame_larger_than: Warning<"%0">, - BackendInfo, InGroup; + BackendInfo, InGroup; def err_fe_backend_frame_larger_than: Error<"%0">, BackendInfo; def note_fe_backend_frame_larger_than: Note<"%0">, BackendInfo; diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index b4be0fcfb454..ca8e05f27fc5 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -1192,7 +1192,9 @@ def OpenMP : DiagGroup<"openmp", [ // Backend warnings. def BackendInlineAsm : DiagGroup<"inline-asm">; def BackendSourceMgr : DiagGroup<"source-mgr">; -def BackendFrameLargerThanEQ : DiagGroup<"frame-larger-than=">; +def BackendFrameLargerThan : DiagGroup<"frame-larger-than">; +// Compatibility flag name from old versions of Clang. +def : DiagGroup<"frame-larger-than=", [BackendFrameLargerThan]>; def BackendPlugin : DiagGroup<"backend-plugin">; def RemarkBackendPlugin : DiagGroup<"remark-backend-plugin">; def BackendOptimizationRemark : DiagGroup<"pass">; diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 151968de1789..0ccf5ef89199 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1488,9 +1488,6 @@ defm cxx_static_destructors : BoolFOption<"c++-static-destructors", PosFlag>; def fsymbol_partition_EQ : Joined<["-"], "fsymbol-partition=">, Group, Flags<[CC1Option]>, MarshallingInfoString>; -def fwarn_stack_size_EQ : Joined<["-"], "fwarn-stack-size=">, Group, - Flags<[CC1Option]>, - MarshallingInfoInt, "UINT_MAX">; defm memory_profile : OptInFFlag<"memory-profile", "Enable", "Disable", " heap memory profiling">; def fmemory_profile_EQ : Joined<["-"], "fmemory-profile=">, @@ -2590,7 +2587,12 @@ def Wlarge_by_value_copy_EQ : Joined<["-"], "Wlarge-by-value-copy=">, Flags<[CC1 // Just silence warnings about -Wlarger-than for now. 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]>; + +// This is converted to -fwarn-stack-size=N and also passed through by the driver. +// FIXME: The driver should strip out the = when passing W_value_Group through. +def Wframe_larger_than_EQ : Joined<["-"], "Wframe-larger-than=">, Group, + Flags<[NoXarchOption, CC1Option]>; +def Wframe_larger_than : Flag<["-"], "Wframe-larger-than">, Alias; def : Flag<["-"], "fterminated-vtables">, Alias; defm threadsafe_statics : BoolFOption<"threadsafe-statics", @@ -5047,6 +5049,9 @@ def fverify_debuginfo_preserve_export "into specified (JSON) file (should be abs path as we use " "append mode to insert new JSON objects).">, MarshallingInfoString>; +def fwarn_stack_size_EQ + : Joined<["-"], "fwarn-stack-size=">, + MarshallingInfoInt, "UINT_MAX">; // The driver option takes the key as a parameter to the -msign-return-address= // and -mbranch-protection= options, but CC1 has a separate option so we // don't have to parse the parameter twice. diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index ddec79abd45f..f6e3447eccb0 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -4828,7 +4828,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, if (Arg *A = Args.getLastArg(options::OPT_Wframe_larger_than_EQ)) { StringRef v = A->getValue(); - CmdArgs.push_back(Args.MakeArgString("-fwarn-stack-size=" + v)); + // FIXME: Validate the argument here so we don't produce meaningless errors + // about -fwarn-stack-size=. + if (v.empty()) + D.Diag(diag::err_drv_missing_argument) << A->getSpelling() << 1; + else + CmdArgs.push_back(Args.MakeArgString("-fwarn-stack-size=" + v)); A->claim(); } diff --git a/clang/test/Driver/Wframe-larger-than.c b/clang/test/Driver/Wframe-larger-than.c index 178632570d0e..cc5b5d0a2ca1 100644 --- a/clang/test/Driver/Wframe-larger-than.c +++ b/clang/test/Driver/Wframe-larger-than.c @@ -1,15 +1,31 @@ // RUN: %clang -Wframe-larger-than=42 \ -// RUN: -v -E - < /dev/null 2>&1 | FileCheck %s --check-prefix=ENABLE -// RUN: %clang -Wframe-larger-than=42 -Wno-frame-larger-than= \ -// RUN: -v -E - < /dev/null 2>&1 | FileCheck %s --check-prefix=DISABLE -// RUN: %clang -Wframe-larger-than=42 -Wno-frame-larger-than= -Wframe-larger-than=43 \ -// RUN: -v -E - < /dev/null 2>&1 | FileCheck %s --check-prefix=REENABLE -// -// TODO: we might want to look into being able to disable, then re-enable this -// warning properly. We could have the driver turn -Wframe-larger-than=X into -// -Wframe-larger-than -fwarn-stack-size=X. Also, we should support -// -Wno-frame-larger-than (no = suffix) like GCC. +// RUN: -v -E %s 2>&1 | FileCheck %s --check-prefix=ENABLE +// RUN: %clang -Wframe-larger-than=42 -Wno-frame-larger-than \ +// RUN: -v -E %s 2>&1 | FileCheck %s --check-prefix=DISABLE +// RUN: %clang -Wframe-larger-than=42 -Wno-frame-larger-than -Wframe-larger-than=43 \ +// RUN: -v -E %s 2>&1 | FileCheck %s --check-prefix=REENABLE +// RUN: not %clang -Wframe-larger-than= \ +// RUN: -v -E %s 2>&1 | FileCheck %s --check-prefix=NOARG +// RUN: not %clang -Wframe-larger-than \ +// RUN: -v -E %s 2>&1 | FileCheck %s --check-prefix=NOARG -// ENABLE: cc1 {{.*}} -fwarn-stack-size=42 -// DISABLE: cc1 {{.*}} -fwarn-stack-size=42 {{.*}} -Wno-frame-larger-than= -// REENABLE: cc1 {{.*}} -fwarn-stack-size=43 {{.*}} -Wno-frame-larger-than= +// ENABLE: cc1 {{.*}} -fwarn-stack-size=42 {{.*}} -Wframe-larger-than=42 +// ENABLE: frame-larger-than: +// ENABLE-SAME: warning + +// DISABLE: cc1 {{.*}} -fwarn-stack-size=42 {{.*}} -Wframe-larger-than=42 -Wno-frame-larger-than +// DISABLE: frame-larger-than: +// DISABLE-SAME: ignored + +// REENABLE: cc1 {{.*}} -fwarn-stack-size=43 {{.*}} -Wframe-larger-than=42 -Wno-frame-larger-than -Wframe-larger-than=43 +// REENABLE: frame-larger-than: +// REENABLE-SAME: warning + +// NOARG: error: argument to '-Wframe-larger-than=' is missing + +// We need to create some state transitions before the pragma will dump anything. +#pragma clang diagnostic push +#pragma clang diagnostic warning "-Wframe-larger-than" +#pragma clang diagnostic pop + +#pragma clang __debug diag_mapping "frame-larger-than" diff --git a/clang/test/Frontend/backend-diagnostic.c b/clang/test/Frontend/backend-diagnostic.c index 8ec3b90cdd96..01029d7f83d6 100644 --- a/clang/test/Frontend/backend-diagnostic.c +++ b/clang/test/Frontend/backend-diagnostic.c @@ -6,9 +6,9 @@ // // RUN: not %clang_cc1 %s -fwarn-stack-size=0 -no-integrated-as -S -o - -triple=i386-apple-darwin 2> %t.err // RUN: FileCheck < %t.err %s --check-prefix=REGULAR --check-prefix=ASM -// RUN: not %clang_cc1 %s -fwarn-stack-size=0 -no-integrated-as -S -o - -triple=i386-apple-darwin -Werror=frame-larger-than= 2> %t.err +// RUN: not %clang_cc1 %s -fwarn-stack-size=0 -no-integrated-as -S -o - -triple=i386-apple-darwin -Werror=frame-larger-than 2> %t.err // RUN: FileCheck < %t.err %s --check-prefix=PROMOTE --check-prefix=ASM -// RUN: not %clang_cc1 %s -fwarn-stack-size=0 -no-integrated-as -S -o - -triple=i386-apple-darwin -Wno-frame-larger-than= 2> %t.err +// RUN: not %clang_cc1 %s -fwarn-stack-size=0 -no-integrated-as -S -o - -triple=i386-apple-darwin -Wno-frame-larger-than 2> %t.err // RUN: FileCheck < %t.err %s --check-prefix=IGNORE --check-prefix=ASM // // RUN: %clang_cc1 %s -S -o - -triple=i386-apple-darwin -verify -no-integrated-as diff --git a/clang/test/Misc/backend-stack-frame-diagnostics.cpp b/clang/test/Misc/backend-stack-frame-diagnostics.cpp index e460294e1c7c..b02e7f4c471d 100644 --- a/clang/test/Misc/backend-stack-frame-diagnostics.cpp +++ b/clang/test/Misc/backend-stack-frame-diagnostics.cpp @@ -36,20 +36,13 @@ void frameSizeWarning(); void frameSizeWarning(int) {} #pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wframe-larger-than=" +#pragma GCC diagnostic ignored "-Wframe-larger-than" void frameSizeWarningIgnored() { char buffer[80]; doIt(buffer); } #pragma GCC diagnostic pop -#pragma GCC diagnostic push -#ifndef IS_SYSHEADER -// expected-warning@+2 {{unknown warning group '-Wframe-larger-than'}} -#endif -#pragma GCC diagnostic ignored "-Wframe-larger-than" -#pragma GCC diagnostic pop - void frameSizeLocalClassWarning() { struct S { S() { // expected-warning-re {{stack frame size of {{[0-9]+}} bytes in function 'frameSizeLocalClassWarning()::S::S'}}