]> granicus.if.org Git - clang/commitdiff
Two changes...
authorSteve Naroff <snaroff@apple.com>
Thu, 12 Jul 2007 21:46:55 +0000 (21:46 +0000)
committerSteve Naroff <snaroff@apple.com>
Thu, 12 Jul 2007 21:46:55 +0000 (21:46 +0000)
- 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

AST/Type.cpp
Sema/SemaExpr.cpp
clang.xcodeproj/project.pbxproj

index cd06c7e7832bbad9d4c847e8353fff2c4079f5a1..ded7af4d6231fdca5c66cf106bb1230e9435775f 100644 (file)
@@ -231,6 +231,8 @@ bool Type::isIntegerType() const {
   if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
     if (TT->getDecl()->getKind() == Decl::Enum)
       return true;
+  if (const VectorType *VT = dyn_cast<VectorType>(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<VectorType>(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<VectorType>(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<ComplexType>(CanonicalType))
     return CT->isFloatingType();
+  if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
+    return VT->getElementType()->isFloatingType();
   return false;
 }
 
@@ -263,6 +271,8 @@ bool Type::isRealFloatingType() const {
   if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
     return BT->getKind() >= BuiltinType::Float &&
            BT->getKind() <= BuiltinType::LongDouble;
+  if (const VectorType *VT = dyn_cast<VectorType>(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<TagType>(CanonicalType))
     return TT->getDecl()->getKind() == Decl::Enum;
+  if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
+    return VT->getElementType()->isRealType();
   return false;
 }
 
@@ -300,7 +312,8 @@ bool Type::isScalarType() const {
       return true;
     return false;
   }
-  return isa<PointerType>(CanonicalType) || isa<ComplexType>(CanonicalType);
+  return isa<PointerType>(CanonicalType) || isa<ComplexType>(CanonicalType) ||
+         isa<VectorType>(CanonicalType);
 }
 
 bool Type::isAggregateType() const {
index 4685468eddf5c905d6352ed1a884ecb2adb55a2f..72e2c44a81ba2d335c0204ab8a93f3dc2e97c6fb 100644 (file)
@@ -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).
index 560076196ae1d974557e7afbc5b596fea14a62a5..6059d2ac79eefbca737b5bd881fcf8a670180fc4 100644 (file)
                1A869AA70BA21ABA008DA07A /* LiteralSupport.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = LiteralSupport.cpp; sourceTree = "<group>"; };
                84D9A8870C1A57E100AC7ABC /* AttributeList.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = AttributeList.cpp; path = Parse/AttributeList.cpp; sourceTree = "<group>"; };
                84D9A88B0C1A581300AC7ABC /* AttributeList.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = AttributeList.h; path = clang/Parse/AttributeList.h; sourceTree = "<group>"; };
-               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 = "<group>"; };
                DE06756B0C051CFE00EBBFD8 /* ParseExprCXX.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ParseExprCXX.cpp; path = Parse/ParseExprCXX.cpp; sourceTree = "<group>"; };
                DE06B73D0A8307640050E87E /* LangOptions.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = LangOptions.h; sourceTree = "<group>"; };