From 81ead5a1bbc942e46d9988c21d6f4c78bff013a0 Mon Sep 17 00:00:00 2001 From: Luke Shingles Date: Tue, 12 Nov 2024 08:46:32 +0000 Subject: [PATCH] Add STACKTRACE=ON for assertion failures (C++23 feature supported by gcc >= 14) (#151) --- .clangd | 7 ++++++- Makefile | 39 +++++++++++++++++++++++++-------------- decay.cc | 2 +- input.cc | 2 +- sn3d.h | 11 +++++++++-- 5 files changed, 42 insertions(+), 19 deletions(-) diff --git a/.clangd b/.clangd index 16adac4c8..2cea2fc80 100644 --- a/.clangd +++ b/.clangd @@ -12,7 +12,8 @@ Diagnostics: Includes: # std::ranges::upper_bound is triggering warning to include a private libc++ header __algorithm/ranges_upper_bound.h # IgnoreHeader: '.*(ranges).*' - IgnoreHeader: '.*(__algorithm).*' + IgnoreHeader: 'signal.h|(_).*(.h)|.*(__algorithm).*' + AnalyzeAngledIncludes: true Completion: AllScopes: true @@ -23,3 +24,7 @@ InlayHints: Designators: true Enabled: true ParameterNames: true + DeducedTypes: false + +Hover: + ShowAKA: Yes diff --git a/Makefile b/Makefile index 7a047e0d0..e8e5632e7 100644 --- a/Makefile +++ b/Makefile @@ -26,21 +26,31 @@ endif CXX := mpicxx COMPILER_VERSION := $(shell $(CXX) --version) +COMPILER_VERSION_NUMBER := $(shell $(CXX) -dumpversion -dumpfullversion) +COMPILER_VERSION_NUMBER_MAJOR := $(shell echo $(COMPILER_VERSION_NUMBER) | cut -f1 -d.) $(info $(COMPILER_VERSION)) ifneq '' '$(findstring clang,$(COMPILER_VERSION))' - COMPILER_NAME := CLANG - CXXFLAGS += -flto=thin + COMPILER_NAME := CLANG + CXXFLAGS += -flto=thin else ifneq '' '$(findstring g++,$(COMPILER_VERSION))' - COMPILER_NAME := GCC - CXXFLAGS += -flto=auto + COMPILER_NAME := GCC + CXXFLAGS += -flto=auto + # std::stacktrace is available in GCC 14 and later + # but it is not enabled by default because it slowed down the GitHub CI by > 2x + ifeq ($(shell expr $(COMPILER_VERSION_NUMBER_MAJOR) \>= 14),1) + ifeq ($(STACKTRACE),ON) + CXXFLAGS += -DSTACKTRACE_ON=true -rdynamic + LDFLAGS += -lstdc++exp + endif + endif else ifneq '' '$(findstring nvc++,$(COMPILER_VERSION))' - COMPILER_NAME := NVHPC + COMPILER_NAME := NVHPC else - $(warning Unknown compiler) - COMPILER_NAME := unknown + $(warning Unknown compiler) + COMPILER_NAME := unknown endif -$(info detected compiler is $(COMPILER_NAME)) +$(info detected compiler is $(COMPILER_NAME) major version $(COMPILER_VERSION_NUMBER_MAJOR)) ifeq ($(COMPILER_NAME),NVHPC) CXXFLAGS += -std=c++20 @@ -192,15 +202,16 @@ ifneq ($(MAX_NODE_SIZE),) endif ifeq ($(TESTMODE),ON) - CXXFLAGS += -DTESTMODE=true -D_LIBCPP_DEBUG=0 + CXXFLAGS += -DTESTMODE=true - CXXFLAGS += -D_GLIBCXX_ASSERTIONS - # CXXFLAGS += -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_BACKTRACE=1 + CXXFLAGS += -fno-omit-frame-pointer -g - CXXFLAGS += -fno-omit-frame-pointer -g + CXXFLAGS += -D_GLIBCXX_ASSERTIONS + # CXXFLAGS += -D_GLIBCXX_DEBUG + # CXXFLAGS += -D_GLIBCXX_DEBUG_BACKTRACE - # CXXFLAGS += -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE CXXFLAGS += -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG + # CXXFLAGS += -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE CXXFLAGS += -fsanitize=undefined,address @@ -227,7 +238,7 @@ else endif endif -CXXFLAGS += -Winline -Wall -Wextra -pedantic -Wpedantic -Wredundant-decls -Wno-unused-parameter -Wno-unused-function -Wno-inline -Wsign-compare -Wshadow +CXXFLAGS += -Winline -Wall -Wextra -pedantic -Wpedantic -Wredundant-decls -Wno-unused-parameter -Wno-unused-function -Wno-inline -Wsign-compare -Wshadow # sn3d.cc and exspec.cc have main() defined common_files := $(filter-out sn3d.cc exspec.cc, $(wildcard *.cc)) diff --git a/decay.cc b/decay.cc index 55d3ba88b..af34ef139 100644 --- a/decay.cc +++ b/decay.cc @@ -475,7 +475,7 @@ void filter_unused_nuclides(const std::vector &custom_zlist, const std::vec }); nuclides.shrink_to_fit(); - // update the nuclide indicies in the decay paths after we possibly removed some nuclides + // update the nuclide indices in the decay paths after we possibly removed some nuclides for (auto &decaypath : decaypaths) { std::ranges::transform(decaypath.z, decaypath.a, decaypath.nucindex.begin(), [](const auto z, const auto a) { return get_nucindex(z, a); }); diff --git a/input.cc b/input.cc index 53ab10dfe..f9a1114d9 100644 --- a/input.cc +++ b/input.cc @@ -780,7 +780,7 @@ void setup_phixs_list() { globals::bfestimcount = 0; if (nbfcontinua > 0) { - // indicies above were temporary only. continuum index should be to the sorted list + // indices above were temporary only. continuum index should be to the sorted list std::ranges::SORT_OR_STABLE_SORT(std::span(nonconstallcont, nbfcontinua), std::ranges::less{}, &FullPhotoionTransition::nu_edge); diff --git a/sn3d.h b/sn3d.h index 1d81bb393..743724e72 100644 --- a/sn3d.h +++ b/sn3d.h @@ -14,7 +14,6 @@ #define __device__ #endif -#include #include #include #include @@ -38,6 +37,13 @@ #include #include +#ifdef STACKTRACE_ON +#include +#define STACKTRACEIFSUPPORTED << std::stacktrace::current() +#else +#define STACKTRACEIFSUPPORTED +#endif + #ifdef STDPAR_ON #include @@ -133,7 +139,7 @@ __attribute__((__format__(__printf__, 1, 2))) inline auto printout(const char *f output_file.flush(); \ } \ std::cerr << "\n[rank " << globals::my_rank << "] " << __FILE__ << ":" << __LINE__ << ": failed assertion `" \ - << #e << "` in function " << __PRETTY_FUNCTION__ << "\n"; \ + << #e << "` in function " << __PRETTY_FUNCTION__ << "\n" STACKTRACEIFSUPPORTED; \ } \ assert(assertpass); \ } @@ -218,6 +224,7 @@ inline void gsl_error_handler_printout(const char *reason, const char *file, int } return file; } + #include "globals.h" [[nodiscard]] inline auto get_bflutindex(const int tempindex, const int element, const int ion, const int level,