diff --git a/src/shambackends/include/shambackends/benchmarks/fma_chains.hpp b/src/shambackends/include/shambackends/benchmarks/fma_chains.hpp index 8f92ea0f0b..8a802c2aa0 100644 --- a/src/shambackends/include/shambackends/benchmarks/fma_chains.hpp +++ b/src/shambackends/include/shambackends/benchmarks/fma_chains.hpp @@ -148,7 +148,7 @@ namespace sham::benchmarks { double flops = flop_count / (sec); return { - .func_name = SourceLocation{}.loc.function_name(), + .func_name = std::source_location::current().function_name(), .seconds = sec, .flops = flops, .nrotations = nrotation}; diff --git a/src/shambackends/include/shambackends/benchmarks/saxpy.hpp b/src/shambackends/include/shambackends/benchmarks/saxpy.hpp index c43b240f00..0a1ed8d7ab 100644 --- a/src/shambackends/include/shambackends/benchmarks/saxpy.hpp +++ b/src/shambackends/include/shambackends/benchmarks/saxpy.hpp @@ -155,7 +155,7 @@ namespace sham::benchmarks { } return { - .func_name = SourceLocation{}.loc.function_name(), + .func_name = std::source_location::current().function_name(), .seconds = seconds, .bandwidth = double(N) * load_size * 3 / seconds / 1e9, .byte_used = u64(N) * u64(load_size) * 2_u64}; diff --git a/src/shambackends/include/shambackends/kernel_call.hpp b/src/shambackends/include/shambackends/kernel_call.hpp index 95ace0b3a9..ef85459124 100644 --- a/src/shambackends/include/shambackends/kernel_call.hpp +++ b/src/shambackends/include/shambackends/kernel_call.hpp @@ -285,7 +285,7 @@ namespace sham { RefOut in_out, index_t n, Functor &&kernel_gen, - SourceLocation &&callsite = SourceLocation{}) { + std::source_location &&callsite = std::source_location::current()) { __shamrock_stack_entry_with_callsite(callsite); @@ -324,7 +324,7 @@ namespace sham { RefOut in_out, index_t n, Functor &&func, - SourceLocation &&callsite = SourceLocation{}) { + std::source_location &&callsite = std::source_location::current()) { __shamrock_log_callsite(callsite); @@ -517,7 +517,7 @@ namespace sham { RefOut in_out, u32 n, Functor &&func, - SourceLocation &&callsite = SourceLocation{}) { + std::source_location &&callsite = std::source_location::current()) { __shamrock_log_callsite(callsite); @@ -533,7 +533,7 @@ namespace sham { RefOut in_out, u64 n, Functor &&func, - SourceLocation &&callsite = SourceLocation{}) { + std::source_location &&callsite = std::source_location::current()) { __shamrock_log_callsite(callsite); @@ -549,7 +549,7 @@ namespace sham { RefOut in_out, u32 n, Functor &&kernel_gen, - SourceLocation &&callsite = SourceLocation{}) { + std::source_location &&callsite = std::source_location::current()) { __shamrock_log_callsite(callsite); @@ -565,7 +565,7 @@ namespace sham { RefOut in_out, u64 n, Functor &&kernel_gen, - SourceLocation &&callsite = SourceLocation{}) { + std::source_location &&callsite = std::source_location::current()) { __shamrock_log_callsite(callsite); diff --git a/src/shambackends/include/shambackends/kernel_call_distrib.hpp b/src/shambackends/include/shambackends/kernel_call_distrib.hpp index 44e291c0b5..d61f4b1d9d 100644 --- a/src/shambackends/include/shambackends/kernel_call_distrib.hpp +++ b/src/shambackends/include/shambackends/kernel_call_distrib.hpp @@ -53,7 +53,7 @@ namespace sham { "kern call", "called DDMultiRef.get, id =", id, - SourceLocation{}.format_one_line_func()); + shambase::format_one_line_func(std::source_location::current())); return std::apply( [id](auto &...args) { return sham::MultiRef{args.get(id)...}; diff --git a/src/shambase/include/shambase/stacktrace.hpp b/src/shambase/include/shambase/stacktrace.hpp index f0753f4fff..b59a4d9fb5 100644 --- a/src/shambase/include/shambase/stacktrace.hpp +++ b/src/shambase/include/shambase/stacktrace.hpp @@ -85,11 +85,16 @@ namespace shambase::details { /// Helper class to manage the call stack entry struct CallStackEntry { - inline CallStackEntry(SourceLocation &loc) { + inline CallStackEntry(const SourceLocation &loc) { // Push the source location to the call stack call_stack.emplace(loc); } + inline CallStackEntry(const std::source_location &loc) { + // Push the source location to the call stack + call_stack.emplace(SourceLocation{loc}); + } + // This class is not safe if copied or moved CallStackEntry(const CallStackEntry &) = delete; @@ -138,7 +143,9 @@ namespace shambase::details { * @param loc Source location attached to the entry (default: SourceLocation{}) */ inline BasicStackEntry( - SourceLocation &callsite, bool do_timer = true, SourceLocation &&loc = SourceLocation{}) + const SourceLocation &callsite, + bool do_timer = true, + SourceLocation &&loc = SourceLocation{}) : loc(loc), do_timer(do_timer), scoped_callstack_entry(callsite) { #ifdef SHAMROCK_USE_PROFILING if (do_timer) { @@ -150,6 +157,12 @@ namespace shambase::details { #endif } + inline BasicStackEntry( + const std::source_location &callsite, + bool do_timer = true, + std::source_location &&loc = std::source_location::current()) + : BasicStackEntry(SourceLocation{callsite}, do_timer, SourceLocation{loc}) {} + /** * @brief Destroy the Basic Stack Entry object. * diff --git a/src/shamtest/shamtest.hpp b/src/shamtest/shamtest.hpp index 620078f4cf..6da4b37ce5 100644 --- a/src/shamtest/shamtest.hpp +++ b/src/shamtest/shamtest.hpp @@ -203,8 +203,8 @@ namespace shamtest::details { shamtest::asserts().assert_bool_with_log( \ assert_name, \ eval, \ - STDSTRINGIFY(a) + " evaluated to false\n\n" \ - + " -> location : " + SourceLocation{}.format_one_line()); \ + STDSTRINGIFY(a) + " evaluated to false\n\n" + " -> location : " \ + + shambase::format_one_line(std::source_location::current())); \ } \ } while (0) @@ -232,8 +232,8 @@ namespace shamtest::details { eval, \ assert_name + " evaluated to false\n\n" + " -> " #_a \ + shambase::format(" = {}", _______a) + "\n" + " -> " #_b \ - + shambase::format(" = {}", _______b) + "\n" \ - + " -> location : " + SourceLocation{}.format_one_line()); \ + + shambase::format(" = {}", _______b) + "\n" + " -> location : " \ + + shambase::format_one_line(std::source_location::current())); \ } \ } while (0) @@ -276,8 +276,8 @@ namespace shamtest::details { eval, \ assert_name + " evaluated to false\n\n" + shambase::format(" -> " #_a " = {}", a) \ + "\n" + shambase::format(" -> " #_b " = {}", b) + "\n" \ - + shambase::format(" -> " #prec " = {}", prec) + "\n" \ - + " -> location : " + SourceLocation{}.format_one_line()); \ + + shambase::format(" -> " #prec " = {}", prec) + "\n" + " -> location : " \ + + shambase::format_one_line(std::source_location::current())); \ } \ } while (0) @@ -368,7 +368,7 @@ namespace shamtest::details { false, \ "Expected throw of type " #exception_type ", but nothing was thrown\n" \ " -> location : " \ - + SourceLocation{}.format_one_line()); \ + + shambase::format_one_line(std::source_location::current())); \ } catch (const exception_type &ex) { \ /* If wanted exception is thrown, assert that the test pass */ \ shamtest::asserts().assert_bool_with_log( \ @@ -379,7 +379,8 @@ namespace shamtest::details { #exception_type " was not thrown", \ false, \ "Expected throw of type " #exception_type ", but got " + std::string(e.what()) \ - + "\n" + " -> location : " + SourceLocation{}.format_one_line()); \ + + "\n" + " -> location : " \ + + shambase::format_one_line(std::source_location::current())); \ } catch (...) { \ /* If an unknown exception is thrown, assert that the test failed */ \ shamtest::asserts().assert_bool_with_log( \ @@ -387,6 +388,6 @@ namespace shamtest::details { false, \ "Expected throw of type " #exception_type ", but got unknown exception\n" \ " -> location : " \ - + SourceLocation{}.format_one_line()); \ + + shambase::format_one_line(std::source_location::current())); \ } \ } while (0)