diff options
Diffstat (limited to 'contrib/llvm-project/clang/lib/Sema/SemaCast.cpp')
-rw-r--r-- | contrib/llvm-project/clang/lib/Sema/SemaCast.cpp | 81 |
1 files changed, 61 insertions, 20 deletions
diff --git a/contrib/llvm-project/clang/lib/Sema/SemaCast.cpp b/contrib/llvm-project/clang/lib/Sema/SemaCast.cpp index 2efe26052c78..671820afd485 100644 --- a/contrib/llvm-project/clang/lib/Sema/SemaCast.cpp +++ b/contrib/llvm-project/clang/lib/Sema/SemaCast.cpp @@ -105,10 +105,10 @@ namespace { // If this is an unbridged cast, wrap the result in an implicit // cast that yields the unbridged-cast placeholder type. if (IsARCUnbridgedCast) { - castExpr = ImplicitCastExpr::Create(Self.Context, - Self.Context.ARCUnbridgedCastTy, - CK_Dependent, castExpr, nullptr, - castExpr->getValueKind()); + castExpr = ImplicitCastExpr::Create( + Self.Context, Self.Context.ARCUnbridgedCastTy, CK_Dependent, + castExpr, nullptr, castExpr->getValueKind(), + Self.CurFPFeatureOverrides()); } updatePartOfExplicitCastFlags(castExpr); return castExpr; @@ -361,11 +361,10 @@ Sema::BuildCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, DiscardMisalignedMemberAddress(DestType.getTypePtr(), E); } - return Op.complete(CXXStaticCastExpr::Create(Context, Op.ResultType, - Op.ValueKind, Op.Kind, Op.SrcExpr.get(), - &Op.BasePath, DestTInfo, - OpLoc, Parens.getEnd(), - AngleBrackets)); + return Op.complete(CXXStaticCastExpr::Create( + Context, Op.ResultType, Op.ValueKind, Op.Kind, Op.SrcExpr.get(), + &Op.BasePath, DestTInfo, CurFPFeatureOverrides(), OpLoc, + Parens.getEnd(), AngleBrackets)); } } } @@ -510,12 +509,10 @@ static void diagnoseBadCast(Sema &S, unsigned msg, CastType castType, if (RecFrom && RecTo) { auto DeclFrom = RecFrom->getAsCXXRecordDecl(); if (!DeclFrom->isCompleteDefinition()) - S.Diag(DeclFrom->getLocation(), diag::note_type_incomplete) - << DeclFrom->getDeclName(); + S.Diag(DeclFrom->getLocation(), diag::note_type_incomplete) << DeclFrom; auto DeclTo = RecTo->getAsCXXRecordDecl(); if (!DeclTo->isCompleteDefinition()) - S.Diag(DeclTo->getLocation(), diag::note_type_incomplete) - << DeclTo->getDeclName(); + S.Diag(DeclTo->getLocation(), diag::note_type_incomplete) << DeclTo; } } } @@ -892,6 +889,18 @@ void CastOperation::CheckDynamicCast() { return; } + // Warns when dynamic_cast is used with RTTI data disabled. + if (!Self.getLangOpts().RTTIData) { + bool MicrosoftABI = + Self.getASTContext().getTargetInfo().getCXXABI().isMicrosoft(); + bool isClangCL = Self.getDiagnostics().getDiagnosticOptions().getFormat() == + DiagnosticOptions::MSVC; + if (MicrosoftABI || !DestPointee->isVoidType()) + Self.Diag(OpRange.getBegin(), + diag::warn_no_dynamic_cast_with_rtti_disabled) + << isClangCL; + } + // Done. Everything else is run-time checks. Kind = CK_Dynamic; } @@ -1245,7 +1254,13 @@ static TryCastResult TryStaticCast(Sema &Self, ExprResult &SrcExpr, return TC_Failed; } if (SrcType->isIntegralOrEnumerationType()) { - Kind = CK_IntegralCast; + // [expr.static.cast]p10 If the enumeration type has a fixed underlying + // type, the value is first converted to that type by integral conversion + const EnumType *Enum = DestType->getAs<EnumType>(); + Kind = Enum->getDecl()->isFixed() && + Enum->getDecl()->getIntegerType()->isBooleanType() + ? CK_IntegralToBoolean + : CK_IntegralCast; return TC_Success; } else if (SrcType->isRealFloatingType()) { Kind = CK_FloatingToIntegral; @@ -2204,6 +2219,12 @@ static TryCastResult TryReinterpretCast(Sema &Self, ExprResult &SrcExpr, bool destIsVector = DestType->isVectorType(); bool srcIsVector = SrcType->isVectorType(); if (srcIsVector || destIsVector) { + // Allow bitcasting between SVE VLATs and VLSTs, and vice-versa. + if (Self.isValidSveBitcast(SrcType, DestType)) { + Kind = CK_BitCast; + return TC_Success; + } + // The non-vector type, if any, must have integral type. This is // the same rule that C vector casts use; note, however, that enum // types are not integral in C++. @@ -2659,6 +2680,8 @@ static void DiagnoseBadFunctionCast(Sema &Self, const ExprResult &SrcExpr, return; if (SrcType->isComplexIntegerType() && DestType->isComplexIntegerType()) return; + if (SrcType->isFixedPointType() && DestType->isFixedPointType()) + return; Self.Diag(SrcExpr.get()->getExprLoc(), diag::warn_bad_function_cast) @@ -2690,6 +2713,17 @@ void CastOperation::CheckCStyleCast() { return; } + // If the type is dependent, we won't do any other semantic analysis now. + if (Self.getASTContext().isDependenceAllowed() && + (DestType->isDependentType() || SrcExpr.get()->isTypeDependent() || + SrcExpr.get()->isValueDependent())) { + assert((DestType->containsErrors() || SrcExpr.get()->containsErrors() || + SrcExpr.get()->containsErrors()) && + "should only occur in error-recovery path."); + assert(Kind == CK_Dependent); + return; + } + // Overloads are allowed with C extensions, so we need to support them. if (SrcExpr.get()->getType() == Self.Context.OverloadTy) { DeclAccessPair DAP; @@ -2724,6 +2758,13 @@ void CastOperation::CheckCStyleCast() { return; } + // Allow bitcasting between compatible SVE vector types. + if ((SrcType->isVectorType() || DestType->isVectorType()) && + Self.isValidSveBitcast(SrcType, DestType)) { + Kind = CK_BitCast; + return; + } + if (!DestType->isScalarType() && !DestType->isVectorType()) { const RecordType *DestRecordTy = DestType->getAs<RecordType>(); @@ -3027,9 +3068,9 @@ ExprResult Sema::BuildCStyleCastExpr(SourceLocation LPLoc, // -Wcast-qual DiagnoseCastQual(Op.Self, Op.SrcExpr, Op.DestType); - return Op.complete(CStyleCastExpr::Create(Context, Op.ResultType, - Op.ValueKind, Op.Kind, Op.SrcExpr.get(), - &Op.BasePath, CastTypeInfo, LPLoc, RPLoc)); + return Op.complete(CStyleCastExpr::Create( + Context, Op.ResultType, Op.ValueKind, Op.Kind, Op.SrcExpr.get(), + &Op.BasePath, CurFPFeatureOverrides(), CastTypeInfo, LPLoc, RPLoc)); } ExprResult Sema::BuildCXXFunctionalCastExpr(TypeSourceInfo *CastTypeInfo, @@ -3052,7 +3093,7 @@ ExprResult Sema::BuildCXXFunctionalCastExpr(TypeSourceInfo *CastTypeInfo, if (auto *ConstructExpr = dyn_cast<CXXConstructExpr>(SubExpr)) ConstructExpr->setParenOrBraceRange(SourceRange(LPLoc, RPLoc)); - return Op.complete(CXXFunctionalCastExpr::Create(Context, Op.ResultType, - Op.ValueKind, CastTypeInfo, Op.Kind, - Op.SrcExpr.get(), &Op.BasePath, LPLoc, RPLoc)); + return Op.complete(CXXFunctionalCastExpr::Create( + Context, Op.ResultType, Op.ValueKind, CastTypeInfo, Op.Kind, + Op.SrcExpr.get(), &Op.BasePath, CurFPFeatureOverrides(), LPLoc, RPLoc)); } |