From: Douglas Gregor Date: Tue, 22 Jun 2010 23:41:02 +0000 (+0000) Subject: Vector types are not arithmetic types, either. Note that we now ban X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=00619623af0b9d3271e31402ec1a95e84c2c4526;p=clang Vector types are not arithmetic types, either. Note that we now ban __real myvec and __imag myvec, since they aren't all that useful (it's just an identity function) but we might want to use them in more restricted cases in the future (e.g., "__real mycomplexvec" could extract the real parts of a vector of complex numbers). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106601 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index af4b7eb3a6..5a7aa89d6d 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -596,7 +596,7 @@ bool Type::isArithmeticType() const { // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2). // If a body isn't seen by the time we get here, return false. return ET->getDecl()->isDefinition(); - return isa(CanonicalType) || isa(CanonicalType); + return isa(CanonicalType); } bool Type::isScalarType() const { diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index eb66d9d6c0..e5c8e973c5 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -4626,7 +4626,7 @@ Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) { if (lhsType->isExtVectorType()) { if (rhsType->isExtVectorType()) return lhsType == rhsType ? Compatible : Incompatible; - if (!rhsType->isVectorType() && rhsType->isArithmeticType()) + if (rhsType->isArithmeticType()) return Compatible; } @@ -6511,7 +6511,8 @@ Action::OwningExprResult Sema::CreateBuiltinUnaryOp(SourceLocation OpLoc, resultType = Input->getType(); if (resultType->isDependentType()) break; - if (resultType->isArithmeticType()) // C99 6.5.3.3p1 + if (resultType->isArithmeticType() || // C99 6.5.3.3p1 + resultType->isVectorType()) break; else if (getLangOptions().CPlusPlus && // C++ [expr.unary.op]p6-7 resultType->isEnumeralType()) diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 61d42f083c..317e8cd6d3 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -845,7 +845,7 @@ static bool IsVectorConversion(ASTContext &Context, QualType FromType, return false; // Vector splat from any arithmetic type to a vector. - if (!FromType->isVectorType() && FromType->isArithmeticType()) { + if (FromType->isArithmeticType()) { ICK = ICK_Vector_Splat; return true; } @@ -1041,8 +1041,7 @@ Sema::IsStandardConversion(Expr* From, QualType ToType, FromType->isAnyPointerType() || FromType->isBlockPointerType() || FromType->isMemberPointerType() || - FromType->isNullPtrType()) && - /*FIXME*/!FromType->isVectorType()) { + FromType->isNullPtrType())) { // Boolean conversions (C++ 4.12). SCS.Second = ICK_Boolean_Conversion; FromType = Context.BoolTy; diff --git a/test/Sema/ext_vector_casts.c b/test/Sema/ext_vector_casts.c index 7b7b0caf0a..143ce04e21 100644 --- a/test/Sema/ext_vector_casts.c +++ b/test/Sema/ext_vector_casts.c @@ -48,4 +48,5 @@ typedef __attribute__(( ext_vector_type(2) )) float2 vecfloat2; // expected-erro void inc(float2 f2) { f2++; // expected-error{{cannot increment value of type 'float2'}} + __real f2; // expected-error{{invalid type 'float2' to __real operator}} } diff --git a/test/Sema/init.c b/test/Sema/init.c index c2c29ad9b0..ac274a4ce2 100644 --- a/test/Sema/init.c +++ b/test/Sema/init.c @@ -118,8 +118,6 @@ int* ptest1 = __builtin_choose_expr(1, (int*)0, (int*)0); typedef int32_t ivector4 __attribute((vector_size(16))); ivector4 vtest1 = 1 ? (ivector4){1} : (ivector4){1}; ivector4 vtest2 = __builtin_choose_expr(1, (ivector4){1}, (ivector4){1}); -ivector4 vtest3 = __real__ (ivector4){1}; -ivector4 vtest4 = __imag__ (ivector4){1}; uintptr_t ptrasintadd1 = (uintptr_t)&a - 4; uintptr_t ptrasintadd2 = (uintptr_t)&a + 4;