41#include "llvm/ADT/DenseSet.h"
42#include "llvm/ADT/STLExtras.h"
43#include "llvm/ADT/STLForwardCompat.h"
44#include "llvm/ADT/ScopeExit.h"
45#include "llvm/ADT/SmallPtrSet.h"
46#include "llvm/ADT/SmallString.h"
47#include "llvm/ADT/SmallVector.h"
48#include "llvm/Support/Casting.h"
62 return P->hasAttr<PassObjectSizeAttr>();
83 if (HadMultipleCandidates)
94 CK_FunctionToPointerDecay);
98 bool InOverloadResolution,
101 bool AllowObjCWritebackConversion);
105 bool InOverloadResolution,
113 bool AllowObjCConversionOnExplicit);
174 return Rank[(
int)Kind];
199 static const char *
const Name[] = {
203 "Function-to-pointer",
204 "Function pointer conversion",
206 "Integral promotion",
207 "Floating point promotion",
209 "Integral conversion",
210 "Floating conversion",
211 "Complex conversion",
212 "Floating-integral conversion",
213 "Pointer conversion",
214 "Pointer-to-member conversion",
215 "Boolean conversion",
216 "Compatible-types conversion",
217 "Derived-to-base conversion",
219 "SVE Vector conversion",
220 "RVV Vector conversion",
222 "Complex-real conversion",
223 "Block Pointer conversion",
224 "Transparent Union Conversion",
225 "Writeback conversion",
226 "OpenCL Zero Event Conversion",
227 "OpenCL Zero Queue Conversion",
228 "C specific type conversion",
229 "Incompatible pointer conversion",
230 "Fixed point conversion",
231 "HLSL vector truncation",
232 "Non-decaying array conversion",
320 const Expr *Converted) {
323 if (
auto *EWC = dyn_cast<ExprWithCleanups>(Converted)) {
330 while (
auto *ICE = dyn_cast<ImplicitCastExpr>(Converted)) {
331 switch (ICE->getCastKind()) {
333 case CK_IntegralCast:
334 case CK_IntegralToBoolean:
335 case CK_IntegralToFloating:
336 case CK_BooleanToSignedIntegral:
337 case CK_FloatingToIntegral:
338 case CK_FloatingToBoolean:
339 case CK_FloatingCast:
340 Converted = ICE->getSubExpr();
364 QualType &ConstantType,
bool IgnoreFloatToIntegralConversion)
const {
366 "narrowing check outside C++");
377 ToType = ET->getDecl()->getIntegerType();
383 goto FloatingIntegralConversion;
385 goto IntegralConversion;
396 FloatingIntegralConversion:
401 if (IgnoreFloatToIntegralConversion)
404 assert(
Initializer &&
"Unknown conversion expression");
410 if (std::optional<llvm::APSInt> IntConstantValue =
414 Result.convertFromAPInt(*IntConstantValue, IntConstantValue->isSigned(),
415 llvm::APFloat::rmNearestTiesToEven);
417 llvm::APSInt ConvertedValue = *IntConstantValue;
419 Result.convertToInteger(ConvertedValue,
420 llvm::APFloat::rmTowardZero, &ignored);
422 if (*IntConstantValue != ConvertedValue) {
423 ConstantValue =
APValue(*IntConstantValue);
450 Initializer->isCXX11ConstantExpr(Ctx, &ConstantValue)) {
453 ConstantValue = R.
Val;
454 assert(ConstantValue.
isFloat());
455 llvm::APFloat FloatVal = ConstantValue.
getFloat();
458 llvm::APFloat Converted = FloatVal;
459 llvm::APFloat::opStatus ConvertStatus =
461 llvm::APFloat::rmNearestTiesToEven, &ignored);
463 llvm::APFloat::rmNearestTiesToEven, &ignored);
465 if (FloatVal.isNaN() && Converted.isNaN() &&
466 !FloatVal.isSignaling() && !Converted.isSignaling()) {
472 if (!Converted.bitwiseIsEqual(FloatVal)) {
479 if (ConvertStatus & llvm::APFloat::opOverflow) {
501 IntegralConversion: {
509 constexpr auto CanRepresentAll = [](
bool FromSigned,
unsigned FromWidth,
510 bool ToSigned,
unsigned ToWidth) {
511 return (FromWidth < ToWidth + (FromSigned == ToSigned)) &&
512 (FromSigned <= ToSigned);
515 if (CanRepresentAll(FromSigned, FromWidth, ToSigned, ToWidth))
521 bool DependentBitField =
false;
523 if (BitField->getBitWidth()->isValueDependent())
524 DependentBitField =
true;
525 else if (
unsigned BitFieldWidth = BitField->getBitWidthValue(Ctx);
526 BitFieldWidth < FromWidth) {
527 if (CanRepresentAll(FromSigned, BitFieldWidth, ToSigned, ToWidth))
531 FromWidth = BitFieldWidth;
539 std::optional<llvm::APSInt> OptInitializerValue =
541 if (!OptInitializerValue) {
545 if (DependentBitField && (FromSigned <= ToSigned))
551 llvm::APSInt &InitializerValue = *OptInitializerValue;
552 bool Narrowing =
false;
553 if (FromWidth < ToWidth) {
556 if (InitializerValue.isSigned() && InitializerValue.isNegative())
562 InitializerValue.extend(InitializerValue.getBitWidth() + 1);
564 llvm::APSInt ConvertedValue = InitializerValue;
565 ConvertedValue = ConvertedValue.trunc(ToWidth);
566 ConvertedValue.setIsSigned(ToSigned);
567 ConvertedValue = ConvertedValue.extend(InitializerValue.getBitWidth());
568 ConvertedValue.setIsSigned(InitializerValue.isSigned());
570 if (ConvertedValue != InitializerValue)
575 ConstantValue =
APValue(InitializerValue);
591 ConstantValue = R.
Val;
592 assert(ConstantValue.
isFloat());
593 llvm::APFloat FloatVal = ConstantValue.
getFloat();
598 if (FloatVal.isNaN() && FloatVal.isSignaling()) {
614 raw_ostream &OS = llvm::errs();
615 bool PrintedSomething =
false;
618 PrintedSomething =
true;
622 if (PrintedSomething) {
628 OS <<
" (by copy constructor)";
630 OS <<
" (direct reference binding)";
632 OS <<
" (reference binding)";
634 PrintedSomething =
true;
638 if (PrintedSomething) {
642 PrintedSomething =
true;
645 if (!PrintedSomething) {
646 OS <<
"No conversions required";
653 raw_ostream &OS = llvm::errs();
661 OS <<
"aggregate initialization";
671 raw_ostream &OS = llvm::errs();
673 OS <<
"Worst list element conversion: ";
674 switch (ConversionKind) {
676 OS <<
"Standard conversion: ";
680 OS <<
"User-defined conversion: ";
684 OS <<
"Ellipsis conversion";
687 OS <<
"Ambiguous conversion";
690 OS <<
"Bad conversion";
715 struct DFIArguments {
721 struct DFIParamWithArguments : DFIArguments {
726 struct DFIDeducedMismatchArgs : DFIArguments {
728 unsigned CallArgIndex;
745 Result.Result =
static_cast<unsigned>(TDK);
746 Result.HasDiagnostic =
false;
765 auto *Saved =
new (Context) DFIDeducedMismatchArgs;
776 DFIArguments *Saved =
new (Context) DFIArguments;
788 DFIParamWithArguments *Saved =
new (Context) DFIParamWithArguments;
789 Saved->Param = Info.
Param;
802 Result.HasDiagnostic =
true;
807 CNSInfo *Saved =
new (Context) CNSInfo;
817 llvm_unreachable(
"not a deduction failure");
850 Diag->~PartialDiagnosticAt();
859 Diag->~PartialDiagnosticAt();
895 return TemplateParameter::getFromOpaqueValue(
Data);
900 return static_cast<DFIParamWithArguments*
>(
Data)->Param;
930 return static_cast<DFIDeducedMismatchArgs*
>(
Data)->TemplateArgs;
936 return static_cast<CNSInfo*
>(
Data)->TemplateArgs;
968 return &
static_cast<DFIArguments*
>(
Data)->FirstArg;
1000 return &
static_cast<DFIArguments*
>(
Data)->SecondArg;
1015 return static_cast<DFIDeducedMismatchArgs*
>(
Data)->CallArgIndex;
1018 return std::nullopt;
1031 for (
unsigned I = 0; I <
X->getNumParams(); ++I)
1035 if (
auto *FTX =
X->getDescribedFunctionTemplate()) {
1040 FTY->getTemplateParameters()))
1049 OverloadedOperatorKind::OO_EqualEqual);
1061 OverloadedOperatorKind::OO_ExclaimEqual);
1062 if (isa<CXXMethodDecl>(EqFD)) {
1079 auto *NotEqFD = Op->getAsFunction();
1080 if (
auto *UD = dyn_cast<UsingShadowDecl>(Op))
1081 NotEqFD = UD->getUnderlyingDecl()->getAsFunction();
1084 cast<Decl>(Op->getLexicalDeclContext())))
1094 return Op == OO_EqualEqual || Op == OO_Spaceship;
1100 if (!allowsReversed(Op))
1102 if (Op == OverloadedOperatorKind::OO_EqualEqual) {
1103 assert(OriginalArgs.size() == 2);
1105 S, OpLoc, OriginalArgs[1], FD))
1116void OverloadCandidateSet::destroyCandidates() {
1118 for (
auto &
C : i->Conversions)
1119 C.~ImplicitConversionSequence();
1121 i->DeductionFailure.Destroy();
1126 destroyCandidates();
1127 SlabAllocator.Reset();
1128 NumInlineBytesUsed = 0;
1135 class UnbridgedCastsSet {
1145 Entry entry = { &
E,
E };
1146 Entries.push_back(entry);
1152 i = Entries.begin(), e = Entries.end(); i != e; ++i)
1153 *i->Addr = i->Saved;
1167 UnbridgedCastsSet *unbridgedCasts =
nullptr) {
1171 if (placeholder->getKind() == BuiltinType::Overload)
return false;
1175 if (placeholder->getKind() == BuiltinType::ARCUnbridgedCast &&
1177 unbridgedCasts->save(S,
E);
1197 UnbridgedCastsSet &unbridged) {
1198 for (
unsigned i = 0, e = Args.size(); i != e; ++i)
1207 NamedDecl *&Match,
bool NewIsUsingDecl) {
1212 bool OldIsUsingDecl =
false;
1213 if (isa<UsingShadowDecl>(OldD)) {
1214 OldIsUsingDecl =
true;
1218 if (NewIsUsingDecl)
continue;
1220 OldD = cast<UsingShadowDecl>(OldD)->getTargetDecl();
1225 if ((OldIsUsingDecl || NewIsUsingDecl) && !isVisible(*I))
1233 bool UseMemberUsingDeclRules =
1234 (OldIsUsingDecl || NewIsUsingDecl) && CurContext->isRecord() &&
1238 if (!IsOverload(New, OldF, UseMemberUsingDeclRules)) {
1239 if (UseMemberUsingDeclRules && OldIsUsingDecl) {
1240 HideUsingShadowDecl(S, cast<UsingShadowDecl>(*I));
1244 if (!isa<FunctionTemplateDecl>(OldD) &&
1245 !shouldLinkPossiblyHiddenDecl(*I, New))
1254 if (!getASTContext().canBuiltinBeRedeclared(OldF)) {
1256 return Ovl_NonFunction;
1258 }
else if (isa<UsingDecl>(OldD) || isa<UsingPackDecl>(OldD)) {
1262 }
else if (isa<TagDecl>(OldD)) {
1264 }
else if (
auto *UUD = dyn_cast<UnresolvedUsingValueDecl>(OldD)) {
1271 if (UUD->getQualifier()->isDependent() && !UUD->isCXXClassMember()) {
1273 return Ovl_NonFunction;
1280 return Ovl_NonFunction;
1305 if (CheckFunctionTemplateSpecialization(New,
nullptr, TemplateSpecResult,
1308 return Ovl_Overload;
1315 return Ovl_Overload;
1320 bool UseMemberUsingDeclRules,
1321 bool ConsiderCudaAttrs,
1322 bool UseOverrideRules =
false) {
1339 if ((OldTemplate ==
nullptr) != (NewTemplate ==
nullptr))
1352 if (isa<FunctionNoProtoType>(OldQType.
getTypePtr()) ||
1353 isa<FunctionNoProtoType>(NewQType.
getTypePtr()))
1356 const auto *OldType = cast<FunctionProtoType>(OldQType);
1357 const auto *NewType = cast<FunctionProtoType>(NewQType);
1362 if (OldQType != NewQType && OldType->isVariadic() != NewType->isVariadic())
1377 OldDecl = OldTemplate;
1378 NewDecl = NewTemplate;
1396 bool ConstraintsInTemplateHead =
1407 if (UseMemberUsingDeclRules && ConstraintsInTemplateHead &&
1408 !SameTemplateParameterList)
1410 if (!UseMemberUsingDeclRules &&
1411 (!SameTemplateParameterList || !SameReturnType))
1415 const auto *OldMethod = dyn_cast<CXXMethodDecl>(Old);
1416 const auto *NewMethod = dyn_cast<CXXMethodDecl>(New);
1418 int OldParamsOffset = 0;
1419 int NewParamsOffset = 0;
1437 !isa<CXXConstructorDecl>(NewMethod))
1443 auto BS =
Base.getNonReferenceType().getCanonicalType().split();
1444 BS.Quals = NormalizeQualifiers(OldMethod, BS.Quals);
1446 auto DS =
D.getNonReferenceType().getCanonicalType().split();
1447 DS.Quals = NormalizeQualifiers(NewMethod, DS.Quals);
1449 if (BS.Quals != DS.Quals)
1452 if (OldMethod->isImplicitObjectMemberFunction() &&
1453 OldMethod->getParent() != NewMethod->getParent()) {
1466 if (
Base->isLValueReferenceType())
1467 return D->isLValueReferenceType();
1468 return Base->isRValueReferenceType() ==
D->isRValueReferenceType();
1473 auto DiagnoseInconsistentRefQualifiers = [&]() {
1476 if (OldMethod->getRefQualifier() == NewMethod->getRefQualifier())
1478 if (OldMethod->isExplicitObjectMemberFunction() ||
1479 NewMethod->isExplicitObjectMemberFunction())
1481 if (!UseMemberUsingDeclRules && (OldMethod->getRefQualifier() ==
RQ_None ||
1482 NewMethod->getRefQualifier() ==
RQ_None)) {
1483 SemaRef.
Diag(NewMethod->getLocation(), diag::err_ref_qualifier_overload)
1484 << NewMethod->getRefQualifier() << OldMethod->getRefQualifier();
1485 SemaRef.
Diag(OldMethod->getLocation(), diag::note_previous_declaration);
1491 if (OldMethod && OldMethod->isExplicitObjectMemberFunction())
1493 if (NewMethod && NewMethod->isExplicitObjectMemberFunction())
1496 if (OldType->getNumParams() - OldParamsOffset !=
1497 NewType->getNumParams() - NewParamsOffset ||
1499 {OldType->param_type_begin() + OldParamsOffset,
1500 OldType->param_type_end()},
1501 {NewType->param_type_begin() + NewParamsOffset,
1502 NewType->param_type_end()},
1507 if (OldMethod && NewMethod && !OldMethod->isStatic() &&
1508 !NewMethod->isStatic()) {
1509 bool HaveCorrespondingObjectParameters = [&](
const CXXMethodDecl *Old,
1511 auto NewObjectType = New->getFunctionObjectParameterReferenceType();
1515 return F->getRefQualifier() ==
RQ_None &&
1516 !F->isExplicitObjectMemberFunction();
1519 if (IsImplicitWithNoRefQual(Old) != IsImplicitWithNoRefQual(New) &&
1520 CompareType(OldObjectType.getNonReferenceType(),
1521 NewObjectType.getNonReferenceType()))
1523 return CompareType(OldObjectType, NewObjectType);
1524 }(OldMethod, NewMethod);
1526 if (!HaveCorrespondingObjectParameters) {
1527 if (DiagnoseInconsistentRefQualifiers())
1532 if (!UseOverrideRules || (!NewMethod->isExplicitObjectMemberFunction() &&
1533 !OldMethod->isExplicitObjectMemberFunction()))
1538 if (!UseOverrideRules &&
1542 if ((NewRC !=
nullptr) != (OldRC !=
nullptr))
1549 if (NewMethod && OldMethod && OldMethod->isImplicitObjectMemberFunction() &&
1550 NewMethod->isImplicitObjectMemberFunction()) {
1551 if (DiagnoseInconsistentRefQualifiers())
1569 NewI != NewE || OldI != OldE; ++NewI, ++OldI) {
1570 if (NewI == NewE || OldI == OldE)
1572 llvm::FoldingSetNodeID NewID, OldID;
1574 OldI->getCond()->Profile(OldID, SemaRef.
Context,
true);
1579 if (SemaRef.
getLangOpts().CUDA && ConsiderCudaAttrs) {
1582 if (!isa<CXXDestructorDecl>(New)) {
1587 "Unexpected invalid target.");
1591 if (NewTarget != OldTarget)
1602 bool UseMemberUsingDeclRules,
bool ConsiderCudaAttrs) {
1608 bool UseMemberUsingDeclRules,
bool ConsiderCudaAttrs) {
1621 bool SuppressUserConversions,
1623 bool InOverloadResolution,
1625 bool AllowObjCWritebackConversion,
1626 bool AllowObjCConversionOnExplicit) {
1629 if (SuppressUserConversions) {
1640 Conversions, AllowExplicit,
1641 AllowObjCConversionOnExplicit)) {
1662 if (
const auto *InitList = dyn_cast<InitListExpr>(From);
1663 InitList && InitList->getNumInits() == 1 &&
1665 const Expr *SingleInit = InitList->getInit(0);
1666 FromType = SingleInit->
getType();
1676 if ((FromCanon == ToCanon ||
1687 if (ToCanon != FromCanon)
1698 Cand != Conversions.
end(); ++Cand)
1741 bool SuppressUserConversions,
1743 bool InOverloadResolution,
1745 bool AllowObjCWritebackConversion,
1746 bool AllowObjCConversionOnExplicit) {
1749 ICS.
Standard, CStyle, AllowObjCWritebackConversion)){
1789 AllowExplicit, InOverloadResolution, CStyle,
1790 AllowObjCWritebackConversion,
1791 AllowObjCConversionOnExplicit);
1796 bool SuppressUserConversions,
1798 bool InOverloadResolution,
1800 bool AllowObjCWritebackConversion) {
1801 return ::TryImplicitConversion(*
this, From, ToType, SuppressUserConversions,
1802 AllowExplicit, InOverloadResolution, CStyle,
1803 AllowObjCWritebackConversion,
1809 bool AllowExplicit) {
1814 bool AllowObjCWritebackConversion
1815 = getLangOpts().ObjCAutoRefCount &&
1816 (Action == AA_Passing || Action == AA_Sending);
1817 if (getLangOpts().ObjC)
1821 *
this, From, ToType,
1823 AllowExplicit ? AllowedExplicit::All : AllowedExplicit::None,
1825 false, AllowObjCWritebackConversion,
1827 return PerformImplicitConversion(From, ToType, ICS, Action);
1845 if (TyClass != CanFrom->getTypeClass())
return false;
1846 if (TyClass != Type::FunctionProto && TyClass != Type::FunctionNoProto) {
1847 if (TyClass == Type::Pointer) {
1850 }
else if (TyClass == Type::BlockPointer) {
1853 }
else if (TyClass == Type::MemberPointer) {
1857 if (ToMPT->getClass() != FromMPT->
getClass())
1859 CanTo = ToMPT->getPointeeType();
1865 TyClass = CanTo->getTypeClass();
1866 if (TyClass != CanFrom->getTypeClass())
return false;
1867 if (TyClass != Type::FunctionProto && TyClass != Type::FunctionNoProto)
1871 const auto *FromFn = cast<FunctionType>(CanFrom);
1874 const auto *ToFn = cast<FunctionType>(CanTo);
1877 bool Changed =
false;
1886 if (
const auto *FromFPT = dyn_cast<FunctionProtoType>(FromFn)) {
1887 const auto *ToFPT = cast<FunctionProtoType>(ToFn);
1888 if (FromFPT->isNothrow() && !ToFPT->isNothrow()) {
1889 FromFn = cast<FunctionType>(
1900 bool CanUseToFPT, CanUseFromFPT;
1902 CanUseFromFPT, NewParamInfos) &&
1903 CanUseToFPT && !CanUseFromFPT) {
1906 NewParamInfos.empty() ? nullptr : NewParamInfos.data();
1908 FromFPT->getParamTypes(), ExtInfo);
1918 FromFPT = cast<FunctionProtoType>(FromFn);
1922 const auto FromFX = FromFPT->getFunctionEffects();
1923 const auto ToFX = ToFPT->getFunctionEffects();
1924 if (FromFX != ToFX) {
1928 FromFPT->getReturnType(), FromFPT->getParamTypes(), ExtInfo);
1938 assert(
QualType(FromFn, 0).isCanonical());
1939 if (
QualType(FromFn, 0) != CanTo)
return false;
1967 if ((&FromSem == &llvm::APFloat::PPCDoubleDouble() &&
1968 &ToSem == &llvm::APFloat::IEEEquad()) ||
1969 (&FromSem == &llvm::APFloat::IEEEquad() &&
1970 &ToSem == &llvm::APFloat::PPCDoubleDouble()))
2025 bool InOverloadResolution,
bool CStyle) {
2040 unsigned FromElts = FromExtType->getNumElements();
2041 unsigned ToElts = ToExtType->getNumElements();
2042 if (FromElts < ToElts)
2044 if (FromElts == ToElts)
2049 QualType FromElTy = FromExtType->getElementType();
2050 QualType ToElTy = ToExtType->getElementType();
2064 QualType ToElTy = ToExtType->getElementType();
2098 !ToType->
hasAttr(attr::ArmMveStrictPolymorphism))) {
2103 !InOverloadResolution && !CStyle) {
2105 << FromType << ToType;
2116 bool InOverloadResolution,
2129 bool InOverloadResolution,
2132 bool AllowObjCWritebackConversion) {
2158 FromType = Fn->getType();
2179 if (Method && !Method->
isStatic() &&
2182 "Non-unary operator on non-static member address");
2183 assert(cast<UnaryOperator>(From->
IgnoreParens())->getOpcode()
2185 "Non-address-of operator on non-static member address");
2186 const Type *ClassType
2190 assert(cast<UnaryOperator>(From->
IgnoreParens())->getOpcode() ==
2192 "Non-address-of operator for overloaded function expression");
2211 FromType =
Atomic->getValueType();
2259 if (
auto *FD = dyn_cast<FunctionDecl>(DRE->getDecl()))
2279 bool IncompatibleObjC =
false;
2334 }
else if (AllowObjCWritebackConversion &&
2338 FromType, IncompatibleObjC)) {
2344 InOverloadResolution, FromType)) {
2348 From, InOverloadResolution, CStyle)) {
2358 S, From, ToType, InOverloadResolution, SCS, CStyle)) {
2394 bool ObjCLifetimeConversion;
2400 ObjCLifetimeConversion)) {
2419 CanonFrom = CanonTo;
2424 if (CanonFrom == CanonTo)
2429 if (S.
getLangOpts().CPlusPlus || !InOverloadResolution)
2473 bool InOverloadResolution,
2483 for (
const auto *it : UD->
fields()) {
2486 ToType = it->getType();
2512 return To->
getKind() == BuiltinType::Int;
2515 return To->
getKind() == BuiltinType::UInt;
2539 if (FromEnumType->getDecl()->isScoped())
2546 if (FromEnumType->getDecl()->isFixed()) {
2547 QualType Underlying = FromEnumType->getDecl()->getIntegerType();
2549 IsIntegralPromotion(
nullptr, Underlying, ToType);
2556 ToType, FromEnumType->getDecl()->getPromotionType());
2581 uint64_t FromSize = Context.
getTypeSize(FromType);
2590 for (
int Idx = 0; Idx < 6; ++Idx) {
2591 uint64_t ToSize = Context.
getTypeSize(PromoteTypes[Idx]);
2592 if (FromSize < ToSize ||
2593 (FromSize == ToSize &&
2594 FromIsSigned == PromoteTypes[Idx]->isSignedIntegerType())) {
2619 std::optional<llvm::APSInt> BitWidth;
2622 MemberDecl->getBitWidth()->getIntegerConstantExpr(Context))) {
2623 llvm::APSInt ToSize(BitWidth->getBitWidth(), BitWidth->isUnsigned());
2627 if (*BitWidth < ToSize ||
2629 return To->
getKind() == BuiltinType::Int;
2635 return To->
getKind() == BuiltinType::UInt;
2663 if (FromBuiltin->getKind() == BuiltinType::Float &&
2664 ToBuiltin->getKind() == BuiltinType::Double)
2671 (FromBuiltin->getKind() == BuiltinType::Float ||
2672 FromBuiltin->getKind() == BuiltinType::Double) &&
2673 (ToBuiltin->getKind() == BuiltinType::LongDouble ||
2674 ToBuiltin->getKind() == BuiltinType::Float128 ||
2675 ToBuiltin->getKind() == BuiltinType::Ibm128))
2680 if (getLangOpts().
HLSL && FromBuiltin->getKind() == BuiltinType::Half &&
2681 (ToBuiltin->getKind() == BuiltinType::Float ||
2682 ToBuiltin->getKind() == BuiltinType::Double))
2686 if (!getLangOpts().NativeHalfType &&
2687 FromBuiltin->getKind() == BuiltinType::Half &&
2688 ToBuiltin->getKind() == BuiltinType::Float)
2720 bool StripObjCLifetime =
false) {
2723 "Invalid similarly-qualified pointer type");
2734 if (StripObjCLifetime)
2745 if (isa<ObjCObjectPointerType>(ToType))
2754 if (isa<ObjCObjectPointerType>(ToType))
2760 bool InOverloadResolution,
2766 return !InOverloadResolution;
2774 bool InOverloadResolution,
2776 bool &IncompatibleObjC) {
2777 IncompatibleObjC =
false;
2778 if (isObjCPointerConversion(FromType, ToType, ConvertedType,
2785 ConvertedType = ToType;
2792 ConvertedType = ToType;
2799 ConvertedType = ToType;
2807 ConvertedType = ToType;
2817 ConvertedType = ToType;
2825 !getLangOpts().ObjCAutoRefCount) {
2855 if (getLangOpts().MSVCCompat && FromPointeeType->
isFunctionType() &&
2889 IsDerivedFrom(From->
getBeginLoc(), FromPointeeType, ToPointeeType)) {
2923 bool &IncompatibleObjC) {
2924 if (!getLangOpts().
ObjC)
2936 if (ToObjCPtr && FromObjCPtr) {
2947 if (getLangOpts().CPlusPlus && LHS && RHS &&
2949 FromObjCPtr->getPointeeType()))
2954 ConvertedType =
AdoptQualifiers(Context, ConvertedType, FromQualifiers);
2962 IncompatibleObjC =
true;
2966 ConvertedType =
AdoptQualifiers(Context, ConvertedType, FromQualifiers);
2978 if (FromObjCPtr && FromObjCPtr->isObjCBuiltinType()) {
3006 isObjCPointerConversion(FromPointeeType, ToPointeeType, ConvertedType,
3007 IncompatibleObjC)) {
3009 IncompatibleObjC =
true;
3011 ConvertedType =
AdoptQualifiers(Context, ConvertedType, FromQualifiers);
3018 isObjCPointerConversion(FromPointeeType, ToPointeeType, ConvertedType,
3019 IncompatibleObjC)) {
3022 ConvertedType =
AdoptQualifiers(Context, ConvertedType, FromQualifiers);
3034 if (FromFunctionType && ToFunctionType) {
3043 if (FromFunctionType->
getNumParams() != ToFunctionType->getNumParams() ||
3044 FromFunctionType->
isVariadic() != ToFunctionType->isVariadic() ||
3045 FromFunctionType->
getMethodQuals() != ToFunctionType->getMethodQuals())
3048 bool HasObjCConversion =
false;
3052 }
else if (isObjCPointerConversion(FromFunctionType->
getReturnType(),
3053 ToFunctionType->getReturnType(),
3054 ConvertedType, IncompatibleObjC)) {
3056 HasObjCConversion =
true;
3063 for (
unsigned ArgIdx = 0, NumArgs = FromFunctionType->
getNumParams();
3064 ArgIdx != NumArgs; ++ArgIdx) {
3066 QualType ToArgType = ToFunctionType->getParamType(ArgIdx);
3070 }
else if (isObjCPointerConversion(FromArgType, ToArgType,
3071 ConvertedType, IncompatibleObjC)) {
3073 HasObjCConversion =
true;
3080 if (HasObjCConversion) {
3084 IncompatibleObjC =
true;
3116 if (!FromFunctionType || !ToFunctionType)
3119 if (Context.
hasSameType(FromPointeeType, ToPointeeType))
3124 if (FromFunctionType->
getNumParams() != ToFunctionType->getNumParams() ||
3125 FromFunctionType->
isVariadic() != ToFunctionType->isVariadic())
3130 if (FromEInfo != ToEInfo)
3133 bool IncompatibleObjC =
false;
3135 ToFunctionType->getReturnType())) {
3139 QualType LHS = ToFunctionType->getReturnType();
3140 if ((!getLangOpts().CPlusPlus || !RHS->
isRecordType()) &&
3146 }
else if (isObjCPointerConversion(RHS, LHS,
3147 ConvertedType, IncompatibleObjC)) {
3148 if (IncompatibleObjC)
3157 for (
unsigned ArgIdx = 0, NumArgs = FromFunctionType->
getNumParams();
3158 ArgIdx != NumArgs; ++ArgIdx) {
3159 IncompatibleObjC =
false;
3161 QualType ToArgType = ToFunctionType->getParamType(ArgIdx);
3162 if (Context.
hasSameType(FromArgType, ToArgType)) {
3164 }
else if (isObjCPointerConversion(ToArgType, FromArgType,
3165 ConvertedType, IncompatibleObjC)) {
3166 if (IncompatibleObjC)
3175 bool CanUseToFPT, CanUseFromFPT;
3177 CanUseToFPT, CanUseFromFPT,
3181 ConvertedType = ToType;
3219 if (!Context.
hasSameType(FromMember->getClass(), ToMember->getClass())) {
3221 <<
QualType(FromMember->getClass(), 0);
3254 if (!FromFunction || !ToFunction) {
3259 if (FromFunction->
getNumParams() != ToFunction->getNumParams()) {
3267 if (!FunctionParamTypesAreEqual(FromFunction, ToFunction, &ArgPos)) {
3269 << ToFunction->getParamType(ArgPos)
3276 ToFunction->getReturnType())) {
3282 if (FromFunction->
getMethodQuals() != ToFunction->getMethodQuals()) {
3292 cast<FunctionProtoType>(ToFunction->getCanonicalTypeUnqualified())
3305 assert(llvm::size(Old) == llvm::size(New) &&
3306 "Can't compare parameters of functions with different number of "
3309 for (
auto &&[Idx,
Type] : llvm::enumerate(Old)) {
3311 size_t J =
Reversed ? (llvm::size(New) - Idx - 1) : Idx;
3332 return FunctionParamTypesAreEqual(OldType->
param_types(),
3345 unsigned OldIgnore =
3347 unsigned NewIgnore =
3350 auto *OldPT = cast<FunctionProtoType>(OldFunction->
getFunctionType());
3351 auto *NewPT = cast<FunctionProtoType>(NewFunction->
getFunctionType());
3353 return FunctionParamTypesAreEqual(OldPT->param_types().slice(OldIgnore),
3354 NewPT->param_types().slice(NewIgnore),
3361 bool IgnoreBaseAccess,
3364 bool IsCStyleOrFunctionalCast = IgnoreBaseAccess;
3368 if (Diagnose && !IsCStyleOrFunctionalCast && !FromType->
isAnyPointerType() &&
3372 DiagRuntimeBehavior(From->
getExprLoc(), From,
3373 PDiag(diag::warn_impcast_bool_to_null_pointer)
3375 else if (!isUnevaluatedContext())
3384 if (FromPointeeType->
isRecordType() && ToPointeeType->isRecordType() &&
3388 unsigned InaccessibleID = 0;
3389 unsigned AmbiguousID = 0;
3391 InaccessibleID = diag::err_upcast_to_inaccessible_base;
3392 AmbiguousID = diag::err_ambiguous_derived_to_base_conv;
3394 if (CheckDerivedToBaseConversion(
3395 FromPointeeType, ToPointeeType, InaccessibleID, AmbiguousID,
3397 &BasePath, IgnoreBaseAccess))
3401 Kind = CK_DerivedToBase;
3404 if (Diagnose && !IsCStyleOrFunctionalCast &&
3405 FromPointeeType->
isFunctionType() && ToPointeeType->isVoidType()) {
3406 assert(getLangOpts().MSVCCompat &&
3407 "this should only be possible with MSVCCompat!");
3419 if (FromPtrType->isObjCBuiltinType() || ToPtrType->isObjCBuiltinType())
3422 Kind = CK_BlockPointerToObjCPointerCast;
3424 Kind = CK_CPointerToObjCPointerCast;
3428 Kind = CK_AnyPointerToBlockPointerCast;
3434 Kind = CK_NullToPointer;
3441 bool InOverloadResolution,
3451 ConvertedType = ToType;
3466 IsDerivedFrom(From->
getBeginLoc(), ToClass, FromClass)) {
3478 bool IgnoreBaseAccess) {
3485 "Expr must be null pointer constant!");
3486 Kind = CK_NullToMemberPointer;
3491 assert(ToPtrType &&
"No member pointer cast has a target type "
3492 "that is not a member pointer.");
3498 assert(FromClass->
isRecordType() &&
"Pointer into non-class.");
3499 assert(ToClass->
isRecordType() &&
"Pointer into non-class.");
3503 bool DerivationOkay =
3504 IsDerivedFrom(From->
getBeginLoc(), ToClass, FromClass, Paths);
3505 assert(DerivationOkay &&
3506 "Should not have been called if derivation isn't OK.");
3507 (void)DerivationOkay;
3510 getUnqualifiedType())) {
3511 std::string PathDisplayStr = getAmbiguousPathsDisplayString(Paths);
3513 << 0 << FromClass << ToClass << PathDisplayStr << From->
getSourceRange();
3517 if (
const RecordType *VBase = Paths.getDetectedVirtual()) {
3519 << FromClass << ToClass <<
QualType(VBase, 0)
3524 if (!IgnoreBaseAccess)
3525 CheckBaseClassAccess(From->
getExprLoc(), FromClass, ToClass,
3527 diag::err_downcast_from_inaccessible_base);
3531 Kind = CK_BaseToDerivedMemberPointer;
3554 bool CStyle,
bool IsTopLevel,
3555 bool &PreviousToQualsIncludeConst,
3556 bool &ObjCLifetimeConversion) {
3568 ObjCLifetimeConversion =
true;
3604 !PreviousToQualsIncludeConst)
3622 PreviousToQualsIncludeConst =
3623 PreviousToQualsIncludeConst && ToQuals.
hasConst();
3629 bool CStyle,
bool &ObjCLifetimeConversion) {
3632 ObjCLifetimeConversion =
false;
3642 bool PreviousToQualsIncludeConst =
true;
3643 bool UnwrappedAnyPointer =
false;
3646 FromType, ToType, CStyle, !UnwrappedAnyPointer,
3647 PreviousToQualsIncludeConst, ObjCLifetimeConversion))
3649 UnwrappedAnyPointer =
true;
3666 bool InOverloadResolution,
3675 InOverloadResolution, InnerSCS,
3692 if (CtorType->getNumParams() > 0) {
3693 QualType FirstArg = CtorType->getParamType(0);
3705 bool AllowExplicit) {
3712 bool Usable = !Info.Constructor->isInvalidDecl() &&
3715 bool SuppressUserConversions =
false;
3716 if (Info.ConstructorTmpl)
3719 CandidateSet, SuppressUserConversions,
3724 CandidateSet, SuppressUserConversions,
3725 false, AllowExplicit);
3729 bool HadMultipleCandidates = (CandidateSet.
size() > 1);
3738 QualType ThisType = Constructor->getFunctionObjectParameterType();
3756 llvm_unreachable(
"Invalid OverloadResult!");
3778 bool AllowObjCConversionOnExplicit) {
3779 assert(AllowExplicit != AllowedExplicit::None ||
3780 !AllowObjCConversionOnExplicit);
3784 bool ConstructorsOnly =
false;
3800 ConstructorsOnly =
true;
3805 = dyn_cast<CXXRecordDecl>(ToRecordType->getDecl())) {
3807 Expr **Args = &From;
3808 unsigned NumArgs = 1;
3809 bool ListInitializing =
false;
3810 if (
InitListExpr *InitList = dyn_cast<InitListExpr>(From)) {
3813 S, From, ToType, ToRecordDecl, User, CandidateSet,
3814 AllowExplicit == AllowedExplicit::All);
3823 Args = InitList->getInits();
3824 NumArgs = InitList->getNumInits();
3825 ListInitializing =
true;
3833 bool Usable = !Info.Constructor->isInvalidDecl();
3834 if (!ListInitializing)
3835 Usable = Usable && Info.Constructor->isConvertingConstructor(
3838 bool SuppressUserConversions = !ConstructorsOnly;
3846 if (SuppressUserConversions && ListInitializing) {
3847 SuppressUserConversions =
3848 NumArgs == 1 && isa<InitListExpr>(Args[0]) &&
3852 if (Info.ConstructorTmpl)
3854 Info.ConstructorTmpl, Info.FoundDecl,
3856 CandidateSet, SuppressUserConversions,
3858 AllowExplicit == AllowedExplicit::All);
3864 SuppressUserConversions,
3866 AllowExplicit == AllowedExplicit::All);
3873 if (ConstructorsOnly || isa<InitListExpr>(From)) {
3876 }
else if (
const RecordType *FromRecordType =
3879 = dyn_cast<CXXRecordDecl>(FromRecordType->getDecl())) {
3881 const auto &Conversions = FromRecordDecl->getVisibleConversionFunctions();
3882 for (
auto I = Conversions.begin(),
E = Conversions.end(); I !=
E; ++I) {
3886 if (isa<UsingShadowDecl>(
D))
3887 D = cast<UsingShadowDecl>(
D)->getTargetDecl();
3891 if ((ConvTemplate = dyn_cast<FunctionTemplateDecl>(
D)))
3894 Conv = cast<CXXConversionDecl>(
D);
3898 ConvTemplate, FoundDecl, ActingContext, From, ToType,
3899 CandidateSet, AllowObjCConversionOnExplicit,
3900 AllowExplicit != AllowedExplicit::None);
3903 CandidateSet, AllowObjCConversionOnExplicit,
3904 AllowExplicit != AllowedExplicit::None);
3909 bool HadMultipleCandidates = (CandidateSet.
size() > 1);
3918 = dyn_cast<CXXConstructorDecl>(Best->Function)) {
3925 if (isa<InitListExpr>(From)) {
3929 if (Best->Conversions[0].isEllipsis())
3932 User.
Before = Best->Conversions[0].Standard;
3945 = dyn_cast<CXXConversionDecl>(Best->Function)) {
3952 User.
Before = Best->Conversions[0].Standard;
3967 User.
After = Best->FinalConversion;
3970 llvm_unreachable(
"Not a constructor or conversion function?");
3979 llvm_unreachable(
"Invalid OverloadResult!");
3989 CandidateSet, AllowedExplicit::None,
false);
4003 if (!RequireCompleteType(From->
getBeginLoc(), ToType,
4004 diag::err_typecheck_nonviable_condition_incomplete,
4011 *
this, From, Cands);
4037 if (!Conv1 || !Conv2)
4052 if (Block1 != Block2)
4065 if (Conv1FuncRet && Conv2FuncRet &&
4076 CallOpProto->isVariadic(),
false);
4078 CallOpProto->isVariadic(),
true);
4080 CallingConv PrefOrder[] = {DefaultFree, DefaultMember, CallOpCC};
4175 if (!ICS1.
isBad()) {
4176 bool StdInit1 =
false, StdInit2 =
false;
4183 if (StdInit1 != StdInit2)
4194 CAT2->getElementType())) {
4196 if (CAT1->getSize() != CAT2->getSize())
4198 return CAT1->getSize().ult(CAT2->getSize())
4320 return FixedEnumPromotion::None;
4324 return FixedEnumPromotion::None;
4327 if (!
Enum->isFixed())
4328 return FixedEnumPromotion::None;
4332 return FixedEnumPromotion::ToUnderlyingType;
4334 return FixedEnumPromotion::ToPromotedUnderlyingType;
4363 else if (Rank2 < Rank1)
4386 if (FEP1 != FixedEnumPromotion::None && FEP2 != FixedEnumPromotion::None &&
4388 return FEP1 == FixedEnumPromotion::ToUnderlyingType
4398 bool SCS1ConvertsToVoid
4400 bool SCS2ConvertsToVoid
4402 if (SCS1ConvertsToVoid != SCS2ConvertsToVoid) {
4407 }
else if (!SCS1ConvertsToVoid && !SCS2ConvertsToVoid) {
4413 }
else if (SCS1ConvertsToVoid && SCS2ConvertsToVoid &&
4442 if (FromObjCPtr1 && FromObjCPtr2) {
4447 if (AssignLeft != AssignRight) {
4482 if (UnqualT1 == UnqualT2) {
4494 if (isa<ArrayType>(T1) && T1Quals)
4496 if (isa<ArrayType>(T2) && T2Quals)
4544 if (SCS1IsCompatibleVectorConversion != SCS2IsCompatibleVectorConversion)
4545 return SCS1IsCompatibleVectorConversion
4552 bool SCS1IsCompatibleSVEVectorConversion =
4554 bool SCS2IsCompatibleSVEVectorConversion =
4557 if (SCS1IsCompatibleSVEVectorConversion !=
4558 SCS2IsCompatibleSVEVectorConversion)
4559 return SCS1IsCompatibleSVEVectorConversion
4566 bool SCS1IsCompatibleRVVVectorConversion =
4568 bool SCS2IsCompatibleRVVVectorConversion =
4571 if (SCS1IsCompatibleRVVVectorConversion !=
4572 SCS2IsCompatibleRVVVectorConversion)
4573 return SCS1IsCompatibleRVVVectorConversion
4613 if (UnqualT1 == UnqualT2)
4631 bool ObjCLifetimeConversion;
4641 if (CanPick1 != CanPick2)
4695 if (FromPointee1 == FromPointee2 && ToPointee1 != ToPointee2) {
4703 if (FromPointee1 != FromPointee2 && ToPointee1 == ToPointee2) {
4720 if (FromPtr1 && FromPtr2 && ToPtr1 && ToPtr2) {
4727 bool FromAssignRight
4736 if (ToPtr1->isObjCIdType() &&
4737 (ToPtr2->isObjCQualifiedIdType() || ToPtr2->getInterfaceDecl()))
4739 if (ToPtr2->isObjCIdType() &&
4740 (ToPtr1->isObjCQualifiedIdType() || ToPtr1->getInterfaceDecl()))
4745 if (ToPtr1->isObjCQualifiedIdType() && ToPtr2->getInterfaceDecl())
4747 if (ToPtr2->isObjCQualifiedIdType() && ToPtr1->getInterfaceDecl())
4752 if (ToPtr1->isObjCClassType() &&
4753 (ToPtr2->isObjCQualifiedClassType() || ToPtr2->getInterfaceDecl()))
4755 if (ToPtr2->isObjCClassType() &&
4756 (ToPtr1->isObjCQualifiedClassType() || ToPtr1->getInterfaceDecl()))
4761 if (ToPtr1->isObjCQualifiedClassType() && ToPtr2->getInterfaceDecl())
4763 if (ToPtr2->isObjCQualifiedClassType() && ToPtr1->getInterfaceDecl())
4769 (ToAssignLeft != ToAssignRight)) {
4780 }
else if (IsSecondSame)
4789 (FromAssignLeft != FromAssignRight))
4803 const Type *FromPointeeType1 = FromMemPointer1->getClass();
4804 const Type *ToPointeeType1 = ToMemPointer1->
getClass();
4805 const Type *FromPointeeType2 = FromMemPointer2->
getClass();
4806 const Type *ToPointeeType2 = ToMemPointer2->
getClass();
4812 if (FromPointee1 == FromPointee2 && ToPointee1 != ToPointee2) {
4819 if (ToPointee1 == ToPointee2 && FromPointee1 != FromPointee2) {