]> granicus.if.org Git - clang/commitdiff
Fix a problem with false diagnostics when comparing distinct NULL pointer types,...
authorDouglas Gregor <dgregor@apple.com>
Mon, 6 Jul 2009 20:14:23 +0000 (20:14 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 6 Jul 2009 20:14:23 +0000 (20:14 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74850 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/Sema/compare.c

index a5e5083964222d93697410549994c15abe71dc8d..d6e07bb6b39438508bd632213159b1afcdc0126a 100644 (file)
@@ -4110,17 +4110,23 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc,
     QualType RCanPointeeTy =
       Context.getCanonicalType(rType->getAsPointerType()->getPointeeType());
 
-    if (rType->isFunctionPointerType() || lType->isFunctionPointerType()) {
-      if (isRelational) {
+    if (isRelational) {
+      if (lType->isFunctionPointerType() || rType->isFunctionPointerType()) {
         Diag(Loc, diag::ext_typecheck_ordered_comparison_of_function_pointers)
           << lType << rType << lex->getSourceRange() << rex->getSourceRange();
       }
+      if (LCanPointeeTy->isVoidType() != RCanPointeeTy->isVoidType()) {
+        Diag(Loc, diag::ext_typecheck_comparison_of_distinct_pointers)
+          << lType << rType << lex->getSourceRange() << rex->getSourceRange();
+      }
+    } else {
+      if (lType->isFunctionPointerType() != rType->isFunctionPointerType()) {
+        if (!LHSIsNull && !RHSIsNull)
+          Diag(Loc, diag::ext_typecheck_comparison_of_distinct_pointers)
+            << lType << rType << lex->getSourceRange() << rex->getSourceRange();
+      }
     }
-    if (((!LHSIsNull || isRelational) && LCanPointeeTy->isVoidType()) !=
-        ((!RHSIsNull || isRelational) && RCanPointeeTy->isVoidType())) {
-      Diag(Loc, diag::ext_typecheck_comparison_of_distinct_pointers)
-        << lType << rType << lex->getSourceRange() << rex->getSourceRange();
-    }
+
     // Simple check: if the pointee types are identical, we're done.
     if (LCanPointeeTy == RCanPointeeTy)
       return ResultTy;
index 51f77317385ca1674c9155dd5bd1852df49924d9..b7c5c25ddb6f4451ce0acb48f6b5296df293a6a0 100644 (file)
@@ -1,5 +1,7 @@
 // RUN: clang-cc -fsyntax-only -pedantic -verify %s
 
+#include <stddef.h>
+
 int test(char *C) { // nothing here should warn.
   return C != ((void*)0);
   return C != (void*)0;
@@ -29,3 +31,8 @@ int function_pointers(int (*a)(int), int (*b)(int))
   return a == (void *) 0;
   return a == (void *) 1; // expected-warning {{comparison of distinct pointer types}}
 }
+
+int void_pointers(void *foo)
+{
+  return foo == NULL;
+}