30#include "llvm/ADT/SmallVector.h"
31#include "llvm/ADT/StringExtras.h"
61 struct CastOperation {
62 CastOperation(Sema &S, QualType destType,
ExprResult src)
63 :
Self(S), SrcExpr(src), DestType(destType),
66 Kind(CK_Dependent), IsARCUnbridgedCast(
false) {
80 !DestType->isArrayType() && !DestType.getPointerAuth()) {
81 DestType = DestType.getAtomicUnqualifiedType();
84 if (
const BuiltinType *placeholder =
86 PlaceholderKind = placeholder->getKind();
100 bool IsARCUnbridgedCast;
103 SourceLocation Locations[3];
105 OpRangeType(SourceLocation Begin, SourceLocation LParen,
106 SourceLocation RParen)
107 : Locations{Begin, LParen, RParen} {}
109 OpRangeType() =
default;
111 SourceLocation getBegin()
const {
return Locations[0]; }
113 SourceLocation getLParenLoc()
const {
return Locations[1]; }
115 SourceLocation getRParenLoc()
const {
return Locations[2]; }
117 friend const StreamingDiagnostic &
118 operator<<(
const StreamingDiagnostic &DB, OpRangeType Op) {
119 return DB << SourceRange(Op);
122 SourceRange getParenRange()
const {
123 return SourceRange(getLParenLoc(), getRParenLoc());
126 operator SourceRange()
const {
127 return SourceRange(getBegin(), getRParenLoc());
132 SourceRange DestRange;
135 void CheckConstCast();
136 void CheckReinterpretCast();
137 void CheckStaticCast();
138 void CheckDynamicCast();
139 void CheckCXXCStyleCast(
bool FunctionalCast,
bool ListInitialization);
141 void CheckCStyleCast();
142 void CheckBuiltinBitCast();
143 void CheckAddrspaceCast();
145 void updatePartOfExplicitCastFlags(
CastExpr *CE) {
149 for (;
auto *ICE = dyn_cast<ImplicitCastExpr>(CE->
getSubExpr()); CE = ICE)
150 ICE->setIsPartOfExplicitCast(
true);
158 if (IsARCUnbridgedCast) {
160 Self.Context, Self.Context.ARCUnbridgedCastTy, CK_Dependent,
162 Self.CurFPFeatureOverrides());
164 updatePartOfExplicitCastFlags(
castExpr);
174 if (PlaceholderKind != K)
return false;
180 bool isPlaceholder()
const {
181 return PlaceholderKind != 0;
184 return PlaceholderKind == K;
188 void checkAddressSpaceCast(QualType SrcType, QualType DestType);
190 void checkCastAlign() {
191 Self.CheckCastAlign(SrcExpr.get(), DestType, OpRange);
195 bool IsReinterpretCast =
false) {
196 assert(Self.getLangOpts().allowsNonTrivialObjCLifetimeQualifiers());
198 Expr *src = SrcExpr.
get();
199 if (Self.ObjC().CheckObjCConversion(
200 OpRange, DestType, src, CCK,
true,
false, BO_PtrMemD,
202 IsARCUnbridgedCast =
true;
206 void checkQualifiedDestType() {
208 if (DestType.getPointerAuth()) {
209 Self.Diag(DestRange.getBegin(), diag::err_ptrauth_qualifier_cast)
210 << DestType << DestRange;
215 void checkNonOverloadPlaceholders() {
216 if (!isPlaceholder() || isPlaceholder(BuiltinType::Overload))
219 SrcExpr = Self.CheckPlaceholderExpr(SrcExpr.get());
220 if (SrcExpr.isInvalid())
228 if (
const auto *PtrType = dyn_cast<PointerType>(FromType)) {
229 if (PtrType->getPointeeType()->hasAttr(attr::NoDeref)) {
230 if (
const auto *DestType = dyn_cast<PointerType>(ToType)) {
231 if (!DestType->getPointeeType()->hasAttr(attr::NoDeref)) {
232 S.
Diag(OpLoc, diag::warn_noderef_to_dereferenceable_pointer);
239 struct CheckNoDerefRAII {
240 CheckNoDerefRAII(CastOperation &Op) : Op(Op) {}
241 ~CheckNoDerefRAII() {
242 if (!Op.SrcExpr.isInvalid())
243 CheckNoDeref(Op.Self, Op.SrcExpr.get()->getType(), Op.ResultType,
244 Op.OpRange.getBegin());
272 bool CStyle, CastOperation::OpRangeType OpRange,
277 bool CStyle, CastOperation::OpRangeType OpRange,
281 CastOperation::OpRangeType OpRange,
283 QualType OrigDestType,
unsigned &msg,
288 CastOperation::OpRangeType OpRange,
unsigned &msg,
294 CastOperation::OpRangeType OpRange,
296 bool ListInitialization);
299 CastOperation::OpRangeType OpRange,
302 bool ListInitialization);
308 CastOperation::OpRangeType OpRange,
348 CastOperation Op(*
this, DestType, E);
350 CastOperation::OpRangeType(OpLoc,
Parens.getBegin(),
Parens.getEnd());
351 Op.DestRange = AngleBrackets;
353 Op.checkQualifiedDestType();
356 default: llvm_unreachable(
"Unknown C++ cast!");
358 case tok::kw_addrspace_cast:
359 if (!TypeDependent) {
360 Op.CheckAddrspaceCast();
365 Context, Op.ResultType, Op.ValueKind, Op.Kind, Op.SrcExpr.
get(),
366 DestTInfo, OpLoc,
Parens.getEnd(), AngleBrackets));
368 case tok::kw_const_cast:
369 if (!TypeDependent) {
376 Op.ValueKind, Op.SrcExpr.
get(), DestTInfo,
380 case tok::kw_dynamic_cast: {
383 return ExprError(
Diag(OpLoc, diag::err_openclcxx_not_supported)
387 if (!TypeDependent) {
388 Op.CheckDynamicCast();
393 Op.ValueKind, Op.Kind, Op.SrcExpr.
get(),
394 &Op.BasePath, DestTInfo,
398 case tok::kw_reinterpret_cast: {
399 if (!TypeDependent) {
400 Op.CheckReinterpretCast();
406 Op.ValueKind, Op.Kind, Op.SrcExpr.
get(),
407 nullptr, DestTInfo, OpLoc,
411 case tok::kw_static_cast: {
412 if (!TypeDependent) {
413 Op.CheckStaticCast();
420 Context, Op.ResultType, Op.ValueKind, Op.Kind, Op.SrcExpr.
get(),
422 Parens.getEnd(), AngleBrackets));
442 if (Operand->hasPlaceholderType()) {
449 CastOperation Op(*
this, TSI->
getType(), Operand);
450 Op.OpRange = CastOperation::OpRangeType(KWLoc, KWLoc, RParenLoc);
455 Op.CheckBuiltinBitCast();
462 Op.SrcExpr.
get(), TSI, KWLoc, RParenLoc);
463 return Op.complete(BCE);
469 CastOperation::OpRangeType range,
471 bool listInitialization) {
494 range.getBegin(), range, listInitialization)
497 range.getBegin(), range.getParenRange(), listInitialization)
508 default:
return false;
540 case OR_Success: llvm_unreachable(
"successful failed overload");
542 if (candidates.
empty())
543 msg = diag::err_ovl_no_conversion_in_cast;
545 msg = diag::err_ovl_no_viable_conversion_in_cast;
550 msg = diag::err_ovl_ambiguous_conversion_in_cast;
558 assert(Res ==
OR_Deleted &&
"Inconsistent overload resolution");
563 S.
PDiag(diag::err_ovl_deleted_conversion_in_cast)
564 << CT << srcType << destType << (Msg !=
nullptr)
565 << (Msg ? Msg->
getString() : StringRef())
574 S.
PDiag(msg) << CT << srcType << destType << range
576 S, howManyCandidates, src);
583 CastOperation::OpRangeType opRange,
Expr *src,
584 QualType destType,
bool listInitialization) {
585 if (msg == diag::err_bad_cxx_cast_generic &&
590 S.
Diag(opRange.getBegin(), msg) << castType
594 int DifferentPtrness = 0;
605 if (!DifferentPtrness) {
608 DeclFrom && DeclTo) {
609 if (!DeclFrom->isCompleteDefinition())
610 S.
Diag(DeclFrom->getLocation(), diag::note_type_incomplete) << DeclFrom;
611 if (!DeclTo->isCompleteDefinition())
612 S.
Diag(DeclTo->getLocation(), diag::note_type_incomplete) << DeclTo;
620enum CastAwayConstnessKind {
627 CACK_SimilarKind = 2,
646static CastAwayConstnessKind
648 enum {
None, Ptr, MemPtr, BlockPtr,
Array };
650 if (T->isAnyPointerType())
return Ptr;
651 if (T->isMemberPointerType())
return MemPtr;
652 if (T->isBlockPointerType())
return BlockPtr;
655 if (T->isConstantArrayType() || T->isIncompleteArrayType())
return Array;
660 if (
auto *AT = Context.getAsArrayType(T))
661 return AT->getElementType();
662 return T->getPointeeType();
665 CastAwayConstnessKind Kind;
673 Kind = CastAwayConstnessKind::CACK_Similar;
674 }
else if (Context.UnwrapSimilarTypes(T1, T2)) {
675 Kind = CastAwayConstnessKind::CACK_Similar;
678 int T1Class = Classify(T1);
680 return CastAwayConstnessKind::CACK_None;
682 int T2Class = Classify(T2);
684 return CastAwayConstnessKind::CACK_None;
688 Kind = T1Class == T2Class ? CastAwayConstnessKind::CACK_SimilarKind
689 : CastAwayConstnessKind::CACK_Incoherent;
697 Context.UnwrapSimilarArrayTypes(T1, T2);
699 if (Classify(T1) !=
Array)
702 auto T2Class = Classify(T2);
706 if (T2Class !=
Array)
707 Kind = CastAwayConstnessKind::CACK_Incoherent;
708 else if (Kind != CastAwayConstnessKind::CACK_Incoherent)
709 Kind = CastAwayConstnessKind::CACK_SimilarKind;
724static CastAwayConstnessKind
726 bool CheckCVR,
bool CheckObjCLifetime,
727 QualType *TheOffendingSrcType =
nullptr,
728 QualType *TheOffendingDestType =
nullptr,
732 if (!CheckCVR && CheckObjCLifetime && !
Self.Context.getLangOpts().ObjC)
733 return CastAwayConstnessKind::CACK_None;
738 "Source type is not pointer or pointer to member.");
741 "Destination type is not pointer or pointer to member.");
744 QualType UnwrappedSrcType =
Self.Context.getCanonicalType(SrcType),
745 UnwrappedDestType =
Self.Context.getCanonicalType(DestType);
750 QualType PrevUnwrappedSrcType = UnwrappedSrcType;
751 QualType PrevUnwrappedDestType = UnwrappedDestType;
752 auto WorstKind = CastAwayConstnessKind::CACK_Similar;
753 bool AllConstSoFar =
true;
755 Self.Context, UnwrappedSrcType, UnwrappedDestType)) {
758 if (Kind > WorstKind)
763 Self.Context.getUnqualifiedArrayType(UnwrappedSrcType, SrcQuals);
764 Self.Context.getUnqualifiedArrayType(UnwrappedDestType, DestQuals);
770 UnwrappedDestType->isObjCObjectType())
779 if (SrcCvrQuals != DestCvrQuals) {
780 if (CastAwayQualifiers)
781 *CastAwayQualifiers = SrcCvrQuals - DestCvrQuals;
784 if (!DestCvrQuals.compatiblyIncludes(SrcCvrQuals,
785 Self.getASTContext())) {
786 if (TheOffendingSrcType)
787 *TheOffendingSrcType = PrevUnwrappedSrcType;
788 if (TheOffendingDestType)
789 *TheOffendingDestType = PrevUnwrappedDestType;
800 if (CheckObjCLifetime &&
806 if (AllConstSoFar && !DestQuals.
hasConst()) {
807 AllConstSoFar =
false;
808 if (TheOffendingSrcType)
809 *TheOffendingSrcType = PrevUnwrappedSrcType;
810 if (TheOffendingDestType)
811 *TheOffendingDestType = PrevUnwrappedDestType;
814 PrevUnwrappedSrcType = UnwrappedSrcType;
815 PrevUnwrappedDestType = UnwrappedDestType;
818 return CastAwayConstnessKind::CACK_None;
824 case CastAwayConstnessKind::CACK_None:
825 llvm_unreachable(
"did not cast away constness");
827 case CastAwayConstnessKind::CACK_Similar:
829 case CastAwayConstnessKind::CACK_SimilarKind:
830 DiagID = diag::err_bad_cxx_cast_qualifiers_away;
833 case CastAwayConstnessKind::CACK_Incoherent:
834 DiagID = diag::ext_bad_cxx_cast_qualifiers_away_incoherent;
838 llvm_unreachable(
"unexpected cast away constness kind");
844void CastOperation::CheckDynamicCast() {
845 CheckNoDerefRAII NoderefCheck(*
this);
848 SrcExpr =
Self.DefaultFunctionArrayLvalueConversion(SrcExpr.get());
849 else if (isPlaceholder())
850 SrcExpr =
Self.CheckPlaceholderExpr(SrcExpr.get());
851 if (SrcExpr.isInvalid())
854 QualType OrigSrcType = SrcExpr.get()->getType();
855 QualType DestType =
Self.Context.getCanonicalType(this->DestType);
868 Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_ref_or_ptr)
869 << this->DestType << DestRange;
874 const auto *DestRecord = DestPointee->
getAsCanonical<RecordType>();
876 assert(DestPointer &&
"Reference to void is not possible");
877 }
else if (DestRecord) {
878 if (
Self.RequireCompleteType(OpRange.getBegin(), DestPointee,
879 diag::err_bad_cast_incomplete,
885 Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_class)
895 QualType SrcType =
Self.Context.getCanonicalType(OrigSrcType);
901 Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_ptr)
902 << OrigSrcType << this->DestType << SrcExpr.get()->getSourceRange();
906 }
else if (DestReference->isLValueReferenceType()) {
907 if (!SrcExpr.get()->isLValue()) {
908 Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_rvalue)
909 <<
CT_Dynamic << OrigSrcType << this->DestType << OpRange;
911 SrcPointee = SrcType;
915 if (SrcExpr.get()->isPRValue())
916 SrcExpr =
Self.CreateMaterializeTemporaryExpr(
917 SrcType, SrcExpr.get(),
false);
918 SrcPointee = SrcType;
923 if (
Self.RequireCompleteType(OpRange.getBegin(), SrcPointee,
924 diag::err_bad_cast_incomplete,
930 Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_class)
936 assert((DestPointer || DestReference) &&
937 "Bad destination non-ptr/ref slipped through.");
938 assert((DestRecord || DestPointee->
isVoidType()) &&
939 "Bad destination pointee slipped through.");
940 assert(SrcRecord &&
"Bad source pointee slipped through.");
944 Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_qualifiers_away)
945 <<
CT_Dynamic << OrigSrcType << this->DestType << OpRange;
952 if (DestRecord == SrcRecord) {
960 Self.IsDerivedFrom(OpRange.getBegin(), SrcPointee, DestPointee)) {
961 if (
Self.CheckDerivedToBaseConversion(SrcPointee, DestPointee,
962 OpRange.getBegin(), OpRange,
968 Kind = CK_DerivedToBase;
974 assert(SrcDecl &&
"Definition missing");
976 Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_polymorphic)
985 Self.Diag(OpRange.getBegin(), diag::err_no_dynamic_cast_with_fno_rtti);
991 if (!
Self.getLangOpts().RTTIData) {
993 Self.getASTContext().getTargetInfo().getCXXABI().isMicrosoft();
994 bool isClangCL =
Self.getDiagnostics().getDiagnosticOptions().getFormat() ==
996 if (MicrosoftABI || !DestPointee->
isVoidType())
997 Self.Diag(OpRange.getBegin(),
998 diag::warn_no_dynamic_cast_with_rtti_disabled)
1005 auto *DestDecl = DestRecord->getAsCXXRecordDecl();
1006 if (DestDecl->isEffectivelyFinal())
1007 Self.MarkVTableUsed(OpRange.getBegin(), DestDecl);
1019void CastOperation::CheckConstCast() {
1020 CheckNoDerefRAII NoderefCheck(*
this);
1023 SrcExpr =
Self.DefaultFunctionArrayLvalueConversion(SrcExpr.get());
1024 else if (isPlaceholder())
1025 SrcExpr =
Self.CheckPlaceholderExpr(SrcExpr.get());
1026 if (SrcExpr.isInvalid())
1029 unsigned msg = diag::err_bad_cxx_cast_generic;
1033 << SrcExpr.get()->getType() << DestType << OpRange;
1039void CastOperation::CheckAddrspaceCast() {
1040 unsigned msg = diag::err_bad_cxx_cast_generic;
1044 Self.Diag(OpRange.getBegin(), msg)
1045 <<
CT_Addrspace << SrcExpr.get()->getType() << DestType << OpRange;
1055 CastOperation::OpRangeType OpRange) {
1082 ReinterpretKind = ReinterpretUpcast;
1084 ReinterpretKind = ReinterpretDowncast;
1089 bool NonZeroOffset =
false;
1091 E = BasePaths.
end();
1095 bool IsVirtual =
false;
1096 for (CXXBasePath::const_iterator IElem = Path.begin(), EElem = Path.end();
1097 IElem != EElem; ++IElem) {
1098 IsVirtual = IElem->Base->isVirtual();
1101 const CXXRecordDecl *BaseRD = IElem->Base->getType()->getAsCXXRecordDecl();
1102 assert(BaseRD &&
"Base type should be a valid unqualified class type");
1107 if (Class->isInvalidDecl() || !ClassDefinition ||
1108 !ClassDefinition->isCompleteDefinition())
1112 Self.Context.getASTRecordLayout(Class);
1117 if (Offset.isZero())
1121 NonZeroOffset =
true;
1126 (void) NonZeroOffset;
1128 "Should have returned if has non-virtual base with zero offset");
1131 ReinterpretKind == ReinterpretUpcast? DestType : SrcType;
1133 ReinterpretKind == ReinterpretUpcast? SrcType : DestType;
1136 Self.Diag(BeginLoc, diag::warn_reinterpret_different_from_static)
1137 << DerivedType << BaseType << !
VirtualBase <<
int(ReinterpretKind)
1139 Self.Diag(BeginLoc, diag::note_reinterpret_updowncast_use_static)
1140 <<
int(ReinterpretKind)
1152 if (Context.getTypeSizeInChars(SrcType) ==
1153 Context.getTypeSizeInChars(DestType))
1156 return Context.hasSameUnqualifiedType(SrcType, DestType);
1161 unsigned int DiagID = 0;
1162 const unsigned int DiagList[] = {diag::warn_cast_function_type_strict,
1163 diag::warn_cast_function_type};
1188 assert(SrcFTy && DstFTy);
1190 if (
Self.Context.hasSameType(SrcFTy, DstFTy))
1194 if (DiagID == diag::warn_cast_function_type_strict)
1198 if (!T->getReturnType()->isVoidType())
1201 return !PT->isVariadic() && PT->getNumParams() == 0;
1214 if (!T->getReturnType()->isIntegerType())
1217 return !PT->isVariadic() && PT->getNumParams() == 0;
1222 if (IsVoidVoid(SrcFTy) || IsVoidVoid(DstFTy))
1228 if (
Self.getASTContext().getTargetInfo().getTriple().isOSWindows() &&
1248 unsigned NumParams = SrcFPTy->getNumParams();
1249 unsigned DstNumParams = DstFPTy->getNumParams();
1250 if (NumParams > DstNumParams) {
1251 if (!DstFPTy->isVariadic())
1253 NumParams = DstNumParams;
1254 }
else if (NumParams < DstNumParams) {
1255 if (!SrcFPTy->isVariadic())
1259 for (
unsigned i = 0; i < NumParams; ++i)
1261 DstFPTy->getParamType(i),
Self.Context))
1272void CastOperation::CheckReinterpretCast() {
1273 if (ValueKind ==
VK_PRValue && !isPlaceholder(BuiltinType::Overload))
1274 SrcExpr =
Self.DefaultFunctionArrayLvalueConversion(SrcExpr.get());
1276 checkNonOverloadPlaceholders();
1277 if (SrcExpr.isInvalid())
1280 unsigned msg = diag::err_bad_cxx_cast_generic;
1283 false, OpRange, msg, Kind);
1285 if (SrcExpr.isInvalid())
1287 if (SrcExpr.get()->getType() ==
Self.Context.OverloadTy) {
1289 Self.Diag(OpRange.getBegin(), diag::err_bad_reinterpret_cast_overload)
1291 << DestType << OpRange;
1292 Self.NoteAllOverloadCandidates(SrcExpr.get());
1301 if (
Self.getLangOpts().allowsNonTrivialObjCLifetimeQualifiers())
1307 Self.Diag(OpRange.getBegin(), DiagID)
1308 << SrcExpr.get()->getType() << DestType << OpRange;
1318void CastOperation::CheckStaticCast() {
1319 CheckNoDerefRAII NoderefCheck(*
this);
1321 if (isPlaceholder()) {
1322 checkNonOverloadPlaceholders();
1323 if (SrcExpr.isInvalid())
1333 if (claimPlaceholder(BuiltinType::Overload)) {
1334 Self.ResolveAndFixSingleFunctionTemplateSpecialization(SrcExpr,
1337 OpRange, DestType, diag::err_bad_static_cast_overload);
1338 if (SrcExpr.isInvalid())
1342 SrcExpr =
Self.IgnoredValueConversions(SrcExpr.get());
1347 !isPlaceholder(BuiltinType::Overload)) {
1348 SrcExpr =
Self.DefaultFunctionArrayLvalueConversion(SrcExpr.get());
1349 if (SrcExpr.isInvalid())
1353 unsigned msg = diag::err_bad_cxx_cast_generic;
1356 OpRange, msg, Kind, BasePath,
false);
1358 if (SrcExpr.isInvalid())
1360 if (SrcExpr.get()->getType() ==
Self.Context.OverloadTy) {
1362 Self.Diag(OpRange.getBegin(), diag::err_bad_static_cast_overload)
1363 << oe->
getName() << DestType << OpRange
1365 Self.NoteAllOverloadCandidates(SrcExpr.get());
1373 if (Kind == CK_BitCast)
1375 if (
Self.getLangOpts().allowsNonTrivialObjCLifetimeQualifiers())
1390 DestPtrType->getPointeeType().getAddressSpace();
1398 CastOperation::OpRangeType OpRange,
1401 bool ListInitialization) {
1427 OpRange, msg, Kind, BasePath);
1435 Kind, BasePath, msg);
1442 Kind, ListInitialization);
1463 if (
const EnumType *
Enum = dyn_cast<EnumType>(SrcType)) {
1464 if (
Enum->getDecl()->isScoped()) {
1466 Kind = CK_IntegralToBoolean;
1469 Kind = CK_IntegralCast;
1472 Kind = CK_IntegralToFloating;
1487 if (
Self.RequireCompleteType(OpRange.getBegin(), DestType,
1488 diag::err_bad_cast_incomplete)) {
1496 Kind = ED->
isFixed() && ED->getIntegerType()->isBooleanType()
1497 ? CK_IntegralToBoolean
1501 Kind = CK_FloatingToIntegral;
1517 OpRange, msg, Kind, BasePath);
1540 if (DestPointeeQuals != SrcPointeeQuals &&
1542 Self.getASTContext())) {
1543 msg = diag::err_bad_cxx_cast_qualifiers_away;
1548 ? CK_AddressSpaceConversion
1555 if (!CStyle &&
Self.getLangOpts().MSVCCompat &&
1557 Self.Diag(OpRange.getBegin(), diag::ext_ms_cast_fn_obj) << OpRange;
1565 Kind = CK_CPointerToObjCPointerCast;
1570 Kind = CK_AnyPointerToBlockPointerCast;
1584 Self.ObjC().CheckTollFreeBridgeStaticCast(DestType, SrcExpr.
get(), Kind))
1591 if (SrcPointer->getPointeeType()->isRecordType() &&
1593 msg = diag::err_bad_cxx_cast_unrelated_class;
1596 if (
Self.CheckMatrixCast(OpRange, DestType, SrcType, Kind)) {
1603 if (SrcType ==
Self.Context.AMDGPUFeaturePredicateTy &&
1604 DestType ==
Self.Context.getLogicalOperationType()) {
1605 SrcExpr =
Self.AMDGPU().ExpandAMDGPUPredicateBuiltIn(SrcExpr.
get());
1632 QualType ToType = R->getPointeeType();
1640 SrcExpr->
getBeginLoc(), ToType, FromType, &RefConv);
1647 msg = SrcExpr->
isLValue() ? diag::err_bad_lvalue_to_rvalue_cast
1648 : diag::err_bad_rvalue_to_rvalue_cast;
1652 if (RefConv & Sema::ReferenceConversions::DerivedToBase) {
1653 Kind = CK_DerivedToBase;
1654 if (
Self.CheckDerivedToBaseConversion(FromType, ToType,
1656 &BasePath, CStyle)) {
1669 CastOperation::OpRangeType OpRange,
1682 if (!DestReference) {
1686 if (!RValueRef && !SrcExpr->
isLValue()) {
1688 msg = diag::err_bad_cxx_cast_rvalue;
1698 Self.Context.getCanonicalType(SrcExpr->
getType()),
1699 Self.Context.getCanonicalType(DestPointee), CStyle,
1700 OpRange, SrcExpr->
getType(), DestType, msg, Kind,
1707 CastOperation::OpRangeType OpRange,
1725 msg = diag::err_bad_static_cast_pointer_nonpointer;
1732 CStyle, OpRange, SrcType, DestType, msg, Kind,
1741 CastOperation::OpRangeType OpRange,
1746 if (!
Self.isCompleteType(OpRange.getBegin(), SrcType) ||
1747 !
Self.isCompleteType(OpRange.getBegin(), DestType))
1751 if (!DestType->
getAs<RecordType>() || !SrcType->
getAs<RecordType>()) {
1757 if (!
Self.IsDerivedFrom(OpRange.getBegin(), DestType, SrcType, Paths)) {
1782 msg = diag::err_bad_cxx_cast_qualifiers_away;
1794 Self.IsDerivedFrom(OpRange.getBegin(), DestType, SrcType, Paths);
1796 std::string PathDisplayStr;
1797 std::set<unsigned> DisplayedPaths;
1799 if (DisplayedPaths.insert(Path.back().SubobjectNumber).second) {
1802 PathDisplayStr +=
"\n ";
1804 PathDisplayStr += PE.Base->getType().getAsString() +
" -> ";
1809 Self.Diag(OpRange.getBegin(), diag::err_ambiguous_base_to_derived_cast)
1812 << PathDisplayStr << OpRange;
1819 Self.Diag(OpRange.getBegin(), diag::err_static_downcast_via_virtual)
1820 << OrigSrcType << OrigDestType <<
VirtualBase << OpRange;
1826 switch (
Self.CheckBaseClassAccess(OpRange.getBegin(),
1829 diag::err_downcast_from_inaccessible_base)) {
1841 Self.BuildBasePathArray(Paths, BasePath);
1842 Kind = CK_BaseToDerived;
1856 CastOperation::OpRangeType OpRange,
1863 bool WasOverloadedFunction =
false;
1867 =
Self.ResolveAddressOfOverloadedFunction(SrcExpr.
get(), DestType,
false,
1870 SrcType =
Self.Context.getMemberPointerType(
1871 Fn->getType(), std::nullopt, M->
getParent());
1872 WasOverloadedFunction =
true;
1876 switch (
Self.CheckMemberPointerConversion(
1877 SrcType, DestMemPtr, Kind, BasePath, OpRange.getBegin(), OpRange, CStyle,
1880 if (Kind == CK_NullToMemberPointer) {
1881 msg = diag::err_bad_static_cast_member_pointer_nonmp;
1895 if (WasOverloadedFunction) {
1907 SrcExpr =
Self.FixOverloadedFunctionReference(SrcExpr, FoundOverload, Fn);
1924 CastOperation::OpRangeType OpRange,
1926 bool ListInitialization) {
1928 if (
Self.RequireCompleteType(OpRange.getBegin(), DestType,
1929 diag::err_bad_cast_incomplete) ||
1930 Self.RequireNonAbstractType(OpRange.getBegin(), DestType,
1931 diag::err_allocation_of_abstract_type)) {
1944 OpRange.getBegin(), OpRange.getParenRange(), ListInitialization)
1946 Expr *SrcExprRaw = SrcExpr.
get();
1963 if (
Result.isInvalid()) {
1969 Kind = CK_ConstructorConversion;
1982 DestType =
Self.Context.getCanonicalType(DestType);
1984 bool NeedToMaterializeTemporary =
false;
2002 msg = diag::err_bad_cxx_cast_rvalue;
2010 msg = diag::err_bad_cxx_cast_rvalue;
2016 NeedToMaterializeTemporary =
true;
2025 msg = diag::err_bad_cxx_cast_bitfield;
2029 DestType =
Self.Context.getPointerType(DestTypeTmp->getPointeeType());
2030 SrcType =
Self.Context.getPointerType(SrcType);
2045 msg = diag::err_bad_const_cast_dest;
2054 msg = diag::err_bad_const_cast_dest;
2064 if (!
Self.Context.hasCvrSimilarType(SrcType, DestType))
2067 if (NeedToMaterializeTemporary)
2070 SrcExpr =
Self.CreateMaterializeTemporaryExpr(SrcExpr.
get()->
getType(),
2085 unsigned DiagID = IsDereference ?
2086 diag::warn_pointer_indirection_from_incompatible_type :
2087 diag::warn_undefined_reinterpret_cast;
2089 if (
Diags.isIgnored(DiagID, Range.getBegin()))
2093 if (IsDereference) {
2108 if (
Context.hasSameUnqualifiedType(DestTy, SrcTy)) {
2133 Diag(Range.getBegin(), DiagID) << SrcType << DestType << Range;
2139 if (
Self.Context.hasSameType(SrcType, DestType))
2142 if (SrcPtrTy->isObjCSelType()) {
2148 diag::warn_cast_pointer_from_sel)
2157 CastOperation::OpRangeType OpRange) {
2161 if (
Self.Context.hasSameType(SrcType, DstType) ||
2164 const auto *SrcFTy =
2166 const auto *DstFTy =
2176 if (
auto *UO = dyn_cast<UnaryOperator>(Src))
2177 if (UO->getOpcode() == UO_AddrOf)
2179 auto *DRE = dyn_cast<DeclRefExpr>(Src);
2182 auto *FD = dyn_cast<FunctionDecl>(DRE->getDecl());
2190 CallingConv DefaultCC =
Self.getASTContext().getDefaultCallingConvention(
2191 FD->isVariadic(), FD->isCXXInstanceMember());
2192 if (DstCC == DefaultCC || SrcCC != DefaultCC)
2198 Self.Diag(OpRange.getBegin(), diag::warn_cast_calling_conv)
2199 << SrcCCName << DstCCName << OpRange;
2204 if (
Self.Diags.isIgnored(diag::warn_cast_calling_conv, OpRange.getBegin()))
2211 SourceLocation NameLoc = FD->getFirstDecl()->getNameInfo().getLoc();
2215 llvm::raw_svector_ostream OS(CCAttrText);
2216 if (
Self.getLangOpts().MicrosoftExt) {
2218 OS <<
"__" << DstCCName;
2225 OS <<
"__attribute__((" << DstCCName <<
"))";
2226 AttrTokens.push_back(tok::kw___attribute);
2227 AttrTokens.push_back(tok::l_paren);
2228 AttrTokens.push_back(tok::l_paren);
2233 AttrTokens.push_back(tok::r_paren);
2234 AttrTokens.push_back(tok::r_paren);
2237 if (!AttrSpelling.empty())
2238 CCAttrText = AttrSpelling;
2240 Self.Diag(NameLoc, diag::note_change_calling_conv_fixit)
2256 &&
Self.Context.getTypeSize(DestType) >
2257 Self.Context.getTypeSize(SrcType)) {
2264 diag::warn_int_to_void_pointer_cast
2265 : diag::warn_int_to_pointer_cast;
2281 if (
Self.ResolveAndFixSingleFunctionTemplateSpecialization(
2292 if (!
Self.resolveAndFixAddressOfSingleOverloadCandidate(
2295 return Result.isUsable();
2300 CastOperation::OpRangeType OpRange,
2302 bool IsLValueCast =
false;
2304 DestType =
Self.Context.getCanonicalType(DestType);
2309 if (SrcType ==
Self.Context.OverloadTy) {
2314 assert(FixedExpr.
isUsable() &&
"Invalid result fixing overloaded expr");
2315 SrcExpr = FixedExpr;
2323 msg = diag::err_bad_cxx_cast_rvalue;
2328 Self.CheckCompatibleReinterpretCast(SrcType, DestType,
2336 const char *inappropriate =
nullptr;
2341 msg = diag::err_bad_cxx_cast_bitfield;
2346 inappropriate =
"matrix element";
2349 case OK_ObjCSubscript: inappropriate =
"container subscripting expression";
2352 if (inappropriate) {
2353 Self.Diag(OpRange.getBegin(), diag::err_bad_reinterpret_cast_reference)
2354 << inappropriate << DestType
2361 DestType =
Self.Context.getPointerType(DestTypeTmp->getPointeeType());
2362 SrcType =
Self.Context.getPointerType(SrcType);
2364 IsLValueCast =
true;
2368 SrcType =
Self.Context.getCanonicalType(SrcType);
2372 if (DestMemPtr && SrcMemPtr) {
2378 SrcMemPtr->isMemberFunctionPointer())
2381 if (
Self.Context.getTargetInfo().getCXXABI().isMicrosoft()) {
2384 (void)
Self.isCompleteType(OpRange.getBegin(), SrcType);
2385 (void)
Self.isCompleteType(OpRange.getBegin(), DestType);
2389 if (
Self.Context.getTypeSize(DestMemPtr) !=
2390 Self.Context.getTypeSize(SrcMemPtr)) {
2391 msg = diag::err_bad_cxx_cast_member_pointer_size;
2405 assert(!IsLValueCast);
2406 Kind = CK_ReinterpretMemberPointer;
2416 if (
Self.Context.getTypeSize(SrcType) >
2417 Self.Context.getTypeSize(DestType)) {
2418 msg = diag::err_bad_reinterpret_cast_small_int;
2421 Kind = CK_PointerToIntegral;
2429 if (srcIsVector || destIsVector) {
2431 if (
Self.isValidSveBitcast(SrcType, DestType)) {
2437 if (
Self.RISCV().isValidRVVBitcast(SrcType, DestType)) {
2451 if (
Self.areLaxCompatibleVectorTypes(SrcType, DestType)) {
2456 if (
Self.LangOpts.OpenCL && !CStyle) {
2459 if (
Self.areVectorTypesSameSize(SrcType, DestType)) {
2468 msg = diag::err_bad_cxx_cast_vector_to_scalar_different_size;
2469 else if (!srcIsVector)
2470 msg = diag::err_bad_cxx_cast_scalar_to_vector_different_size;
2472 msg = diag::err_bad_cxx_cast_vector_to_vector_different_size;
2477 if (SrcType == DestType) {
2501 if (!destIsPtr && !srcIsPtr) {
2508 assert(srcIsPtr &&
"One type must be a pointer");
2512 if ((
Self.Context.getTypeSize(SrcType) >
2513 Self.Context.getTypeSize(DestType))) {
2514 bool MicrosoftException =
2516 if (MicrosoftException) {
2518 ? diag::warn_void_pointer_to_int_cast
2519 : diag::warn_pointer_to_int_cast;
2520 Self.Diag(OpRange.getBegin(),
Diag) << SrcType << DestType << OpRange;
2522 msg = diag::err_bad_reinterpret_cast_small_int;
2526 Kind = CK_PointerToIntegral;
2531 assert(destIsPtr &&
"One type must be a pointer");
2537 Kind = CK_IntegralToPointer;
2541 if (!destIsPtr || !srcIsPtr) {
2561 Kind = CK_AddressSpaceConversion;
2568 }
else if (IsLValueCast) {
2569 Kind = CK_LValueBitCast;
2571 Kind =
Self.ObjC().PrepareCastToObjCObjectPointer(SrcExpr);
2574 Kind = CK_AnyPointerToBlockPointerCast;
2585 return SuccessResult;
2599 return SuccessResult;
2608 Self.Diag(OpRange.getBegin(),
2609 Self.getLangOpts().CPlusPlus11 ?
2610 diag::warn_cxx98_compat_cast_fn_obj : diag::ext_cast_fn_obj)
2612 return SuccessResult;
2617 Self.Diag(OpRange.getBegin(),
2618 Self.getLangOpts().CPlusPlus11 ?
2619 diag::warn_cxx98_compat_cast_fn_obj : diag::ext_cast_fn_obj)
2621 return SuccessResult;
2633 Self.Diag(OpRange.getBegin(),
2634 diag::warn_bad_cxx_cast_nested_pointer_addr_space)
2647 return SuccessResult;
2653 if (!
Self.getLangOpts().OpenCL && !
Self.getLangOpts().SYCLIsDevice)
2670 auto SrcPointeeType = SrcPtrType->getPointeeType();
2671 auto DestPointeeType = DestPtrType->getPointeeType();
2672 if (!DestPointeeType.isAddressSpaceOverlapping(SrcPointeeType,
2673 Self.getASTContext())) {
2674 msg = diag::err_bad_cxx_cast_addr_space_mismatch;
2677 auto SrcPointeeTypeWithoutAS =
2678 Self.Context.removeAddrSpaceQualType(SrcPointeeType.getCanonicalType());
2679 auto DestPointeeTypeWithoutAS =
2680 Self.Context.removeAddrSpaceQualType(DestPointeeType.getCanonicalType());
2681 if (
Self.Context.hasSameType(SrcPointeeTypeWithoutAS,
2682 DestPointeeTypeWithoutAS)) {
2683 Kind = SrcPointeeType.getAddressSpace() == DestPointeeType.getAddressSpace()
2685 : CK_AddressSpaceConversion;
2692void CastOperation::checkAddressSpaceCast(
QualType SrcType,
QualType DestType) {
2704 if (
Self.getLangOpts().OpenCL) {
2705 const Type *DestPtr, *SrcPtr;
2706 bool Nested =
false;
2707 unsigned DiagID = diag::err_typecheck_incompatible_address_space;
2708 DestPtr =
Self.getASTContext().getCanonicalType(DestType.
getTypePtr()),
2709 SrcPtr =
Self.getASTContext().getCanonicalType(SrcType.
getTypePtr());
2719 Self.getASTContext())) {
2720 Self.Diag(OpRange.getBegin(), DiagID)
2722 << SrcExpr.get()->getSourceRange();
2731 DiagID = diag::ext_nested_pointer_qualifier_mismatch;
2737 bool SrcCompatXL = this->
getLangOpts().getAltivecSrcCompat() ==
2751 bool SrcCompatGCC = this->
getLangOpts().getAltivecSrcCompat() ==
2753 if (this->
getLangOpts().AltiVec && SrcCompatGCC) {
2755 diag::err_invalid_conversion_between_vector_and_integer)
2756 << VecTy << SrcTy << R;
2762void CastOperation::CheckCXXCStyleCast(
bool FunctionalStyle,
2763 bool ListInitialization) {
2764 assert(
Self.getLangOpts().CPlusPlus);
2767 if (isPlaceholder()) {
2769 if (claimPlaceholder(BuiltinType::UnknownAny)) {
2770 SrcExpr =
Self.checkUnknownAnyCast(DestRange, DestType,
2771 SrcExpr.get(), Kind,
2772 ValueKind, BasePath);
2776 checkNonOverloadPlaceholders();
2777 if (SrcExpr.isInvalid())
2787 if (claimPlaceholder(BuiltinType::Overload)) {
2788 Self.ResolveAndFixSingleFunctionTemplateSpecialization(
2790 true, DestRange, DestType,
2791 diag::err_bad_cstyle_cast_overload);
2792 if (SrcExpr.isInvalid())
2796 SrcExpr =
Self.IgnoredValueConversions(SrcExpr.get());
2801 if (DestType->
isDependentType() || SrcExpr.get()->isTypeDependent() ||
2802 SrcExpr.get()->isValueDependent()) {
2803 assert(Kind == CK_Dependent);
2810 if (
Self.getLangOpts().HLSL) {
2811 if (CheckHLSLCStyleCast(CCK))
2816 !isPlaceholder(BuiltinType::Overload)) {
2817 SrcExpr =
Self.DefaultFunctionArrayLvalueConversion(SrcExpr.get());
2818 if (SrcExpr.isInvalid())
2824 if (
Self.CheckAltivecInitFromScalar(OpRange, DestType,
2825 SrcExpr.get()->getType())) {
2829 if (
Self.ShouldSplatAltivecScalarInCast(vecTy) &&
2830 (SrcExpr.get()->getType()->isIntegerType() ||
2831 SrcExpr.get()->getType()->isFloatingType())) {
2832 Kind = CK_VectorSplat;
2833 SrcExpr =
Self.prepareVectorSplat(DestType, SrcExpr.get());
2839 QualType SrcType = SrcExpr.get()->getType();
2841 Self.Diag(OpRange.getBegin(), diag::err_wasm_cast_table)
2842 << 1 << SrcExpr.get()->getSourceRange();
2859 unsigned msg = diag::err_bad_cxx_cast_generic;
2862 if (SrcExpr.isInvalid())
2870 if (SrcExpr.isInvalid())
2877 BasePath, ListInitialization);
2878 if (SrcExpr.isInvalid())
2884 OpRange, msg, Kind);
2885 if (SrcExpr.isInvalid())
2891 if (
Self.getLangOpts().allowsNonTrivialObjCLifetimeQualifiers() &&
2893 checkObjCConversion(CCK);
2896 if (SrcExpr.get()->getType() ==
Self.Context.OverloadTy) {
2907 Self.Diag(OpRange.getBegin(), diag::err_bad_cstyle_cast_overload)
2908 << OE->
getName() << DestType << OpRange
2910 Self.NoteAllOverloadCandidates(SrcExpr.get());
2914 OpRange, SrcExpr.get(), DestType, ListInitialization);
2919 if (Kind == CK_BitCast)
2923 Self.Diag(OpRange.getBegin(), DiagID)
2924 << SrcExpr.get()->getType() << DestType << OpRange;
2935 assert(
Self.getLangOpts().HLSL &&
"Must be HLSL!");
2936 QualType SrcTy = SrcExpr.get()->getType();
2940 if (
Self.HLSL().CanPerformElementwiseCast(SrcExpr.get(), DestType)) {
2942 SrcExpr =
Self.ImpCastExprToType(
2943 SrcExpr.get(),
Self.Context.getArrayParameterType(SrcTy),
2944 CK_HLSLArrayRValue,
VK_PRValue,
nullptr, CCK);
2946 SrcExpr =
Self.DefaultLvalueConversion(SrcExpr.get());
2947 Kind = CK_HLSLElementwiseCast;
2954 if (
Self.HLSL().CanPerformAggregateSplatCast(SrcExpr.get(), DestType)) {
2955 SrcExpr =
Self.DefaultLvalueConversion(SrcExpr.get());
2960 SrcExpr =
Self.ImpCastExprToType(
2962 SrcExpr.get()->getValueKind(),
nullptr, CCK);
2964 else if (MT && MT->getNumElementsFlattened() == 1)
2965 SrcExpr =
Self.ImpCastExprToType(
2966 SrcExpr.get(), MT->getElementType(), CK_HLSLMatrixTruncation,
2967 SrcExpr.get()->getValueKind(),
nullptr, CCK);
2971 SrcExpr =
Self.ImpCastExprToType(
2972 SrcExpr.get(), DVT->getElementType(),
2973 Self.PrepareScalarCast(SrcExpr, DVT->getElementType()),
2974 SrcExpr.get()->getValueKind(),
nullptr, CCK);
2975 Kind = CK_HLSLAggregateSplatCast;
2982 Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_generic)
2983 << 4 << SrcTy << DestType;
2995 if (
Self.Diags.isIgnored(diag::warn_bad_function_cast,
3024 diag::warn_bad_function_cast)
3029void CastOperation::CheckCStyleCast() {
3030 assert(!
Self.getLangOpts().CPlusPlus);
3033 if (claimPlaceholder(BuiltinType::UnknownAny)) {
3034 SrcExpr =
Self.checkUnknownAnyCast(DestRange, DestType,
3035 SrcExpr.get(), Kind,
3036 ValueKind, BasePath);
3044 SrcExpr =
Self.IgnoredValueConversions(SrcExpr.get());
3045 if (SrcExpr.isInvalid())
3054 if (
Self.getASTContext().isDependenceAllowed() &&
3056 SrcExpr.get()->isValueDependent())) {
3057 assert((DestType->
containsErrors() || SrcExpr.get()->containsErrors() ||
3058 SrcExpr.get()->containsErrors()) &&
3059 "should only occur in error-recovery path.");
3060 assert(Kind == CK_Dependent);
3065 if (SrcExpr.get()->getType() ==
Self.Context.OverloadTy) {
3068 SrcExpr.get(), DestType,
true, DAP))
3069 SrcExpr =
Self.FixOverloadedFunctionReference(SrcExpr.get(), DAP, FD);
3072 assert(SrcExpr.isUsable());
3074 SrcExpr =
Self.DefaultFunctionArrayLvalueConversion(SrcExpr.get());
3075 if (SrcExpr.isInvalid())
3077 QualType SrcType = SrcExpr.get()->getType();
3080 Self.Diag(OpRange.getBegin(), diag::err_wasm_cast_table)
3081 << 1 << SrcExpr.get()->getSourceRange();
3088 checkAddressSpaceCast(SrcType, DestType);
3089 if (SrcExpr.isInvalid())
3092 if (
Self.RequireCompleteType(OpRange.getBegin(), DestType,
3093 diag::err_typecheck_cast_to_incomplete)) {
3100 Self.Context.hasSameUnqualifiedType(DestType, SrcType)) {
3107 Self.isValidSveBitcast(SrcType, DestType)) {
3114 Self.RISCV().isValidRVVBitcast(SrcType, DestType)) {
3121 if (
const RecordType *DestRecordTy =
3123 if (
Self.Context.hasSameUnqualifiedType(DestType, SrcType)) {
3125 Self.Diag(OpRange.getBegin(), diag::ext_typecheck_cast_nonscalar)
3126 << DestType << SrcExpr.get()->getSourceRange();
3135 Self.Diag(OpRange.getBegin(), diag::ext_typecheck_cast_to_union)
3136 << SrcExpr.get()->getSourceRange();
3140 Self.Diag(OpRange.getBegin(), diag::err_typecheck_cast_to_union_no_type)
3141 << SrcType << SrcExpr.get()->getSourceRange();
3148 if (
Self.getLangOpts().OpenCL && DestType->
isEventT()) {
3150 if (SrcExpr.get()->EvaluateAsInt(
Result,
Self.Context)) {
3151 llvm::APSInt CastInt =
Result.Val.getInt();
3153 Kind = CK_ZeroToOCLOpaqueType;
3156 Self.Diag(OpRange.getBegin(),
3157 diag::err_opencl_cast_non_zero_to_event_t)
3158 <<
toString(CastInt, 10) << SrcExpr.get()->getSourceRange();
3165 Self.Diag(OpRange.getBegin(), diag::err_typecheck_cond_expect_scalar)
3166 << DestType << SrcExpr.get()->getSourceRange();
3176 Self.Diag(SrcExpr.get()->getExprLoc(),
3177 diag::err_typecheck_expect_scalar_operand)
3178 << SrcType << SrcExpr.get()->getSourceRange();
3193 Self.Diag(SrcExpr.get()->getExprLoc(), diag::err_nullptr_cast)
3200 Self.Context, DestType, CK_PointerToBoolean, SrcExpr.get(),
nullptr,
3209 Self.CurFPFeatureOverrides());
3214 if (!SrcExpr.get()->isNullPointerConstant(
Self.Context,
3216 Self.Diag(SrcExpr.get()->getExprLoc(), diag::err_nullptr_cast)
3225 Self.CurFPFeatureOverrides());
3229 SrcExpr =
Self.CheckExtVectorCast(OpRange, DestType, SrcExpr.get(), Kind);
3234 if (
Self.CheckMatrixCast(OpRange, DestType, SrcType, Kind))
3240 if (
Self.CheckAltivecInitFromScalar(OpRange, DestType, SrcType)) {
3244 if (
Self.ShouldSplatAltivecScalarInCast(DestVecTy) &&
3246 Kind = CK_VectorSplat;
3247 SrcExpr =
Self.prepareVectorSplat(DestType, SrcExpr.get());
3248 }
else if (
Self.CheckVectorCast(OpRange, DestType, SrcType, Kind)) {
3255 if (
Self.CheckVectorCast(OpRange, SrcType, DestType, Kind))
3266 Self.Diag(SrcExpr.get()->getExprLoc(), diag::err_cast_selector_expr);
3275 Self.Diag(SrcExpr.get()->getExprLoc(),
3276 diag::err_cast_pointer_from_non_pointer_int)
3277 << SrcType << SrcExpr.get()->getSourceRange();
3286 Self.Diag(SrcExpr.get()->getBeginLoc(),
3287 diag::err_cast_pointer_to_non_pointer_int)
3288 << DestType << SrcExpr.get()->getSourceRange();
3293 if ((
Self.Context.getTypeSize(SrcType) >
3294 Self.Context.getTypeSize(DestType)) &&
3304 : diag::warn_void_pointer_to_int_cast;
3306 Diag = diag::warn_pointer_to_enum_cast;
3308 Diag = diag::warn_pointer_to_int_cast;
3309 Self.Diag(OpRange.getBegin(),
Diag) << SrcType << DestType << OpRange;
3313 if (
Self.getLangOpts().OpenCL && !
Self.getOpenCLOptions().isAvailableOption(
3314 "cl_khr_fp16",
Self.getLangOpts())) {
3316 Self.Diag(SrcExpr.get()->getBeginLoc(), diag::err_opencl_cast_to_half)
3317 << DestType << SrcExpr.get()->getSourceRange();
3324 if (
Self.getLangOpts().allowsNonTrivialObjCLifetimeQualifiers()) {
3326 if (SrcExpr.isInvalid())
3330 if (
Self.getLangOpts().ObjCAutoRefCount && CastPtr) {
3333 Qualifiers ExprQuals = ExprPtr->getPointeeType().getQualifiers();
3335 ExprPtr->getPointeeType()->isObjCLifetimeType() &&
3337 Self.Diag(SrcExpr.get()->getBeginLoc(),
3338 diag::err_typecheck_incompatible_ownership)
3340 << SrcExpr.get()->getSourceRange();
3344 }
else if (!
Self.ObjC().CheckObjCARCUnavailableWeakConversion(DestType,
3346 Self.Diag(SrcExpr.get()->getBeginLoc(),
3347 diag::err_arc_convesion_of_weak_unavailable)
3348 << 1 << SrcType << DestType << SrcExpr.get()->getSourceRange();
3355 Self.Diag(OpRange.getBegin(), DiagID) << SrcType << DestType << OpRange;
3364 if (SrcRD && DestRD && SrcRD->
hasAttr<RandomizeLayoutAttr>() &&
3367 Self.Diag(OpRange.getBegin(), diag::err_cast_from_randomized_struct)
3368 << SrcType << DestType;
3377 Kind =
Self.PrepareScalarCast(SrcExpr, DestType);
3378 if (SrcExpr.isInvalid())
3381 if (Kind == CK_BitCast)
3385void CastOperation::CheckBuiltinBitCast() {
3386 QualType SrcType = SrcExpr.get()->getType();
3388 if (
Self.RequireCompleteType(OpRange.getBegin(), DestType,
3389 diag::err_typecheck_cast_to_incomplete) ||
3390 Self.RequireCompleteType(OpRange.getBegin(), SrcType,
3391 diag::err_incomplete_type)) {
3396 if (SrcExpr.get()->isPRValue())
3397 SrcExpr =
Self.CreateMaterializeTemporaryExpr(SrcType, SrcExpr.get(),
3400 CharUnits DestSize =
Self.Context.getTypeSizeInChars(DestType);
3401 CharUnits SourceSize =
Self.Context.getTypeSizeInChars(SrcType);
3402 if (DestSize != SourceSize) {
3403 Self.Diag(OpRange.getBegin(), diag::err_bit_cast_type_size_mismatch)
3411 Self.Diag(OpRange.getBegin(), diag::err_bit_cast_non_trivially_copyable)
3418 Self.Diag(OpRange.getBegin(), diag::err_bit_cast_non_trivially_copyable)
3424 Kind = CK_LValueToRValueBitCast;
3439 QualType TheOffendingSrcType, TheOffendingDestType;
3442 &TheOffendingSrcType, &TheOffendingDestType,
3443 &CastAwayQualifiers) !=
3444 CastAwayConstnessKind::CACK_Similar)
3448 int qualifiers = -1;
3451 }
else if (CastAwayQualifiers.
hasConst()) {
3457 if (qualifiers == -1)
3459 << SrcType << DestType;
3462 << TheOffendingSrcType << TheOffendingDestType << qualifiers;
3474 Op.CheckCXXCStyleCast(
false,
3477 Op.CheckCStyleCast();
3486 Op.checkQualifiedDestType();
3489 Context, Op.ResultType, Op.ValueKind, Op.Kind, Op.SrcExpr.
get(),
3498 assert(LPLoc.
isValid() &&
"List-initialization shouldn't get here.");
3502 CastOperation::OpRangeType(Op.DestRange.
getBegin(), LPLoc, RPLoc);
3504 Op.CheckCXXCStyleCast(
true,
false);
3508 Op.checkQualifiedDestType();
3514 Context, Op.ResultType, Op.ValueKind, CastTypeInfo, Op.Kind,
Defines the clang::ASTContext interface.
Defines the clang::Expr interface and subclasses for C++ expressions.
Result
Implement __builtin_bit_cast and related operations.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream.
Defines the clang::Preprocessor interface.
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
This file declares semantic analysis functions specific to AMDGPU.
static TryCastResult TryStaticDowncast(Sema &Self, CanQualType SrcType, CanQualType DestType, bool CStyle, CastOperation::OpRangeType OpRange, QualType OrigSrcType, QualType OrigDestType, unsigned &msg, CastKind &Kind, CXXCastPath &BasePath)
TryStaticDowncast - Common functionality of TryStaticReferenceDowncast and TryStaticPointerDowncast.
static CastAwayConstnessKind CastsAwayConstness(Sema &Self, QualType SrcType, QualType DestType, bool CheckCVR, bool CheckObjCLifetime, QualType *TheOffendingSrcType=nullptr, QualType *TheOffendingDestType=nullptr, Qualifiers *CastAwayQualifiers=nullptr)
Check if the pointer conversion from SrcType to DestType casts away constness as defined in C++ [expr...
static TryCastResult TryStaticPointerDowncast(Sema &Self, QualType SrcType, QualType DestType, bool CStyle, CastOperation::OpRangeType OpRange, unsigned &msg, CastKind &Kind, CXXCastPath &BasePath)
Tests whether a conversion according to C++ 5.2.9p8 is valid.
static TryCastResult getCastAwayConstnessCastKind(CastAwayConstnessKind CACK, unsigned &DiagID)
static bool IsAddressSpaceConversion(QualType SrcType, QualType DestType)
@ CT_Reinterpret
reinterpret_cast
@ CT_Functional
Type(expr)
@ CT_Addrspace
addrspace_cast
static TryCastResult TryConstCast(Sema &Self, ExprResult &SrcExpr, QualType DestType, bool CStyle, unsigned &msg)
TryConstCast - See if a const_cast from source to destination is allowed, and perform it if it is.
static TryCastResult TryReinterpretCast(Sema &Self, ExprResult &SrcExpr, QualType DestType, bool CStyle, CastOperation::OpRangeType OpRange, unsigned &msg, CastKind &Kind)
static bool isValidCast(TryCastResult TCR)
static TryCastResult TryStaticReferenceDowncast(Sema &Self, Expr *SrcExpr, QualType DestType, bool CStyle, CastOperation::OpRangeType OpRange, unsigned &msg, CastKind &Kind, CXXCastPath &BasePath)
Tests whether a conversion according to C++ 5.2.9p5 is valid.
static bool argTypeIsABIEquivalent(QualType SrcType, QualType DestType, ASTContext &Context)
static unsigned int checkCastFunctionType(Sema &Self, const ExprResult &SrcExpr, QualType DestType)
static TryCastResult TryLValueToRValueCast(Sema &Self, Expr *SrcExpr, QualType DestType, bool CStyle, SourceRange OpRange, CastKind &Kind, CXXCastPath &BasePath, unsigned &msg)
Tests whether a conversion according to N2844 is valid.
@ TC_Success
The cast method is appropriate and successful.
@ TC_Extension
The cast method is appropriate and accepted as a language extension.
@ TC_Failed
The cast method is appropriate, but failed.
@ TC_NotApplicable
The cast method is not applicable.
static void DiagnoseReinterpretUpDownCast(Sema &Self, const Expr *SrcExpr, QualType DestType, CastOperation::OpRangeType OpRange)
Check that a reinterpret_cast<DestType>(SrcExpr) is not used as upcast or downcast between respective...
static void DiagnoseCastQual(Sema &Self, const ExprResult &SrcExpr, QualType DestType)
DiagnoseCastQual - Warn whenever casts discards a qualifiers, be it either const, volatile or both.
static TryCastResult TryStaticMemberPointerUpcast(Sema &Self, ExprResult &SrcExpr, QualType SrcType, QualType DestType, bool CStyle, CastOperation::OpRangeType OpRange, unsigned &msg, CastKind &Kind, CXXCastPath &BasePath)
TryStaticMemberPointerUpcast - Tests whether a conversion according to C++ 5.2.9p9 is valid:
static void DiagnoseCallingConvCast(Sema &Self, const ExprResult &SrcExpr, QualType DstType, CastOperation::OpRangeType OpRange)
Diagnose casts that change the calling convention of a pointer to a function defined in the current T...
static TryCastResult TryStaticCast(Sema &Self, ExprResult &SrcExpr, QualType DestType, CheckedConversionKind CCK, CastOperation::OpRangeType OpRange, unsigned &msg, CastKind &Kind, CXXCastPath &BasePath, bool ListInitialization)
TryStaticCast - Check if a static cast can be performed, and do so if possible.
static void DiagnoseCastOfObjCSEL(Sema &Self, const ExprResult &SrcExpr, QualType DestType)
static void DiagnoseBadFunctionCast(Sema &Self, const ExprResult &SrcExpr, QualType DestType)
DiagnoseBadFunctionCast - Warn whenever a function call is cast to a non-matching type.
static TryCastResult TryStaticImplicitCast(Sema &Self, ExprResult &SrcExpr, QualType DestType, CheckedConversionKind CCK, CastOperation::OpRangeType OpRange, unsigned &msg, CastKind &Kind, bool ListInitialization)
TryStaticImplicitCast - Tests whether a conversion according to C++ 5.2.9p2 is valid:
static bool fixOverloadedReinterpretCastExpr(Sema &Self, QualType DestType, ExprResult &Result)
static bool tryDiagnoseOverloadedCast(Sema &S, CastType CT, CastOperation::OpRangeType range, Expr *src, QualType destType, bool listInitialization)
Try to diagnose a failed overloaded cast.
static void diagnoseBadCast(Sema &S, unsigned msg, CastType castType, CastOperation::OpRangeType opRange, Expr *src, QualType destType, bool listInitialization)
Diagnose a failed cast.
static CastAwayConstnessKind unwrapCastAwayConstnessLevel(ASTContext &Context, QualType &T1, QualType &T2)
Unwrap one level of types for CastsAwayConstness.
static void checkIntToPointerCast(bool CStyle, const SourceRange &OpRange, const Expr *SrcExpr, QualType DestType, Sema &Self)
static TryCastResult TryAddressSpaceCast(Sema &Self, ExprResult &SrcExpr, QualType DestType, bool CStyle, unsigned &msg, CastKind &Kind)
This file declares semantic analysis for HLSL constructs.
This file declares semantic analysis for Objective-C.
This file declares semantic analysis functions specific to RISC-V.
static QualType getPointeeType(const MemRegion *R)
TextDiagnosticBuffer::DiagList DiagList
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const LangOptions & getLangOpts() const
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
Represents a C++2a __builtin_bit_cast(T, v) expression.
static CStyleCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *BasePath, FPOptionsOverride FPO, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation R)
static CXXAddrspaceCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind Kind, Expr *Op, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Represents a path from a specific derived class (which is not represented as part of the path) to a p...
BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...
const RecordType * getDetectedVirtual() const
The virtual base discovered on the path (if we are merely detecting virtuals).
bool isRecordingPaths() const
Whether we are recording paths.
void setRecordingPaths(bool RP)
Specify whether we should be recording paths or not.
void clear()
Clear the base-paths results.
std::list< CXXBasePath >::const_iterator const_paths_iterator
bool isAmbiguous(CanQualType BaseType) const
Determine whether the path from the most-derived type to the given base type is ambiguous (i....
static CXXConstCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, Expr *Op, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
static CXXDynamicCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind Kind, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *Written, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
static CXXFunctionalCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, TypeSourceInfo *Written, CastKind Kind, Expr *Op, const CXXCastPath *Path, FPOptionsOverride FPO, SourceLocation LPLoc, SourceLocation RPLoc)
Represents a static or instance method of a struct/union/class.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
Represents a C++ struct/union/class.
CXXRecordDecl * getDefinition() const
bool isDerivedFrom(const CXXRecordDecl *Base) const
Determine whether this class is derived from the class Base.
static CXXReinterpretCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind Kind, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
static CXXStaticCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *Written, FPOptionsOverride FPO, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
bool isAtLeastAsQualifiedAs(CanQual< T > Other, const ASTContext &Ctx) const
Determines whether this canonical type is at least as qualified as the Other canonical type.
CanQual< T > getUnqualifiedType() const
Retrieve the unqualified form of this type.
CanProxy< U > getAs() const
Retrieve a canonical type pointer with a different static type, upcasting or downcasting as needed.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
static const FieldDecl * getTargetFieldForToUnionCast(QualType unionType, QualType opType)
CharUnits - This is an opaque type for sizes expressed in character units.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
Represents a concrete matrix type with constant number of rows and columns.
A POD class for pairing a NamedDecl* with an access specifier.
bool isInvalidDecl() const
Information about one declarator, including the parsed type information and the identifier.
bool isInvalidType() const
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
This represents one expression.
bool isIntegerConstantExpr(const ASTContext &Ctx) const
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
@ NPC_NeverValueDependent
Specifies that the expression should never be value-dependent.
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
bool refersToBitField() const
Returns true if this expression is a gl-value that potentially refers to a bit-field.
static ExprValueKind getValueKindForType(QualType T)
getValueKindForType - Given a formal return or parameter type, give its value kind.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
Represents a function declaration or definition.
Represents a prototype with parameter type info, e.g.
FunctionType - C99 6.7.5.3 - Function Declarators.
static StringRef getNameForCallConv(CallingConv CC)
CallingConv getCallConv() const
QualType getReturnType() const
One of these records is kept for each identifier that is lexed.
tok::TokenKind getTokenID() const
If this is a source-language token (e.g.
bool isKeyword(const LangOptions &LangOpts) const
Return true if this token is a keyword in the specified language.
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Describes the kind of initialization being performed, along with location information for tokens rela...
static InitializationKind CreateCast(SourceRange TypeRange)
Create a direct initialization due to a cast that isn't a C-style or functional cast.
static InitializationKind CreateFunctionalCast(SourceLocation StartLoc, SourceRange ParenRange, bool InitList)
Create a direct initialization for a functional cast.
static InitializationKind CreateCStyleCast(SourceLocation StartLoc, SourceRange TypeRange, bool InitList)
Create a direct initialization for a C-style cast.
Describes the sequence of initializations required to initialize a given object or reference with a s...
ExprResult Perform(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, MultiExprArg Args, QualType *ResultType=nullptr)
Perform the actual initialization of the given entity based on the computed initialization sequence.
FailureKind getFailureKind() const
Determine why initialization failed.
OverloadingResult getFailedOverloadResult() const
Get the overloading result, for when the initialization sequence failed due to a bad overload.
bool Failed() const
Determine whether the initialization sequence is invalid.
@ FK_UserConversionOverloadFailed
Overloading for a user-defined conversion failed.
@ FK_ConstructorOverloadFailed
Overloading for initialization by constructor failed.
@ FK_ParenthesizedListInitFailed
Parenthesized list initialization failed at some point.
bool isConstructorInitialization() const
Determine whether this initialization is direct call to a constructor.
OverloadCandidateSet & getFailedCandidateSet()
Retrieve a reference to the candidate set when overload resolution fails.
Describes an entity that is being initialized.
static InitializedEntity InitializeTemporary(QualType Type)
Create the initialization entity for a temporary.
Represents a matrix type, as defined in the Matrix Types clang extensions.
A pointer to member type per C++ 8.3.3 - Pointers to members.
bool isMemberFunctionPointer() const
Returns true if the member type (i.e.
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covering the entirety of this nested-name-specifier.
OverloadCandidateSet - A set of overload candidates, used in C++ overload resolution (C++ 13....
SmallVectorImpl< OverloadCandidate >::iterator iterator
void NoteCandidates(PartialDiagnosticAt PA, Sema &S, OverloadCandidateDisplayKind OCD, ArrayRef< Expr * > Args, StringRef Opc="", SourceLocation Loc=SourceLocation(), llvm::function_ref< bool(OverloadCandidate &)> Filter=[](OverloadCandidate &) { return true;})
When overload resolution fails, prints diagnostic messages containing the candidates in the candidate...
OverloadingResult BestViableFunction(Sema &S, SourceLocation Loc, OverloadCandidateSet::iterator &Best)
Find the best viable function on this overload set, if it exists.
A reference to an overloaded function set, either an UnresolvedLookupExpr or an UnresolvedMemberExpr.
static FindResult find(Expr *E)
Finds the overloaded expression in the given expression E of OverloadTy.
NestedNameSpecifierLoc getQualifierLoc() const
Fetches the nested-name qualifier with source-location information, if one was given.
DeclarationName getName() const
Gets the name looked up.
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
StringRef getLastMacroWithSpelling(SourceLocation Loc, ArrayRef< TokenValue > Tokens) const
Return the name of the macro defined before Loc that has spelling Tokens.
A (possibly-)qualified type.
bool isTriviallyCopyableType(const ASTContext &Context) const
Return true if this is a trivially copyable type (C++0x [basic.types]p9)
QualType getNonLValueExprType(const ASTContext &Context) const
Determine the type of a (typically non-lvalue) expression with the specified result type.
bool isAddressSpaceOverlapping(QualType T, const ASTContext &Ctx) const
Returns true if address space qualifiers overlap with T address space qualifiers.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
LangAS getAddressSpace() const
Return the address space of this type.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
QualType getCanonicalType() const
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
QualType withCVRQualifiers(unsigned CVR) const
unsigned getCVRQualifiers() const
Retrieve the set of CVR (const-volatile-restrict) qualifiers applied to this type.
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
bool isAtLeastAsQualifiedAs(QualType Other, const ASTContext &Ctx) const
Determine whether this type is at least as qualified as the other given type, requiring exact equalit...
The collection of all-type qualifiers we support.
unsigned getCVRQualifiers() const
void removeObjCLifetime()
bool compatiblyIncludes(Qualifiers other, const ASTContext &Ctx) const
Determines if these qualifiers compatibly include another set.
static bool isAddressSpaceSupersetOf(LangAS A, LangAS B, const ASTContext &Ctx)
Returns true if address space A is equal to or a superset of B.
static Qualifiers fromCVRMask(unsigned CVR)
bool compatiblyIncludesObjCLifetime(Qualifiers other) const
Determines if these qualifiers compatibly include another set of qualifiers from the narrow perspecti...
An rvalue reference type, per C++11 [dcl.ref].
Represents a struct/union/class.
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Base for LValueReferenceType and RValueReferenceType.
QualType getPointeeType() const
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Sema - This implements semantic analysis and AST building for C.
ReferenceCompareResult
ReferenceCompareResult - Expresses the result of comparing two types (cv1 T1 and cv2 T2) to determine...
@ Ref_Incompatible
Ref_Incompatible - The two types are incompatible, so direct reference binding is not possible.
@ Ref_Compatible
Ref_Compatible - The two types are reference-compatible.
ExprResult BuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, QualType Type, SourceLocation LParenLoc, Expr *CastExpr, SourceLocation RParenLoc)
ExprResult BuildBuiltinBitCastExpr(SourceLocation KWLoc, TypeSourceInfo *TSI, Expr *Operand, SourceLocation RParenLoc)
FPOptionsOverride CurFPFeatureOverrides()
bool ShouldSplatAltivecScalarInCast(const VectorType *VecTy)
ExprResult ActOnBuiltinBitCastExpr(SourceLocation KWLoc, Declarator &Dcl, ExprResult Operand, SourceLocation RParenLoc)
const LangOptions & getLangOpts() const
void CheckExtraCXXDefaultArguments(Declarator &D)
CheckExtraCXXDefaultArguments - Check for any extra default arguments in the declarator,...
ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc, TypeSourceInfo *Ty, SourceLocation RParenLoc, Expr *Op)
ReferenceConversionsScope::ReferenceConversions ReferenceConversions
ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, SourceLocation LAngleBracketLoc, Declarator &D, SourceLocation RAngleBracketLoc, SourceLocation LParenLoc, Expr *E, SourceLocation RParenLoc)
ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const,addrspace}_cast's.
ExprResult CheckPlaceholderExpr(Expr *E)
Check for operands with placeholder types and complain if found.
void DiscardMisalignedMemberAddress(const Type *T, Expr *E)
This function checks if the expression is in the sef of potentially misaligned members and it is conv...
void CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType, bool IsDereference, SourceRange Range)
TypeSourceInfo * GetTypeForDeclaratorCast(Declarator &D, QualType FromTy)
DiagnosticsEngine & Diags
ExprResult BuildCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, TypeSourceInfo *Ty, Expr *E, SourceRange AngleBrackets, SourceRange Parens)
bool CheckAltivecInitFromScalar(SourceRange R, QualType VecTy, QualType SrcTy)
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
A trivial tuple used to represent a source range.
SourceLocation getBegin() const
SourceLocation getEndLoc() const LLVM_READONLY
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
SourceLocation getBeginLoc() const LLVM_READONLY
StringLiteral - This represents a string literal expression, e.g.
StringRef getString() const
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Stores token information for comparing actual tokens with predefined values.
Base wrapper for a particular "section" of type source info.
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
SourceLocation getEndLoc() const
Get the end source location.
SourceLocation getBeginLoc() const
Get the begin source location.
A container of type source information.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
QualType getType() const
Return the type wrapped by this type source info.
The base class of the type hierarchy.
bool isIncompleteOrObjectType() const
Return true if this is an incomplete or object type, in other words, not a function type.
bool isBlockPointerType() const
bool isBooleanType() const
bool isFunctionReferenceType() const
bool isPlaceholderType() const
Test for a type which does not represent an actual type-system type but is instead used as a placehol...
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char,...
bool isComplexType() const
isComplexType() does not include complex integers (a GCC extension).
bool isRValueReferenceType() const
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isConstantArrayType() const
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
bool isVoidPointerType() const
bool isFunctionPointerType() const
bool isArithmeticType() const
bool isPointerType() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
bool isEnumeralType() const
bool isScalarType() const
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that the type refers to.
bool isSizelessBuiltinType() const
bool isIntegralType(const ASTContext &Ctx) const
Determine whether this type is an integral type.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
bool isExtVectorType() const
bool isAnyCharacterType() const
Determine whether this type is any of the built-in character types.
bool isLValueReferenceType() const
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
bool isFixedPointType() const
Return true if this is a fixed point type according to ISO/IEC JTC1 SC22 WG14 N1169.
const BuiltinType * getAsPlaceholderType() const
bool isWebAssemblyTableType() const
Returns true if this is a WebAssembly table type: either an array of reference types,...
bool containsErrors() const
Whether this type is an error type.
bool isMemberPointerType() const
bool isMatrixType() const
EnumDecl * castAsEnumDecl() const
bool isComplexIntegerType() const
bool isObjCObjectType() const
bool isObjCLifetimeType() const
Returns true if objects of this type have lifetime semantics under ARC.
bool isFunctionType() const
bool isObjCObjectPointerType() const
bool isMemberFunctionPointerType() const
bool isVectorType() const
bool isRealFloatingType() const
Floating point categories.
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
bool isFloatingType() const
bool isUnsignedIntegerType() const
Return true if this is an integer type that is unsigned, according to C99 6.2.5p6 [which returns true...
bool isAnyPointerType() const
const T * getAs() const
Member-template getAs<specific type>'.
bool isNullPtrType() const
bool isRecordType() const
bool isFunctionNoProtoType() const
Represents a GCC generic vector type.
unsigned getNumElements() const
VectorKind getVectorKind() const
QualType getElementType() const
Defines the clang::TargetInfo interface.
const internal::VariadicDynCastAllOfMatcher< Stmt, CastExpr > castExpr
Matches any cast nodes of Clang's AST.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
The JSON file list parser is used to communicate input to InstallAPI.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
bool isa(CodeGen::Address addr)
OverloadingResult
OverloadingResult - Capture the result of performing overload resolution.
@ OR_Deleted
Succeeded, but refers to a deleted function.
@ OR_Success
Overload resolution succeeded.
@ OR_Ambiguous
Ambiguous candidates found.
@ OR_No_Viable_Function
No viable function found.
OverloadCandidateDisplayKind
@ OCD_AmbiguousCandidates
Requests that only tied-for-best candidates be shown.
@ OCD_ViableCandidates
Requests that only viable candidates be shown.
@ OCD_AllCandidates
Requests that all candidates be shown.
@ OK_VectorComponent
A vector component is an element or range of elements of a vector.
@ OK_ObjCProperty
An Objective-C property is a logical field of an Objective-C object which is read and written via Obj...
@ OK_ObjCSubscript
An Objective-C array/dictionary subscripting which reads an object or writes at the subscripted array...
@ OK_Ordinary
An ordinary object is located at an address in memory.
@ OK_BitField
A bitfield object is a bitfield on a C or C++ record.
@ OK_MatrixComponent
A matrix component is a single element or range of elements of a matrix.
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
@ Result
The result type of a method or function.
CastKind
CastKind - The kind of operation required for a conversion.
std::pair< SourceLocation, PartialDiagnostic > PartialDiagnosticAt
A partial diagnostic along with the source location where this diagnostic occurs.
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
SmallVector< CXXBaseSpecifier *, 4 > CXXCastPath
A simple array of base specifiers.
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ConceptReference *C)
Insertion operator for diagnostics.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
@ AltiVecBool
is AltiVec 'vector bool ...'
@ AltiVecVector
is AltiVec vector
@ AltiVecPixel
is AltiVec 'vector Pixel'
U cast(CodeGen::Address addr)
@ None
The alignment was not explicit in code.
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
ActionResult< Expr * > ExprResult
@ Parens
New-expression has a C++98 paren-delimited initializer.
CheckedConversionKind
The kind of conversion being performed.
@ CStyleCast
A C-style cast.
@ OtherCast
A cast other than a C-style cast.
@ FunctionalCast
A functional-style cast.
Represents an element in a path from a derived class to a base class.
EvalResult is a struct with detailed info about an evaluated expression.
OverloadExpr * Expression