Author: Aaron Ballman Date: 2023-09-27T14:26:49-04:00 New Revision: 9243b1bfdbf4c8b8f3f8c8e45b57f784311adaac
URL: https://github.com/llvm/llvm-project/commit/9243b1bfdbf4c8b8f3f8c8e45b57f784311adaac DIFF: https://github.com/llvm/llvm-project/commit/9243b1bfdbf4c8b8f3f8c8e45b57f784311adaac.diff LOG: Revert "[clang-cl] Fix value of __FUNCTION__ and __FUNC__ in MSVC mode for c++. (#66120)" This reverts commit 265568c136f94b108790e9be73cd8071e714aad1. See https://github.com/llvm/llvm-project/issues/66114#issuecomment-1732319259 Added: Modified: clang/include/clang/AST/PrettyPrinter.h clang/lib/AST/Expr.cpp clang/lib/AST/TypePrinter.cpp clang/test/AST/Interp/literals.cpp clang/test/Analysis/eval-predefined-exprs.cpp clang/test/CodeGenCXX/predefined-expr.cpp clang/test/SemaCXX/source_location.cpp Removed: ################################################################################ diff --git a/clang/include/clang/AST/PrettyPrinter.h b/clang/include/clang/AST/PrettyPrinter.h index 17d4e1a326d31ca..cee3cce7729c30f 100644 --- a/clang/include/clang/AST/PrettyPrinter.h +++ b/clang/include/clang/AST/PrettyPrinter.h @@ -76,8 +76,8 @@ struct PrintingPolicy { SuppressImplicitBase(false), FullyQualifiedName(false), PrintCanonicalTypes(false), PrintInjectedClassNameWithArguments(true), UsePreferredNames(true), AlwaysIncludeTypeForTemplateArgument(false), - UseClassForTemplateArgument(false), CleanUglifiedParameters(false), - EntireContentsOfLargeArray(true), UseEnumerators(true) {} + CleanUglifiedParameters(false), EntireContentsOfLargeArray(true), + UseEnumerators(true) {} /// Adjust this printing policy for cases where it's known that we're /// printing C++ code (for instance, if AST dumping reaches a C++-only @@ -291,10 +291,6 @@ struct PrintingPolicy { /// parameters. unsigned AlwaysIncludeTypeForTemplateArgument : 1; - // Prints "class" keyword before type template arguments. This is used when - // printing a function via the _FUNCTION__ or __func__ macro in MSVC mode. - unsigned UseClassForTemplateArgument : 1; - /// Whether to strip underscores when printing reserved parameter names. /// e.g. std::vector<class _Tp> becomes std::vector<class Tp>. /// This only affects parameter names, and so describes a compatible API. diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index af82ca0784af413..4f3837371b3fc5e 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -772,21 +772,18 @@ std::string PredefinedExpr::ComputeName(IdentKind IK, const Decl *CurrentDecl) { return std::string(Out.str()); } if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurrentDecl)) { - const auto &LO = Context.getLangOpts(); - if (((IK == Func || IK == Function) && !LO.MicrosoftExt) || - (IK == LFunction && LO.MicrosoftExt)) + if (IK != PrettyFunction && IK != PrettyFunctionNoVirtual && + IK != FuncSig && IK != LFuncSig) return FD->getNameAsString(); SmallString<256> Name; llvm::raw_svector_ostream Out(Name); - if (IK != Function) { - if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { - if (MD->isVirtual() && IK != PrettyFunctionNoVirtual) - Out << "virtual "; - if (MD->isStatic()) - Out << "static "; - } + if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { + if (MD->isVirtual() && IK != PrettyFunctionNoVirtual) + Out << "virtual "; + if (MD->isStatic()) + Out << "static "; } class PrettyCallbacks final : public PrintingCallbacks { @@ -801,10 +798,9 @@ std::string PredefinedExpr::ComputeName(IdentKind IK, const Decl *CurrentDecl) { private: const LangOptions &LO; }; - PrintingPolicy Policy(LO); - PrettyCallbacks PrettyCB(LO); + PrintingPolicy Policy(Context.getLangOpts()); + PrettyCallbacks PrettyCB(Context.getLangOpts()); Policy.Callbacks = &PrettyCB; - Policy.UseClassForTemplateArgument = LO.MicrosoftExt; std::string Proto; llvm::raw_string_ostream POut(Proto); @@ -831,11 +827,6 @@ std::string PredefinedExpr::ComputeName(IdentKind IK, const Decl *CurrentDecl) { FD->printQualifiedName(POut, Policy); - if ((IK == Function || IK == Func) && LO.MicrosoftExt) { - Out << Proto; - return std::string(Name); - } - POut << "("; if (FT) { for (unsigned i = 0, e = Decl->getNumParams(); i != e; ++i) { diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp index 3771a29f26b173f..eb69d0bb8755b48 100644 --- a/clang/lib/AST/TypePrinter.cpp +++ b/clang/lib/AST/TypePrinter.cpp @@ -2218,10 +2218,6 @@ printTo(raw_ostream &OS, ArrayRef<TA> Args, const PrintingPolicy &Policy, } else { if (!FirstArg) OS << Comma; - if (Policy.UseClassForTemplateArgument && - Argument.getKind() == TemplateArgument::Type) - OS << "class "; - // Tries to print the argument with location info if exists. printArgument(Arg, Policy, ArgOS, TemplateParameterList::shouldIncludeTypeForArgument( diff --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp index aabc909b3328e48..ceda59405ea9105 100644 --- a/clang/test/AST/Interp/literals.cpp +++ b/clang/test/AST/Interp/literals.cpp @@ -1046,8 +1046,8 @@ namespace PredefinedExprs { static_assert(strings_match(__FUNCSIG__, "void __cdecl PredefinedExprs::foo(void)"), ""); static_assert(strings_match(L__FUNCSIG__, L"void __cdecl PredefinedExprs::foo(void)"), ""); static_assert(strings_match(L__FUNCTION__, L"foo"), ""); - static_assert(strings_match(__FUNCTION__, "PredefinedExprs::foo"), ""); - static_assert(strings_match(__func__, "PredefinedExprs::foo"), ""); + static_assert(strings_match(__FUNCTION__, "foo"), ""); + static_assert(strings_match(__func__, "foo"), ""); static_assert(strings_match(__PRETTY_FUNCTION__, "void PredefinedExprs::foo()"), ""); } @@ -1058,9 +1058,9 @@ namespace PredefinedExprs { // expected-warning {{result unused}} return __FUNCTION__[index]; } - static_assert(heh(0) == 'P', ""); - static_assert(heh(1) == 'r', ""); - static_assert(heh(2) == 'e', ""); + static_assert(heh(0) == 'h', ""); + static_assert(heh(1) == 'e', ""); + static_assert(heh(2) == 'h', ""); #endif } diff --git a/clang/test/Analysis/eval-predefined-exprs.cpp b/clang/test/Analysis/eval-predefined-exprs.cpp index 7be441eb5bad943..1eec4476a065f31 100644 --- a/clang/test/Analysis/eval-predefined-exprs.cpp +++ b/clang/test/Analysis/eval-predefined-exprs.cpp @@ -55,14 +55,9 @@ struct A { clang_analyzer_dump(__func__); clang_analyzer_dump(__FUNCTION__); clang_analyzer_dump(__PRETTY_FUNCTION__); -#ifdef ANALYZER_MS - // expected-warning@-4 {{&Element{"A::A",0 S64b,char}}} - // expected-warning@-4 {{&Element{"A::A",0 S64b,char}}} -#else - // expected-warning@-7 {{&Element{"A",0 S64b,char}}} - // expected-warning@-7 {{&Element{"A",0 S64b,char}}} -#endif - // expected-warning@-8 {{&Element{"A::A()",0 S64b,char}}} + // expected-warning@-3 {{&Element{"A",0 S64b,char}}} + // expected-warning@-3 {{&Element{"A",0 S64b,char}}} + // expected-warning@-3 {{&Element{"A::A()",0 S64b,char}}} #ifdef ANALYZER_MS clang_analyzer_dump(__FUNCDNAME__); @@ -79,14 +74,9 @@ struct A { clang_analyzer_dump(__func__); clang_analyzer_dump(__FUNCTION__); clang_analyzer_dump(__PRETTY_FUNCTION__); -#ifdef ANALYZER_MS - // expected-warning@-4 {{&Element{"A::~A",0 S64b,char}}} - // expected-warning@-4 {{&Element{"A::~A",0 S64b,char}}} -#else - // expected-warning@-7 {{&Element{"~A",0 S64b,char}}} - // expected-warning@-7 {{&Element{"~A",0 S64b,char}}} -#endif - // expected-warning@-8 {{&Element{"A::~A()",0 S64b,char}}} + // expected-warning@-3 {{&Element{"~A",0 S64b,char}}} + // expected-warning@-3 {{&Element{"~A",0 S64b,char}}} + // expected-warning@-3 {{&Element{"A::~A()",0 S64b,char}}} #ifdef ANALYZER_MS clang_analyzer_dump(__FUNCDNAME__); diff --git a/clang/test/CodeGenCXX/predefined-expr.cpp b/clang/test/CodeGenCXX/predefined-expr.cpp index af76e0538a9ec9f..815bcbb3bd8992f 100644 --- a/clang/test/CodeGenCXX/predefined-expr.cpp +++ b/clang/test/CodeGenCXX/predefined-expr.cpp @@ -5,8 +5,6 @@ // CHECK-DAG: private unnamed_addr constant [49 x i8] c"void functionTemplateExplicitSpecialization(int)\00" // CHECK-DAG: private unnamed_addr constant [95 x i8] c"void SpecializedClassTemplate<char>::memberFunctionTemplate(T, U) const [T = char, U = double]\00" -// CHECK-DAG: private unnamed_addr constant [43 x i8] c"TestClass<class UnitTestNative>::TestClass\00" -// CHECK-DAG: private unnamed_addr constant [10 x i8] c"TestClass\00" // CHECK-DAG: private unnamed_addr constant [85 x i8] c"void SpecializedClassTemplate<int>::memberFunctionTemplate(int, U) const [U = float]\00" // CHECK-DAG: private unnamed_addr constant [57 x i8] c"void NonTypeTemplateParam<42>::size() const [Count = 42]\00" // CHECK-DAG: private unnamed_addr constant [103 x i8] c"static void ClassWithTemplateTemplateParam<char>::staticMember() [T = char, Param = NS::ClassTemplate]\00" @@ -103,7 +101,6 @@ int printf(const char * _Format, ...); -int strcmp(const char *, const char *); class ClassInTopLevelNamespace { public: @@ -458,21 +455,6 @@ class SpecializedClassTemplate<int> } }; - -template <class T> -class TestClass { -public: - TestClass() { - const char* expected = "TestClass<class UnitTestNative>::TestClass"; - if (strcmp(expected,__FUNCTION__)==0) - printf("PASSED\n"); - else - printf("FAILED %s\n",__FUNCTION__); - } -}; - -class UnitTestNative {}; - int main() { ClassInAnonymousNamespace anonymousNamespace; anonymousNamespace.anonymousNamespaceFunction(); @@ -553,7 +535,6 @@ int main() { SpecializedClassTemplate<char> sct2; sct2.memberFunctionTemplate('0', 0.0); - TestClass<UnitTestNative> t; return 0; } diff --git a/clang/test/SemaCXX/source_location.cpp b/clang/test/SemaCXX/source_location.cpp index d4d4c8fa650e1af..e92fb35b653a8f3 100644 --- a/clang/test/SemaCXX/source_location.cpp +++ b/clang/test/SemaCXX/source_location.cpp @@ -649,16 +649,8 @@ constexpr bool test_in_func() { static_assert(is_equal(b.a.f, "test_func_passed.cpp")); static_assert(is_equal(b.a.f2, "test_func_passed.cpp")); static_assert(is_equal(b.a.info.file(), "test_func_passed.cpp")); -#ifdef MS - static_assert(is_equal(b.a.func, "test_out_of_line_init::test_in_func")); -#else static_assert(is_equal(b.a.func, "test_in_func")); -#endif -#ifdef MS - static_assert(is_equal(b.a.func, "test_out_of_line_init::test_in_func")); -#else static_assert(is_equal(b.a.func2, "test_in_func")); -#endif static_assert(is_equal(b.a.info.function(), "bool test_out_of_line_init::test_in_func()")); return true; } @@ -685,11 +677,7 @@ constexpr InInit II; static_assert(II.l == 5200, ""); static_assert(is_equal(II.f, "in_init.cpp")); -#ifdef MS -static_assert(is_equal(II.func, "test_global_scope::InInit::InInit")); -#else static_assert(is_equal(II.func, "InInit")); -#endif #line 5400 struct AggInit { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits