diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-05-18 22:42:18 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-05-18 22:42:18 +0000 |
commit | fb4a5436839aae5f5599f2970997e23ee6b895b6 (patch) | |
tree | 8ae0c1e20cfd6a7a6938a58eccb0b2443ffc9c66 /lib/Sema/SemaOverload.cpp | |
parent | b12903e1a4b8d1b611b8c7e4f910665d628e68cd (diff) |
Implement C++ support for vector and extended vector types. This
involves extending implicit conversion sequences to model vector
conversions and vector splats, along with teaching the C++ conditional
operator-checking code about vector types.
Fixes <rdar://problem/7983501>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@104081 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaOverload.cpp')
-rw-r--r-- | lib/Sema/SemaOverload.cpp | 57 |
1 files changed, 55 insertions, 2 deletions
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 4c48e6159c..365daa6018 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -52,6 +52,8 @@ GetConversionCategory(ImplicitConversionKind Kind) { ICC_Conversion, ICC_Conversion, ICC_Conversion, + ICC_Conversion, + ICC_Conversion, ICC_Conversion }; return Category[(int)Kind]; @@ -80,6 +82,8 @@ ImplicitConversionRank GetConversionRank(ImplicitConversionKind Kind) { ICR_Conversion, ICR_Conversion, ICR_Conversion, + ICR_Conversion, + ICR_Conversion, ICR_Complex_Real_Conversion }; return Rank[(int)Kind]; @@ -102,12 +106,14 @@ const char* GetImplicitConversionName(ImplicitConversionKind Kind) { "Floating conversion", "Complex conversion", "Floating-integral conversion", - "Complex-real conversion", "Pointer conversion", "Pointer-to-member conversion", "Boolean conversion", "Compatible-types conversion", - "Derived-to-base conversion" + "Derived-to-base conversion", + "Vector conversion", + "Vector splat", + "Complex-real conversion" }; return Name[Kind]; } @@ -773,6 +779,48 @@ static bool IsNoReturnConversion(ASTContext &Context, QualType FromType, ResultTy = FromType; return true; } + +/// \brief Determine whether the conversion from FromType to ToType is a valid +/// vector conversion. +/// +/// \param ICK Will be set to the vector conversion kind, if this is a vector +/// conversion. +static bool IsVectorConversion(ASTContext &Context, QualType FromType, + QualType ToType, ImplicitConversionKind &ICK) { + // We need at least one of these types to be a vector type to have a vector + // conversion. + if (!ToType->isVectorType() && !FromType->isVectorType()) + return false; + + // Identical types require no conversions. + if (Context.hasSameUnqualifiedType(FromType, ToType)) + return false; + + // There are no conversions between extended vector types, only identity. + if (ToType->isExtVectorType()) { + // There are no conversions between extended vector types other than the + // identity conversion. + if (FromType->isExtVectorType()) + return false; + + // Vector splat from any arithmetic type to a vector. + if (!FromType->isVectorType() && FromType->isArithmeticType()) { + ICK = ICK_Vector_Splat; + return true; + } + } + + // If lax vector conversions are permitted and the vector types are of the + // same size, we can perform the conversion. + if (Context.getLangOptions().LaxVectorConversions && + FromType->isVectorType() && ToType->isVectorType() && + Context.getTypeSize(FromType) == Context.getTypeSize(ToType)) { + ICK = ICK_Vector_Conversion; + return true; + } + + return false; +} /// IsStandardConversion - Determines whether there is a standard /// conversion sequence (C++ [conv], C++ [over.ics.scs]) from the @@ -895,6 +943,7 @@ Sema::IsStandardConversion(Expr* From, QualType ToType, // For overloading in C, this can also be a "compatible-type" // conversion. bool IncompatibleObjC = false; + ImplicitConversionKind SecondICK = ICK_Identity; if (Context.hasSameUnqualifiedType(FromType, ToType)) { // The unqualified versions of the types are the same: there's no // conversion to do. @@ -956,10 +1005,14 @@ Sema::IsStandardConversion(Expr* From, QualType ToType, // Boolean conversions (C++ 4.12). SCS.Second = ICK_Boolean_Conversion; FromType = Context.BoolTy; + } else if (IsVectorConversion(Context, FromType, ToType, SecondICK)) { + SCS.Second = SecondICK; + FromType = ToType.getUnqualifiedType(); } else if (!getLangOptions().CPlusPlus && Context.typesAreCompatible(ToType, FromType)) { // Compatible conversions (Clang extension for C function overloading) SCS.Second = ICK_Compatible_Conversion; + FromType = ToType.getUnqualifiedType(); } else if (IsNoReturnConversion(Context, FromType, ToType, FromType)) { // Treat a conversion that strips "noreturn" as an identity conversion. SCS.Second = ICK_NoReturn_Adjustment; |