From 75ab3ff66b2380e4042ac9859d49d3c7bdf105ec Mon Sep 17 00:00:00 2001 From: Lucas de Sousa Rosa Date: Mon, 27 Oct 2025 11:33:06 -0300 Subject: [PATCH] Fix segmentation fault on macOS ARM64 with Clang 19 This commit fixes two issues causing crashes on modern macOS systems with Clang 19: 1. Add virtual destructor to PajeEntity class - Prevents undefined behavior when deleting derived objects through base pointers - Resolves -Wdelete-abstract-non-virtual-dtor compiler warnings 2. Fix dangling iterator in valuesForEntityType - Store container returned by values() before iterating - Prevents iteration over destroyed temporary object - Resolves -Wdangling-gsl compiler warning These issues manifest as segmentation faults on Apple Silicon Macs with Clang 19.1.7. It modifies src/tools/CMakeLists.txt to compile correctly in Apple systems. --- src/libpaje/PajeEntity.h | 3 ++- src/libpaje/PajeSimulator+Queries.cc | 4 +++- src/tools/CMakeLists.txt | 7 ++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/libpaje/PajeEntity.h b/src/libpaje/PajeEntity.h index 7e37c60a..333b0dfd 100644 --- a/src/libpaje/PajeEntity.h +++ b/src/libpaje/PajeEntity.h @@ -77,7 +77,8 @@ class PajeEntity : public PajeVirtualEntity public: PajeEntity (PajeContainer *container, PajeType *type, PajeTraceEvent *event); - ~PajeEntity (void); + // Add virtual destructor to prevent undefined behavior when deleting derived objects via base pointer + virtual ~PajeEntity (void); void addPajeTraceEvent (PajeTraceEvent *event); PajeContainer *container (void) const; PajeType *type (void) const; diff --git a/src/libpaje/PajeSimulator+Queries.cc b/src/libpaje/PajeSimulator+Queries.cc index 3b1f9cb2..6bd2d8ba 100644 --- a/src/libpaje/PajeSimulator+Queries.cc +++ b/src/libpaje/PajeSimulator+Queries.cc @@ -165,7 +165,9 @@ std::vector PajeSimulator::valuesForEntityType (PajeType *type) PajeCategorizedType *catType = dynamic_cast(type); if (catType){ std::pair val; - for (auto it = catType->values().begin(); it != catType->values().end(); ++it) + // Store the returned container to avoid dangling iterators from temporary + auto vals = catType->values(); + for (auto it = vals.begin(); it != vals.end(); ++it) ret.push_back((std::pair(*it)).second); } return ret; diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt index 5b2278a3..4965aad1 100644 --- a/src/tools/CMakeLists.txt +++ b/src/tools/CMakeLists.txt @@ -42,7 +42,12 @@ INCLUDE_DIRECTORIES (pj_equals ${PROJECT_SOURCE_DIR}/src/libpaje/) INCLUDE_DIRECTORIES(${pajeng_SOURCE_DIR}/src/fb/) include_directories(${CMAKE_BINARY_DIR}) # FIXME check for libgomp / OpenMP support -set_target_properties(pj_equals PROPERTIES COMPILE_FLAGS "-fopenmp") +IF(APPLE) + set_target_properties(pj_equals PROPERTIES COMPILE_FLAGS "-Xpreprocessor -fopenmp") + TARGET_LINK_LIBRARIES(pj_equals omp) +ELSE() + set_target_properties(pj_equals PROPERTIES COMPILE_FLAGS "-fopenmp") +ENDIF() IF(STATIC_LINKING) TARGET_LINK_LIBRARIES(pj_equals paje_library_static)