Hi all,
made changes according to the rules for the '(...)' 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.
Can I commit the patch?
--
Anton
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp (revision 122561)
+++ lib/Sema/SemaExpr.cpp (working copy)
@@ -4862,9 +4862,9 @@
TypeSourceInfo *TInfo) {
ParenListExpr *PE = cast<ParenListExpr>(Op);
QualType Ty = TInfo->getType();
- bool isAltiVecLiteral = false;
+ bool isVectorLiteral = false;
- // Check for an altivec literal,
+ // Check for an altivec or OpenCL literal,
// i.e. all the elements are integer constants.
if (getLangOptions().AltiVec && Ty->isVectorType()) {
if (PE->getNumExprs() == 0) {
@@ -4873,19 +4873,45 @@
}
if (PE->getNumExprs() == 1) {
if (!PE->getExpr(0)->getType()->isVectorType())
- isAltiVecLiteral = true;
+ isVectorLiteral = true;
}
else
- isAltiVecLiteral = true;
+ isVectorLiteral = true;
}
- // If this is an altivec initializer, '(' type ')' '(' init, ..., init ')'
+ // If this is a vector initializer, '(' type ')' '(' init, ..., init ')'
// then handle it as such.
- if (isAltiVecLiteral) {
+ if (isVectorLiteral) {
llvm::SmallVector<Expr *, 8> initExprs;
- for (unsigned i = 0, e = PE->getNumExprs(); i != e; ++i)
- initExprs.push_back(PE->getExpr(i));
+ // '(...)' 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();
+ // 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 (PE->getNumExprs() == 1) {
+ Expr* initExpr = PE->getExpr(0);
+ for (unsigned i = 0; i != numElems; ++i)
+ initExprs.push_back(initExpr);
+ }
+ else if (PE->getNumExprs() < numElems) {
+ Diag(PE->getExprLoc(),
+ diag::err_incorrect_number_of_vector_initializers);
+ return ExprError();
+ }
+ else
+ for (unsigned i = 0, e = PE->getNumExprs(); i != e; ++i)
+ initExprs.push_back(PE->getExpr(i));
+ }
+ else
+ for (unsigned i = 0, e = PE->getNumExprs(); i != e; ++i)
+ initExprs.push_back(PE->getExpr(i));
+
// FIXME: This means that pretty-printing the final AST will produce curly
// braces instead of the original commas.
InitListExpr *E = new (Context) InitListExpr(Context, LParenLoc,
Index: test/CodeGen/builtins-ppc-altivec.c
===================================================================
--- test/CodeGen/builtins-ppc-altivec.c (revision 122561)
+++ test/CodeGen/builtins-ppc-altivec.c (working copy)
@@ -3113,3 +3113,9 @@
res_i = (vf1 <= vf2); // CHECK:
@llvm.ppc.altivec.vcmpgefp.p(i32 2
res_i = (vf1 >= vf2); // CHECK:
@llvm.ppc.altivec.vcmpgefp.p(i32 2
}
+
+/* --------------------------------- initialization
--------------------------------- */
+// CHECK: define void @test8
+void test8() {
+ vector int vi = (vector int)(1); // CHECK: <i32 1, i32 1, i32 1, i32
1>
+}
Index: test/Sema/altivec-init.c
===================================================================
--- test/Sema/altivec-init.c (revision 122561)
+++ test/Sema/altivec-init.c (working copy)
@@ -6,9 +6,11 @@
v8 foo(void) {
v8 a;
v4 b;
+ vector int c;
a = (v8){4, 2};
b = (v4)(5, 6, 7, 8, 9); // expected-warning {{excess elements in vector
initializer}}
b = (v4)(5, 6, 8, 8.0f);
+ c = (vector int)(5, 6); // expected-error {{number of elements must be
either one or match the size of the vector}}
return (v8){0, 1, 2, 3, 1, 2, 3, 4};
// FIXME: test that (type)(fn)(args) still works with -faltivec
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits