[clang] [Driver] Treat -O4 as -O3 in clang::getOptimizationLevel, which is called when building LTO link command (PR #216450)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 14 20:18:49 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Wael Yehia (w2yehia)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/216450.diff
2 Files Affected:
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+1-1)
- (modified) clang/test/Driver/lto.c (+2)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/216450
More information about the cfe-commits
mailing list