Skip to content

[clang] Add deprecation warning for -Ofast driver option #98736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion clang/docs/CommandGuide/clang.rst
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ Code Generation Options

:option:`-Ofast` Enables all the optimizations from :option:`-O3` along
with other aggressive optimizations that may violate strict compliance with
language standards.
language standards. This is deprecated in favor of :option:`-O3`
in combination with :option:`-ffast-math`.

:option:`-Os` Like :option:`-O2` with extra optimizations to reduce code
size.
Expand Down
7 changes: 7 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,13 @@ New Compiler Flags
Deprecated Compiler Flags
-------------------------

- The ``-Ofast`` command-line option has been deprecated. This option both
enables the ``-O3`` optimization-level, as well as enabling non-standard
``-ffast-math`` behaviors. As such, it is somewhat misleading as an
"optimization level". Users are advised to switch to ``-O3 -ffast-math`` if
the use of non-standard math behavior is intended, and ``-O3`` otherwise.
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
Expand Down
4 changes: 4 additions & 0 deletions clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,10 @@ 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 -ffast math' for the same behavior,"
" or '-O3' to enable only conforming optimizations">,
InGroup<DeprecatedOFast>;
def warn_drv_deprecated_custom : Warning<
"argument '%0' is deprecated, %1">, InGroup<Deprecated>;
def warn_drv_assuming_mfloat_abi_is : Warning<
Expand Down
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticGroups.td
Original file line number Diff line number Diff line change
Expand Up @@ -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">;
Expand Down Expand Up @@ -228,6 +229,7 @@ def Deprecated : DiagGroup<"deprecated", [DeprecatedAnonEnumEnumConversion,
DeprecatedPragma,
DeprecatedRegister,
DeprecatedNoRelaxedTemplateTemplateArgs,
DeprecatedOFast,
DeprecatedThisCapture,
DeprecatedType,
DeprecatedVolatile,
Expand Down
4 changes: 3 additions & 1 deletion clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,9 @@ 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 -ffast math' for the same behavior,"
" or '-O3' to enable only conforming optimizations">;
def P : Flag<["-"], "P">,
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
Group<Preprocessor_Group>,
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
7 changes: 6 additions & 1 deletion clang/test/Driver/Ofast.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,43 @@
// RUN: %clang -fno-fast-math -Ofast -### %s 2>&1 | FileCheck -check-prefix=CHECK-OFAST %s
// RUN: %clang -fno-strict-aliasing -Ofast -### %s 2>&1 | FileCheck -check-prefix=CHECK-OFAST %s
// RUN: %clang -fno-vectorize -Ofast -### %s 2>&1 | FileCheck -check-prefix=CHECK-OFAST %s
// RUN: %clang -Ofast -O2 -### %s 2>&1 | FileCheck -check-prefix=CHECK-OFAST-O2 \
// RUN: %clang -Ofast -O2 -### -Werror %s 2>&1 | FileCheck -check-prefix=CHECK-OFAST-O2 \
// RUN: %if target={{.*-windows-msvc.*}} %{ --check-prefix=CHECK-OFAST-O2-ALIASING-MSVC %} \
// RUN: %else %{ --check-prefix=CHECK-OFAST-O2-ALIASING %} %s
// RUN: %clang -Ofast -fno-fast-math -### %s 2>&1 | FileCheck -check-prefix=CHECK-OFAST-NO-FAST-MATH %s
// 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: use '-O3 -ffast math' for the same behavior, or '-O3' to enable only conforming optimizations
// CHECK-OFAST: -cc1
// CHECK-OFAST-NOT: -relaxed-aliasing
// CHECK-OFAST: -ffast-math
// CHECK-OFAST: -Ofast
// CHECK-OFAST: -vectorize-loops

// Lack of warning about '-Ofast' deprecation is checked via -Werror
// CHECK-OFAST-O2: -cc1
// CHECK-OFAST-O2-ALIASING-NOT: -relaxed-aliasing
// CHECK-OFAST-O2-ALIASING-MSVC: -relaxed-aliasing
// CHECK-OFAST-O2-NOT: -ffast-math
// CHECK-OFAST-O2-NOT: -Ofast
// CHECK-OFAST-O2: -vectorize-loops

// CHECK-OFAST-NO-FAST-MATH: use '-O3 -ffast math' for the same behavior, or '-O3' to enable only conforming optimizations
// 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: use '-O3 -ffast math' for the same behavior, or '-O3' to enable only conforming optimizations
// 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: use '-O3 -ffast math' for the same behavior, or '-O3' to enable only conforming optimizations
// CHECK-OFAST-NO-VECTORIZE: -cc1
// CHECK-OFAST-NO-VECTORIZE-NOT: -relaxed-aliasing
// CHECK-OFAST-NO-VECTORIZE: -ffast-math
Expand Down
Loading