diff options
Diffstat (limited to 'lib/Sema/SemaExpr.cpp')
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index a99a5d2cc4..5efc36559d 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -4222,13 +4222,14 @@ ExprResult Sema::BuildVectorLiteral(SourceLocation LParenLoc, assert(Ty->isVectorType() && "Expected vector type"); llvm::SmallVector<Expr *, 8> initExprs; + const VectorType *VTy = Ty->getAs<VectorType>(); + unsigned numElems = Ty->getAs<VectorType>()->getNumElements(); + // '(...)' form of vector initialization in AltiVec: the number of // initializers must be one or must match the size of the vector. // If a single value is specified in the initializer then it will be // replicated to all the components of the vector - if (Ty->getAs<VectorType>()->getVectorKind() == - VectorType::AltiVecVector) { - unsigned numElems = Ty->getAs<VectorType>()->getNumElements(); + if (VTy->getVectorKind() == VectorType::AltiVecVector) { // The number of initializers must be one or must match the size of the // vector. If a single value is specified in the initializer then it will // be replicated to all the components of the vector @@ -4248,10 +4249,22 @@ ExprResult Sema::BuildVectorLiteral(SourceLocation LParenLoc, for (unsigned i = 0, e = numExprs; i != e; ++i) initExprs.push_back(exprs[i]); } - else + else { + // For OpenCL, when the number of initializers is a single value, + // it will be replicated to all components of the vector. + if (getLangOptions().OpenCL && + VTy->getVectorKind() == VectorType::GenericVector && + numExprs == 1) { + QualType ElemTy = Ty->getAs<VectorType>()->getElementType(); + ExprResult Literal = Owned(exprs[0]); + Literal = ImpCastExprToType(Literal.take(), ElemTy, + PrepareScalarCast(*this, Literal, ElemTy)); + return BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, Literal.take()); + } + for (unsigned i = 0, e = numExprs; i != e; ++i) initExprs.push_back(exprs[i]); - + } // FIXME: This means that pretty-printing the final AST will produce curly // braces instead of the original commas. InitListExpr *initE = new (Context) InitListExpr(Context, LParenLoc, |