From 5ac257d738d43768a2ebd88d94555575da9f2f89 Mon Sep 17 00:00:00 2001 From: Tanya Lattner Date: Fri, 15 Apr 2011 22:42:59 +0000 Subject: [PATCH] Fix bug in vector initializer when initializing a vector with another vector. Add test case. llvm-svn: 129617 --- clang/lib/AST/ExprConstant.cpp | 6 ++++++ .../CodeGenOpenCL/2011-04-15-vec-init-from-vec.cl | 12 ++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 clang/test/CodeGenOpenCL/2011-04-15-vec-init-from-vec.cl diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 0ec122dc353a..14a1222cad57 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/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(E->getInit(0))); + APValue InitValue; if (EltTy->isIntegerType()) { llvm::APSInt sInt(32); diff --git a/clang/test/CodeGenOpenCL/2011-04-15-vec-init-from-vec.cl b/clang/test/CodeGenOpenCL/2011-04-15-vec-init-from-vec.cl new file mode 100644 index 000000000000..8454b17cf598 --- /dev/null +++ b/clang/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