llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-driver Author: Vlad Serebrennikov (Endilll) <details> <summary>Changes</summary> This patch implements consensus on the corresponding RFC documented here: https://discourse.llvm.org/t/rfc-deprecate-ofast/78687/72 Specifically, I added a deprecation warning for `-Ofast`, that suggests to use `-O3` or `-O3` with `-ffast-math`, and a new diagnostic group for aforementioned warning. --- Full diff: https://github.com/llvm/llvm-project/pull/98736.diff 6 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+3) - (modified) clang/include/clang/Basic/DiagnosticDriverKinds.td (+3) - (modified) clang/include/clang/Basic/DiagnosticGroups.td (+2) - (modified) clang/include/clang/Driver/Options.td (+2-1) - (modified) clang/lib/Driver/ToolChains/Clang.cpp (+2) - (modified) clang/test/Driver/Ofast.c (+4) ``````````diff diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index ceead8c362e9c..2f5f40f355901 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -470,6 +470,9 @@ New Compiler Flags Deprecated Compiler Flags ------------------------- +- ``-Ofast`` is deprecated in favor of ``-O3``, possibly combined with ``-ffast-math``. + See `RFC <https://discourse.llvm.org/t/rfc-deprecate-ofast/78687>`_ for details. + Modified Compiler Flags ----------------------- - Added a new diagnostic flag ``-Wreturn-mismatch`` which is grouped under diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index 359c0de7f811c..3857f2f3a33ce 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -442,6 +442,9 @@ def warn_drv_deprecated_arg : Warning< def warn_drv_deprecated_arg_no_relaxed_template_template_args : Warning< "argument '-fno-relaxed-template-template-args' is deprecated">, InGroup<DeprecatedNoRelaxedTemplateTemplateArgs>; +def warn_drv_deprecated_arg_ofast : Warning< + "argument '-Ofast' is deprecated; use '-O3', possibly with '-ffast-math'">, + InGroup<DeprecatedOFast>; def warn_drv_deprecated_custom : Warning< "argument '%0' is deprecated, %1">, InGroup<Deprecated>; def warn_drv_assuming_mfloat_abi_is : Warning< diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 2241f8481484e..d7dba76a0fcf8 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -103,6 +103,7 @@ def EnumConversion : DiagGroup<"enum-conversion", EnumFloatConversion, EnumCompareConditional]>; def DeprecatedNoRelaxedTemplateTemplateArgs : DiagGroup<"deprecated-no-relaxed-template-template-args">; +def DeprecatedOFast : DiagGroup<"deprecated-ofast">; def ObjCSignedCharBoolImplicitIntConversion : DiagGroup<"objc-signed-char-bool-implicit-int-conversion">; def Shorten64To32 : DiagGroup<"shorten-64-to-32">; @@ -228,6 +229,7 @@ def Deprecated : DiagGroup<"deprecated", [DeprecatedAnonEnumEnumConversion, DeprecatedPragma, DeprecatedRegister, DeprecatedNoRelaxedTemplateTemplateArgs, + DeprecatedOFast, DeprecatedThisCapture, DeprecatedType, DeprecatedVolatile, diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index f1e8cb87e5321..269790476c1c3 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -931,7 +931,8 @@ def O : Joined<["-"], "O">, Group<O_Group>, def O_flag : Flag<["-"], "O">, Visibility<[ClangOption, CC1Option, FC1Option]>, Alias<O>, AliasArgs<["1"]>; def Ofast : Joined<["-"], "Ofast">, Group<O_Group>, - Visibility<[ClangOption, CC1Option, FlangOption]>; + Visibility<[ClangOption, CC1Option, FlangOption]>, + HelpText<"Deprecated; use -O3, possibly with -ffast-math">; def P : Flag<["-"], "P">, Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>, Group<Preprocessor_Group>, diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index bc21d03a627b9..33e7152343171 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -5712,6 +5712,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, options::OPT_fno_zero_initialized_in_bss); bool OFastEnabled = isOptimizationLevelFast(Args); + if (OFastEnabled) + D.Diag(diag::warn_drv_deprecated_arg_ofast); // If -Ofast is the optimization level, then -fstrict-aliasing should be // enabled. This alias option is being used to simplify the hasFlag logic. OptSpecifier StrictAliasingAliasOption = diff --git a/clang/test/Driver/Ofast.c b/clang/test/Driver/Ofast.c index 8b7f2217eca2f..f5a2aabe257f1 100644 --- a/clang/test/Driver/Ofast.c +++ b/clang/test/Driver/Ofast.c @@ -10,6 +10,7 @@ // RUN: %clang -Ofast -fno-strict-aliasing -### %s 2>&1 | FileCheck -check-prefix=CHECK-OFAST-NO-STRICT-ALIASING %s // RUN: %clang -Ofast -fno-vectorize -### %s 2>&1 | FileCheck -check-prefix=CHECK-OFAST-NO-VECTORIZE %s +// CHECK-OFAST: warning: argument '-Ofast' is deprecated; use '-O3', possibly with '-ffast-math' // CHECK-OFAST: -cc1 // CHECK-OFAST-NOT: -relaxed-aliasing // CHECK-OFAST: -ffast-math @@ -23,18 +24,21 @@ // CHECK-OFAST-O2-NOT: -Ofast // CHECK-OFAST-O2: -vectorize-loops +// CHECK-OFAST-NO-FAST-MATH: warning: argument '-Ofast' is deprecated; use '-O3', possibly with '-ffast-math' // CHECK-OFAST-NO-FAST-MATH: -cc1 // CHECK-OFAST-NO-FAST-MATH-NOT: -relaxed-aliasing // CHECK-OFAST-NO-FAST-MATH-NOT: -ffast-math // CHECK-OFAST-NO-FAST-MATH: -Ofast // CHECK-OFAST-NO-FAST-MATH: -vectorize-loops +// CHECK-OFAST-NO-STRICT-ALIASING: warning: argument '-Ofast' is deprecated; use '-O3', possibly with '-ffast-math' // CHECK-OFAST-NO-STRICT-ALIASING: -cc1 // CHECK-OFAST-NO-STRICT-ALIASING: -relaxed-aliasing // CHECK-OFAST-NO-STRICT-ALIASING: -ffast-math // CHECK-OFAST-NO-STRICT-ALIASING: -Ofast // CHECK-OFAST-NO-STRICT-ALIASING: -vectorize-loops +// CHECK-OFAST-NO-VECTORIZE: warning: argument '-Ofast' is deprecated; use '-O3', possibly with '-ffast-math' // CHECK-OFAST-NO-VECTORIZE: -cc1 // CHECK-OFAST-NO-VECTORIZE-NOT: -relaxed-aliasing // CHECK-OFAST-NO-VECTORIZE: -ffast-math `````````` </details> https://github.com/llvm/llvm-project/pull/98736 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits