diff options
author | Tanya Lattner <tonic@nondot.org> | 2011-04-15 22:42:59 +0000 |
---|---|---|
committer | Tanya Lattner <tonic@nondot.org> | 2011-04-15 22:42:59 +0000 |
commit | b92ae0e31126e5630d7022f2d6abe7eed2e17746 (patch) | |
tree | 0e99c3f552e5a22b07af099735c1e0ed5b1d5cb3 | |
parent | 5272adfe7066c4847b7339a75777252de64e79c2 (diff) |
Fix bug in vector initializer when initializing a vector with another vector.
Add test case.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129617 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/AST/ExprConstant.cpp | 6 | ||||
-rw-r--r-- | test/CodeGenOpenCL/2011-04-15-vec-init-from-vec.cl | 12 |
2 files changed, 18 insertions, 0 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 0ec122dc35..14a1222cad 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -841,6 +841,12 @@ VectorExprEvaluator::VisitInitListExpr(const InitListExpr *E) { // becomes every element of the vector, not just the first. // This is the behavior described in the IBM AltiVec documentation. if (NumInits == 1) { + + // Handle the case where the vector is initialized by a another + // vector (OpenCL 6.1.6). + if (E->getInit(0)->getType()->isVectorType()) + return this->Visit(const_cast<Expr*>(E->getInit(0))); + APValue InitValue; if (EltTy->isIntegerType()) { llvm::APSInt sInt(32); diff --git a/test/CodeGenOpenCL/2011-04-15-vec-init-from-vec.cl b/test/CodeGenOpenCL/2011-04-15-vec-init-from-vec.cl new file mode 100644 index 0000000000..8454b17cf5 --- /dev/null +++ b/test/CodeGenOpenCL/2011-04-15-vec-init-from-vec.cl @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 %s -emit-llvm -o %t + +typedef __attribute__((ext_vector_type(8))) unsigned char uchar8; +typedef __attribute__((ext_vector_type(4))) unsigned long ulong4; +typedef __attribute__((ext_vector_type(16))) unsigned char uchar16; + +// OpenCL allows vectors to be initialized by vectors Handle bug in +// VisitInitListExpr for this case below. +void foo( ulong4 v ) +{ + uchar8 val[4] = {{(uchar8){((uchar16)(v.lo)).lo}}}; +}
\ No newline at end of file |