Skip to content
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

clang windows segfault #195

Open
adamdusty opened this issue Nov 19, 2024 · 4 comments
Open

clang windows segfault #195

adamdusty opened this issue Nov 19, 2024 · 4 comments
Labels
bug:unconfirmed Something isn't working (to be confirmed)

Comments

@adamdusty
Copy link

Getting a segfault with a minimal test setup on windows with clang 19. Same code compiles and runs with g++ 14.2.

>clang++ --version
clang version 19.1.1
Target: x86_64-w64-windows-gnu
Thread model: posix

Minimal example

#include <snitch/snitch.hpp>

TEST_CASE("Hello world", "[tag]") {
    CHECK(1 == 1);
}

LLDB output and backtrace

* thread #1, stop reason = Exception 0xc0000005 encountered at address 0x7ff71a86764c: Access violation reading location 0x19ef1883c08
    frame #0: 0x00007ff71a86764c tests.exe`snitch::impl::try_get_current_test() at snitch_test_data.cpp:22:12
   19   }
   20  
   21   test_state* try_get_current_test() noexcept {
-> 22       return thread_current_test;
   23   }
   24
   25   void set_current_test(test_state* current) noexcept {
(lldb) bt
* thread #1, stop reason = Exception 0xc0000005 encountered at address 0x7ff71a86764c: Access violation reading location 0x19ef1883c08
  * frame #0: 0x00007ff71a86764c tests.exe`snitch::impl::try_get_current_test() at snitch_test_data.cpp:22:12
    frame #1: 0x00007ff71a8670c8 tests.exe`snitch::registry::run(this=0x00007ff71a89f040, test=0x00007ff71a89f040) at snitch_registry.cpp:500:38
    frame #2: 0x00007ff71a8678b8 tests.exe`snitch::registry::run_selected_tests(this=0x00007ff71a89f040, run_name=(_M_len = 13, _M_str = "tests.exe"), 
filter_strings=0x0000001d459eb520, predicate=0x0000001d459eb508) at snitch_registry.cpp:618:22
    frame #3: 0x00007ff71a867c02 tests.exe`snitch::registry::run_tests(this=0x00007ff71a89f040, run_name=(_M_len = 13, _M_str = "tests.exe")) at snitch_registry.cpp:695:12
    frame #4: 0x00007ff71a8680f0 tests.exe`snitch::(anonymous namespace)::run_tests_impl(r=0x00007ff71a89f040, args=0x0000001d459efdc0) at snitch_registry.cpp:780:22
    frame #5: 0x00007ff71a864f72 tests.exe`snitch::registry::run_tests(this=0x00007ff71a89f040, args=0x0000001d459efdc0) at snitch_registry.cpp:788:26
    frame #6: 0x00007ff71a86493f tests.exe`main(argc=1, argv=0x0000019f17029a80) at snitch_main.cpp:13:26
    frame #7: 0x00007ff71a861340 tests.exe`__tmainCRTStartup + 492
    frame #8: 0x00007ff71a861146 tests.exe`.l_start + 18
    frame #9: 0x00007ffdea747374 kernel32.dll`BaseThreadInitThunk + 20
    frame #10: 0x00007ffdeb3fcc91 ntdll.dll`RtlUserThreadStart + 33
@cschreib
Copy link
Member

I am unable to reproduce so far, but I have only tested clang-16. While I try with clang-19, would you mind posting the content of snitch_config.hpp?

@cschreib cschreib added the bug:unconfirmed Something isn't working (to be confirmed) label Nov 22, 2024
@cschreib
Copy link
Member

I tried clang-19 (the exact same version as you) on Windows and still running OK. I think I'm going to need more info:

  • the content of snitch_config.hpp
  • the full command line used to build the library and the test application, or the sequence of commands used to build (with cmake etc.)

Another possibility is that you are using a different set of build options between the compiled snitch library and your test application. This shouldn't happen in normal use, but perhaps there's an issue with your build setup.

@adamdusty
Copy link
Author

adamdusty commented Dec 6, 2024

My bad for closing and reopening. I didn't mean to spam you, I accidentally clicked the close button somehow.

I am using the library via cmake and fetch_content

