Skip to content

Commit

Permalink
Add STACKTRACE=ON for assertion failures (C++23 feature supported by …
Browse files Browse the repository at this point in the history
…gcc >= 14) (#151)
  • Loading branch information
lukeshingles authored Nov 12, 2024
1 parent 8e01c64 commit 81ead5a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 19 deletions.
7 changes: 6 additions & 1 deletion .clangd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,3 +24,7 @@ InlayHints:
Designators: true
Enabled: true
ParameterNames: true
DeducedTypes: false

Hover:
ShowAKA: Yes
39 changes: 25 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion decay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ void filter_unused_nuclides(const std::vector<int> &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); });
Expand Down
2 changes: 1 addition & 1 deletion input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
11 changes: 9 additions & 2 deletions sn3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#define __device__
#endif

#include <getopt.h>
#include <gsl/gsl_integration.h>
#include <sys/wait.h>
#include <unistd.h>
Expand All @@ -38,6 +37,13 @@
#include <string>
#include <tuple>

#ifdef STACKTRACE_ON
#include <stacktrace>
#define STACKTRACEIFSUPPORTED << std::stacktrace::current()
#else
#define STACKTRACEIFSUPPORTED
#endif

#ifdef STDPAR_ON
#include <execution>

Expand Down Expand Up @@ -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); \
}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 81ead5a

Please sign in to comment.