From 3ced23976aa8a86a17017c87821c873b4ca80bc2 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 18 Dec 2019 14:01:40 -0800 Subject: Refactor CompareReferenceRelationship and its callers in preparation for implementing the resolution of CWG2352. No functionality change, except that we now convert the referent of a reference binding to the underlying type of the reference in more cases; we used to happen to preserve the type sugar from the referent if the only type change was in the cv-qualifiers. This exposed a bug in how we generate code for trivial assignment operators: if the type sugar (particularly the may_alias attribute) got lost during reference binding, we'd use the "wrong" TBAA information for the load during the assignment. --- clang/lib/Sema/SemaCast.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'clang/lib/Sema/SemaCast.cpp') diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp index d0b9fe12289..6216206690b 100644 --- a/clang/lib/Sema/SemaCast.cpp +++ b/clang/lib/Sema/SemaCast.cpp @@ -1306,10 +1306,6 @@ TryCastResult TryLValueToRValueCast(Sema &Self, Expr *SrcExpr, // Because we try the reference downcast before this function, from now on // this is the only cast possibility, so we issue an error if we fail now. // FIXME: Should allow casting away constness if CStyle. - bool DerivedToBase; - bool ObjCConversion; - bool ObjCLifetimeConversion; - bool FunctionConversion; QualType FromType = SrcExpr->getType(); QualType ToType = R->getPointeeType(); if (CStyle) { @@ -1317,9 +1313,9 @@ TryCastResult TryLValueToRValueCast(Sema &Self, Expr *SrcExpr, ToType = ToType.getUnqualifiedType(); } + Sema::ReferenceConversions RefConv; Sema::ReferenceCompareResult RefResult = Self.CompareReferenceRelationship( - SrcExpr->getBeginLoc(), ToType, FromType, DerivedToBase, ObjCConversion, - ObjCLifetimeConversion, FunctionConversion); + SrcExpr->getBeginLoc(), ToType, FromType, &RefConv); if (RefResult != Sema::Ref_Compatible) { if (CStyle || RefResult == Sema::Ref_Incompatible) return TC_NotApplicable; @@ -1331,7 +1327,7 @@ TryCastResult TryLValueToRValueCast(Sema &Self, Expr *SrcExpr, return TC_Failed; } - if (DerivedToBase) { + if (RefConv & Sema::ReferenceConversions::DerivedToBase) { Kind = CK_DerivedToBase; CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true, /*DetectVirtual=*/true); -- cgit v1.2.3