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

Douglas Gregor dgregor at apple.com
Mon Jul 6 13:14:33 PDT 2009


Author: dgregor
Date: Mon Jul  6 15:14:23 2009
New Revision: 74850

URL: http://llvm.org/viewvc/llvm-project?rev=74850&view=rev
Log:
Fix a problem with false diagnostics when comparing distinct NULL pointer types, from David Majnemer

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=74850&r1=74849&r2=74850&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Jul  6 15:14:23 2009
@@ -4110,17 +4110,23 @@
     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;

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

==============================================================================
--- cfe/trunk/test/Sema/compare.c (original)
+++ cfe/trunk/test/Sema/compare.c Mon Jul  6 15:14:23 2009
@@ -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 @@
   return a == (void *) 0;
   return a == (void *) 1; // expected-warning {{comparison of distinct pointer types}}
 }
+
+int void_pointers(void *foo)
+{
+  return foo == NULL;
+}





More information about the cfe-commits mailing list