diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2022-03-20 11:40:34 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2022-05-14 11:43:05 +0000 |
commit | 349cc55c9796c4596a5b9904cd3281af295f878f (patch) | |
tree | 410c5a785075730a35f1272ca6a7adf72222ad03 /contrib/llvm-project/clang/lib/Sema/SemaCast.cpp | |
parent | cb2ae6163174b90e999326ecec3699ee093a5d43 (diff) | |
parent | c0981da47d5696fe36474fcf86b4ce03ae3ff818 (diff) |
Merge llvm-project main llvmorg-14-init-10186-gff7f2cfa959b
This updates llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and
openmp to llvmorg-14-init-10186-gff7f2cfa959b.
PR: 261742
MFC after: 2 weeks
Diffstat (limited to 'contrib/llvm-project/clang/lib/Sema/SemaCast.cpp')
-rw-r--r-- | contrib/llvm-project/clang/lib/Sema/SemaCast.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/contrib/llvm-project/clang/lib/Sema/SemaCast.cpp b/contrib/llvm-project/clang/lib/Sema/SemaCast.cpp index cac43075f860..7ef1732496c2 100644 --- a/contrib/llvm-project/clang/lib/Sema/SemaCast.cpp +++ b/contrib/llvm-project/clang/lib/Sema/SemaCast.cpp @@ -1313,7 +1313,9 @@ static TryCastResult TryStaticCast(Sema &Self, ExprResult &SrcExpr, // lvalue-to-rvalue, array-to-pointer, function-to-pointer, and boolean // conversions, subject to further restrictions. // Also, C++ 5.2.9p1 forbids casting away constness, which makes reversal - // of qualification conversions impossible. + // of qualification conversions impossible. (In C++20, adding an array bound + // would be the reverse of a qualification conversion, but adding permission + // to add an array bound in a static_cast is a wording oversight.) // In the CStyle case, the earlier attempt to const_cast should have taken // care of reverse qualification conversions. @@ -2637,6 +2639,19 @@ bool Sema::ShouldSplatAltivecScalarInCast(const VectorType *VecTy) { return false; } +bool Sema::CheckAltivecInitFromScalar(SourceRange R, QualType VecTy, + QualType SrcTy) { + bool SrcCompatGCC = this->getLangOpts().getAltivecSrcCompat() == + LangOptions::AltivecSrcCompatKind::GCC; + if (this->getLangOpts().AltiVec && SrcCompatGCC) { + this->Diag(R.getBegin(), + diag::err_invalid_conversion_between_vector_and_integer) + << VecTy << SrcTy << R; + return true; + } + return false; +} + void CastOperation::CheckCXXCStyleCast(bool FunctionalStyle, bool ListInitialization) { assert(Self.getLangOpts().CPlusPlus); @@ -2690,7 +2705,12 @@ void CastOperation::CheckCXXCStyleCast(bool FunctionalStyle, } // AltiVec vector initialization with a single literal. - if (const VectorType *vecTy = DestType->getAs<VectorType>()) + if (const VectorType *vecTy = DestType->getAs<VectorType>()) { + if (Self.CheckAltivecInitFromScalar(OpRange, DestType, + SrcExpr.get()->getType())) { + SrcExpr = ExprError(); + return; + } if (Self.ShouldSplatAltivecScalarInCast(vecTy) && (SrcExpr.get()->getType()->isIntegerType() || SrcExpr.get()->getType()->isFloatingType())) { @@ -2698,6 +2718,7 @@ void CastOperation::CheckCXXCStyleCast(bool FunctionalStyle, SrcExpr = Self.prepareVectorSplat(DestType, SrcExpr.get()); return; } + } // C++ [expr.cast]p5: The conversions performed by // - a const_cast, @@ -2976,6 +2997,10 @@ void CastOperation::CheckCStyleCast() { } if (const VectorType *DestVecTy = DestType->getAs<VectorType>()) { + if (Self.CheckAltivecInitFromScalar(OpRange, DestType, SrcType)) { + SrcExpr = ExprError(); + return; + } if (Self.ShouldSplatAltivecScalarInCast(DestVecTy) && (SrcType->isIntegerType() || SrcType->isFloatingType())) { Kind = CK_VectorSplat; |