llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-driver

Author: Sam Elliott (lenary)

<details>
<summary>Changes</summary>

It was not clear from the deprecation warning or from the documentation that 
Ofast has an effect on strict aliasing as well.

This seeks to make the warning more accurate, for developers trying to move 
away from using Ofast

---
Full diff: https://github.com/llvm/llvm-project/pull/183002.diff


3 Files Affected:

- (modified) clang/docs/CommandGuide/clang.rst (+6-5) 
- (modified) clang/include/clang/Basic/DiagnosticDriverKinds.td (+3-2) 
- (modified) clang/test/Driver/Ofast.c (+5-5) 


``````````diff
diff --git a/clang/docs/CommandGuide/clang.rst 
b/clang/docs/CommandGuide/clang.rst
index 4c1f8e47ce381..ef175fdea1c09 100644
--- a/clang/docs/CommandGuide/clang.rst
+++ b/clang/docs/CommandGuide/clang.rst
@@ -445,12 +445,13 @@ Code Generation Options
     take longer to perform or that may generate larger code (in an attempt to
     make the program run faster).
 
-    :option:`-Ofast` Enables all the optimizations from :option:`-O3` along
-    with other aggressive optimizations that may violate strict compliance with
+    :option:`-Ofast` Enables all the optimizations from :option:`-O3` along 
with
+    other aggressive optimizations that may violate strict compliance with
     language standards. This is deprecated in Clang 19 and a warning is emitted
-    that :option:`-O3` in combination with :option:`-ffast-math` should be used
-    instead if the request for non-standard math behavior is intended. There
-    is no timeline yet for removal; the aim is to discourage use of
+    that :option:`-O3` in combination with :option:`-ffast-math` (and
+    ``-fstrict-aliasing`` if your platform is not MSVC Windows or UEFI) should
+    be used instead if the request for non-standard math behavior is intended.
+    There is no timeline yet for removal; the aim is to discourage use of
     :option:`-Ofast` due to the surprising behavior of an optimization flag
     changing the observable behavior of correct code.
 
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 3206b5c78a6f1..30e758dacc409 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -490,8 +490,9 @@ def warn_drv_clang_unsupported : Warning<
 def warn_drv_deprecated_arg : Warning<
   "argument '%0' is deprecated%select{|, use '%2' instead}1">, 
InGroup<Deprecated>;
 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">,
+  "argument '-Ofast' is deprecated; use '-O3' to enable only conforming "
+  "optimizations, or see the clang docs for which flags to use to get the same 
"
+  "behavior">,
   InGroup<DeprecatedOFast>;
 def warn_drv_deprecated_arg_ofast_for_flang : Warning<
   "argument '-Ofast' is deprecated; use '-O3 -ffast-math -fstack-arrays 
-fno-protect-parens' for the same behavior,"
diff --git a/clang/test/Driver/Ofast.c b/clang/test/Driver/Ofast.c
index e04ce036638f9..1516344fd5282 100644
--- a/clang/test/Driver/Ofast.c
+++ b/clang/test/Driver/Ofast.c
@@ -10,14 +10,14 @@
 // RUN: %clang -c -Ofast -fno-strict-aliasing -### %s 2>&1 | FileCheck 
-check-prefix=CHECK-OFAST-NO-STRICT-ALIASING %s
 // RUN: %clang -c -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: warning: argument '-Ofast' is deprecated; use '-O3' to enable 
only conforming optimizations
 // CHECK-OFAST: -cc1
 // CHECK-OFAST: -Ofast
 // CHECK-OFAST-NOT: -relaxed-aliasing
 // CHECK-OFAST: -ffast-math
 // CHECK-OFAST: -vectorize-loops
 
-// Lack of warning about '-Ofast' deprecation is checked via -Werror
+// Lack of warning about '-Ofast -fstrict-aliasing' deprecation is checked via 
-Werror
 // CHECK-OFAST-O2: -cc1
 // CHECK-OFAST-O2-NOT: -Ofast
 // CHECK-OFAST-O2-ALIASING-NOT: -relaxed-aliasing
@@ -25,21 +25,21 @@
 // CHECK-OFAST-O2-NOT: -ffast-math
 // 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: warning: argument '-Ofast' is deprecated; use 
'-O3' to enable only conforming optimizations
 // CHECK-OFAST-NO-FAST-MATH: -cc1
 // CHECK-OFAST-NO-FAST-MATH: -Ofast
 // CHECK-OFAST-NO-FAST-MATH-NOT: -relaxed-aliasing
 // CHECK-OFAST-NO-FAST-MATH-NOT: -ffast-math
 // 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: warning: argument '-Ofast' is deprecated; 
use '-O3' to enable only conforming optimizations
 // CHECK-OFAST-NO-STRICT-ALIASING: -cc1
 // CHECK-OFAST-NO-STRICT-ALIASING: -Ofast
 // CHECK-OFAST-NO-STRICT-ALIASING: -relaxed-aliasing
 // CHECK-OFAST-NO-STRICT-ALIASING: -ffast-math
 // 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: warning: argument '-Ofast' is deprecated; use 
'-O3' to enable only conforming optimizations
 // CHECK-OFAST-NO-VECTORIZE: -cc1
 // CHECK-OFAST-NO-VECTORIZE: -Ofast
 // CHECK-OFAST-NO-VECTORIZE-NOT: -relaxed-aliasing

``````````

</details>


https://github.com/llvm/llvm-project/pull/183002
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to