]> granicus.if.org Git - clang/commitdiff
teach getCorrespondingUnsignedType how to handle vectors of integers,
authorChris Lattner <sabre@nondot.org>
Sat, 17 Oct 2009 20:33:28 +0000 (20:33 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 17 Oct 2009 20:33:28 +0000 (20:33 +0000)
fixing PR4838.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84353 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ASTContext.cpp
lib/Sema/SemaExpr.cpp
test/Sema/vector-assign.c

index 507baeab27a0eb8703e2ae6131a23d36037673f5..1b77bbe1dbd8cc1f9c71d91e56781b25e8dfb2b5 100644 (file)
@@ -3930,7 +3930,7 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS) {
 unsigned ASTContext::getIntWidth(QualType T) {
   if (T == BoolTy)
     return 1;
-  if (FixedWidthIntTypeFWIT = dyn_cast<FixedWidthIntType>(T)) {
+  if (FixedWidthIntType *FWIT = dyn_cast<FixedWidthIntType>(T)) {
     return FWIT->getWidth();
   }
   // For builtin types, just use the standard type sizing method
@@ -3939,10 +3939,18 @@ unsigned ASTContext::getIntWidth(QualType T) {
 
 QualType ASTContext::getCorrespondingUnsignedType(QualType T) {
   assert(T->isSignedIntegerType() && "Unexpected type");
-  if (const EnumType* ETy = T->getAs<EnumType>())
+  
+  // Turn <4 x signed int> -> <4 x unsigned int>
+  if (const VectorType *VTy = T->getAs<VectorType>())
+    return getVectorType(getCorrespondingUnsignedType(VTy->getElementType()),
+                         VTy->getNumElements());
+
+  // For enums, we return the unsigned version of the base type.
+  if (const EnumType *ETy = T->getAs<EnumType>())
     T = ETy->getDecl()->getIntegerType();
-  const BuiltinType* BTy = T->getAs<BuiltinType>();
-  assert (BTy && "Unexpected signed integer type");
+  
+  const BuiltinType *BTy = T->getAs<BuiltinType>();
+  assert(BTy && "Unexpected signed integer type");
   switch (BTy->getKind()) {
   case BuiltinType::Char_S:
   case BuiltinType::SChar:
index 67058860d6de2c86e9f6d50a1e53640a0a4efcfd..b69e1fbcd6c3e9280595f4adb7ccd4c07b6885b2 100644 (file)
@@ -3753,16 +3753,16 @@ Sema::CheckPointerTypesForAssignment(QualType lhsType, QualType rhsType) {
     // Check if the pointee types are compatible ignoring the sign.
     // We explicitly check for char so that we catch "char" vs
     // "unsigned char" on systems where "char" is unsigned.
-    if (lhptee->isCharType()) {
+    if (lhptee->isCharType())
       lhptee = Context.UnsignedCharTy;
-    } else if (lhptee->isSignedIntegerType()) {
+    else if (lhptee->isSignedIntegerType())
       lhptee = Context.getCorrespondingUnsignedType(lhptee);
-    }
-    if (rhptee->isCharType()) {
+    
+    if (rhptee->isCharType())
       rhptee = Context.UnsignedCharTy;
-    } else if (rhptee->isSignedIntegerType()) {
+    else if (rhptee->isSignedIntegerType())
       rhptee = Context.getCorrespondingUnsignedType(rhptee);
-    }
+
     if (lhptee == rhptee) {
       // Types are compatible ignoring the sign. Qualifier incompatibility
       // takes priority over sign incompatibility because the sign
index 5162e1a41c2117fc5eddaaf3f7148445ef2726df..bf9c7f37ca6dcb2be6c2c1cc658cc4f64a7e14f4 100644 (file)
@@ -5,7 +5,7 @@ typedef signed int v1s __attribute__ ((vector_size (4)));
 typedef float v2f __attribute__ ((vector_size(8)));
 typedef signed short v4ss __attribute__ ((vector_size (8)));
 
-void f() {
+void test1() {
   v2s v1;
   v2u v2;
   v1s v3;
@@ -39,7 +39,15 @@ void f() {
 }
 
 // PR2263
-float f2(__attribute__((vector_size(16))) float a, int b) {
+float test2(__attribute__((vector_size(16))) float a, int b) {
    return a[b];
 }
 
+// PR4838
+typedef long long __attribute__((__vector_size__(2 * sizeof(long long))))
+longlongvec;
+
+void test3a(longlongvec *);
+void test3(const unsigned *src) {
+  test3a(src);  // expected-warning {{incompatible pointer types passing 'unsigned int const *', expected 'longlongvec *'}}
+}