-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Conversation
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-driver Author: Vlad Serebrennikov (Endilll) ChangesThis patch implements consensus on the corresponding RFC documented here: https://discourse.llvm.org/t/rfc-deprecate-ofast/78687/72 Full diff: https://github.com/llvm/llvm-project/pull/98736.diff 6 Files Affected:
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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sending this. I had planned to, but hadn't gotten around to it yet.
@@ -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'">, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe worth using a few more words? E.g.
argument '-Ofast' is deprecated; use '-O3' for standard optimization, or '-O3 -ffast-math' if non-standard "fast-math" was desired
I'm not sure if that's too long.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could shorten slightly it to:
'-Ofast' is deprecated; use '-O3' for conforming optimizations or '-O3 -ffast-math' for nonconforming optimizations"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in this diagnostic it's more important to inform the user that he should replace -Ofast
with -O3 -ffast-math
in order to just circumvent the deprecation and keep the current behavior, and this should be clear. Throwing the option of using just O3
as equally valid is a bit misleading, but we can, as a note, inform the user that it's possible he made the wrong choice in the first place, and advise a switch to O3
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @mizvekov raised a good point, so I tried to take it into account.
@jyknight @AaronBallman What do you think of the new wording (use '-O3 -ffast math' instead, or just '-O3' if you don't intend to enable non-conforming optimizations
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use '-O3 -ffast math' instead, or just '-O3' if you don't intend to enable non-conforming optimizations
This message LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about a slight rewording?
use '-O3 -ffast math' for the same behavior, or '-O3' to enable conforming optimizations only
(I mostly want to drop "just" and to make it more clear that -Ofast
was non-conforming because of -ffast-math
.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switched to Aaron's wording
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for working on this!
@@ -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'">, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could shorten slightly it to:
'-Ofast' is deprecated; use '-O3' for conforming optimizations or '-O3 -ffast-math' for nonconforming optimizations"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
We are deprecating -Ofast and I would prefer to hint users first at conforming behaviour -O3 and then as last resort at -O3 with -ffast-math. |
@tschuett I'm sympathetic to this argument, but I think it's no less important to tell users in no uncertain terms how to preserve their current behavior. If there's a wording that achieves both goals, I'd be happy to incorporate it into this PR. |
No worries. I have zero voting rights in Clang. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@jyknight As the author of the RFC, are you happy with the current state of this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good enough to me, thank you!
Could you add a flang driver test as well? |
I have troubles building Flang on my machine to test the change, so I'd prefer this be done in a separate PR by someone who knows how to do this. Is this fine by you? |
Fine with me.
…On Tue, 16 Jul 2024, 17:50 Vlad Serebrennikov, ***@***.***> wrote:
Could you add a flang driver test as well?
I have troubles building Flang on my machine to test the change, so I'd
prefer this be done in a separate PR by someone who knows how to do this.
Is this fine by you?
—
Reply to this email directly, view it on GitHub
<#98736 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA4YEDKN4VQV5UOT7QBQOWTZMVFOLAVCNFSM6AAAAABK2EZQH2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMZRGM4DSMBVHE>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Excellent, thank you for confirming! |
This PR has passed CI before latest wording suggestion by Shafik, so I'll go ahead and merge this. |
I will copy here what I wrote on the RFC:
|
This seems to break tests on my Windows box: http://45.33.8.238/win/91548/step_6.txt |
This is the failed test:
Somehow |
FWIW, I'm not able to reproduce that behavior on my Windows machine. |
One possibility is that -Wno-msvc-not-found is relevant: c3a5087 . The same "diagnostics are suppressed" issue happened recently on two bots that @dyung maintains, but I do not know whether theirs are Windows bots. |
For my bots, the bot description should tell you what the bot is running, but I only maintain two builders that run Windows at the moment, but they are the same configuration, only one is a release branch version of the builder, but they run on the same physical worker. Do you have a link to the failures? |
Just making sure this doesn't fall through the cracks now that we've branched. Is Flang in a good state? e.g., are flang folks okay with deprecating -Ofast, and if so, has the test coverage been added? Or does the driver for Flang need be updated to not deprecate -Ofast? |
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. Deprecation period is going to be lengthy, so I hope this PR can be merged in time for Clang 19. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251517
Summary: A follow-up for #98736 Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251383
Finally coming back to this. The problem is that I run tests without vcvarsall.bat run, i.e. I don't have MSVC's tools on PATH. a) schedules to run the linker and Just adding a (Alternatively, |
…passing |
Without this, `-###` prints the linker invocation as well, which can lead to `-Wno-msvc-not-found` warnings on Windows bots that don't have MSVC on path, causing the test to fail. Since the test isn't trying to test linker-related things, just pass `-c`. See discussion on #98736.
I made that change in 5cf3677. |
'-Ofast' enables optimizations that are not standards compliant, which can produce unexpected results unless used carefully. When building with clang 19 and newer, it warns: clang: error: argument '-Ofast' is deprecated; use '-O3 -ffast-math' for the same behavior, or '-O3' to enable only conforming optimizations [-Werror,-Wdeprecated-ofast] Relevant discussion: * llvm/llvm-project#98736 * https://discourse.llvm.org/t/rfc-deprecate-ofast/78687/109 * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115990 Signed-off-by: Tom Hughes <[email protected]>
'-Ofast' enables optimizations that are not standards compliant, which can produce unexpected results unless used carefully. When building with clang 19 and newer, it warns: clang: error: argument '-Ofast' is deprecated; use '-O3 -ffast-math' for the same behavior, or '-O3' to enable only conforming optimizations [-Werror,-Wdeprecated-ofast] Relevant discussion: * llvm/llvm-project#98736 * https://discourse.llvm.org/t/rfc-deprecate-ofast/78687/109 * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115990 Signed-off-by: Tom Hughes <[email protected]>
'-Ofast' enables optimizations that are not standards compliant, which can produce unexpected results unless used carefully. When building with clang 19 and newer, it warns: clang: error: argument '-Ofast' is deprecated; use '-O3 -ffast-math' for the same behavior, or '-O3' to enable only conforming optimizations [-Werror,-Wdeprecated-ofast] Relevant discussion: * llvm/llvm-project#98736 * https://discourse.llvm.org/t/rfc-deprecate-ofast/78687/109 * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115990 Signed-off-by: Tom Hughes <[email protected]>
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.Deprecation period is going to be lengthy, so I hope this PR can be merged in time for Clang 19.