From: Steve Naroff Date: Thu, 12 Jul 2007 21:46:55 +0000 (+0000) Subject: Two changes... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c63b96ad706e054a1390dd2ab53af9f05d33bbb1;p=clang Two changes... - Teach all the integer/float predicates on Type about Vectors. - Disallow bitwise compliment on float vectors. For example... typedef float __attribute__(( vector_size(16) )) float4; float4 float4_return() { float4 xx; return ~xx; } ...now emits the following diagnostic... [administrators-powerbook59:~/llvm/tools/clang] admin% ../../Debug/bin/clang bug.c bug.c:8:12: error: invalid argument type to unary expression 'float4' return ~xx; ^ 1 diagnostic generated. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39791 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/AST/Type.cpp b/AST/Type.cpp index cd06c7e783..ded7af4d62 100644 --- a/AST/Type.cpp +++ b/AST/Type.cpp @@ -231,6 +231,8 @@ bool Type::isIntegerType() const { if (const TagType *TT = dyn_cast(CanonicalType)) if (TT->getDecl()->getKind() == Decl::Enum) return true; + if (const VectorType *VT = dyn_cast(CanonicalType)) + return VT->getElementType()->isIntegerType(); return false; } @@ -239,6 +241,8 @@ bool Type::isSignedIntegerType() const { return BT->getKind() >= BuiltinType::Char_S && BT->getKind() <= BuiltinType::LongLong; } + if (const VectorType *VT = dyn_cast(CanonicalType)) + return VT->getElementType()->isSignedIntegerType(); return false; } @@ -247,6 +251,8 @@ bool Type::isUnsignedIntegerType() const { return BT->getKind() >= BuiltinType::Bool && BT->getKind() <= BuiltinType::ULongLong; } + if (const VectorType *VT = dyn_cast(CanonicalType)) + return VT->getElementType()->isUnsignedIntegerType(); return false; } @@ -256,6 +262,8 @@ bool Type::isFloatingType() const { BT->getKind() <= BuiltinType::LongDouble; if (const ComplexType *CT = dyn_cast(CanonicalType)) return CT->isFloatingType(); + if (const VectorType *VT = dyn_cast(CanonicalType)) + return VT->getElementType()->isFloatingType(); return false; } @@ -263,6 +271,8 @@ bool Type::isRealFloatingType() const { if (const BuiltinType *BT = dyn_cast(CanonicalType)) return BT->getKind() >= BuiltinType::Float && BT->getKind() <= BuiltinType::LongDouble; + if (const VectorType *VT = dyn_cast(CanonicalType)) + return VT->getElementType()->isRealFloatingType(); return false; } @@ -272,6 +282,8 @@ bool Type::isRealType() const { BT->getKind() <= BuiltinType::LongDouble; if (const TagType *TT = dyn_cast(CanonicalType)) return TT->getDecl()->getKind() == Decl::Enum; + if (const VectorType *VT = dyn_cast(CanonicalType)) + return VT->getElementType()->isRealType(); return false; } @@ -300,7 +312,8 @@ bool Type::isScalarType() const { return true; return false; } - return isa(CanonicalType) || isa(CanonicalType); + return isa(CanonicalType) || isa(CanonicalType) || + isa(CanonicalType); } bool Type::isAggregateType() const { diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp index 4685468edd..72e2c44a81 100644 --- a/Sema/SemaExpr.cpp +++ b/Sema/SemaExpr.cpp @@ -1312,14 +1312,10 @@ Action::ExprResult Sema::ParseUnaryOp(SourceLocation OpLoc, tok::TokenKind Op, resultType.getAsString()); break; case UnaryOperator::Not: // bitwise complement - if (Input->getType()->isVectorType()) - resultType = Input->getType(); - else { - resultType = UsualUnaryConversions(Input->getType()); - if (!resultType->isIntegerType()) // C99 6.5.3.3p1 - return Diag(OpLoc, diag::err_typecheck_unary_expr, - resultType.getAsString()); - } + resultType = UsualUnaryConversions(Input->getType()); + if (!resultType->isIntegerType()) // C99 6.5.3.3p1 + return Diag(OpLoc, diag::err_typecheck_unary_expr, + resultType.getAsString()); break; case UnaryOperator::LNot: // logical negation // Unlike +/-/~, integer promotions aren't done here (C99 6.5.3.3p5). diff --git a/clang.xcodeproj/project.pbxproj b/clang.xcodeproj/project.pbxproj index 560076196a..6059d2ac79 100644 --- a/clang.xcodeproj/project.pbxproj +++ b/clang.xcodeproj/project.pbxproj @@ -189,7 +189,7 @@ 1A869AA70BA21ABA008DA07A /* LiteralSupport.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = LiteralSupport.cpp; sourceTree = ""; }; 84D9A8870C1A57E100AC7ABC /* AttributeList.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = AttributeList.cpp; path = Parse/AttributeList.cpp; sourceTree = ""; }; 84D9A88B0C1A581300AC7ABC /* AttributeList.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = AttributeList.h; path = clang/Parse/AttributeList.h; sourceTree = ""; }; - 8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = clang; sourceTree = BUILT_PRODUCTS_DIR; }; + 8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = clang; sourceTree = BUILT_PRODUCTS_DIR; }; DE01DA480B12ADA300AC22CE /* PPCallbacks.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PPCallbacks.h; sourceTree = ""; }; DE06756B0C051CFE00EBBFD8 /* ParseExprCXX.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ParseExprCXX.cpp; path = Parse/ParseExprCXX.cpp; sourceTree = ""; }; DE06B73D0A8307640050E87E /* LangOptions.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = LangOptions.h; sourceTree = ""; };