From 8bb59a828ef21d0b2ed2b0efab60e4eddcb81c62 Mon Sep 17 00:00:00 2001 From: John Thompson Date: Wed, 30 Jun 2010 22:55:51 +0000 Subject: [PATCH] Fix vector literal/cast confusion - bug 6895. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107347 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExpr.cpp | 15 +++++++++++++-- test/Parser/altivec.c | 8 ++++++++ test/Parser/cxx-altivec.cpp | 8 ++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index c6d5c6590d..572699302f 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -4017,15 +4017,26 @@ Sema::ActOnCastOfParenListExpr(Scope *S, SourceLocation LParenLoc, TypeSourceInfo *TInfo) { ParenListExpr *PE = (ParenListExpr *)Op.get(); QualType Ty = TInfo->getType(); + bool isAltiVecLiteral = false; - // If this is an altivec initializer, '(' type ')' '(' init, ..., init ')' - // then handle it as such. + // Check for an altivec literal, + // i.e. all the elements are integer constants. if (getLangOptions().AltiVec && Ty->isVectorType()) { if (PE->getNumExprs() == 0) { Diag(PE->getExprLoc(), diag::err_altivec_empty_initializer); return ExprError(); } + if (PE->getNumExprs() == 1) { + if (!PE->getExpr(0)->getType()->isVectorType()) + isAltiVecLiteral = true; + } + else + isAltiVecLiteral = true; + } + // If this is an altivec initializer, '(' type ')' '(' init, ..., init ')' + // then handle it as such. + if (isAltiVecLiteral) { llvm::SmallVector initExprs; for (unsigned i = 0, e = PE->getNumExprs(); i != e; ++i) initExprs.push_back(PE->getExpr(i)); diff --git a/test/Parser/altivec.c b/test/Parser/altivec.c index d8744b800d..92ec688bc0 100644 --- a/test/Parser/altivec.c +++ b/test/Parser/altivec.c @@ -101,3 +101,11 @@ void f() { gccv = v; gccvector unsigned int tgv = v; } + +// bug 6895 - Vectorl literal casting confusion. +vector char v1 = (vector char)((vector int)(1, 2, 3, 4)); +vector char v2 = (vector char)((vector float)(1.0f, 2.0f, 3.0f, 4.0f)); +vector char v3 = (vector char)((vector int)('a', 'b', 'c', 'd')); +vector int v4 = (vector int)(1, 2, 3, 4); +vector float v5 = (vector float)(1.0f, 2.0f, 3.0f, 4.0f); +vector char v6 = (vector char)((vector int)(1+2, -2, (int)(2.0 * 3), -(5-3))); diff --git a/test/Parser/cxx-altivec.cpp b/test/Parser/cxx-altivec.cpp index 7916b4305a..a70eea077e 100644 --- a/test/Parser/cxx-altivec.cpp +++ b/test/Parser/cxx-altivec.cpp @@ -118,3 +118,11 @@ class c_v { void f__a2(int b, vector int a); }; + +// bug 6895 - Vectorl literal casting confusion. +vector char v1 = (vector char)((vector int)(1, 2, 3, 4)); +vector char v2 = (vector char)((vector float)(1.0f, 2.0f, 3.0f, 4.0f)); +vector char v3 = (vector char)((vector int)('a', 'b', 'c', 'd')); +vector int v4 = (vector int)(1, 2, 3, 4); +vector float v5 = (vector float)(1.0f, 2.0f, 3.0f, 4.0f); +vector char v6 = (vector char)((vector int)(1+2, -2, (int)(2.0 * 3), -(5-3))); -- 2.40.0