[PATCH] D150183: [Clang][clang-cl] Implement `__builtin_FUNCSIG`
JMazurkiewicz created this revision. JMazurkiewicz added a reviewer: clang. Herald added a project: All. JMazurkiewicz requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits. This patch implements `__builtin_FUNCSIG` intrinsic which returns the same string as `__FUNCSIG__`. Closes #58951. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D150183 Files: clang/docs/LanguageExtensions.rst clang/docs/ReleaseNotes.rst clang/include/clang/AST/Expr.h clang/include/clang/Basic/TokenKinds.def clang/include/clang/Sema/Sema.h clang/lib/AST/Expr.cpp clang/lib/Parse/ParseExpr.cpp clang/lib/Sema/SemaExpr.cpp clang/test/Preprocessor/feature_tests.c clang/test/Sema/source_location.c clang/test/SemaCXX/source_location.cpp Index: clang/test/SemaCXX/source_location.cpp === --- clang/test/SemaCXX/source_location.cpp +++ clang/test/SemaCXX/source_location.cpp @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify %s -// RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -DUSE_CONSTEVAL -fexceptions -verify %s +// RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fms-extensions -fexceptions -verify %s +// RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -fms-extensions -DUSE_CONSTEVAL -fexceptions -verify %s // expected-no-diagnostics #define assert(...) ((__VA_ARGS__) ? ((void)0) : throw 42) @@ -86,6 +86,7 @@ static_assert(is_same); static_assert(is_same); static_assert(is_same); +static_assert(is_same); static_assert(is_same); // test noexcept @@ -94,6 +95,7 @@ static_assert(noexcept(__builtin_FILE())); static_assert(noexcept(__builtin_FILE_NAME())); static_assert(noexcept(__builtin_FUNCTION())); +static_assert(noexcept(__builtin_FUNCSIG())); static_assert(noexcept(__builtin_source_location())); //===--===// @@ -450,6 +452,55 @@ } // namespace test_func +//===--===// +//__builtin_FUNCSIG() +//===--===// + +namespace test_funcsig { + +constexpr const char *test_funcsig_simple(const char *f = __builtin_FUNCSIG()) { + return f; +} +constexpr const char *get_funcsig() { + return __FUNCSIG__; +} +constexpr bool test_funcsig() { + return is_equal(__FUNCSIG__, test_funcsig_simple()) && + !is_equal(get_funcsig(), test_funcsig_simple()); +} +static_assert(test_funcsig()); + +template +constexpr Pair test_funcsig_template(T, const char* f = __builtin_FUNCSIG()) { + return {f, __builtin_FUNCSIG()}; +} +template +void func_template_tests() { + constexpr auto P = test_funcsig_template(42); + static_assert(is_equal(P.first, __FUNCSIG__), ""); + static_assert(!is_equal(P.second, __FUNCSIG__), ""); +} +template void func_template_tests(); + +template +struct TestCtor { + T funcsig = __builtin_FUNCSIG(); + T ctor_funcsig; + TestCtor() = default; + template + constexpr TestCtor(int, F f = __builtin_FUNCSIG()) : ctor_funcsig(f) {} +}; +void ctor_tests() { + constexpr TestCtor<> Template{42}; + static_assert(is_equal(Template.funcsig, "__cdecl test_funcsig::TestCtor<>::TestCtor(int, F) [T = const char *, F = const char *]")); + static_assert(is_equal(Template.ctor_funcsig, __FUNCSIG__)); +} + +constexpr const char* global_funcsig = __builtin_FUNCSIG(); +static_assert(is_equal(global_funcsig, "")); + +} // namespace test_funcsig + //===--===// //__builtin_COLUMN() //===--===// Index: clang/test/Sema/source_location.c === --- clang/test/Sema/source_location.c +++ clang/test/Sema/source_location.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -std=c90 -fconst-strings -DCONST_STRINGS -verify %s -// RUN: %clang_cc1 -std=c90 -verify %s +// RUN: %clang_cc1 -std=c90 -fms-extensions -fconst-strings -DCONST_STRINGS -verify %s +// RUN: %clang_cc1 -std=c90 -fms-extensions -verify %s // expected-no-diagnostics @@ -13,6 +13,7 @@ #ifndef CONST_STRINGS char *const NCFILE = __builtin_FILE(); char *const NCFUNC = __builtin_FUNCTION(); +char *const NCFNSG = __builtin_FUNCSIG(); #endif #ifdef CONST_STRINGS @@ -20,6 +21,7 @@ _Static_assert(IsEqual(__builtin_FILE_NAME(), __FILE_NAME__), ""); _Static_assert(__builtin_LINE() == __LINE__, ""); _Static_assert(IsEqual("", __builtin_FUNCTION()), ""); +_Static_assert(IsEqual("", __builtin_FUNCSIG()), ""); #line 42 "my_file.c" _Static_assert(__builtin_LINE() == 42, ""); @@ -30,5 +32,6 @@ void foo(void) { _Static_assert(IsEqual(__builtin_FUNCTION(), "foo"), ""); + _Static_assert(IsEqual(__builtin_FUNCSIG(), "void __cdecl foo(void)"), "");
[PATCH] D150183: [Clang][clang-cl] Implement `__builtin_FUNCSIG`
JMazurkiewicz updated this revision to Diff 523082. JMazurkiewicz added a comment. Try to fix formatting in `ParseExpr.cpp`. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D150183/new/ https://reviews.llvm.org/D150183 Files: clang/docs/LanguageExtensions.rst clang/docs/ReleaseNotes.rst clang/include/clang/AST/Expr.h clang/include/clang/Basic/TokenKinds.def clang/include/clang/Sema/Sema.h clang/lib/AST/Expr.cpp clang/lib/Parse/ParseExpr.cpp clang/lib/Sema/SemaExpr.cpp clang/test/Preprocessor/feature_tests.c clang/test/Sema/source_location.c clang/test/SemaCXX/source_location.cpp Index: clang/test/SemaCXX/source_location.cpp === --- clang/test/SemaCXX/source_location.cpp +++ clang/test/SemaCXX/source_location.cpp @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify %s -// RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -DUSE_CONSTEVAL -fexceptions -verify %s +// RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fms-extensions -fexceptions -verify %s +// RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -fms-extensions -DUSE_CONSTEVAL -fexceptions -verify %s // expected-no-diagnostics #define assert(...) ((__VA_ARGS__) ? ((void)0) : throw 42) @@ -86,6 +86,7 @@ static_assert(is_same); static_assert(is_same); static_assert(is_same); +static_assert(is_same); static_assert(is_same); // test noexcept @@ -94,6 +95,7 @@ static_assert(noexcept(__builtin_FILE())); static_assert(noexcept(__builtin_FILE_NAME())); static_assert(noexcept(__builtin_FUNCTION())); +static_assert(noexcept(__builtin_FUNCSIG())); static_assert(noexcept(__builtin_source_location())); //===--===// @@ -450,6 +452,55 @@ } // namespace test_func +//===--===// +//__builtin_FUNCSIG() +//===--===// + +namespace test_funcsig { + +constexpr const char *test_funcsig_simple(const char *f = __builtin_FUNCSIG()) { + return f; +} +constexpr const char *get_funcsig() { + return __FUNCSIG__; +} +constexpr bool test_funcsig() { + return is_equal(__FUNCSIG__, test_funcsig_simple()) && + !is_equal(get_funcsig(), test_funcsig_simple()); +} +static_assert(test_funcsig()); + +template +constexpr Pair test_funcsig_template(T, const char* f = __builtin_FUNCSIG()) { + return {f, __builtin_FUNCSIG()}; +} +template +void func_template_tests() { + constexpr auto P = test_funcsig_template(42); + static_assert(is_equal(P.first, __FUNCSIG__), ""); + static_assert(!is_equal(P.second, __FUNCSIG__), ""); +} +template void func_template_tests(); + +template +struct TestCtor { + T funcsig = __builtin_FUNCSIG(); + T ctor_funcsig; + TestCtor() = default; + template + constexpr TestCtor(int, F f = __builtin_FUNCSIG()) : ctor_funcsig(f) {} +}; +void ctor_tests() { + constexpr TestCtor<> Template{42}; + static_assert(is_equal(Template.funcsig, "__cdecl test_funcsig::TestCtor<>::TestCtor(int, F) [T = const char *, F = const char *]")); + static_assert(is_equal(Template.ctor_funcsig, __FUNCSIG__)); +} + +constexpr const char* global_funcsig = __builtin_FUNCSIG(); +static_assert(is_equal(global_funcsig, "")); + +} // namespace test_funcsig + //===--===// //__builtin_COLUMN() //===--===// Index: clang/test/Sema/source_location.c === --- clang/test/Sema/source_location.c +++ clang/test/Sema/source_location.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -std=c90 -fconst-strings -DCONST_STRINGS -verify %s -// RUN: %clang_cc1 -std=c90 -verify %s +// RUN: %clang_cc1 -std=c90 -fms-extensions -fconst-strings -DCONST_STRINGS -verify %s +// RUN: %clang_cc1 -std=c90 -fms-extensions -verify %s // expected-no-diagnostics @@ -13,6 +13,7 @@ #ifndef CONST_STRINGS char *const NCFILE = __builtin_FILE(); char *const NCFUNC = __builtin_FUNCTION(); +char *const NCFNSG = __builtin_FUNCSIG(); #endif #ifdef CONST_STRINGS @@ -20,6 +21,7 @@ _Static_assert(IsEqual(__builtin_FILE_NAME(), __FILE_NAME__), ""); _Static_assert(__builtin_LINE() == __LINE__, ""); _Static_assert(IsEqual("", __builtin_FUNCTION()), ""); +_Static_assert(IsEqual("", __builtin_FUNCSIG()), ""); #line 42 "my_file.c" _Static_assert(__builtin_LINE() == 42, ""); @@ -30,5 +32,6 @@ void foo(void) { _Static_assert(IsEqual(__builtin_FUNCTION(), "foo"), ""); + _Static_assert(IsEqual(__builtin_FUNCSIG(), "void __cdecl foo(void)"), ""); } #endif // CONST_STRINGS Index: clang/test/Preprocessor/feature_tests.c === --- clang/test/Preprocessor/feature_tests.c +++
[PATCH] D150183: [Clang][clang-cl] Implement `__builtin_FUNCSIG`
JMazurkiewicz updated this revision to Diff 523360. JMazurkiewicz marked 2 inline comments as done. JMazurkiewicz added a comment. - Address comments (thanks for the review @aaron.ballman!), - Remove `clang-format` changes (CI might fail), - Add extra tests in `clang/test/Preprocessor/feature_tests.cpp`. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D150183/new/ https://reviews.llvm.org/D150183 Files: clang/docs/LanguageExtensions.rst clang/docs/ReleaseNotes.rst clang/include/clang/AST/Expr.h clang/include/clang/Basic/TokenKinds.def clang/include/clang/Sema/Sema.h clang/lib/AST/Expr.cpp clang/lib/Parse/ParseExpr.cpp clang/lib/Sema/SemaExpr.cpp clang/test/Preprocessor/feature_tests.c clang/test/Preprocessor/feature_tests.cpp clang/test/Sema/source_location.c clang/test/SemaCXX/source_location.cpp Index: clang/test/SemaCXX/source_location.cpp === --- clang/test/SemaCXX/source_location.cpp +++ clang/test/SemaCXX/source_location.cpp @@ -1,5 +1,7 @@ // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify %s // RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -DUSE_CONSTEVAL -fexceptions -verify %s +// RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fms-extensions -DMS -fexceptions -verify %s +// RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -fms-extensions -DMS -DUSE_CONSTEVAL -fexceptions -verify %s // expected-no-diagnostics #define assert(...) ((__VA_ARGS__) ? ((void)0) : throw 42) @@ -86,6 +88,9 @@ static_assert(is_same); static_assert(is_same); static_assert(is_same); +#ifdef MS +static_assert(is_same); +#endif static_assert(is_same); // test noexcept @@ -94,6 +99,9 @@ static_assert(noexcept(__builtin_FILE())); static_assert(noexcept(__builtin_FILE_NAME())); static_assert(noexcept(__builtin_FUNCTION())); +#ifdef MS +static_assert(noexcept(__builtin_FUNCSIG())); +#endif static_assert(noexcept(__builtin_source_location())); //===--===// @@ -450,6 +458,57 @@ } // namespace test_func +//===--===// +//__builtin_FUNCSIG() +//===--===// + +#ifdef MS +namespace test_funcsig { + +constexpr const char *test_funcsig_simple(const char *f = __builtin_FUNCSIG()) { + return f; +} +constexpr const char *get_funcsig() { + return __FUNCSIG__; +} +constexpr bool test_funcsig() { + return is_equal(__FUNCSIG__, test_funcsig_simple()) && + !is_equal(get_funcsig(), test_funcsig_simple()); +} +static_assert(test_funcsig()); + +template +constexpr Pair test_funcsig_template(T, const char* f = __builtin_FUNCSIG()) { + return {f, __builtin_FUNCSIG()}; +} +template +void func_template_tests() { + constexpr auto P = test_funcsig_template(42); + static_assert(is_equal(P.first, __FUNCSIG__), ""); + static_assert(!is_equal(P.second, __FUNCSIG__), ""); +} +template void func_template_tests(); + +template +struct TestCtor { + T funcsig = __builtin_FUNCSIG(); + T ctor_funcsig; + TestCtor() = default; + template + constexpr TestCtor(int, F f = __builtin_FUNCSIG()) : ctor_funcsig(f) {} +}; +void ctor_tests() { + constexpr TestCtor<> Template{42}; + static_assert(is_equal(Template.funcsig, "__cdecl test_funcsig::TestCtor<>::TestCtor(int, F) [T = const char *, F = const char *]")); + static_assert(is_equal(Template.ctor_funcsig, __FUNCSIG__)); +} + +constexpr const char* global_funcsig = __builtin_FUNCSIG(); +static_assert(is_equal(global_funcsig, "")); + +} // namespace test_funcsig +#endif + //===--===// //__builtin_COLUMN() //===--===// Index: clang/test/Sema/source_location.c === --- clang/test/Sema/source_location.c +++ clang/test/Sema/source_location.c @@ -1,5 +1,7 @@ // RUN: %clang_cc1 -std=c90 -fconst-strings -DCONST_STRINGS -verify %s // RUN: %clang_cc1 -std=c90 -verify %s +// RUN: %clang_cc1 -std=c90 -fms-extensions -DMS -fconst-strings -DCONST_STRINGS -verify %s +// RUN: %clang_cc1 -std=c90 -fms-extensions -DMS -verify %s // expected-no-diagnostics @@ -13,6 +15,9 @@ #ifndef CONST_STRINGS char *const NCFILE = __builtin_FILE(); char *const NCFUNC = __builtin_FUNCTION(); +#ifdef MS +char *const NCFNSG = __builtin_FUNCSIG(); +#endif #endif #ifdef CONST_STRINGS @@ -20,6 +25,9 @@ _Static_assert(IsEqual(__builtin_FILE_NAME(), __FILE_NAME__), ""); _Static_assert(__builtin_LINE() == __LINE__, ""); _Static_assert(IsEqual("", __builtin_FUNCTION()), ""); +#ifdef MS +_Static_assert(IsEqual("", __builtin_FUNCSIG()), ""); +#endif #line 42 "my_file.c" _Static_assert(__builtin_LINE() == 42, ""); @@ -30,5 +38,8 @@ void fo
[PATCH] D150183: [Clang][clang-cl] Implement `__builtin_FUNCSIG`
JMazurkiewicz added a comment. > Do you need someone to commit on your behalf? If so, what name and email > address would you like used for patch attribution? Yes, my name and email: "Jakub Mazurkiewicz ". > I can fix up the release notes when I land, so you don't have to upload a new > patch. Thank you in advance. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D150183/new/ https://reviews.llvm.org/D150183 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits