From: Richard Smith Date: Thu, 27 Oct 2011 23:31:58 +0000 (+0000) Subject: Add missing lvalue-to-rvalue conversion to vector splat casts. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=61ffd09797d661ae4ae18674d144a27be2d2f5f3;p=clang Add missing lvalue-to-rvalue conversion to vector splat casts. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143166 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 885b9664d6..880199bc7a 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -4334,7 +4334,9 @@ ExprResult Sema::BuildVectorLiteral(SourceLocation LParenLoc, // be replicated to all the components of the vector if (numExprs == 1) { QualType ElemTy = Ty->getAs()->getElementType(); - ExprResult Literal = Owned(exprs[0]); + ExprResult Literal = DefaultLvalueConversion(exprs[0]); + if (Literal.isInvalid()) + return ExprError(); Literal = ImpCastExprToType(Literal.take(), ElemTy, PrepareScalarCast(Literal, ElemTy)); return BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, Literal.take()); @@ -4355,7 +4357,9 @@ ExprResult Sema::BuildVectorLiteral(SourceLocation LParenLoc, VTy->getVectorKind() == VectorType::GenericVector && numExprs == 1) { QualType ElemTy = Ty->getAs()->getElementType(); - ExprResult Literal = Owned(exprs[0]); + ExprResult Literal = DefaultLvalueConversion(exprs[0]); + if (Literal.isInvalid()) + return ExprError(); Literal = ImpCastExprToType(Literal.take(), ElemTy, PrepareScalarCast(Literal, ElemTy)); return BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, Literal.take()); diff --git a/test/SemaCXX/altivec.cpp b/test/SemaCXX/altivec.cpp index 504eb1b336..39421b7c40 100644 --- a/test/SemaCXX/altivec.cpp +++ b/test/SemaCXX/altivec.cpp @@ -66,3 +66,13 @@ void test2() (++vi)[1]=1; template_f(vi); } + +namespace LValueToRValueConversions { + struct Struct { + float f(); + int n(); + }; + + vector float initFloat = (vector float)(Struct().f); // expected-error {{did you mean to call it}} + vector int initInt = (vector int)(Struct().n); // expected-error {{did you mean to call it}} +}