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

Steve Naroff snaroff at apple.com
Wed Jul 11 09:46:42 PDT 2007


Author: snaroff
Date: Wed Jul 11 11:46:42 2007
New Revision: 39654

URL: http://llvm.org/viewvc/llvm-project?rev=39654&view=rev
Log:
Bug #:
Submitted by:
Reviewed by:
Fix CheckRelationalOperands/CheckEqualityOperands to deal with null pointer
constants. The new logic also deals (more) correctly for non-pointer/integer
operands.

Modified:
    cfe/cfe/trunk/Sema/SemaExpr.cpp

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

==============================================================================
--- cfe/cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaExpr.cpp Wed Jul 11 11:46:42 2007
@@ -813,12 +813,22 @@
   if (lType->isRealType() && rType->isRealType())
     return Context.IntTy;
   
-  if (lType->isPointerType() &&  rType->isPointerType())
-    return Context.IntTy;
-
-  if (lType->isIntegerType() || rType->isIntegerType()) { // GCC extension.
-    Diag(loc, diag::ext_typecheck_comparison_of_pointer_integer);
-    return Context.IntTy;
+  if (lType->isPointerType()) {
+    if (rType->isPointerType())
+      return Context.IntTy;
+    if (rType->isIntegerType()) {
+      if (!rex->isNullPointerConstant())
+        Diag(loc, diag::ext_typecheck_comparison_of_pointer_integer,
+             lex->getSourceRange(), rex->getSourceRange());
+      return Context.IntTy; // the previous diagnostic is a GCC extension.
+    }
+  } else if (rType->isPointerType()) {
+    if (lType->isIntegerType()) {
+      if (!lex->isNullPointerConstant())
+        Diag(loc, diag::ext_typecheck_comparison_of_pointer_integer,
+             lex->getSourceRange(), rex->getSourceRange());
+      return Context.IntTy; // the previous diagnostic is a GCC extension.
+    }
   }
   InvalidOperands(loc, lex, rex);
   return QualType();
@@ -832,12 +842,23 @@
   
   if (lType->isArithmeticType() && rType->isArithmeticType())
     return Context.IntTy;
-  if (lType->isPointerType() &&  rType->isPointerType())
-    return Context.IntTy;
     
-  if (lType->isIntegerType() || rType->isIntegerType()) { // GCC extension.
-    Diag(loc, diag::ext_typecheck_comparison_of_pointer_integer);
-    return Context.IntTy;
+  if (lType->isPointerType()) {
+    if (rType->isPointerType())
+      return Context.IntTy;
+    if (rType->isIntegerType()) {
+      if (!rex->isNullPointerConstant())
+        Diag(loc, diag::ext_typecheck_comparison_of_pointer_integer,
+             lex->getSourceRange(), rex->getSourceRange());
+      return Context.IntTy; // the previous diagnostic is a GCC extension.
+    }
+  } else if (rType->isPointerType()) {
+    if (lType->isIntegerType()) {
+      if (!lex->isNullPointerConstant())
+        Diag(loc, diag::ext_typecheck_comparison_of_pointer_integer,
+             lex->getSourceRange(), rex->getSourceRange());
+      return Context.IntTy; // the previous diagnostic is a GCC extension.
+    }
   }
   InvalidOperands(loc, lex, rex);
   return QualType();





More information about the cfe-commits mailing list