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

Update source_location to use __builtin_FUNCSIG #3206

Merged
merged 12 commits into from
Dec 15, 2022
4 changes: 4 additions & 0 deletions stl/inc/source_location
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ _STD_BEGIN
_EXPORT_STD struct source_location {
_NODISCARD static consteval source_location current(const uint_least32_t _Line_ = __builtin_LINE(),
const uint_least32_t _Column_ = __builtin_COLUMN(), const char* const _File_ = __builtin_FILE(),
#ifdef __clang__ // TRANSITION, DevCom-10199227 and LLVM-58951
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
const char* const _Function_ = __builtin_FUNCTION()) noexcept {
#else // ^^^ workaround no workaround vvv
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
const char* const _Function_ = __builtin_FUNCSIG()) noexcept {
#endif // TRANSITION, DevCom-10199227 and LLVM-58951
source_location _Result{};
_Result._Line = _Line_;
_Result._Column = _Column_;
Expand Down
4 changes: 4 additions & 0 deletions tests/std/include/test_header_units_and_modules.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,11 @@ constexpr bool impl_test_source_location() {
const auto sl = source_location::current();
assert(sl.line() == __LINE__ - 1);
assert(sl.column() == 1);
#ifdef __clang__ // TRANSITION, DevCom-10199227 and LLVM-58951
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
assert(sl.function_name() == "impl_test_source_location"sv);
#else // ^^^ workaround // no workaround vvv
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
assert(sl.function_name() == "bool __cdecl impl_test_source_location(void)"sv);
#endif // TRANSITION, DevCom-10199227 and LLVM-58951
assert(string_view{sl.file_name()}.ends_with("test_header_units_and_modules.hpp"sv));
return true;
}
Expand Down
4 changes: 4 additions & 0 deletions tests/std/tests/P1208R6_source_location/header.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ constexpr void header_test() {
const auto x = source_location::current();
assert(x.line() == __LINE__ - 1);
assert(x.column() == 37);
#ifdef __clang__ // TRANSITION, DevCom-10199227 and LLVM-58951
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
assert(x.function_name() == "header_test"sv);
#else // ^^^ workaround no workaround vvv
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
assert(x.function_name() == "void __cdecl header_test(void)"sv);
#endif // TRANSITION, DevCom-10199227 and LLVM-58951
assert(string_view{x.file_name()}.ends_with("header.h"sv));
}
62 changes: 52 additions & 10 deletions tests/std/tests/P1208R6_source_location/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,23 @@ constexpr void local_test() {
const auto x = source_location::current();
assert(x.line() == __LINE__ - 1);
assert(x.column() == 37);
#ifdef __clang__ // TRANSITION, DevCom-10199227 and LLVM-58951
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
assert(x.function_name() == "local_test"sv);
#else // ^^^ workaround // workaround vvv
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
assert(x.function_name() == "void __cdecl local_test(void)"sv);
#endif // TRANSITION, DevCom-10199227 and LLVM-58951
assert(string_view{x.file_name()}.ends_with(test_cpp));
}

constexpr void argument_test(
const unsigned int line, const unsigned int column, const source_location x = source_location::current()) {
assert(x.line() == line);
assert(x.column() == column);
#ifdef __clang__ // TRANSITION, DevCom-10199227 and LLVM-58951
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
assert(x.function_name() == "test"sv);
#else // ^^^ workaround // workaround vvv
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
assert(x.function_name() == "bool __cdecl test(void)"sv);
#endif // TRANSITION, DevCom-10199227 and LLVM-58951
assert(string_view{x.file_name()}.ends_with(test_cpp));
}

Expand All @@ -67,9 +75,13 @@ constexpr void sloc_constructor_test() {
assert(x.loc.line() == __LINE__ - 1);
assert(x.loc.column() == 13);
if (is_constant_evaluated()) {
assert(x.loc.function_name() == "main"sv); // TRANSITION, VSO-1285783
assert(x.loc.function_name() == "int __cdecl main(void)"sv); // TRANSITION, VSO-1285783
} else {
#ifdef __clang__ // TRANSITION, DevCom-10199227 and LLVM-58951
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
assert(x.loc.function_name() == "sloc_constructor_test"sv);
#else // ^^^ workaround // workaround vvv
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
assert(x.loc.function_name() == "void __cdecl sloc_constructor_test(void)"sv);
#endif // TRANSITION, DevCom-10199227 and LLVM-58951
}
assert(string_view{x.loc.file_name()}.ends_with(test_cpp));
}
Expand All @@ -78,7 +90,11 @@ constexpr void different_constructor_test() {
const s x{1};
assert(x.loc.line() == s_int_line);
assert(x.loc.column() == 5);
#ifdef __clang__ // TRANSITION, DevCom-10199227 and LLVM-58951
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
assert(x.loc.function_name() == "s"sv);
#else // ^^^ workaround // workaround vvv
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
assert(x.loc.function_name() == "__cdecl s::s(int)"sv);
#endif // TRANSITION, DevCom-10199227 and LLVM-58951
assert(string_view{x.loc.file_name()}.ends_with(test_cpp));
}

Expand All @@ -87,28 +103,46 @@ constexpr void sub_member_test() {
assert(s.x.loc.line() == __LINE__ - 1);
assert(s.x.loc.column() == 14);
if (is_constant_evaluated()) {
assert(s.x.loc.function_name() == "main"sv); // TRANSITION, VSO-1285783
assert(s.x.loc.function_name() == "int __cdecl main(void)"sv); // TRANSITION, VSO-1285783
} else {
#ifdef __clang__ // TRANSITION, DevCom-10199227 and LLVM-58951
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
assert(s.x.loc.function_name() == "sub_member_test"sv);
#else // ^^^ workaround // workaround vvv
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
assert(s.x.loc.function_name() == "void __cdecl sub_member_test(void)"sv);
#endif // TRANSITION, DevCom-10199227 and LLVM-58951
}
assert(string_view{s.x.loc.file_name()}.ends_with(test_cpp));

const s2 s_i{1};
assert(s_i.x.loc.line() == s2_int_line);
assert(s_i.x.loc.column() == 5);
#ifdef __clang__ // TRANSITION, DevCom-10199227 and LLVM-58951
assert(s_i.x.loc.function_name() == "s2"sv);
#else
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
assert(s_i.x.loc.function_name() == "__cdecl s2::s2(int)"sv);
#endif // TRANSITION, DevCom-10199227 and LLVM-58951
assert(string_view{s_i.x.loc.file_name()}.ends_with(test_cpp));
}

constexpr void lambda_test() {
const auto l = [loc = source_location::current()] { return loc; };
const auto x = l();
assert(x.line() == __LINE__ - 2);
const auto x1 = [loc = source_location::current()] { return loc; }();
const auto x2 = [] { return source_location::current(); }();
assert(x1.line() == __LINE__ - 2);
assert(x2.line() == __LINE__ - 2);
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
#ifndef _M_CEE // TRANSITION, VSO-1665663
assert(x.column() == 51);
#endif // _M_CEE
assert(x.function_name() == "lambda_test"sv);
assert(string_view{x.file_name()}.ends_with(test_cpp));
assert(x1.column() == 52);
#endif // M_CEE
SuperWig marked this conversation as resolved.
Show resolved Hide resolved
assert(x2.column() == 50);
#ifdef __clang__ // TRANSITION, DevCom-10199227 and LLVM-58951
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
assert(x1.function_name() == "lambda_test"sv);
assert(x2.function_name() == "operator()"sv);
#else // ^^^ workaround // workaround vvv
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
assert(x1.function_name() == "void __cdecl lambda_test(void)"sv);
assert(string_view{x2.function_name()}.starts_with("struct std::source_location __cdecl lambda_test::<lambda_"sv));
assert(string_view{x2.function_name()}.ends_with("::operator ()(void) const"sv));
#endif // TRANSITION, DevCom-10199227 and LLVM-58951
assert(string_view{x1.file_name()}.ends_with(test_cpp));
assert(string_view{x2.file_name()}.ends_with(test_cpp));
}

template <class T>
Expand All @@ -120,13 +154,21 @@ constexpr void function_template_test() {
const auto x1 = function_template<void>();
assert(x1.line() == __LINE__ - 5);
assert(x1.column() == 29);
#ifdef __clang__ // TRANSITION, DevCom-10199227 and LLVM-58951
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
assert(x1.function_name() == "function_template"sv);
#else // ^^^ workaround // workaround vvv
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
assert(x1.function_name() == "struct std::source_location __cdecl function_template<void>(void)"sv);
#endif // TRANSITION, DevCom-10199227 and LLVM-58951
assert(string_view{x1.file_name()}.ends_with(test_cpp));

const auto x2 = function_template<int>();
assert(x1.line() == x2.line());
assert(x1.column() == x2.column());
assert(string_view{x1.function_name()} == string_view{x2.function_name()});
#ifdef __clang__ // TRANSITION, DevCom-10199227 and LLVM-58951
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
assert(x2.function_name() == "function_template"sv);
#else // ^^^ workaround // workaround vvv
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
assert(x2.function_name() == "struct std::source_location __cdecl function_template<int>(void)"sv);
#endif // TRANSITION, DevCom-10199227 and LLVM-58951
assert(string_view{x1.file_name()} == string_view{x2.file_name()});
}

Expand Down