From 15d94a7d0f8f0d6b3b5308fff51b286957e45650 Mon Sep 17 00:00:00 2001 From: Leonard Chan Date: Tue, 22 Sep 2020 17:40:53 -0700 Subject: [PATCH] Revert "Canonicalize declaration pointers when forming APValues." This reverts commit 905b9ca26c94fa86339451a528cedde5004fc1bb. Reverting because this strips `weak` attributes off function declarations, leading to the linker error we see at https://ci.chromium.org/p/fuchsia/builders/ci/clang_toolchain.fuchsia-arm64-debug-subbuild/b8868932035091473008. See https://reviews.llvm.org/rG905b9ca26c94 for reproducer details. --- clang/include/clang/AST/APValue.h | 4 ++-- clang/lib/AST/APValue.cpp | 26 +++++++--------------- clang/lib/AST/Decl.cpp | 2 +- clang/lib/AST/DeclBase.cpp | 2 +- clang/lib/AST/ExprConstant.cpp | 18 ++++++++++----- .../test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p9.cpp | 3 ++- clang/test/OpenMP/ordered_messages.cpp | 5 +---- 7 files changed, 27 insertions(+), 33 deletions(-) diff --git a/clang/include/clang/AST/APValue.h b/clang/include/clang/AST/APValue.h index 6307f8a..5103cfa 100644 --- a/clang/include/clang/AST/APValue.h +++ b/clang/include/clang/AST/APValue.h @@ -174,7 +174,6 @@ public: return !(LHS == RHS); } friend llvm::hash_code hash_value(const LValueBase &Base); - friend struct llvm::DenseMapInfo; private: PtrTy Ptr; @@ -202,7 +201,8 @@ public: public: LValuePathEntry() : Value() {} - LValuePathEntry(BaseOrMemberType BaseOrMember); + LValuePathEntry(BaseOrMemberType BaseOrMember) + : Value{reinterpret_cast(BaseOrMember.getOpaqueValue())} {} static LValuePathEntry ArrayIndex(uint64_t Index) { LValuePathEntry Result; Result.Value = Index; diff --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp index 32d3ff7..08ae0ff 100644 --- a/clang/lib/AST/APValue.cpp +++ b/clang/lib/AST/APValue.cpp @@ -38,7 +38,7 @@ static_assert( "Type is insufficiently aligned"); APValue::LValueBase::LValueBase(const ValueDecl *P, unsigned I, unsigned V) - : Ptr(P ? cast(P->getCanonicalDecl()) : nullptr), Local{I, V} {} + : Ptr(P), Local{I, V} {} APValue::LValueBase::LValueBase(const Expr *P, unsigned I, unsigned V) : Ptr(P), Local{I, V} {} @@ -82,19 +82,13 @@ bool operator==(const APValue::LValueBase &LHS, const APValue::LValueBase &RHS) { if (LHS.Ptr != RHS.Ptr) return false; - if (LHS.is() || LHS.is()) + if (LHS.is()) return true; return LHS.Local.CallIndex == RHS.Local.CallIndex && LHS.Local.Version == RHS.Local.Version; } } -APValue::LValuePathEntry::LValuePathEntry(BaseOrMemberType BaseOrMember) { - if (const Decl *D = BaseOrMember.getPointer()) - BaseOrMember.setPointer(D->getCanonicalDecl()); - Value = reinterpret_cast(BaseOrMember.getOpaqueValue()); -} - namespace { struct LVBase { APValue::LValueBase Base; @@ -119,16 +113,14 @@ APValue::LValueBase::operator bool () const { clang::APValue::LValueBase llvm::DenseMapInfo::getEmptyKey() { - clang::APValue::LValueBase B; - B.Ptr = DenseMapInfo::getEmptyKey(); - return B; + return clang::APValue::LValueBase( + DenseMapInfo::getEmptyKey()); } clang::APValue::LValueBase llvm::DenseMapInfo::getTombstoneKey() { - clang::APValue::LValueBase B; - B.Ptr = DenseMapInfo::getTombstoneKey(); - return B; + return clang::APValue::LValueBase( + DenseMapInfo::getTombstoneKey()); } namespace clang { @@ -781,10 +773,8 @@ void APValue::MakeMemberPointer(const ValueDecl *Member, bool IsDerivedMember, assert(isAbsent() && "Bad state change"); MemberPointerData *MPD = new ((void*)(char*)Data.buffer) MemberPointerData; Kind = MemberPointer; - MPD->MemberAndIsDerivedMember.setPointer( - Member ? cast(Member->getCanonicalDecl()) : nullptr); + MPD->MemberAndIsDerivedMember.setPointer(Member); MPD->MemberAndIsDerivedMember.setInt(IsDerivedMember); MPD->resizePath(Path.size()); - for (unsigned I = 0; I != Path.size(); ++I) - MPD->getPath()[I] = Path[I]->getCanonicalDecl(); + memcpy(MPD->getPath(), Path.data(), Path.size()*sizeof(const CXXRecordDecl*)); } diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index ae38e3d..0ee1399 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -4686,7 +4686,7 @@ char *Buffer = new (getASTContext(), 1) char[Name.size() + 1]; void ValueDecl::anchor() {} bool ValueDecl::isWeak() const { - for (const auto *I : getMostRecentDecl()->attrs()) + for (const auto *I : attrs()) if (isa(I) || isa(I)) return true; diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp index ab2b55c..f4314d0 100644 --- a/clang/lib/AST/DeclBase.cpp +++ b/clang/lib/AST/DeclBase.cpp @@ -720,7 +720,7 @@ bool Decl::isWeakImported() const { if (!canBeWeakImported(IsDefinition)) return false; - for (const auto *A : getMostRecentDecl()->attrs()) { + for (const auto *A : attrs()) { if (isa(A)) return true; diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 8e43b62..e8f132d 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -1978,11 +1978,18 @@ static bool HasSameBase(const LValue &A, const LValue &B) { return false; if (A.getLValueBase().getOpaqueValue() != - B.getLValueBase().getOpaqueValue()) - return false; + B.getLValueBase().getOpaqueValue()) { + const Decl *ADecl = GetLValueBaseDecl(A); + if (!ADecl) + return false; + const Decl *BDecl = GetLValueBaseDecl(B); + if (!BDecl || ADecl->getCanonicalDecl() != BDecl->getCanonicalDecl()) + return false; + } - return A.getLValueCallIndex() == B.getLValueCallIndex() && - A.getLValueVersion() == B.getLValueVersion(); + return IsGlobalLValue(A.getLValueBase()) || + (A.getLValueCallIndex() == B.getLValueCallIndex() && + A.getLValueVersion() == B.getLValueVersion()); } static void NoteLValueLocation(EvalInfo &Info, APValue::LValueBase Base) { @@ -3101,8 +3108,7 @@ static bool evaluateVarDeclInit(EvalInfo &Info, const Expr *E, // If we're currently evaluating the initializer of this declaration, use that // in-flight value. - if (declaresSameEntity(Info.EvaluatingDecl.dyn_cast(), - VD)) { + if (Info.EvaluatingDecl.dyn_cast() == VD) { Result = Info.EvaluatingDeclValue; return true; } diff --git a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p9.cpp b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p9.cpp index 3720b27..8d51dbd 100644 --- a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p9.cpp +++ b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p9.cpp @@ -24,10 +24,11 @@ constexpr double &ni3; // expected-error {{declaration of reference variable 'ni constexpr int nc1 = i; // expected-error {{constexpr variable 'nc1' must be initialized by a constant expression}} expected-note {{read of non-const variable 'i' is not allowed in a constant expression}} constexpr C nc2 = C(); // expected-error {{cannot have non-literal type 'const C'}} -int &f(); // expected-note 2{{declared here}} +int &f(); // expected-note {{declared here}} constexpr int &nc3 = f(); // expected-error {{constexpr variable 'nc3' must be initialized by a constant expression}} expected-note {{non-constexpr function 'f' cannot be used in a constant expression}} constexpr int nc4(i); // expected-error {{constexpr variable 'nc4' must be initialized by a constant expression}} expected-note {{read of non-const variable 'i' is not allowed in a constant expression}} constexpr C nc5((C())); // expected-error {{cannot have non-literal type 'const C'}} +int &f(); // expected-note {{here}} constexpr int &nc6(f()); // expected-error {{constexpr variable 'nc6' must be initialized by a constant expression}} expected-note {{non-constexpr function 'f'}} struct pixel { diff --git a/clang/test/OpenMP/ordered_messages.cpp b/clang/test/OpenMP/ordered_messages.cpp index 8a3a864..f6b9dbd 100644 --- a/clang/test/OpenMP/ordered_messages.cpp +++ b/clang/test/OpenMP/ordered_messages.cpp @@ -16,9 +16,6 @@ void xxx(int argc) { } int foo(); -#if __cplusplus >= 201103L -// expected-note@-2 {{declared here}} -#endif template T foo() { @@ -179,7 +176,7 @@ T foo() { int foo() { #if __cplusplus >= 201103L -// expected-note@-2 {{declared here}} +// expected-note@-2 2 {{declared here}} #endif int k; #pragma omp for ordered -- 2.7.4