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 2 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
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' instead,"
" or just '-O3' if you do not intend to enable non-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' instead,"
" or just '-O3' if you don't intend to enable non-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
5 changes: 5 additions & 0 deletions clang/test/Driver/Ofast.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,36 @@
// 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: argument '-Ofast' is deprecated; use '-O3 -ffast-math' instead, or just '-O3' if you do not intend to enable non-conforming optimizations
// CHECK-OFAST: -cc1
// CHECK-OFAST-NOT: -relaxed-aliasing
// CHECK-OFAST: -ffast-math
// CHECK-OFAST: -Ofast
// CHECK-OFAST: -vectorize-loops

// CHECK-OFAST-O2-NOT: argument '-Ofast' is deprecated; use '-O3 -ffast-math' instead, or just '-O3' if you do not intend to enable non-conforming optimizations
// 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: argument '-Ofast' is deprecated; use '-O3 -ffast-math' instead, or just '-O3' if you do not intend to enable non-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: argument '-Ofast' is deprecated; use '-O3 -ffast-math' instead, or just '-O3' if you do not intend to enable non-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: argument '-Ofast' is deprecated; use '-O3 -ffast-math' instead, or just '-O3' if you do not intend to enable non-conforming optimizations
// CHECK-OFAST-NO-VECTORIZE: -cc1
// CHECK-OFAST-NO-VECTORIZE-NOT: -relaxed-aliasing
// CHECK-OFAST-NO-VECTORIZE: -ffast-math
Expand Down
Loading