Skip to content

Commit

Permalink
[cmake] Disable GCC lifetime DSE
Browse files Browse the repository at this point in the history
LLVM data structures like llvm::User and llvm::MDNode rely on
the value of object storage persisting beyond the lifetime of the
object (#24952).  This is not standard compliant and causes a runtime
crash if LLVM is built with GCC and LTO enabled (#57740).  Until
these issues are fixed, we need to disable dead store eliminations
eliminations based on object lifetime.

Bug: llvm/llvm-project#24952
Bug: llvm/llvm-project#57740
Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106943

(This was originally committed as 94f7c96 but
I reverted it in b974991f4c4457a2104b648d9797a0ed438ecc9 to fix authorship.)

Reviewed By: MaskRay, thesamesam, nikic

Differential Revision: https://reviews.llvm.org/D150505

Signed-off-by: Sam James <sam@gentoo.org>
(cherry picked from commit ce990b5)
  • Loading branch information
xry111 authored and llvmbot committed May 14, 2023
1 parent 3c1576c commit 562fe43
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions llvm/cmake/modules/HandleLLVMOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,16 @@ if ( LLVM_COMPILER_IS_GCC_COMPATIBLE OR CMAKE_CXX_COMPILER_ID MATCHES "XL" )
add_flag_if_supported("-Werror=unguarded-availability-new" WERROR_UNGUARDED_AVAILABILITY_NEW)
endif( LLVM_COMPILER_IS_GCC_COMPATIBLE OR CMAKE_CXX_COMPILER_ID MATCHES "XL" )

if ( LLVM_COMPILER_IS_GCC_COMPATIBLE )
# LLVM data structures like llvm::User and llvm::MDNode rely on
# the value of object storage persisting beyond the lifetime of the
# object (#24952). This is not standard compliant and causes a runtime
# crash if LLVM is built with GCC and LTO enabled (#57740). Until
# these bugs are fixed, we need to disable dead store eliminations
# based on object lifetime.
add_flag_if_supported("-fno-lifetime-dse" CMAKE_CXX_FLAGS)
endif ( LLVM_COMPILER_IS_GCC_COMPATIBLE )

# Modules enablement for GCC-compatible compilers:
if ( LLVM_COMPILER_IS_GCC_COMPATIBLE AND LLVM_ENABLE_MODULES )
set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
Expand Down

0 comments on commit 562fe43

Please sign in to comment.