Re: [mpich-discuss] Extensible Clang type annotation
On Wed, Jan 2, 2013 at 8:09 PM, Dmitri Gribenko <[email protected]> wrote:
On Wed, Jan 2, 2013 at 8:02 PM, Jed Brown <[email protected]> wrote:
On Wed, Jan 2, 2013 at 11:51 AM, Dmitri Gribenko <[email protected]> wrote:
[resending to the list, sorry for duplicates]
On Wed, Jan 2, 2013 at 7:38 PM, Jed Brown <[email protected]> wrote:
Also, could there be a way (maybe in a future clang release) for me to get static type checking for my own types, such as __float128 or pair types like {long,long} (which are not in the MPI standard)? It can't truly be a static value because I have to create the type at run-time, but perhaps there could be a way to tell clang "I promise to set this type up like so."
Sorry, I did not understand your requirements completely, but you can annotate your own 'MPI_Datatype's (as I described in the previous email). Is that sufficient for your task?
I can't annotate mine because they don't have a static value. (Unless there is a way that's not in the documentation.)
I'm actually just setting
MPI_Datatype MY_MPI_ENUM = MPI_INT;
in a different compilation unit.
Sorry if what I wrote was unclear. Here's a complete example:
$ cat t.cc #include <mpi.h>
enum MyEnum { Foo }; MPI_Datatype MyEnumDatatype MPICH_ATTR_TYPE_TAG(MyEnum);
void foo(MyEnum e, int i) { MPI_Send(&e, 1, MyEnumDatatype, 0, 0, MPI_COMM_WORLD); MPI_Send(&i, 1, MyEnumDatatype, 0, 0, MPI_COMM_WORLD); MPI_Send(&e, 1, MPI_INT, 0, 0, MPI_COMM_WORLD); }
$ clang -fsyntax-only -I mpich2-build/src/include/ t.cc t.cc:8:12: warning: argument type 'int *' doesn't match specified 'MPI' type tag that requires 'MyEnum *' [-Wtype-safety] MPI_Send(&i, 1, MyEnumDatatype, 0, 0, MPI_COMM_WORLD); ^~ ~~~~~~~~~~~~~~ t.cc:9:12: warning: argument type 'MyEnum *' doesn't match specified 'MPI' type tag that requires 'int *' [-Wtype-safety] MPI_Send(&e, 1, MPI_INT, 0, 0, MPI_COMM_WORLD); ^~ ~~~~~~~ 2 warnings generated.
Please note that sending values of enumerated types this way might not be a good idea in general, since the underlying type is implementation-defined (C11 6.7.2.2p, C++11 [dcl.enum]p6, except for enumerations with fixed underlying type). So one can not assume that it is always 'int' (unless one uses enumerations with fixed underlying type). It should be OK if you put a static assertion, though. Dmitri -- main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if (j){printf("%d\n",i);}}} /*Dmitri Gribenko <[email protected]>*/
participants (1)
-
Dmitri Gribenko