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

Chris Lattner sabre at nondot.org
Sat Aug 22 11:58:31 PDT 2009


Author: lattner
Date: Sat Aug 22 13:58:31 2009
New Revision: 79743

URL: http://llvm.org/viewvc/llvm-project?rev=79743&view=rev
Log:
tweak some pointer sema checking stuff (which was added to implement PR4175) to 
avoid emitting a warning on "someptr > 0".  This is obviously questionable (they 
could use != instead) but is reasonable, and the warning "ordered comparison 
between pointer and integer" didn't make a ton of sense because 0 is a valid 
null pointer constant.

Just silence the warning in this case, it is unlikely to indicate a bug.

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

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat Aug 22 13:58:31 2009
@@ -4350,31 +4350,33 @@
       return ResultTy;
     }
     if (lType->isObjCObjectPointerType() && rType->isObjCObjectPointerType()) {
-      if (!Context.areComparableObjCPointerTypes(lType, rType)) {
+      if (!Context.areComparableObjCPointerTypes(lType, rType))
         Diag(Loc, diag::ext_typecheck_comparison_of_distinct_pointers)
           << lType << rType << lex->getSourceRange() << rex->getSourceRange();
-      }
       ImpCastExprToType(rex, lType);
       return ResultTy;
     }
   }
   if (lType->isAnyPointerType() && rType->isIntegerType()) {
-    if (isRelational)
-      Diag(Loc, diag::ext_typecheck_ordered_comparison_of_pointer_integer)
-        << lType << rType << lex->getSourceRange() << rex->getSourceRange();
-    else if (!RHSIsNull)
-      Diag(Loc, diag::ext_typecheck_comparison_of_pointer_integer)
+    if (!RHSIsNull) {
+      unsigned DiagID = isRelational
+           ? diag::ext_typecheck_ordered_comparison_of_pointer_integer
+           : diag::ext_typecheck_comparison_of_pointer_integer;
+      Diag(Loc, DiagID)
         << lType << rType << lex->getSourceRange() << rex->getSourceRange();
+    }
     ImpCastExprToType(rex, lType); // promote the integer to pointer
     return ResultTy;
   }
   if (lType->isIntegerType() && rType->isAnyPointerType()) {
-    if (isRelational)
-      Diag(Loc, diag::ext_typecheck_ordered_comparison_of_pointer_integer)
-        << lType << rType << lex->getSourceRange() << rex->getSourceRange();
-    else if (!LHSIsNull)
-      Diag(Loc, diag::ext_typecheck_comparison_of_pointer_integer)
+    if (!LHSIsNull) {
+      unsigned DiagID = isRelational
+        ? diag::ext_typecheck_ordered_comparison_of_pointer_integer
+        : diag::ext_typecheck_comparison_of_pointer_integer;
+      
+      Diag(Loc, DiagID)
         << lType << rType << lex->getSourceRange() << rex->getSourceRange();
+    }
     ImpCastExprToType(lex, rType); // promote the integer to pointer
     return ResultTy;
   }

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

==============================================================================
--- cfe/trunk/test/Sema/compare.c (original)
+++ cfe/trunk/test/Sema/compare.c Sat Aug 22 13:58:31 2009
@@ -8,8 +8,7 @@
   return C != 0;
 }
 
-int equal(char *a, const char *b)
-{
+int equal(char *a, const char *b) {
     return a == b;
 }
 
@@ -18,21 +17,18 @@
   return a == b; // expected-warning {{comparison of distinct pointer types}}
 }
 
-int pointers(int *a)
-{
-  return a > 0; // expected-warning {{ordered comparison between pointer and integer}}
+int pointers(int *a) {
+  return a > 0; // no warning.  rdar://7163039
   return a > (void *)0; // expected-warning {{comparison of distinct pointer types}}
 }
 
-int function_pointers(int (*a)(int), int (*b)(int))
-{
+int function_pointers(int (*a)(int), int (*b)(int)) {
   return a > b; // expected-warning {{ordered comparison of function pointers}}
   return function_pointers > function_pointers; // expected-warning {{ordered comparison of function pointers}}
   return a == (void *) 0;
   return a == (void *) 1; // expected-warning {{comparison of distinct pointer types}}
 }
 
-int void_pointers(void *foo)
-{
+int void_pointers(void *foo) {
   return foo == NULL;
 }





More information about the cfe-commits mailing list