Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
clang/lib/Sema/SemaCast.cpp
Show First 20 Lines • Show All 2,348 Lines • ▼ Show 20 Lines | static TryCastResult TryReinterpretCast(Sema &Self, ExprResult &SrcExpr, | ||||
bool srcIsVector = SrcType->isVectorType(); | bool srcIsVector = SrcType->isVectorType(); | ||||
if (srcIsVector || destIsVector) { | if (srcIsVector || destIsVector) { | ||||
// Allow bitcasting between SVE VLATs and VLSTs, and vice-versa. | // Allow bitcasting between SVE VLATs and VLSTs, and vice-versa. | ||||
if (Self.isValidSveBitcast(SrcType, DestType)) { | if (Self.isValidSveBitcast(SrcType, DestType)) { | ||||
Kind = CK_BitCast; | Kind = CK_BitCast; | ||||
return TC_Success; | return TC_Success; | ||||
} | } | ||||
// Allow bitcasting between SVE VLATs and VLSTs, and vice-versa. | |||||
if (Self.isValidRVVBitcast(SrcType, DestType)) { | |||||
Kind = CK_BitCast; | |||||
return TC_Success; | |||||
} | |||||
// The non-vector type, if any, must have integral type. This is | // The non-vector type, if any, must have integral type. This is | ||||
// the same rule that C vector casts use; note, however, that enum | // the same rule that C vector casts use; note, however, that enum | ||||
// types are not integral in C++. | // types are not integral in C++. | ||||
if ((!destIsVector && !DestType->isIntegralType(Self.Context)) || | if ((!destIsVector && !DestType->isIntegralType(Self.Context)) || | ||||
(!srcIsVector && !SrcType->isIntegralType(Self.Context))) | (!srcIsVector && !SrcType->isIntegralType(Self.Context))) | ||||
return TC_NotApplicable; | return TC_NotApplicable; | ||||
// The size we want to consider is eltCount * eltSize. | // The size we want to consider is eltCount * eltSize. | ||||
▲ Show 20 Lines • Show All 571 Lines • ▼ Show 20 Lines | void CastOperation::CheckCStyleCast() { | ||||
// Allow bitcasting between compatible SVE vector types. | // Allow bitcasting between compatible SVE vector types. | ||||
if ((SrcType->isVectorType() || DestType->isVectorType()) && | if ((SrcType->isVectorType() || DestType->isVectorType()) && | ||||
Self.isValidSveBitcast(SrcType, DestType)) { | Self.isValidSveBitcast(SrcType, DestType)) { | ||||
Kind = CK_BitCast; | Kind = CK_BitCast; | ||||
return; | return; | ||||
} | } | ||||
// Allow bitcasting between compatible RVV vector types. | |||||
if ((SrcType->isVectorType() || DestType->isVectorType()) && | |||||
Self.isValidRVVBitcast(SrcType, DestType)) { | |||||
Kind = CK_BitCast; | |||||
return; | |||||
} | |||||
if (!DestType->isScalarType() && !DestType->isVectorType() && | if (!DestType->isScalarType() && !DestType->isVectorType() && | ||||
!DestType->isMatrixType()) { | !DestType->isMatrixType()) { | ||||
const RecordType *DestRecordTy = DestType->getAs<RecordType>(); | const RecordType *DestRecordTy = DestType->getAs<RecordType>(); | ||||
if (DestRecordTy && Self.Context.hasSameUnqualifiedType(DestType, SrcType)){ | if (DestRecordTy && Self.Context.hasSameUnqualifiedType(DestType, SrcType)){ | ||||
// GCC struct/union extension: allow cast to self. | // GCC struct/union extension: allow cast to self. | ||||
Self.Diag(OpRange.getBegin(), diag::ext_typecheck_cast_nonscalar) | Self.Diag(OpRange.getBegin(), diag::ext_typecheck_cast_nonscalar) | ||||
<< DestType << SrcExpr.get()->getSourceRange(); | << DestType << SrcExpr.get()->getSourceRange(); | ||||
▲ Show 20 Lines • Show All 387 Lines • Show Last 20 Lines |