https://github.com/lenary updated 
https://github.com/llvm/llvm-project/pull/183002

>From 4d91aede8e582bf08b284a526dae119bb68a9d52 Mon Sep 17 00:00:00 2001
From: Sam Elliott <[email protected]>
Date: Mon, 23 Feb 2026 22:35:43 -0800
Subject: [PATCH 1/2] [clang] Improve Ofast Warning

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
---
 clang/docs/CommandGuide/clang.rst                 | 15 ++++++++-------
 .../include/clang/Basic/DiagnosticDriverKinds.td  |  4 ++--
 clang/test/Driver/Ofast.c                         | 10 +++++-----
 3 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/clang/docs/CommandGuide/clang.rst 
b/clang/docs/CommandGuide/clang.rst
index 4c1f8e47ce381..0563420121e9f 100644
--- a/clang/docs/CommandGuide/clang.rst
+++ b/clang/docs/CommandGuide/clang.rst
@@ -445,14 +445,15 @@ 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
-    :option:`-Ofast` due to the surprising behavior of an optimization flag
-    changing the observable behavior of correct code.
+    that :option:`-O3` in combination with :option:`-ffast-math` and
+    :option:`-fstrict-aliasing` 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.
 
     :option:`-Os` Like :option:`-O2` with extra optimizations to reduce code
     size.
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 90a92b1602231..260d97b7a7ba6 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -490,8 +490,8 @@ 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 -ffast-math -fstrict-aliasing' "
+  "for the same behavior, or '-O3' to enable only conforming optimizations">,
   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..22e2c42f53b23 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: use '-O3 -ffast-math -fstrict-aliasing' for the same behavior, 
or '-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: use '-O3 -ffast-math -fstrict-aliasing' for the 
same behavior, or '-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: use '-O3 -ffast-math -fstrict-aliasing' for 
the same behavior, or '-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: use '-O3 -ffast-math -fstrict-aliasing' for the 
same behavior, or '-O3' to enable only conforming optimizations
 // CHECK-OFAST-NO-VECTORIZE: -cc1
 // CHECK-OFAST-NO-VECTORIZE: -Ofast
 // CHECK-OFAST-NO-VECTORIZE-NOT: -relaxed-aliasing

>From a4763856c19d67983189c00063e3efff832724a5 Mon Sep 17 00:00:00 2001
From: Sam Elliott <[email protected]>
Date: Mon, 23 Feb 2026 22:46:43 -0800
Subject: [PATCH 2/2] Fix docs build

---
 clang/docs/CommandGuide/clang.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/CommandGuide/clang.rst 
b/clang/docs/CommandGuide/clang.rst
index 0563420121e9f..c970bb1179747 100644
--- a/clang/docs/CommandGuide/clang.rst
+++ b/clang/docs/CommandGuide/clang.rst
@@ -449,7 +449,7 @@ Code Generation Options
     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` and
-    :option:`-fstrict-aliasing` should be used instead if the request for
+    ``-fstrict-aliasing`` 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

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

Reply via email to