[cfe-commits] r51778 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/Sema/init.c

Eli Friedman eli.friedman at gmail.com
Fri May 30 11:07:22 PDT 2008


Author: efriedma
Date: Fri May 30 13:07:22 2008
New Revision: 51778

URL: http://llvm.org/viewvc/llvm-project?rev=51778&view=rev
Log:
Make sure to allow assigning a pointer to a bool.


Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/Sema/init.c

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=51778&r1=51777&r2=51778&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri May 30 13:07:22 2008
@@ -1267,10 +1267,10 @@
 Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) {
   // Get canonical types.  We're not formatting these types, just comparing
   // them.
-  lhsType = lhsType.getCanonicalType();
-  rhsType = rhsType.getCanonicalType();
-  
-  if (lhsType.getUnqualifiedType() == rhsType.getUnqualifiedType())
+  lhsType = lhsType.getCanonicalType().getUnqualifiedType();
+  rhsType = rhsType.getCanonicalType().getUnqualifiedType();
+
+  if (lhsType == rhsType)
     return Compatible; // Common case: fast path an exact match.
 
   if (lhsType->isReferenceType() || rhsType->isReferenceType()) {
@@ -1278,7 +1278,7 @@
       return Compatible;
     return Incompatible;
   }
-  
+
   if (lhsType->isObjCQualifiedIdType() || rhsType->isObjCQualifiedIdType()) {
     if (ObjCQualifiedIdTypesAreCompatible(lhsType, rhsType, false))
       return Compatible;
@@ -1291,7 +1291,7 @@
       if (LV->getElementType().getTypePtr() == rhsType.getTypePtr())
         return Compatible;
     }
-    
+
     // If LHS and RHS are both vectors of integer or both vectors of floating
     // point types, and the total vector length is the same, allow the
     // conversion.  This is a bitcast; no bits are changed but the result type
@@ -1306,14 +1306,14 @@
     }
     return Incompatible;
   }      
-  
+
   if (lhsType->isArithmeticType() && rhsType->isArithmeticType())
     return Compatible;
-  
+
   if (isa<PointerType>(lhsType)) {
     if (rhsType->isIntegerType())
       return IntToPointer;
-      
+
     if (isa<PointerType>(rhsType))
       return CheckPointerTypesForAssignment(lhsType, rhsType);
     return Incompatible;
@@ -1321,14 +1321,17 @@
 
   if (isa<PointerType>(rhsType)) {
     // C99 6.5.16.1p1: the left operand is _Bool and the right is a pointer.
-    if (lhsType->isIntegerType() && lhsType != Context.BoolTy)
+    if (lhsType == Context.BoolTy)
+      return Compatible;
+
+    if (lhsType->isIntegerType())
       return PointerToInt;
 
     if (isa<PointerType>(lhsType)) 
       return CheckPointerTypesForAssignment(lhsType, rhsType);
     return Incompatible;
   }
-  
+
   if (isa<TagType>(lhsType) && isa<TagType>(rhsType)) {
     if (Context.typesAreCompatible(lhsType, rhsType))
       return Compatible;

Modified: cfe/trunk/test/Sema/init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/init.c?rev=51778&r1=51777&r2=51778&view=diff

==============================================================================
--- cfe/trunk/test/Sema/init.c (original)
+++ cfe/trunk/test/Sema/init.c Fri May 30 13:07:22 2008
@@ -42,3 +42,11 @@
 
   return bp;
 }
+
+int pbool(void) {
+  typedef const _Bool cbool;
+  _Bool pbool1 = (void *) 0;
+  cbool pbool2 = &pbool;
+  return pbool2;
+}
+





More information about the cfe-commits mailing list