[mpich2-dev] [PATCH 1/1] Issue 4120: Fix 8-byte MPI_Aint compile warnings

Jeff Parker jjparker at us.ibm.com
Mon Mar 31 21:41:24 CDT 2008


Fixed compiler warnings by using the configurable cast macros for MPI_Aint.

Signed-off-by: Jeff Parker <jjparker at us.ibm.com>
---
 lib/mpi/mpich2/src/binding/f77/buildiface          |   12 ++--
 lib/mpi/mpich2/src/mpi/datatype/type_get_name.c    |    2 +-
 .../mpid/common/datatype/dataloop/segment_ops.c    |   53 +++++++++++++-------
 lib/mpi/mpich2/src/util/mem/handlemem.c            |    4 +-
 4 files changed, 43 insertions(+), 28 deletions(-)

diff --git a/lib/mpi/mpich2/src/binding/f77/buildiface b/lib/mpi/mpich2/src/binding/f77/buildiface
index f5564b6..a08afa9 100755
--- a/lib/mpi/mpich2/src/binding/f77/buildiface
+++ b/lib/mpi/mpich2/src/binding/f77/buildiface
@@ -1388,7 +1388,7 @@ sub addrint_in_decl {
 }
 sub addrint_in_arg {
     my $count = $_[0];
-    print $OUTFD "(void *)(MPI_Aint)((int)*(int *)v$count)";
+    print $OUTFD "MPI_AINT_CAST_TO_VOID_PTR(MPI_Aint)((int)*(int *)v$count)";
 }
 
 sub attrint_ctof {
@@ -1402,7 +1402,7 @@ sub attrint_ctof {
         *(MPI_Fint*)$cvar = 0;
     }
     else {
-        *(MPI_Fint*)$cvar = (MPI_Fint)(MPI_Aint)attr$cvar;
+        *(MPI_Fint*)$cvar = (MPI_Fint)MPI_VOID_PTR_CAST_TO_MPI_AINT attr$cvar;
     }\n";
 }
 
@@ -1428,7 +1428,7 @@ sub addraint_in_decl {
 }
 sub addraint_in_arg {
     my $count = $_[0];
-    print $OUTFD "(void *)(MPI_Aint)((MPI_Aint)*(MPI_Aint *)v$count)";
+    print $OUTFD "MPI_AINT_CAST_TO_VOID_PTR(MPI_Aint)((MPI_Aint)*(MPI_Aint *)v$count)";
 }
 
 sub attraint_ctof {
@@ -1440,7 +1440,7 @@ sub attraint_ctof {
         *(MPI_Aint*)$cvar = 0;
     }
     else {
-        *(MPI_Aint*)$cvar = (MPI_Aint)attr$cvar;
+        *(MPI_Aint*)$cvar = MPI_VOID_PTR_CAST_TO_MPI_AINT attr$cvar;
     }\n";
 }
 
@@ -2622,7 +2622,7 @@ FORT_DLL_SPEC void FORT_CALL mpirinitc2_( char *a FORT_MIXED_LEN(d1)
 #ifdef USE_POINTER_FOR_BOTTOM
     b = a;
 #else
-    b = a - (MPI_Aint) MPIR_F_MPI_BOTTOM;
+    b = a - MPI_VOID_PTR_CAST_TO_MPI_AINT MPIR_F_MPI_BOTTOM;
 #endif
     *v2 = (MPI_Fint)( b );
 #ifdef HAVE_AINT_LARGER_THAN_FINT
@@ -2661,7 +2661,7 @@ FORT_DLL_SPEC void FORT_CALL mpirinitc2_( char *a FORT_MIXED_LEN(d1)
     &specialInitStatement( $OUTFD );
     print $OUTFD "\
 #ifndef USE_POINTER_FOR_BOTTOM
-    a = a - (MPI_Aint) MPIR_F_MPI_BOTTOM;
+    a = a - MPI_VOID_PTR_CAST_TO_MPI_AINT MPIR_F_MPI_BOTTOM;
 #endif
     *v2 =  a;
 }\n";
diff --git a/lib/mpi/mpich2/src/mpi/datatype/type_get_name.c b/lib/mpi/mpich2/src/mpi/datatype/type_get_name.c
index 2783de0..fbba673 100644
--- a/lib/mpi/mpich2/src/mpi/datatype/type_get_name.c
+++ b/lib/mpi/mpich2/src/mpi/datatype/type_get_name.c
@@ -147,7 +147,7 @@ int MPIR_Datatype_init_names( void )
 	    }
 
 	    MPIU_DBG_MSG_FMT(DATATYPE,VERBOSE,(MPIU_DBG_FDEST,
-		   "mpi_names[%d].name = %x\n", i, (unsigned) (MPI_Aint)mpi_names[i].name )); 
+		   "mpi_names[%d].name = %p\n", i, mpi_names[i].name )); 
 	    
 	    MPIU_Strncpy( datatype_ptr->name, mpi_names[i].name, 
 			  MPI_MAX_OBJECT_NAME );
