Index: docs/LanguageExtensions.rst =================================================================== --- docs/LanguageExtensions.rst +++ docs/LanguageExtensions.rst @@ -1490,6 +1490,50 @@ Query for this feature with ``__has_builtin(__builtin_shufflevector)``. +``__builtin_convertvector`` +--------------------------- + +``__builtin_convertvector`` is used to express generic vector +type-conversion operations. The input vector and the output vector +type must have the same number of elements. + +**Syntax**: + +.. code-block:: c++ + + __builtin_convertvector(src_vec, dst_vec_type) + +**Examples**: + +.. code-block:: c++ + + typedef double vector4double __attribute__((__vector_size__(32))); + typedef float vector4float __attribute__((__vector_size__(16))); + typedef short vector4short __attribute__((__vector_size__(8))); + vector4float vf; vector4short vs; + + // convert from a vector of 4 floats to a vector of 4 doubles. + __builtin_convertvector(vf, vector4double) + // equivalent to: + (vector4double) { (double) vf[0], (double) vf[1], (double) vf[2], (double) vf[3] } + + // convert from a vector of 4 shorts to a vector of 4 floats. + __builtin_convertvector(vs, vector4float) + // equivalent to: + (vector4float) { (float) vf[0], (float) vf[1], (float) vf[2], (float) vf[3] } + +**Description**: + +The first argument to ``__builtin_convertvector`` is a vector, and the second +argument is a vector type with the same number of elements as the first +argument. + +The result of ``__builtin_convertvector`` is a vector with the same element +type as the second argument, with a value defined in terms of the action of a +C-style cast applied to each element of the first argument. + +Query for this feature with ``__has_builtin(__builtin_convertvector)``. + ``__builtin_unreachable`` ------------------------- Index: include/clang/AST/Expr.h =================================================================== --- include/clang/AST/Expr.h +++ include/clang/AST/Expr.h @@ -3468,6 +3468,51 @@ } }; +/// ConvertVectorExpr - Clang builtin function __builtin_convertvector +/// This AST node provides support for converting a vector type to another +/// vector type of the same arity. +class ConvertVectorExpr : public Expr { // Should this be an ExplicitCastExpr? +private: + Stmt *SrcExpr; + SourceLocation BuiltinLoc, RParenLoc; + + friend class ASTReader; + friend class ASTStmtReader; + explicit ConvertVectorExpr(EmptyShell Empty) : Expr(ConvertVectorExprClass, Empty) {} + +public: + ConvertVectorExpr(Expr* SrcExpr, QualType DstType, + ExprValueKind VK, ExprObjectKind OK, + SourceLocation BuiltinLoc, SourceLocation RParenLoc) + : Expr(ConvertVectorExprClass, DstType, VK, OK, + DstType->isDependentType(), + DstType->isDependentType() || SrcExpr->isValueDependent(), + (DstType->isInstantiationDependentType() || + SrcExpr->isInstantiationDependent()), + (DstType->containsUnexpandedParameterPack() || + SrcExpr->containsUnexpandedParameterPack())), + SrcExpr(SrcExpr), BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) {} + + /// getSrcExpr - Return the Expr to be converted. + Expr *getSrcExpr() const { return cast(SrcExpr); } + + /// getBuiltinLoc - Return the location of the __builtin_convertvector token. + SourceLocation getBuiltinLoc() const { return BuiltinLoc; } + + /// getRParenLoc - Return the location of final right parenthesis. + SourceLocation getRParenLoc() const { return RParenLoc; } + + SourceLocation getLocStart() const LLVM_READONLY { return BuiltinLoc; } + SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } + + static bool classof(const Stmt *T) { + return T->getStmtClass() == ConvertVectorExprClass; + } + + // Iterators + child_range children() { return child_range(&SrcExpr, &SrcExpr+1); } +}; + /// ChooseExpr - GNU builtin-in function __builtin_choose_expr. /// This AST node is similar to the conditional operator (?:) in C, with /// the following exceptions: Index: include/clang/AST/RecursiveASTVisitor.h =================================================================== --- include/clang/AST/RecursiveASTVisitor.h +++ include/clang/AST/RecursiveASTVisitor.h @@ -2262,6 +2262,7 @@ DEF_TRAVERSE_STMT(ParenListExpr, { }) DEF_TRAVERSE_STMT(PredefinedExpr, { }) DEF_TRAVERSE_STMT(ShuffleVectorExpr, { }) +DEF_TRAVERSE_STMT(ConvertVectorExpr, { }) DEF_TRAVERSE_STMT(StmtExpr, { }) DEF_TRAVERSE_STMT(UnresolvedLookupExpr, { TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc())); Index: include/clang/Basic/Builtins.def =================================================================== --- include/clang/Basic/Builtins.def +++ include/clang/Basic/Builtins.def @@ -488,6 +488,7 @@ BUILTIN(__builtin_debugtrap, "v", "n") BUILTIN(__builtin_unreachable, "v", "nr") BUILTIN(__builtin_shufflevector, "v." , "nc") +BUILTIN(__builtin_convertvector, "v." , "nct") BUILTIN(__builtin_alloca, "v*z" , "n") // "Overloaded" Atomic operator builtins. These are overloaded to support data Index: include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- include/clang/Basic/DiagnosticSemaKinds.td +++ include/clang/Basic/DiagnosticSemaKinds.td @@ -6370,6 +6370,13 @@ "index for __builtin_shufflevector must be less than the total number " "of vector elements">; +def err_convertvector_non_vector : Error< + "first argument to __builtin_convertvector must be a vector">; +def err_convertvector_non_vector_type : Error< + "second argument to __builtin_convertvector must be a vector type">; +def err_convertvector_incompatible_vector : Error< + "first two arguments to __builtin_convertvector must have the same number of elements">; + def err_vector_incorrect_num_initializers : Error< "%select{too many|too few}0 elements in vector initialization (expected %1 elements, have %2)">; def err_altivec_empty_initializer : Error<"expected initializer">; Index: include/clang/Basic/StmtNodes.td =================================================================== --- include/clang/Basic/StmtNodes.td +++ include/clang/Basic/StmtNodes.td @@ -162,6 +162,7 @@ // Clang Extensions. def ShuffleVectorExpr : DStmt; +def ConvertVectorExpr : DStmt; def BlockExpr : DStmt; def OpaqueValueExpr : DStmt; Index: include/clang/Basic/TokenKinds.def =================================================================== --- include/clang/Basic/TokenKinds.def +++ include/clang/Basic/TokenKinds.def @@ -542,6 +542,7 @@ ALIAS("_pascal" , __pascal , KEYBORLAND) // Clang Extensions. +KEYWORD(__builtin_convertvector , KEYALL) ALIAS("__char16_t" , char16_t , KEYCXX) ALIAS("__char32_t" , char32_t , KEYCXX) Index: include/clang/Sema/Sema.h =================================================================== --- include/clang/Sema/Sema.h +++ include/clang/Sema/Sema.h @@ -3543,6 +3543,13 @@ ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body, Scope *CurScope); + //===---------------------------- Clang Extensions ----------------------===// + + /// __builtin_convertvector(...) + ExprResult ActOnConvertVectorExpr(Expr *E, ParsedType ParsedDestTy, + SourceLocation BuiltinLoc, + SourceLocation RParenLoc); + //===---------------------------- OpenCL Features -----------------------===// /// __builtin_astype(...) Index: include/clang/Serialization/ASTBitCodes.h =================================================================== --- include/clang/Serialization/ASTBitCodes.h +++ include/clang/Serialization/ASTBitCodes.h @@ -1186,6 +1186,8 @@ EXPR_GNU_NULL, /// \brief A ShuffleVectorExpr record. EXPR_SHUFFLE_VECTOR, + /// \brief A ConvertVectorExpr record. + EXPR_CONVERT_VECTOR, /// \brief BlockExpr EXPR_BLOCK, /// \brief A GenericSelectionExpr record. Index: lib/AST/Expr.cpp =================================================================== --- lib/AST/Expr.cpp +++ lib/AST/Expr.cpp @@ -2843,6 +2843,7 @@ case SubstNonTypeTemplateParmExprClass: case MaterializeTemporaryExprClass: case ShuffleVectorExprClass: + case ConvertVectorExprClass: case AsTypeExprClass: // These have a side-effect if any subexpression does. break; Index: lib/AST/ExprClassification.cpp =================================================================== --- lib/AST/ExprClassification.cpp +++ lib/AST/ExprClassification.cpp @@ -155,6 +155,7 @@ case Expr::OffsetOfExprClass: case Expr::CXXThrowExprClass: case Expr::ShuffleVectorExprClass: + case Expr::ConvertVectorExprClass: case Expr::IntegerLiteralClass: case Expr::CharacterLiteralClass: case Expr::AddrLabelExprClass: Index: lib/AST/ExprConstant.cpp =================================================================== --- lib/AST/ExprConstant.cpp +++ lib/AST/ExprConstant.cpp @@ -8141,6 +8141,7 @@ case Expr::ObjCSubscriptRefExprClass: case Expr::ObjCIsaExprClass: case Expr::ShuffleVectorExprClass: + case Expr::ConvertVectorExprClass: case Expr::BlockExprClass: case Expr::NoStmtClass: case Expr::OpaqueValueExprClass: Index: lib/AST/ItaniumMangle.cpp =================================================================== --- lib/AST/ItaniumMangle.cpp +++ lib/AST/ItaniumMangle.cpp @@ -2586,6 +2586,7 @@ case Expr::OffsetOfExprClass: case Expr::PredefinedExprClass: case Expr::ShuffleVectorExprClass: + case Expr::ConvertVectorExprClass: case Expr::StmtExprClass: case Expr::UnaryTypeTraitExprClass: case Expr::BinaryTypeTraitExprClass: Index: lib/AST/StmtPrinter.cpp =================================================================== --- lib/AST/StmtPrinter.cpp +++ lib/AST/StmtPrinter.cpp @@ -1088,6 +1088,14 @@ OS << ")"; } +void StmtPrinter::VisitConvertVectorExpr(ConvertVectorExpr *Node) { + OS << "__builtin_convertvector("; + PrintExpr(Node->getSrcExpr()); + OS << ", "; + Node->getType().print(OS, Policy); + OS << ")"; +} + void StmtPrinter::VisitInitListExpr(InitListExpr* Node) { if (Node->getSyntacticForm()) { Visit(Node->getSyntacticForm()); Index: lib/AST/StmtProfile.cpp =================================================================== --- lib/AST/StmtProfile.cpp +++ lib/AST/StmtProfile.cpp @@ -454,6 +454,10 @@ VisitExpr(S); } +void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) { + VisitExpr(S); +} + void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) { VisitExpr(S); } Index: lib/CodeGen/CGExprScalar.cpp =================================================================== --- lib/CodeGen/CGExprScalar.cpp +++ lib/CodeGen/CGExprScalar.cpp @@ -257,6 +257,7 @@ Value *VisitArraySubscriptExpr(ArraySubscriptExpr *E); Value *VisitShuffleVectorExpr(ShuffleVectorExpr *E); + Value *VisitConvertVectorExpr(ConvertVectorExpr *E); Value *VisitMemberExpr(MemberExpr *E); Value *VisitExtVectorElementExpr(Expr *E) { return EmitLoadOfLValue(E); } Value *VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { @@ -966,6 +967,69 @@ Value *SV = llvm::ConstantVector::get(indices); return Builder.CreateShuffleVector(V1, V2, SV, "shuffle"); } + +Value *ScalarExprEmitter::VisitConvertVectorExpr(ConvertVectorExpr *E) { + QualType SrcType = E->getSrcExpr()->getType(), + DstType = E->getType(); + + Value *Src = CGF.EmitScalarExpr(E->getSrcExpr()); + + SrcType = CGF.getContext().getCanonicalType(SrcType); + DstType = CGF.getContext().getCanonicalType(DstType); + if (SrcType == DstType) return Src; + + assert(SrcType->isVectorType() && + "ConvertVector source type must be a vector"); + assert(DstType->isVectorType() && + "ConvertVector destination type must be a vector"); + + llvm::Type *SrcTy = Src->getType(); + llvm::Type *DstTy = ConvertType(DstType); + + // Ignore conversions like int -> uint. + if (SrcTy == DstTy) + return Src; + + QualType SrcEltType = SrcType->getAs()->getElementType(), + DstEltType = DstType->getAs()->getElementType(); + + assert(SrcTy->isVectorTy() && + "ConvertVector source IR type must be a vector"); + assert(DstTy->isVectorTy() && + "ConvertVector destination IR type must be a vector"); + + llvm::Type *SrcEltTy = SrcTy->getVectorElementType(), + *DstEltTy = DstTy->getVectorElementType(); + + // We have the arithmetic types: real int/float. + Value *Res = NULL; + + if (isa(SrcEltTy)) { + bool InputSigned = SrcEltType->isSignedIntegerOrEnumerationType(); + if (isa(DstEltTy)) + Res = Builder.CreateIntCast(Src, DstTy, InputSigned, "conv"); + else if (InputSigned) + Res = Builder.CreateSIToFP(Src, DstTy, "conv"); + else + Res = Builder.CreateUIToFP(Src, DstTy, "conv"); + } else if (isa(DstEltTy)) { + assert(SrcEltTy->isFloatingPointTy() && "Unknown real conversion"); + if (DstEltType->isSignedIntegerOrEnumerationType()) + Res = Builder.CreateFPToSI(Src, DstTy, "conv"); + else + Res = Builder.CreateFPToUI(Src, DstTy, "conv"); + } else { + assert(SrcEltTy->isFloatingPointTy() && DstEltTy->isFloatingPointTy() && + "Unknown real conversion"); + if (DstEltTy->getTypeID() < SrcEltTy->getTypeID()) + Res = Builder.CreateFPTrunc(Src, DstTy, "conv"); + else + Res = Builder.CreateFPExt(Src, DstTy, "conv"); + } + + return Res; +} + Value *ScalarExprEmitter::VisitMemberExpr(MemberExpr *E) { llvm::APSInt Value; if (E->EvaluateAsInt(Value, CGF.getContext(), Expr::SE_AllowSideEffects)) { Index: lib/Parse/ParseExpr.cpp =================================================================== --- lib/Parse/ParseExpr.cpp +++ lib/Parse/ParseExpr.cpp @@ -888,6 +888,7 @@ case tok::kw___builtin_offsetof: case tok::kw___builtin_choose_expr: case tok::kw___builtin_astype: // primary-expression: [OCL] as_type() + case tok::kw___builtin_convertvector: return ParseBuiltinPrimaryExpression(); case tok::kw___null: return Actions.ActOnGNUNullExpr(ConsumeToken()); @@ -1918,6 +1919,34 @@ ConsumeParen()); break; } + case tok::kw___builtin_convertvector: { + // The first argument is an expression to be converted, followed by a comma. + ExprResult Expr(ParseAssignmentExpression()); + if (Expr.isInvalid()) { + SkipUntil(tok::r_paren); + return ExprError(); + } + + if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "", + tok::r_paren)) + return ExprError(); + + // Second argument is the type to bitcast to. + TypeResult DestTy = ParseTypeName(); + if (DestTy.isInvalid()) + return ExprError(); + + // Attempt to consume the r-paren. + if (Tok.isNot(tok::r_paren)) { + Diag(Tok, diag::err_expected_rparen); + SkipUntil(tok::r_paren); + return ExprError(); + } + + Res = Actions.ActOnConvertVectorExpr(Expr.take(), DestTy.get(), StartLoc, + ConsumeParen()); + break; + } } if (Res.isInvalid()) Index: lib/Sema/SemaExceptionSpec.cpp =================================================================== --- lib/Sema/SemaExceptionSpec.cpp +++ lib/Sema/SemaExceptionSpec.cpp @@ -995,6 +995,7 @@ case Expr::ParenExprClass: case Expr::ParenListExprClass: case Expr::ShuffleVectorExprClass: + case Expr::ConvertVectorExprClass: case Expr::VAArgExprClass: return canSubExprsThrow(*this, E); Index: lib/Sema/SemaExpr.cpp =================================================================== --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -4458,6 +4458,39 @@ RParenLoc)); } +/// ActOnConvertVectorExpr - create a new convert-vector expression from the +/// provided arguments. +/// +/// __builtin_convertvector( value, dst type ) +/// +ExprResult Sema::ActOnConvertVectorExpr(Expr *E, ParsedType ParsedDestTy, + SourceLocation BuiltinLoc, + SourceLocation RParenLoc) { + ExprValueKind VK = VK_RValue; + ExprObjectKind OK = OK_Ordinary; + QualType DstTy = GetTypeFromParser(ParsedDestTy); + QualType SrcTy = E->getType(); + + if (!SrcTy->isVectorType()) + return ExprError(Diag(BuiltinLoc, + diag::err_convertvector_non_vector) + << E->getSourceRange()); + if (!DstTy->isVectorType()) + return ExprError(Diag(BuiltinLoc, + diag::err_convertvector_non_vector_type) + << E->getSourceRange()); + + unsigned SrcElts = SrcTy->getAs()->getNumElements(); + unsigned DstElts = DstTy->getAs()->getNumElements(); + if (SrcElts != DstElts) + return ExprError(Diag(BuiltinLoc, + diag::err_convertvector_incompatible_vector) + << E->getSourceRange()); + + return Owned(new (Context) ConvertVectorExpr(E, DstTy, VK, OK, BuiltinLoc, + RParenLoc)); +} + /// BuildResolvedCallExpr - Build a call to a resolved expression, /// i.e. an expression not of \p OverloadTy. The expression should /// unary-convert to an expression of function-pointer or Index: lib/Sema/TreeTransform.h =================================================================== --- lib/Sema/TreeTransform.h +++ lib/Sema/TreeTransform.h @@ -9166,6 +9166,12 @@ template ExprResult +TreeTransform::TransformConvertVectorExpr(ConvertVectorExpr *E) { + llvm_unreachable("Cannot transform convertVector expressions yet"); +} + +template +ExprResult TreeTransform::TransformBlockExpr(BlockExpr *E) { BlockDecl *oldBlock = E->getBlockDecl(); Index: lib/Serialization/ASTReaderStmt.cpp =================================================================== --- lib/Serialization/ASTReaderStmt.cpp +++ lib/Serialization/ASTReaderStmt.cpp @@ -854,6 +854,13 @@ E->setRParenLoc(ReadSourceLocation(Record, Idx)); } +void ASTStmtReader::VisitConvertVectorExpr(ConvertVectorExpr *E) { + VisitExpr(E); + E->BuiltinLoc = ReadSourceLocation(Record, Idx); + E->RParenLoc = ReadSourceLocation(Record, Idx); + E->SrcExpr = Reader.ReadSubExpr(); +} + void ASTStmtReader::VisitBlockExpr(BlockExpr *E) { VisitExpr(E); E->setBlockDecl(ReadDeclAs(Record, Idx)); @@ -2104,6 +2111,10 @@ S = new (Context) ShuffleVectorExpr(Empty); break; + case EXPR_CONVERT_VECTOR: + S = new (Context) ConvertVectorExpr(Empty); + break; + case EXPR_BLOCK: S = new (Context) BlockExpr(Empty); break; Index: lib/Serialization/ASTWriterStmt.cpp =================================================================== --- lib/Serialization/ASTWriterStmt.cpp +++ lib/Serialization/ASTWriterStmt.cpp @@ -794,6 +794,14 @@ Code = serialization::EXPR_SHUFFLE_VECTOR; } +void ASTStmtWriter::VisitConvertVectorExpr(ConvertVectorExpr *E) { + VisitExpr(E); + Writer.AddSourceLocation(E->getBuiltinLoc(), Record); + Writer.AddSourceLocation(E->getRParenLoc(), Record); + Writer.AddStmt(E->getSrcExpr()); + Code = serialization::EXPR_CONVERT_VECTOR; +} + void ASTStmtWriter::VisitBlockExpr(BlockExpr *E) { VisitExpr(E); Writer.AddDeclRef(E->getBlockDecl(), Record); Index: lib/StaticAnalyzer/Core/ExprEngine.cpp =================================================================== --- lib/StaticAnalyzer/Core/ExprEngine.cpp +++ lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -726,6 +726,7 @@ case Stmt::ParenListExprClass: case Stmt::PredefinedExprClass: case Stmt::ShuffleVectorExprClass: + case Stmt::ConvertVectorExprClass: case Stmt::VAArgExprClass: case Stmt::CUDAKernelCallExprClass: case Stmt::OpaqueValueExprClass: Index: test/CodeGen/convertvector.c =================================================================== --- /dev/null +++ test/CodeGen/convertvector.c @@ -0,0 +1,72 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -target-cpu corei7-avx -emit-llvm %s -o - | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -target-cpu corei7-avx -emit-llvm -x c++ %s -o - | FileCheck %s + +typedef double vector4double __attribute__((__vector_size__(32))); +typedef float vector4float __attribute__((__vector_size__(16))); +typedef long vector4long __attribute__((__vector_size__(32))); +typedef short vector4short __attribute__((__vector_size__(8))); +typedef unsigned long vector4ulong __attribute__((__vector_size__(32))); +typedef unsigned short vector4ushort __attribute__((__vector_size__(8))); + +#ifdef __cplusplus +extern "C" { +#endif + +vector4float flt_trunc(vector4double x) { + return __builtin_convertvector(x, vector4float); + // CHECK-LABEL: @flt_trunc + // CHECK: fptrunc <4 x double> %{{[^ ]}} to <4 x float> +} + +vector4double flt_ext(vector4float x) { + return __builtin_convertvector(x, vector4double); + // CHECK-LABEL: @flt_ext + // CHECK: fpext <4 x float> %{{[^ ]}} to <4 x double> +} + +vector4long flt_tosi(vector4float x) { + return __builtin_convertvector(x, vector4long); + // CHECK-LABEL: @flt_tosi + // CHECK: fptosi <4 x float> %{{[^ ]}} to <4 x i64> +} + +vector4ulong flt_toui(vector4float x) { + return __builtin_convertvector(x, vector4ulong); + // CHECK-LABEL: @flt_toui + // CHECK: fptoui <4 x float> %{{[^ ]}} to <4 x i64> +} + +vector4ulong fltd_toui(vector4double x) { + return __builtin_convertvector(x, vector4ulong); + // CHECK-LABEL: @fltd_toui + // CHECK: fptoui <4 x double> %{{[^ ]}} to <4 x i64> +} + +vector4ulong int_zext(vector4ushort x) { + return __builtin_convertvector(x, vector4ulong); + // CHECK-LABEL: @int_zext + // CHECK: zext <4 x i16> %{{[^ ]}} to <4 x i64> +} + +vector4long int_sext(vector4short x) { + return __builtin_convertvector(x, vector4long); + // CHECK-LABEL: @int_sext + // CHECK: sext <4 x i16> %{{[^ ]}} to <4 x i64> +} + +vector4float int_tofp(vector4short x) { + return __builtin_convertvector(x, vector4float); + // CHECK-LABEL: @int_tofp + // CHECK: sitofp <4 x i16> %{{[^ ]}} to <4 x float> +} + +vector4float uint_tofp(vector4ushort x) { + return __builtin_convertvector(x, vector4float); + // CHECK-LABEL: @uint_tofp + // CHECK: uitofp <4 x i16> %{{[^ ]}} to <4 x float> +} + +#ifdef __cplusplus +} +#endif + Index: test/PCH/exprs.h =================================================================== --- test/PCH/exprs.h +++ test/PCH/exprs.h @@ -102,6 +102,10 @@ // ShuffleVectorExpr typedef typeof(__builtin_shufflevector(vec2, vec2b, 2, 1)) shuffle_expr; +// ConvertVectorExpr +typedef __attribute__(( ext_vector_type(2) )) float float2; +typedef typeof(__builtin_convertvector(vec2, float2)) convert_expr; + // GenericSelectionExpr typedef typeof(_Generic(i, char*: 0, int: 0., default: hello)) generic_selection_expr; Index: test/Preprocessor/feature_tests.c =================================================================== --- test/Preprocessor/feature_tests.c +++ test/Preprocessor/feature_tests.c @@ -11,6 +11,7 @@ #if !__has_builtin(__builtin_huge_val) || \ !__has_builtin(__builtin_shufflevector) || \ + !__has_builtin(__builtin_convertvector) || \ !__has_builtin(__builtin_trap) || \ !__has_builtin(__c11_atomic_init) || \ !__has_feature(attribute_analyzer_noreturn) || \ Index: test/Sema/convertvector.c =================================================================== --- /dev/null +++ test/Sema/convertvector.c @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +typedef double vector4double __attribute__((__vector_size__(32))); +typedef float vector8float __attribute__((__vector_size__(32))); + +vector8float foo1(vector4double x) { + return __builtin_convertvector(x, vector8float); // expected-error {{same number of elements}} +} + +float foo2(vector4double x) { + return __builtin_convertvector(x, float); // expected-error {{must be a vector type}} +} + +vector8float foo3(double x) { + return __builtin_convertvector(x, vector8float); // expected-error {{must be a vector}} +} + Index: tools/libclang/CXCursor.cpp =================================================================== --- tools/libclang/CXCursor.cpp +++ tools/libclang/CXCursor.cpp @@ -232,6 +232,7 @@ case Stmt::ParenListExprClass: case Stmt::PredefinedExprClass: case Stmt::ShuffleVectorExprClass: + case Stmt::ConvertVectorExprClass: case Stmt::UnaryExprOrTypeTraitExprClass: case Stmt::UnaryTypeTraitExprClass: case Stmt::VAArgExprClass: Index: tools/libclang/RecursiveASTVisitor.h =================================================================== --- tools/libclang/RecursiveASTVisitor.h +++ tools/libclang/RecursiveASTVisitor.h @@ -2239,6 +2239,7 @@ DEF_TRAVERSE_STMT(ParenListExpr, { }) DEF_TRAVERSE_STMT(PredefinedExpr, { }) DEF_TRAVERSE_STMT(ShuffleVectorExpr, { }) +DEF_TRAVERSE_STMT(ConvertVectorExpr, { }) DEF_TRAVERSE_STMT(StmtExpr, { }) DEF_TRAVERSE_STMT(UnresolvedLookupExpr, { TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));