Index: llvm/cmake/modules/HandleLLVMOptions.cmake =================================================================== --- llvm/cmake/modules/HandleLLVMOptions.cmake +++ llvm/cmake/modules/HandleLLVMOptions.cmake @@ -594,6 +594,16 @@ 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). Before + # refactoring these data structures, we need to disable dead store + # eliminations based on object lifetime so the issue won't explode. + 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})