[cfe-commits] r167358 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/Sema/warn-type-safety-mpi-hdf5.c test/Sema/warn-type-safety.c test/Sema/warn-type-safety.cpp

Dmitri Gribenko gribozavr at gmail.com
Sat Nov 3 09:07:49 PDT 2012


Author: gribozavr
Date: Sat Nov  3 11:07:49 2012
New Revision: 167358

URL: http://llvm.org/viewvc/llvm-project?rev=167358&view=rev
Log:
Handle CK_NullToPointer casts in -Wtype-safety properly.  Fixes PR14249.

Modified:
    cfe/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/test/Sema/warn-type-safety-mpi-hdf5.c
    cfe/trunk/test/Sema/warn-type-safety.c
    cfe/trunk/test/Sema/warn-type-safety.cpp

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=167358&r1=167357&r2=167358&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Sat Nov  3 11:07:49 2012
@@ -6189,7 +6189,9 @@
   if (IsPointerAttr) {
     // Skip implicit cast of pointer to `void *' (as a function argument).
     if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(ArgumentExpr))
-      if (ICE->getType()->isVoidPointerType())
+      if (ICE->getType()->isVoidPointerType() &&
+          ICE->getCastKind() != CK_NullToPointer &&
+          ICE->getCastKind() != CK_NullToMemberPointer)
         ArgumentExpr = ICE->getSubExpr();
   }
   QualType ArgumentType = ArgumentExpr->getType();

Modified: cfe/trunk/test/Sema/warn-type-safety-mpi-hdf5.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-type-safety-mpi-hdf5.c?rev=167358&r1=167357&r2=167358&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-type-safety-mpi-hdf5.c (original)
+++ cfe/trunk/test/Sema/warn-type-safety-mpi-hdf5.c Sat Nov  3 11:07:49 2012
@@ -147,6 +147,10 @@
   // Layout-compatible scalar types.
   MPI_Send(int_buf,   1, MPI_INT); // no-warning
 
+  // Null pointer constant.
+  MPI_Send(0,         0, MPI_INT); // no-warning
+  MPI_Send(NULL,      0, MPI_INT); // no-warning
+
   // Layout-compatible class types.
   MPI_Send(pfi, 1, MPI_FLOAT_INT); // no-warning
   MPI_Send(pii, 1, MPI_2INT); // no-warning

Modified: cfe/trunk/test/Sema/warn-type-safety.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-type-safety.c?rev=167358&r1=167357&r2=167358&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-type-safety.c (original)
+++ cfe/trunk/test/Sema/warn-type-safety.c Sat Nov  3 11:07:49 2012
@@ -80,6 +80,14 @@
   C_func(ptr, 20); // should warn, but may cause false positives
 }
 
+void test_null_pointer()
+{
+  C_func(0, C_tag); // no-warning
+  C_func((void *) 0, C_tag); // no-warning
+  C_func((int *) 0, C_tag); // no-warning
+  C_func((long *) 0, C_tag); // expected-warning {{argument type 'long *' doesn't match specified 'c' type tag that requires 'int *'}}
+}
+
 // Check that we look through typedefs in the special case of allowing 'char'
 // to be matched with 'signed char' or 'unsigned char'.
 void E_func(void *ptr, int tag) __attribute__(( pointer_with_type_tag(e,1,2) ));

Modified: cfe/trunk/test/Sema/warn-type-safety.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-type-safety.cpp?rev=167358&r1=167357&r2=167358&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-type-safety.cpp (original)
+++ cfe/trunk/test/Sema/warn-type-safety.cpp Sat Nov  3 11:07:49 2012
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
 
 typedef struct ompi_datatype_t *MPI_Datatype;
 
@@ -52,6 +52,8 @@
 {
   c->MPI_Send(int_buf, 1, MPI_INT); // no-warning
   c->MPI_Send(int_buf, 1, MPI_FLOAT); // expected-warning {{argument type 'int *' doesn't match specified 'mpi' type tag that requires 'float *'}}
+  c->MPI_Send(0, 0, MPI_INT); // no-warning
+  c->MPI_Send(nullptr, 0, MPI_INT); // no-warning
 
   OperatorIntStar i;
   c->MPI_Send(i, 1, MPI_INT); // no-warning





More information about the cfe-commits mailing list