[cfe-commits] r64885 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaObjC/exprs.m

Chris Lattner sabre at nondot.org
Tue Feb 17 20:38:21 PST 2009


Author: lattner
Date: Tue Feb 17 22:38:20 2009
New Revision: 64885

URL: http://llvm.org/viewvc/llvm-project?rev=64885&view=rev
Log:
fix rdar://6597252: two exactly identical pointer types are always
compatible, even if they are weird implicit objc pointer types like
Class.

Added:
    cfe/trunk/test/SemaObjC/exprs.m
Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Feb 17 22:38:20 2009
@@ -2218,8 +2218,9 @@
 
 /// Note that lex is not null here, even if this is the gnu "x ?: y" extension.
 /// In that case, lex = cond.
-inline QualType Sema::CheckConditionalOperands( // C99 6.5.15
-  Expr *&Cond, Expr *&LHS, Expr *&RHS, SourceLocation QuestionLoc) {
+/// C99 6.5.15
+QualType Sema::CheckConditionalOperands(Expr *&Cond, Expr *&LHS, Expr *&RHS,
+                                        SourceLocation QuestionLoc) {
   UsualUnaryConversions(Cond);
   UsualUnaryConversions(LHS);
   UsualUnaryConversions(RHS);
@@ -2284,6 +2285,7 @@
     ImpCastExprToType(LHS, RHSTy); // promote the null to a pointer.
     return RHSTy;
   }
+  
   // Handle the case where both operands are pointers before we handle null
   // pointer constants in case both operands are null pointer constants.
   if (const PointerType *LHSPT = LHSTy->getAsPointerType()) { // C99 6.5.15p3,6
@@ -2310,6 +2312,11 @@
         return destType;
       }
 
+      if (Context.getCanonicalType(LHSTy) == Context.getCanonicalType(RHSTy)) {
+        // Two identical pointers types are always compatible.
+        return LHSTy;
+      }
+        
       QualType compositeType = LHSTy;
       
       // If either type is an Objective-C object type then check
@@ -2373,6 +2380,12 @@
       return compositeType;
     }
   }
+  
+  // Selection between block pointer types is ok as long as they are the same.
+  if (LHSTy->isBlockPointerType() && RHSTy->isBlockPointerType() &&
+      Context.getCanonicalType(LHSTy) == Context.getCanonicalType(RHSTy))
+    return LHSTy;
+  
   // Need to handle "id<xx>" explicitly. Unlike "id", whose canonical type
   // evaluates to "struct objc_object *" (and is handled above when comparing
   // id with statically typed objects). 
@@ -2398,11 +2411,6 @@
     }
   }
 
-  // Selection between block pointer types is ok as long as they are the same.
-  if (LHSTy->isBlockPointerType() && RHSTy->isBlockPointerType() &&
-      Context.getCanonicalType(LHSTy) == Context.getCanonicalType(RHSTy))
-    return LHSTy;
-
   // Otherwise, the operands are not compatible.
   Diag(QuestionLoc, diag::err_typecheck_cond_incompatible_operands)
     << LHSTy << RHSTy << LHS->getSourceRange() << RHS->getSourceRange();

Added: cfe/trunk/test/SemaObjC/exprs.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/exprs.m?rev=64885&view=auto

==============================================================================
--- cfe/trunk/test/SemaObjC/exprs.m (added)
+++ cfe/trunk/test/SemaObjC/exprs.m Tue Feb 17 22:38:20 2009
@@ -0,0 +1,7 @@
+// RUN: clang %s -fsyntax-only
+
+// rdar://6597252
+Class foo(Class X) {
+  return 1 ? X : X;
+}
+





More information about the cfe-commits mailing list