diff options
-rw-r--r-- | lib/Sema/SemaChecking.cpp | 4 | ||||
-rw-r--r-- | test/Sema/warn-type-safety-mpi-hdf5.c | 4 | ||||
-rw-r--r-- | test/Sema/warn-type-safety.c | 8 | ||||
-rw-r--r-- | test/Sema/warn-type-safety.cpp | 4 |
4 files changed, 18 insertions, 2 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 6a39ff003c..4a5e8e05c7 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -6189,7 +6189,9 @@ void Sema::CheckArgumentWithTypeTag(const ArgumentWithTypeTagAttr *Attr, 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(); diff --git a/test/Sema/warn-type-safety-mpi-hdf5.c b/test/Sema/warn-type-safety-mpi-hdf5.c index 9c2ee96586..8c50cb24bb 100644 --- a/test/Sema/warn-type-safety-mpi-hdf5.c +++ b/test/Sema/warn-type-safety-mpi-hdf5.c @@ -147,6 +147,10 @@ void test_mpi_predefined_types( // 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 diff --git a/test/Sema/warn-type-safety.c b/test/Sema/warn-type-safety.c index 6f548aa256..4ac453d380 100644 --- a/test/Sema/warn-type-safety.c +++ b/test/Sema/warn-type-safety.c @@ -80,6 +80,14 @@ void test_tag_mismatch(int *ptr) 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) )); diff --git a/test/Sema/warn-type-safety.cpp b/test/Sema/warn-type-safety.cpp index d053fbaa21..a73a9d9d2a 100644 --- a/test/Sema/warn-type-safety.cpp +++ b/test/Sema/warn-type-safety.cpp @@ -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 @@ void test1(C *c, int *int_buf) { 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 |