Skip to content

[CMake] Options to control generation of reproducers #143037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions llvm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,10 @@ option (LLVM_VERSION_PRINTER_SHOW_HOST_TARGET_INFO
option(LLVM_VERSION_PRINTER_SHOW_BUILD_CONFIG
"Show the optional build config flags when tools are invoked with --version." ON)

set(LLVM_CRASH_DIAGNOSTICS "" CACHE STRING "Controls whether to generate crash reproducers. Can be OFF, COMPILER, ALL")
set(LLVM_CRASH_DIAGNOSTICS_DIR "" CACHE PATH "Path to use for crash reproducers")
set(LLVM_GEN_REPRODUCER OFF CACHE STRING "Controls when to generate compiler reproducers. Can be OFF, CRASH, ERROR, ALWAYS")

# You can configure which libraries from LLVM you want to include in the
# shared library by setting LLVM_DYLIB_COMPONENTS to a semi-colon delimited
# list of LLVM components. All component names handled by llvm-config are valid.
Expand Down
20 changes: 20 additions & 0 deletions llvm/cmake/modules/HandleLLVMOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1433,3 +1433,23 @@ if(LLVM_ENABLE_LLVM_LIBC)
message(WARNING "Unable to link against LLVM libc. LLVM will be built without linking against the LLVM libc overlay.")
endif()
endif()

if(LLVM_CRASH_DIAGNOSTICS)
string(TOLOWER "${LLVM_CRASH_DIAGNOSTICS}" LLVM_CRASH_DIAGNOSTICS)
check_c_compiler_flag("-fcrash-diagnostics=${LLVM_CRASH_DIAGNOSTICS}" SUPPORTS_FCRASH_DIAGNOSTICS)
append_if(SUPPORTS_FCRASH_DIAGNOSTICS "-fcrash-diagnostics=${LLVM_CRASH_DIAGNOSTICS}"
CMAKE_C_FLAGS CMAKE_CXX_FLAGS CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
endif()

if(LLVM_CRASH_DIAGNOSTICS_DIR)
check_c_compiler_flag("-fcrash-diagnostics-dir=foo" SUPPORTS_FCRASH_DIAGNOSTICS_DIR)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there value in adding a warning here if this is requested but the host compiler does not support the flag?

append_if(SUPPORTS_FCRASH_DIAGNOSTICS_DIR "-fcrash-diagnostics-dir=${LLVM_CRASH_DIAGNOSTICS_DIR}"
CMAKE_C_FLAGS CMAKE_CXX_FLAGS CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
endif()

if(LLVM_GEN_REPRODUCER)
string(TOLOWER "${LLVM_GEN_REPRODUCER}" LLVM_GEN_REPRODUCER)
check_c_compiler_flag("-gen-reproducer=${LLVM_GEN_REPRODUCER}" SUPPORTS_GEN_REPRODUCER)
append_if(SUPPORTS_GEN_REPRODUCER "-gen-reproducer=${LLVM_GEN_REPRODUCER}"
CMAKE_C_FLAGS CMAKE_CXX_FLAGS CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
endif()
4 changes: 4 additions & 0 deletions llvm/cmake/modules/LLVMConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ set(LLVM_HAVE_OPT_VIEWER_MODULES @LLVM_HAVE_OPT_VIEWER_MODULES@)
set(LLVM_CONFIGURATION_TYPES @CMAKE_CONFIGURATION_TYPES@)
set(LLVM_ENABLE_SHARED_LIBS @BUILD_SHARED_LIBS@)

set(LLVM_CRASH_DIAGNOSTICS "@LLVM_CRASH_DIAGNOSTICS@")
set(LLVM_CRASH_DIAGNOSTICS_DIR "@LLVM_CRASH_DIAGNOSTICS_DIR@")
set(LLVM_GEN_REPRODUCER "@LLVM_GEN_REPRODUCER@")

set(LLVM_DEFAULT_EXTERNAL_LIT "@LLVM_CONFIG_DEFAULT_EXTERNAL_LIT@")
set(LLVM_LIT_ARGS "@LLVM_LIT_ARGS@")

Expand Down
11 changes: 11 additions & 0 deletions llvm/docs/CMake.rst
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,17 @@ enabled sub-projects. Nearly all of these variable names begin with
the linker needs to resolve. It is recommended for platforms using the ELF object
format, like Linux systems when linker memory usage is too high.

**LLVM_CRASH_DIAGNOSTICS**:STRING
Controls whether to generate crash reproducers. Possible values are ``OFF``,
``COMPILER`` for compiler, and ``ALL`` for compiler and linker reproducers.

**LLVM_CRASH_DIAGNOSTICS_DIR**:PATH
Path to use for crash reproducers (controlled by ``LLVM_CRASH_DIAGNOSTICS``).

**LLVM_GEN_REPRODUCER**:STRING
Controls when to generate compiler reproducers. Can be ``OFF``, ``CRASH`` for
crashes, ``ERROR`` for compiler errors, and ``ALWAYS`` for every invocation.

**SPHINX_EXECUTABLE**:STRING
The path to the ``sphinx-build`` executable detected by CMake.
For installation instructions, see
Expand Down
Loading