diff options
author | Anastasia Stulova <anastasia.stulova@arm.com> | 2019-08-02 11:19:35 +0000 |
---|---|---|
committer | Anastasia Stulova <anastasia.stulova@arm.com> | 2019-08-02 11:19:35 +0000 |
commit | 91a14f64f769263deea649999cea32ea5bfa14cd (patch) | |
tree | d56939a4304243bbf7ade00ed65f6751dbd10133 /lib/Sema/SemaInit.cpp | |
parent | 0743ec24e3b1a47b0642a280e3499e8b741199ab (diff) | |
download | clang-91a14f64f769263deea649999cea32ea5bfa14cd.tar.gz |
[OpenCL] Allow OpenCL C style vector initialization in C++
Allow creating vector literals from other vectors.
float4 a = (float4)(1.0f, 2.0f, 3.0f, 4.0f);
float4 v = (float4)(a.s23, a.s01);
Differential revision: https://reviews.llvm.org/D65286
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@367675 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaInit.cpp')
-rw-r--r-- | lib/Sema/SemaInit.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index bc10696093..85af4bc492 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -1289,7 +1289,16 @@ void InitListChecker::CheckSubElementType(const InitializedEntity &Entity, // FIXME: Better EqualLoc? InitializationKind Kind = InitializationKind::CreateCopy(expr->getBeginLoc(), SourceLocation()); - InitializationSequence Seq(SemaRef, Entity, Kind, expr, + + // Vector elements can be initialized from other vectors in which case + // we need initialization entity with a type of a vector (and not a vector + // element!) initializing multiple vector elements. + auto TmpEntity = + (ElemType->isExtVectorType() && !Entity.getType()->isExtVectorType()) + ? InitializedEntity::InitializeTemporary(ElemType) + : Entity; + + InitializationSequence Seq(SemaRef, TmpEntity, Kind, expr, /*TopLevelOfInitList*/ true); // C++14 [dcl.init.aggr]p13: @@ -1300,8 +1309,7 @@ void InitListChecker::CheckSubElementType(const InitializedEntity &Entity, // assignment-expression. if (Seq || isa<InitListExpr>(expr)) { if (!VerifyOnly) { - ExprResult Result = - Seq.Perform(SemaRef, Entity, Kind, expr); + ExprResult Result = Seq.Perform(SemaRef, TmpEntity, Kind, expr); if (Result.isInvalid()) hadError = true; |