summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaExpr.cpp
diff options
context:
space:
mode:
authorTanya Lattner <tonic@nondot.org>2011-07-15 23:07:01 +0000
committerTanya Lattner <tonic@nondot.org>2011-07-15 23:07:01 +0000
commit8355938fcd1b8379c93b4cd3a2c7c96552e88c7a (patch)
tree2313e35e291f304e3f146bbcb7dd40b712eda35d /clang/lib/Sema/SemaExpr.cpp
parent0679e176447bc116f8b5cbb97df1109fbaa1c45c (diff)
downloadbcm5719-llvm-8355938fcd1b8379c93b4cd3a2c7c96552e88c7a.tar.gz
bcm5719-llvm-8355938fcd1b8379c93b4cd3a2c7c96552e88c7a.zip
This handles the missing cases of opencl vector literals.
Test cases provided by Anton Lokhmot. llvm-svn: 135322
Diffstat (limited to 'clang/lib/Sema/SemaExpr.cpp')
-rw-r--r--clang/lib/Sema/SemaExpr.cpp23
1 files changed, 18 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index a99a5d2cc42..5efc36559d9 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/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,
OpenPOWER on IntegriCloud