From 80f470ce8859ddff5114a0cc9c0280663ada0fbc Mon Sep 17 00:00:00 2001 From: sys_ce_bb Date: Sun, 21 Jan 2024 06:30:34 -0800 Subject: [PATCH] Revert "[Clang] Fix dependency of SourceLocExpr. (#78436)" This reverts commit 8c2b0d4175dcfe669a43d0173fd00ed3c16dbdaa. --- clang/docs/ReleaseNotes.rst | 4 ---- clang/include/clang/AST/Expr.h | 11 ----------- clang/lib/AST/Expr.cpp | 5 +---- clang/lib/Sema/TreeTransform.h | 2 +- clang/test/SemaCXX/source_location.cpp | 27 -------------------------- 5 files changed, 2 insertions(+), 47 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 0ea6f93a1f5df..cf52c1e66b91b 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -972,10 +972,6 @@ Bug Fixes to C++ Support (`#57410 `_) and (`#76604 `_) -- Fix a bug where clang would produce inconsistent values when - ``std::source_location::current()`` was used in a function template. - Fixes (`#78128 `_) - Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ - Fixed an import failure of recursive friend class template. diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index ff674f07275e8..2cca5b35478ce 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -4808,17 +4808,6 @@ class SourceLocExpr final : public Expr { return T->getStmtClass() == SourceLocExprClass; } - static bool MayBeDependent(SourceLocIdentKind Kind) { - switch (Kind) { - case SourceLocIdentKind::Function: - case SourceLocIdentKind::FuncSig: - case SourceLocIdentKind::SourceLocStruct: - return true; - default: - return false; - } - } - private: friend class ASTStmtReader; }; diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index e6919e03fd246..0458c8a4f6c2e 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -2274,10 +2274,7 @@ SourceLocExpr::SourceLocExpr(const ASTContext &Ctx, SourceLocIdentKind Kind, : Expr(SourceLocExprClass, ResultTy, VK_PRValue, OK_Ordinary), BuiltinLoc(BLoc), RParenLoc(RParenLoc), ParentContext(ParentContext) { SourceLocExprBits.Kind = llvm::to_underlying(Kind); - // In dependent contexts, function names may change. - setDependence(MayBeDependent(Kind) && ParentContext->isDependentContext() - ? ExprDependence::Value - : ExprDependence::None); + setDependence(ExprDependence::None); } StringRef SourceLocExpr::getBuiltinStr() const { diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 36b68b2272273..30431fa350f46 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -12200,7 +12200,7 @@ TreeTransform::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { template ExprResult TreeTransform::TransformSourceLocExpr(SourceLocExpr *E) { - bool NeedRebuildFunc = SourceLocExpr::MayBeDependent(E->getIdentKind()) && + bool NeedRebuildFunc = E->getIdentKind() == SourceLocIdentKind::Function && getSema().CurContext != E->getParentContext(); if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc) diff --git a/clang/test/SemaCXX/source_location.cpp b/clang/test/SemaCXX/source_location.cpp index 7414fbce7828d..e92fb35b653a8 100644 --- a/clang/test/SemaCXX/source_location.cpp +++ b/clang/test/SemaCXX/source_location.cpp @@ -805,30 +805,3 @@ static_assert(S(0).j == S{0}.j); static_assert(S(0).j == S{0}.i); } #endif - -namespace GH78128 { - -template -constexpr int f() { - return N; -} - -template -void foo() { - constexpr auto* F1 = std::source_location::current().function(); - static_assert(__builtin_strlen(F1) == f<__builtin_strlen(F1)>()); - - constexpr auto* F2 = __builtin_FUNCTION(); - static_assert(__builtin_strlen(F2) == f<__builtin_strlen(F2)>()); - -#ifdef MS - constexpr auto* F3 = __builtin_FUNCSIG(); - static_assert(__builtin_strlen(F3) == f<__builtin_strlen(F3)>()); -#endif -} - -void test() { - foo(); -} - -}