Skip to content

Commit b1641fd

Browse files
committed
[CMake] Limit -momit-leaf-frame-pointer to production builds
When building with asserts or debug information, don't disable leaf frame pointers because some debugging/analysis tools have buggy or nonexistent support for DWARF-style backtraces.
1 parent 9f39c84 commit b1641fd

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,16 @@ function(_add_variant_c_compile_flags)
183183
if(optimized OR CFLAGS_FORCE_BUILD_OPTIMIZED)
184184
list(APPEND result "-O2")
185185

186-
# Omit leaf frame pointers on x86.
187-
if("${CFLAGS_ARCH}" STREQUAL "i386" OR "${CFLAGS_ARCH}" STREQUAL "i686")
188-
if(NOT SWIFT_COMPILER_IS_MSVC_LIKE)
189-
list(APPEND result "-momit-leaf-frame-pointer")
190-
else()
191-
list(APPEND result "/Oy")
186+
# Omit leaf frame pointers on x86 production builds (optimized, no debug
187+
# info, and no asserts).
188+
is_build_type_with_debuginfo("${CFLAGS_BUILD_TYPE}" debug)
189+
if(NOT debug AND NOT CFLAGS_ENABLE_ASSERTIONS)
190+
if("${CFLAGS_ARCH}" STREQUAL "i386" OR "${CFLAGS_ARCH}" STREQUAL "i686")
191+
if(NOT SWIFT_COMPILER_IS_MSVC_LIKE)
192+
list(APPEND result "-momit-leaf-frame-pointer")
193+
else()
194+
list(APPEND result "/Oy")
195+
endif()
192196
endif()
193197
endif()
194198
else()

0 commit comments

Comments
 (0)