[cfe-commits] r45666 - /cfe/trunk/Sema/SemaExpr.cpp

Chris Lattner sabre at nondot.org
Sun Jan 6 14:50:32 PST 2008


Author: lattner
Date: Sun Jan  6 16:50:31 2008
New Revision: 45666

URL: http://llvm.org/viewvc/llvm-project?rev=45666&view=rev
Log:
rearrange some code.

Modified:
    cfe/trunk/Sema/SemaExpr.cpp

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

==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Sun Jan  6 16:50:31 2008
@@ -789,16 +789,8 @@
   if (lexT->isVoidType() && rexT->isVoidType())
     return lexT.getUnqualifiedType();
   
-  // C99 6.5.15p6 - "if one operand is a null pointer constant, the result has
-  // the type of the other operand."
-  if (lexT->isPointerType() && rex->isNullPointerConstant(Context)) {
-    promoteExprToType(rex, lexT); // promote the null to a pointer.
-    return lexT;
-  }
-  if (rexT->isPointerType() && lex->isNullPointerConstant(Context)) {
-    promoteExprToType(lex, rexT); // promote the null to a pointer.
-    return rexT;
-  }
+  // 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 = lexT->getAsPointerType()) { // C99 6.5.15p3,6
     if (const PointerType *RHSPT = rexT->getAsPointerType()) {
       // get the "pointed to" types
@@ -825,10 +817,23 @@
       // differently qualified versions of compatible types, the result type is
       // a pointer to an appropriately qualified version of the *composite*
       // type.
-      return lexT; // FIXME: Need to return the composite type.
+      // FIXME: Need to return the composite type.
+      return lexT;
     }
   }
   
+  // C99 6.5.15p6 - "if one operand is a null pointer constant, the result has
+  // the type of the other operand."
+  if (lexT->isPointerType() && rex->isNullPointerConstant(Context)) {
+    promoteExprToType(rex, lexT); // promote the null to a pointer.
+    return lexT;
+  }
+  
+  if (rexT->isPointerType() && lex->isNullPointerConstant(Context)) {
+    promoteExprToType(lex, rexT); // promote the null to a pointer.
+    return rexT;
+  }
+  
   // Otherwise, the operands are not compatible.
   Diag(questionLoc, diag::err_typecheck_cond_incompatible_operands,
        lexT.getAsString(), rexT.getAsString(),





More information about the cfe-commits mailing list