[libc-commits] [libc] [libc][cmake] Respect MinSizeRel optimization flags (PR #233920)

via libc-commits libc-commits at lists.llvm.org
Tue Oct 20 10:52:29 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Prabhu Rajasekaran (Prabhuk)

<details>
<summary>Changes</summary>

Do not override size-optimized compilation flags with `-O3` when building with `MinSizeRel`.

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


1 Files Affected:

- (modified) libc/CMakeLists.txt (+6-4) 


``````````diff
diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt
index b6c6b0aa546e2..6ef59016a4a4a 100644
--- a/libc/CMakeLists.txt
+++ b/libc/CMakeLists.txt
@@ -577,10 +577,12 @@ foreach(entrypoint IN LISTS TARGET_LLVMLIBC_ENTRYPOINTS)
   list(APPEND TARGET_ENTRYPOINT_NAME_LIST ${entrypoint_name})
 endforeach()
 
-if(MSVC AND NOT MSYS)
-  set(libc_opt_high_flag "/O2")
-else()
-  set(libc_opt_high_flag "-O3")
+if(NOT CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
+  if(MSVC AND NOT MSYS)
+    set(libc_opt_high_flag "/O2")
+  else()
+    set(libc_opt_high_flag "-O3")
+  endif()
 endif()
 
 add_subdirectory(include)

``````````

</details>


https://github.com/llvm/llvm-project/pull/233920


More information about the libc-commits mailing list