diff --git a/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/segment_ops.c b/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/segment_ops.c
index 9087f54..6fe799f 100644
--- a/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/segment_ops.c
+++ b/lib/mpi/mpich2/src/mpid/common/datatype/dataloop/segment_ops.c
@@ -671,7 +671,7 @@ static int DLOOP_Segment_vector_mpi_flatten(DLOOP_Offset *blocks_p,
     struct PREPEND_PREFIX(mpi_flatten_params) *paramp = v_paramp;
 
     DLOOP_Handle_get_size_macro(el_type, el_size);
-    blocks_left = *blocks_p;
+    blocks_left = (int)*blocks_p;
 
     for (i=0; i < count && blocks_left > 0; i++) {
 	int last_idx;
@@ -689,31 +689,37 @@ static int DLOOP_Segment_vector_mpi_flatten(DLOOP_Offset *blocks_p,
 
 	last_idx = paramp->index - 1;
 	if (last_idx >= 0) {
-	    last_end = ((char *) paramp->disps[last_idx]) +
-		paramp->blklens[last_idx];
+	    MPID_Ensure_Aint_fits_in_pointer( paramp->disps[last_idx] +
+					      (MPI_Aint)(paramp->blklens[last_idx]) );
+	    last_end = (char *) MPI_AINT_CAST_TO_VOID_PTR 
+		       ( paramp->disps[last_idx] +
+			 (MPI_Aint)(paramp->blklens[last_idx]) );
 	}
 
+	MPID_Ensure_Aint_fits_in_pointer( MPI_VOID_PTR_CAST_TO_MPI_AINT bufp + rel_off );
 	if ((last_idx == paramp->length-1) &&
-	    (last_end != ((char *) bufp + rel_off)))
+	    (last_end != (char *) MPI_AINT_CAST_TO_VOID_PTR 
+	                 ( MPI_VOID_PTR_CAST_TO_MPI_AINT bufp + rel_off) ) )
 	{
 	    /* we have used up all our entries, and this one doesn't fit on
 	     * the end of the last one.
 	     */
 	    *blocks_p -= (blocks_left + (size / (int) el_size));
 #ifdef MPID_SP_VERBOSE
-	    MPIU_dbg_printf("\t[vector to vec exiting (1): next ind = %d, %d blocks processed.\n",
+	    MPIU_dbg_printf("\t[vector to vec exiting (1): next ind = %d, " MPI_AINT_FMT_DEC_SPEC " blocks processed.\n",
 			    paramp->u.pack_vector.index,
-			    (int) *blocks_p);
+			    *blocks_p);
 #endif
 	    return 1;
 	}
-	else if (last_idx >= 0 && (last_end == ((char *) bufp + rel_off)))
+	else if (last_idx >= 0 && (last_end == (char *) MPI_AINT_CAST_TO_VOID_PTR 
+ 	                                       ( MPI_VOID_PTR_CAST_TO_MPI_AINT bufp + rel_off ) ) )
 	{
 	    /* add this size to the last vector rather than using up new one */
 	    paramp->blklens[last_idx] += size;
 	}
 	else {
-	    paramp->disps[last_idx+1]   = (MPI_Aint) ((char *) bufp + rel_off);
+	    paramp->disps[last_idx+1]   = MPI_VOID_PTR_CAST_TO_MPI_AINT bufp + rel_off;
 	    paramp->blklens[last_idx+1] = size;
 	    paramp->index++;
 	}
@@ -722,9 +728,9 @@ static int DLOOP_Segment_vector_mpi_flatten(DLOOP_Offset *blocks_p,
     }
 
 #ifdef MPID_SP_VERBOSE
-    MPIU_dbg_printf("\t[vector to vec exiting (2): next ind = %d, %d blocks processed.\n",
+    MPIU_dbg_printf("\t[vector to vec exiting (2): next ind = %d, " MPI_AINT_FMT_DEC_SPEC " blocks processed.\n",
 		    paramp->u.pack_vector.index,
-		    (int) *blocks_p);
+		    *blocks_p);
 #endif
 
     /* if we get here then we processed ALL the blocks; don't need to update
@@ -774,7 +780,8 @@ static int DLOOP_Segment_blkidx_mpi_flatten(DLOOP_Offset *blocks_p,
 
 	MPID_Ensure_Aint_fits_in_pointer( (MPI_VOID_PTR_CAST_TO_MPI_AINT bufp) + rel_off );
 	if ((last_idx == paramp->length-1) &&
-	    (last_end != ((char *) bufp + rel_off)))
+	    (last_end != (char *) MPI_AINT_CAST_TO_VOID_PTR
+			 (MPI_VOID_PTR_CAST_TO_MPI_AINT bufp + rel_off) ))
 	{
 	    /* we have used up all our entries, and this one doesn't fit on
 	     * the end of the last one.
@@ -787,13 +794,15 @@ static int DLOOP_Segment_blkidx_mpi_flatten(DLOOP_Offset *blocks_p,
 #endif
 	    return 1;
 	}
-	else if (last_idx >= 0 && (last_end == ((char *) bufp + rel_off)))
+	else if (last_idx >= 0 && (last_end == (char *) MPI_AINT_CAST_TO_VOID_PTR
+			                       (MPI_VOID_PTR_CAST_TO_MPI_AINT bufp + rel_off) ) )
 	{
 	    /* add this size to the last vector rather than using up new one */
 	    paramp->blklens[last_idx] += size;
 	}
 	else {
-	    paramp->disps[last_idx+1]   = (MPI_Aint) ((char *) bufp + rel_off + offsetarray[last_idx+1]);
+	    paramp->disps[last_idx+1]   = (MPI_Aint) (MPI_VOID_PTR_CAST_TO_MPI_AINT bufp + 
+						      rel_off + offsetarray[last_idx+1]);
 	    paramp->blklens[last_idx+1] = size;
 	    paramp->index++;
 	}
@@ -802,9 +811,9 @@ static int DLOOP_Segment_blkidx_mpi_flatten(DLOOP_Offset *blocks_p,
     }
 
 #ifdef MPID_SP_VERBOSE
-    MPIU_dbg_printf("\t[vector to vec exiting (2): next ind = %d, %d blocks processed.\n",
+    MPIU_dbg_printf("\t[vector to vec exiting (2): next ind = %d, " MPI_AINT_FMT_DEC_SPEC " blocks processed.\n",
 		    paramp->u.pack_vector.index,
-		    (int) *blocks_p);
+		    *blocks_p);
 #endif
 
     /* if we get here then we processed ALL the blocks; don't need to update
@@ -847,12 +856,17 @@ static int DLOOP_Segment_index_mpi_flatten(DLOOP_Offset *blocks_p,
 
 	last_idx = paramp->index - 1;
 	if (last_idx >= 0) {
-	    last_end = ((char *) paramp->disps[last_idx]) +
-		paramp->blklens[last_idx];
+	    MPID_Ensure_Aint_fits_in_pointer( paramp->disps[last_idx] +
+					      (MPI_Aint)(paramp->blklens[last_idx]) );
+	    last_end = (char *) MPI_AINT_CAST_TO_VOID_PTR 
+		       ( paramp->disps[last_idx] +
+			 (MPI_Aint)(paramp->blklens[last_idx]) );
 	}
 
+	MPID_Ensure_Aint_fits_in_pointer( (MPI_VOID_PTR_CAST_TO_MPI_AINT bufp) + rel_off );
 	if ((last_idx == paramp->length-1) &&
-	    (last_end != ((char *) bufp + rel_off)))
+	    (last_end != (char *) MPI_AINT_CAST_TO_VOID_PTR
+			 (MPI_VOID_PTR_CAST_TO_MPI_AINT bufp + rel_off) ))
 	{
 	    /* we have used up all our entries, and this one doesn't fit on
 	     * the end of the last one.
@@ -865,7 +879,8 @@ static int DLOOP_Segment_index_mpi_flatten(DLOOP_Offset *blocks_p,
 #endif
 	    return 1;
 	}
-	else if (last_idx >= 0 && (last_end == ((char *) bufp + rel_off)))
+	else if (last_idx >= 0 && (last_end == (char *) MPI_AINT_CAST_TO_VOID_PTR
+			                       (MPI_VOID_PTR_CAST_TO_MPI_AINT bufp + rel_off) ))
 	{
 	    /* add this size to the last vector rather than using up new one */
 	    paramp->blklens[last_idx] += size;
diff --git a/lib/mpi/mpich2/src/util/mem/handlemem.c b/lib/mpi/mpich2/src/util/mem/handlemem.c
index 9c30067..a242e2f 100644
--- a/lib/mpi/mpich2/src/util/mem/handlemem.c
+++ b/lib/mpi/mpich2/src/util/mem/handlemem.c
@@ -312,8 +312,8 @@ void *MPIU_Handle_obj_alloc(MPIU_Object_alloc_t *objmem)
     }
 
     MPIU_DBG_MSG_FMT(HANDLE,TYPICAL,(MPIU_DBG_FDEST,
-				     "Allocating handle %x (0x%08x)\n",
-				     (unsigned) (MPI_Aint)ptr, ptr->handle));
+				     "Allocating handle %p (0x%08x)\n",
+				     ptr, ptr->handle));
 
 #ifdef USE_MEMORY_TRACING
     /* We set the object to an invalid pattern.  This is similar to 
-- 
1.5.3.7




More information about the mpich2-dev mailing list