https://github.com/w2yehia updated 
https://github.com/llvm/llvm-project/pull/216450

>From b507d69f37f6f8dc60de587dd08708c848c7ec64 Mon Sep 17 00:00:00 2001
From: Wael Yehia <[email protected]>
Date: Sat, 15 Aug 2026 00:59:29 +0000
Subject: [PATCH 1/2] treat -O4 as -O3 in clang::getOptimizationLevel, which is
 called when building LTO link command

---
 clang/lib/Frontend/CompilerInvocation.cpp | 2 +-
 clang/test/Driver/lto.c                   | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 256ae636ca9e6..8a72e3c386d56 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2726,7 +2726,7 @@ unsigned clang::getOptimizationLevel(const ArgList &Args, 
InputKind IK,
     if (A->getOption().matches(options::OPT_O0))
       return 0;
 
-    if (A->getOption().matches(options::OPT_Ofast))
+    if (A->getOption().matches(options::OPT_Ofast) || 
A->getOption().matches(options::OPT_O4))
       return 3;
 
     assert(A->getOption().matches(options::OPT_O));
diff --git a/clang/test/Driver/lto.c b/clang/test/Driver/lto.c
index c9ee2f9c26223..838eb74086375 100644
--- a/clang/test/Driver/lto.c
+++ b/clang/test/Driver/lto.c
@@ -66,6 +66,8 @@
 // RUN:   -fuse-ld=lld -flto -O3 -### 2>&1 | FileCheck --check-prefix=O3 %s
 // RUN: %clang --target=x86_64-unknown-linux-gnu 
--sysroot=%S/Inputs/basic_cross_linux_tree %s \
 // RUN:   -fuse-ld=lld -flto -Ofast -### 2>&1 | FileCheck --check-prefix=O3 %s
+// RUN: %clang --target=x86_64-unknown-linux-gnu 
--sysroot=%S/Inputs/basic_cross_linux_tree %s \
+// RUN:   -fuse-ld=lld -flto -O4 -### 2>&1 | FileCheck --check-prefix=O3 %s
 
 // O1: -plugin-opt=O1
 // O2: -plugin-opt=O2

>From f53f73a4d1ccf0dd9d28bc7e60c4fb8864acf696 Mon Sep 17 00:00:00 2001
From: Wael Yehia <[email protected]>
Date: Mon, 17 Aug 2026 23:50:27 +0000
Subject: [PATCH 2/2] clang-format

---
 clang/lib/Frontend/CompilerInvocation.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 8a72e3c386d56..3aadb41072b08 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2726,7 +2726,8 @@ unsigned clang::getOptimizationLevel(const ArgList &Args, 
InputKind IK,
     if (A->getOption().matches(options::OPT_O0))
       return 0;
 
-    if (A->getOption().matches(options::OPT_Ofast) || 
A->getOption().matches(options::OPT_O4))
+    if (A->getOption().matches(options::OPT_Ofast) ||
+        A->getOption().matches(options::OPT_O4))
       return 3;
 
     assert(A->getOption().matches(options::OPT_O));

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

Reply via email to