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 | 8d99a5c0e629131e732baf02cfeea8f42f61f5f2 (patch) | |
tree | f777003fecb385c04998bcf48fe3ca2f5ffaf3dd /clang/lib/Sema/SemaInit.cpp | |
parent | 397a516a52d52a530a29351bbe4de02e72c884bd (diff) | |
download | llvm-8d99a5c0e629131e732baf02cfeea8f42f61f5f2.zip llvm-8d99a5c0e629131e732baf02cfeea8f42f61f5f2.tar.gz llvm-8d99a5c0e629131e732baf02cfeea8f42f61f5f2.tar.bz2 |
[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
llvm-svn: 367675
Diffstat (limited to 'clang/lib/Sema/SemaInit.cpp')
-rw-r--r-- | clang/lib/Sema/SemaInit.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index bc10696..85af4bc 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/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; |