"cacheVariables": {
                "CMAKE_CXX_EXTENSIONS": "OFF",
                "CMAKE_CXX_STANDARD": "23",
                "CMAKE_CXX_COMPILER": "clang++",
                "CMAKE_BUILD_TYPE": "Debug",
                "CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
                "BUILD_TESTING": "ON"
            }
project(
    collection_tests
    LANGUAGES CXX
)
include(FetchContent)

FetchContent_Declare(
    snitch
    GIT_REPOSITORY https://github.com/snitch-org/snitch.git
    GIT_TAG        v1.2.5
    SYSTEM
)
FetchContent_MakeAvailable(snitch)


add_executable(collection_tests)
target_link_libraries(collection_tests PRIVATE ad::collections snitch::snitch)
target_sources(collection_tests PRIVATE "src/vector.cpp")

add_test(NAME collection_tests COMMAND collection_tests)

Here is my snitch_config.hpp

#ifndef SNITCH_CONFIG_HPP
#define SNITCH_CONFIG_HPP

#include <version> // for C++ feature check macros

// These are defined from build-time configuration.
// clang-format off
#define SNITCH_VERSION "1.2.5"
#define SNITCH_FULL_VERSION "1.2.5.86d18cb"
#define SNITCH_VERSION_MAJOR 1
#define SNITCH_VERSION_MINOR 2
#define SNITCH_VERSION_PATCH 5

#if !defined(SNITCH_MAX_TEST_CASES)
#    define SNITCH_MAX_TEST_CASES 5000
#endif
#if !defined(SNITCH_MAX_NESTED_SECTIONS)
#    define SNITCH_MAX_NESTED_SECTIONS 8
#endif
#if !defined(SNITCH_MAX_EXPR_LENGTH)
#    define SNITCH_MAX_EXPR_LENGTH 1024
#endif
#if !defined(SNITCH_MAX_MESSAGE_LENGTH)
#    define SNITCH_MAX_MESSAGE_LENGTH 1024
#endif
#if !defined(SNITCH_MAX_TEST_NAME_LENGTH)
#    define SNITCH_MAX_TEST_NAME_LENGTH 1024
#endif
#if !defined(SNITCH_MAX_TAG_LENGTH)
#    define SNITCH_MAX_TAG_LENGTH 256
#endif
#if !defined(SNITCH_MAX_CAPTURES)
#    define SNITCH_MAX_CAPTURES 8
#endif
#if !defined(SNITCH_MAX_CAPTURE_LENGTH)
#    define SNITCH_MAX_CAPTURE_LENGTH 256
#endif
#if !defined(SNITCH_MAX_UNIQUE_TAGS)
#    define SNITCH_MAX_UNIQUE_TAGS 1024
#endif
#if !defined(SNITCH_MAX_COMMAND_LINE_ARGS)
#    define SNITCH_MAX_COMMAND_LINE_ARGS 1024
#endif
#if !defined(SNITCH_MAX_REGISTERED_REPORTERS)
#    define SNITCH_MAX_REGISTERED_REPORTERS 8
#endif
#if !defined(SNITCH_MAX_PATH_LENGTH)
#    define SNITCH_MAX_PATH_LENGTH 1024
#endif
#if !defined(SNITCH_DEFINE_MAIN)
#define SNITCH_DEFINE_MAIN 1
#endif
#if !defined(SNITCH_WITH_EXCEPTIONS)
#define SNITCH_WITH_EXCEPTIONS 1
#endif
#if !defined(SNITCH_WITH_TIMINGS)
#define SNITCH_WITH_TIMINGS 1
#endif
#if !defined(SNITCH_WITH_SHORTHAND_MACROS)
#define SNITCH_WITH_SHORTHAND_MACROS 1
#endif
#if !defined(SNITCH_DEFAULT_WITH_COLOR)
#define SNITCH_DEFAULT_WITH_COLOR 1
#endif
#if !defined(SNITCH_CONSTEXPR_FLOAT_USE_BITCAST)
#define SNITCH_CONSTEXPR_FLOAT_USE_BITCAST 1
#endif
#if !defined(SNITCH_APPEND_TO_CHARS)
#define SNITCH_APPEND_TO_CHARS 1
#endif
#if !defined(SNITCH_DECOMPOSE_SUCCESSFUL_ASSERTIONS)
#define SNITCH_DECOMPOSE_SUCCESSFUL_ASSERTIONS 0
#endif
#if !defined(SNITCH_WITH_ALL_REPORTERS)
#define SNITCH_WITH_ALL_REPORTERS 1
#endif
#if !defined(SNITCH_WITH_TEAMCITY_REPORTER)
#define SNITCH_WITH_TEAMCITY_REPORTER 0
#endif
#if !defined(SNITCH_WITH_CATCH2_REPORTER)
#define SNITCH_WITH_CATCH2_REPORTER 0
#endif
#if !defined(SNITCH_WITH_MULTITHREADING)
#define SNITCH_WITH_MULTITHREADING 1
#endif
#if !defined(SNITCH_SHARED_LIBRARY)
#define SNITCH_SHARED_LIBRARY 0
#endif
// clang-format on

