[cfe-users] Type safety checking for MPI_2INT

Junchao Zhang junchao.zhang at gmail.com
Sat Dec 28 10:31:00 PST 2013

Dear Clang developers,
  We met a problem in MPI type tag checking for MPI_2INT. In MPICH, we use
this Clang extension as follows:

#define MPI_2INT                           ((MPI_Datatype)0x4c000816
struct mpich_struct_mpi_2int            { int i1; int i2; };
static const MPI_Datatype mpich_mpi_2int
 MPICH_ATTR_TYPE_TAG_LAYOUT_COMPATIBLE(struct mpich_struct_mpi_2int)
     = MPI_2INT;
int MPI_Send(const void *buf, int count, MPI_Datatype datatype, int dest,
int tag,
             MPI_Comm comm) MPICH_ATTR_POINTER_WITH_TYPE_TAG(1,3)

In a program, we have such code and it works fine.

struct {int value; int loc; } in;
MPI_Send(&in, 1, MPI_2INT,...);

But if we write it in other ways, there are warnings.

int in[2];
MPI_Send(in, 1, MPI_2INT,...); // warning: argument type 'int *' doesn't
match specified 'MPI' type tag [-Wtype-safety]


typedef int intpair[2];
intpair in;
MPI_Send(&in, 1, MPI_2INT, ...); // warning: argument type 'intpair *' (aka
'int (*)[2]') doesn't match specified 'MPI' type tag [-Wtype-safety]

Since struct {int i1; int i2} is guaranteed to have the same layout as
int[2]. It seems Clang has generated erroneous warnings in this case. Is it

--Junchao Zhang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20131228/290e628a/attachment.html>

More information about the cfe-users mailing list