Skip to content

Commit

Permalink
Revert "[Clang] Fix dependency of SourceLocExpr. (#78436)"
Browse files Browse the repository at this point in the history
This reverts commit 8c2b0d4.
  • Loading branch information
sys-ce-bb committed Jan 21, 2024
1 parent 69c77fe commit 80f470c
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 47 deletions.
4 changes: 0 additions & 4 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -972,10 +972,6 @@ Bug Fixes to C++ Support
(`#57410 <https://github.com/llvm/llvm-project/issues/57410>`_) and
(`#76604 <https://github.com/llvm/llvm-project/issues/57410>`_)

- Fix a bug where clang would produce inconsistent values when
``std::source_location::current()`` was used in a function template.
Fixes (`#78128 <https://github.com/llvm/llvm-project/issues/78128>`_)

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed an import failure of recursive friend class template.
Expand Down
11 changes: 0 additions & 11 deletions clang/include/clang/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
5 changes: 1 addition & 4 deletions clang/lib/AST/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/TreeTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -12200,7 +12200,7 @@ TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {

template <typename Derived>
ExprResult TreeTransform<Derived>::TransformSourceLocExpr(SourceLocExpr *E) {
bool NeedRebuildFunc = SourceLocExpr::MayBeDependent(E->getIdentKind()) &&
bool NeedRebuildFunc = E->getIdentKind() == SourceLocIdentKind::Function &&
getSema().CurContext != E->getParentContext();

if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc)
Expand Down
27 changes: 0 additions & 27 deletions clang/test/SemaCXX/source_location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,30 +805,3 @@ static_assert(S(0).j == S{0}.j);
static_assert(S(0).j == S{0}.i);
}
#endif

namespace GH78128 {

template<int N>
constexpr int f() {
return N;
}

template<typename T>
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<int>();
}

}

0 comments on commit 80f470c

Please sign in to comment.