#if defined(_MSC_VER)
#    if defined(_KERNEL_MODE) || (defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS)
#        define SNITCH_EXCEPTIONS_NOT_AVAILABLE
#    endif
#elif defined(__clang__) || defined(__GNUC__)
#    if !defined(__EXCEPTIONS)
#        define SNITCH_EXCEPTIONS_NOT_AVAILABLE
#    endif
#endif

#if defined(SNITCH_EXCEPTIONS_NOT_AVAILABLE)
#    undef SNITCH_WITH_EXCEPTIONS
#    define SNITCH_WITH_EXCEPTIONS 0
#endif

#if SNITCH_WITH_MULTITHREADING
#    define SNITCH_THREAD_LOCAL thread_local
#else
#    define SNITCH_THREAD_LOCAL
#endif

#if !defined(__cpp_lib_bit_cast)
#    undef SNITCH_CONSTEXPR_FLOAT_USE_BITCAST
#    define SNITCH_CONSTEXPR_FLOAT_USE_BITCAST 0
#endif

#if (!defined(__cpp_lib_to_chars)) || (defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE <= 11) ||     \
    (defined(_LIBCPP_VERSION) && _LIBCPP_VERSION <= 14000) ||                                      \
    (defined(_MSC_VER) && _MSC_VER <= 1924)
#    undef SNITCH_APPEND_TO_CHARS
#    define SNITCH_APPEND_TO_CHARS 0
#endif

#if SNITCH_SHARED_LIBRARY
#    if defined(_MSC_VER)
#        if defined(SNITCH_EXPORTS)
#            define SNITCH_EXPORT __declspec(dllexport)
#        else
#            define SNITCH_EXPORT __declspec(dllimport)
#        endif
#    elif defined(__clang__) || defined(__GNUC__)
#        define SNITCH_EXPORT [[gnu::visibility("default")]]
#    else
#        define SNITCH_EXPORT
#    endif
#else
#    define SNITCH_EXPORT
#endif

#endif

@adamdusty adamdusty reopened this Dec 6, 2024
@cschreib
Copy link
Member

cschreib commented Dec 7, 2024

No worries! And thanks for the extra information.

I used the minimal example code from your first post, the CMake file from your latest post, clang for Windows 19.1.0, and used CMake to configure the build like so:

mkdir build
cd build
cmake .. -DCMAKE_CXX_COMPILER=clang++ -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_EXTENSIONS=OFF -DCMAKE_CXX_STANDARD=23

I checked that the snitch_config.hpp ends up identical (it does). Then built with ninja. The resulting application runs fine:
image

Here's the executable I obtain from this: standalone.zip; are you able to run it and see if it also runs fine on your end?

If this runs fine, then it's got something to do with your build environment. It could be a difference in the MSVC build tools; I use v14.39.33519. You should be able to tell which one you're using by inspecting your PATH environment variable (in a VC++ command prompt, or after running vcvarsall.bat, whichever you use to set up your development environment on Windows). I think clang may also be configured to build against the MinGW STL, is that what you are using?

If this does not run fine, then it's got something to do with your execution environment. That's going to be harder; could be the MSVC runtime (I use v14.42.34433.0, as read from the Details tab in the properties of C:\Windows\System32\vcruntime140d.dll), Windows version (I am on Windows v10.0.19045), antivirus, ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug:unconfirmed Something isn't working (to be confirmed)
Projects
None yet
Development

No branches or pull requests

2 participants