Author: Wael Yehia
Date: 2026-08-17T19:59:42-04:00
New Revision: 85e76ec53ae4e5caea5a13b084c19ba4e2f3a6ce

URL: 
https://github.com/llvm/llvm-project/commit/85e76ec53ae4e5caea5a13b084c19ba4e2f3a6ce
DIFF: 
https://github.com/llvm/llvm-project/commit/85e76ec53ae4e5caea5a13b084c19ba4e2f3a6ce.diff

LOG: [Driver] Treat -O4 as -O3 in clang::getOptimizationLevel, which is called 
when building LTO link command (#216450)

#169762 (commit e60a69ab8a9e7) replaced the -O option handling in
`tools::addLTOOptions` with `getOptimizationLevel()`, but
`getOptimizationLevel` doesn't expect -O4, while `addLTOOptions` used to
accept and without diagnostics. Teach `getOptimizationLevel` about -O4
and don't diagnose to revert to the old behavior.

---------

Co-authored-by: Wael Yehia <[email protected]>

Added: 
    

Modified: 
    clang/lib/Frontend/CompilerInvocation.cpp
    clang/test/Driver/lto.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 70fc346d85920..9359848d3a29b 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2732,7 +2732,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))
+    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


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

Reply via email to