https://github.com/zahiraam updated https://github.com/llvm/llvm-project/pull/128184
>From bcf2a4708c3f9ae88f5fddafe02c95533601c887 Mon Sep 17 00:00:00 2001 From: Zahira Ammarguellat <zahira.ammarguel...@intel.com> Date: Fri, 21 Feb 2025 07:14:02 -0800 Subject: [PATCH 1/3] [CLANG-CL] Remove the 'static' declaration specifier for _FUNCTION_ in MSVC mode. --- clang/lib/AST/Expr.cpp | 8 +++++-- clang/test/SemaCXX/source_location.cpp | 31 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index b747aa8df807d..14d0955503634 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -747,8 +747,12 @@ std::string PredefinedExpr::ComputeName(PredefinedIdentKind IK, if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { if (MD->isVirtual() && IK != PredefinedIdentKind::PrettyFunctionNoVirtual) Out << "virtual "; - if (MD->isStatic()) - Out << "static "; + if (MD->isStatic()) { + bool IsFunctionInMSVCCommpatEnv = + IK == PredefinedIdentKind::Function && LO.MSVCCompat; + if (ForceElaboratedPrinting && !IsFunctionInMSVCCommpatEnv) + Out << "static "; + } } class PrettyCallbacks final : public PrintingCallbacks { diff --git a/clang/test/SemaCXX/source_location.cpp b/clang/test/SemaCXX/source_location.cpp index 069a9004927a9..a9fca2a17c939 100644 --- a/clang/test/SemaCXX/source_location.cpp +++ b/clang/test/SemaCXX/source_location.cpp @@ -524,6 +524,37 @@ TestClass<test_func::C> t2; TestStruct<test_func::S> t3; TestEnum<test_func::E> t4; +class A { int b;}; +namespace inner { + template <class Ty> + class C { + public: + template <class T> + static void f(int i) { + (void)i; +#ifdef MS + static_assert(is_equal(__FUNCTION__, "test_func::inner::C<class test_func::A>::f")); +#else + static_assert(is_equal(__FUNCTION__, "f")); +#endif + } + template <class T> + static void f(double f) { + (void)f; +#ifdef MS + static_assert(is_equal(__FUNCTION__, "test_func::inner::C<class test_func::A>::f")); +#else + static_assert(is_equal(__FUNCTION__, "f")); +#endif + } + }; +} + + void foo() { + test_func::inner::C<test_func::A>::f<char>(1); + test_func::inner::C<test_func::A>::f<void>(1.0); +} + } // namespace test_func >From b9b312d1dd2335cb09dab54d7a37f58aaddea9b2 Mon Sep 17 00:00:00 2001 From: Zahira Ammarguellat <zahira.ammarguel...@intel.com> Date: Fri, 21 Feb 2025 08:29:21 -0800 Subject: [PATCH 2/3] Condition too restrictive. --- clang/lib/AST/Expr.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 14d0955503634..a019dd2818e59 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -748,9 +748,7 @@ std::string PredefinedExpr::ComputeName(PredefinedIdentKind IK, if (MD->isVirtual() && IK != PredefinedIdentKind::PrettyFunctionNoVirtual) Out << "virtual "; if (MD->isStatic()) { - bool IsFunctionInMSVCCommpatEnv = - IK == PredefinedIdentKind::Function && LO.MSVCCompat; - if (ForceElaboratedPrinting && !IsFunctionInMSVCCommpatEnv) + if (!ForceElaboratedPrinting) Out << "static "; } } >From 601014bf963b57fadfebbcbf55e0440ed4ca9a69 Mon Sep 17 00:00:00 2001 From: Zahira Ammarguellat <zahira.ammarguel...@intel.com> Date: Wed, 5 Mar 2025 05:46:03 -0800 Subject: [PATCH 3/3] Added constexpr functions to the test and added note to the RN. --- clang/docs/ReleaseNotes.rst | 2 ++ clang/lib/AST/Expr.cpp | 6 ++---- clang/test/SemaCXX/source_location.cpp | 28 ++++++++++++++++++++++---- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index db42fc5cc0da7..b08b5eca05fa6 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -157,6 +157,8 @@ Bug Fixes in This Version - Clang now outputs correct values when #embed data contains bytes with negative signed char values (#GH102798). +- Remove the ``static`` specifier for the value of ``_FUNCTION_`` for static functions, in MSVC compatibility mode. + Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index a019dd2818e59..ccfec7fda0cbc 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -747,10 +747,8 @@ std::string PredefinedExpr::ComputeName(PredefinedIdentKind IK, if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { if (MD->isVirtual() && IK != PredefinedIdentKind::PrettyFunctionNoVirtual) Out << "virtual "; - if (MD->isStatic()) { - if (!ForceElaboratedPrinting) - Out << "static "; - } + if (MD->isStatic() && !ForceElaboratedPrinting) + Out << "static "; } class PrettyCallbacks final : public PrintingCallbacks { diff --git a/clang/test/SemaCXX/source_location.cpp b/clang/test/SemaCXX/source_location.cpp index a9fca2a17c939..c8b65d6eab50d 100644 --- a/clang/test/SemaCXX/source_location.cpp +++ b/clang/test/SemaCXX/source_location.cpp @@ -539,12 +539,30 @@ namespace inner { #endif } template <class T> - static void f(double f) { + static constexpr void cf(int i) { + (void)i; +#ifdef MS + static_assert(is_equal(__FUNCTION__, "test_func::inner::C<class test_func::A>::cf")); +#else + static_assert(is_equal(__FUNCTION__, "cf")); +#endif + } + template <class T> + static void df(double f) { (void)f; #ifdef MS - static_assert(is_equal(__FUNCTION__, "test_func::inner::C<class test_func::A>::f")); + static_assert(is_equal(__FUNCTION__, "test_func::inner::C<class test_func::A>::df")); #else - static_assert(is_equal(__FUNCTION__, "f")); + static_assert(is_equal(__FUNCTION__, "df")); +#endif + } + template <class T> + static constexpr void cdf(double f) { + (void)f; +#ifdef MS + static_assert(is_equal(__FUNCTION__, "test_func::inner::C<class test_func::A>::cdf")); +#else + static_assert(is_equal(__FUNCTION__, "cdf")); #endif } }; @@ -552,7 +570,9 @@ namespace inner { void foo() { test_func::inner::C<test_func::A>::f<char>(1); - test_func::inner::C<test_func::A>::f<void>(1.0); + test_func::inner::C<test_func::A>::cf<char>(1); + test_func::inner::C<test_func::A>::df<void>(1.0); + test_func::inner::C<test_func::A>::cdf<void>(1.0); } } // namespace test_func _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits