From steve.white at aei.mpg.de Fri Oct 20 08:44:00 2006 From: steve.white at aei.mpg.de (Steve White) Date: Fri, 20 Oct 2006 15:44:00 +0200 Subject: [Patches] g++ warning: operation on *bla* may be undefined Message-ID: <20061020134400.GJ31820@xeon01.aei.mpg.de> This patch is concerned with g++ warnings like: Preprocessing arrangements/Carpet/Carpet/src/Timing.cc Compiling arrangements/Carpet/Carpet/src/Timing.cc configs/chain_gcc_carpet/build/Carpet/Timing.cc: In function ?void Carpet::InitTimingVariables(const cGH*)?: configs/chain_gcc_carpet/build/Carpet/Timing.cc:120: warning: operation on ?cctki_use? may be undefined The culprit was in generated bindings code meant to get rid of warnings about unused variables corresponding to Cactus parameters included in code by the DECLARE_CCTK_PARAMETERS macro. Typically, a struct was defined to hold copies of the macros, then such ery interesting constructs would appear. const void *PRIVATE_CACTUS_STRUCT_use = ( \ PRIVATE_CACTUS_STRUCT_use = &cctk_run_title, \ PRIVATE_CACTUS_STRUCT_use = &*PRIVATE_CACTUS_STRUCT_use \ ) This code replaces that with a do-nothing enum declaration enum { dummy_cctk_run_title = sizeof( cctk_run_title ) //,etc. }; The nature of all the entities involved is here much clearer, both to compilers and to me. Like the existing solution, this permits the user to proceed to make more declarations after the DECLARE_CCTK_PARAMETERS macro (simply putting a list of variable assignments after the declaration would not have that property). Tested with Gnu 4x, Intel 9x, IBM XL Apply in main Cactus directory, with patch -p1 < operation_maybe_undefined.diff Cheers! -- Steve White : Programmer Max-Planck-Institut f?r Gravitationsphysik Albert-Einstein-Institut Am M?hlenberg 1, D-14476 Golm, Germany +49-331-567-7625 -------------- next part -------------- Index: lib/sbin/CreateParameterBindings.pl =================================================================== RCS file: /cactusdevcvs/Cactus/lib/sbin/CreateParameterBindings.pl,v retrieving revision 1.51 diff -u -r1.51 CreateParameterBindings.pl --- lib/sbin/CreateParameterBindings.pl 28 Sep 2005 17:09:31 -0000 1.51 +++ lib/sbin/CreateParameterBindings.pl 20 Oct 2006 12:32:49 -0000 @@ -201,6 +201,7 @@ if($header_files{"\U$thorn\E PRIVATE"}); @use = (); + my $delim = ' '; foreach $friend (split(' ',$rhparameter_db->{"\U$thorn\E SHARES implementations"})) { $rhinterface_db->{"IMPLEMENTATION \U$friend\E THORNS"} =~ m:([^ ]*):; @@ -222,16 +223,16 @@ } push(@data, " $type_string$varprefix const $parameter = RESTRICTED_\U$friend\E_STRUCT.$realname; \\"); - push(@use, " RESTRICTED_FRIENDS_STRUCT_use = \&$parameter, \\"); + push(@use, " $delim dummy_$friend\_$realname = sizeof( $parameter ) \\"); + $delim = ','; } } if(@use) { - push(@data, ' const void *RESTRICTED_FRIENDS_STRUCT_use = ( \\'); + push(@data, " enum { \\"); push(@data, @use); - push(@data, ' RESTRICTED_FRIENDS_STRUCT_use = &RESTRICTED_FRIENDS_STRUCT_use \\'); - push(@data, ' );'); + push(@data, " };"); } push(@data, ''); push(@data, "#endif /* _\U$thorn\E_PARAMETERS_H_ */"); Index: lib/sbin/create_c_stuff.pl =================================================================== RCS file: /cactusdevcvs/Cactus/lib/sbin/create_c_stuff.pl,v retrieving revision 1.55 diff -u -r1.55 create_c_stuff.pl --- lib/sbin/create_c_stuff.pl 28 Sep 2005 17:09:31 -0000 1.55 +++ lib/sbin/create_c_stuff.pl 20 Oct 2006 12:32:49 -0000 @@ -186,8 +186,8 @@ push(@data, ''); push(@data, 'extern struct'); push(@data, '{'); + my $delim = ' '; - push(@use, " const void *${structure}_use = ( \\"); foreach $parameter (&order_params($rhparameters, $rhparameter_db)) { my $type = $rhparameter_db->{"\U$rhparameters->{$parameter} $parameter\E type"}; @@ -208,10 +208,9 @@ push(@data, " $type_string $realname$suffix;"); push(@definition, " $type_string$varprefix const $parameter = $structure.$realname; \\"); - push(@use, " ${structure}_use = \&$parameter, \\"); + push(@use, " $delim dummy\_$structure\_$parameter = sizeof( $parameter ) \\"); + $delim = ','; } - push(@use, " &${structure}_use \\"); - push(@use, ' );'); # Some compilers don't like an empty structure. if((keys %$rhparameters) == 0) @@ -229,7 +228,12 @@ push(@data, "#define DECLARE_${structure}_PARAMS \\"); push(@data, @definition); - push(@data, @use); + if( @use ) + { + push(@data, " enum { \\"); + push(@data, @use); + push(@data, " }; \\"); + } push(@data, "\n"); # workaround for perl 5.004_04 to add a trailing newline Index: src/include/cctk.h =================================================================== RCS file: /cactusdevcvs/Cactus/src/include/cctk.h,v retrieving revision 1.98 diff -u -r1.98 cctk.h --- src/include/cctk.h 15 Jun 2006 14:35:04 -0000 1.98 +++ src/include/cctk.h 20 Oct 2006 12:32:49 -0000 @@ -252,29 +252,30 @@ int cctk_convfac = cctkGH->cctk_convfac;\ int *cctk_nghostzones = cctkGH->cctk_nghostzones;\ int cctk_iteration = cctkGH->cctk_iteration;\ - const void *cctki_use = (cctki_use = &cctki_dummy_int,\ - cctki_use = &cctk_dim,\ - cctki_use = &cctk_gsh,\ - cctki_use = &cctk_lsh,\ - cctki_use = &cctk_lbnd,\ - cctki_use = &cctk_ubnd,\ - cctki_use = &cctk_lssh,\ - cctki_use = &cctk_from,\ - cctki_use = &cctk_to,\ - cctki_use = &cctk_bbox,\ - cctki_use = &cctk_delta_time,\ - cctki_use = &cctk_time,\ - cctki_use = &cctk_delta_space,\ - cctki_use = &cctk_origin_space,\ - cctki_use = &cctk_levfac,\ - cctki_use = &cctk_levoff,\ - cctki_use = &cctk_levoffdenom,\ - cctki_use = &cctk_timefac,\ - cctki_use = &cctk_convlevel,\ - cctki_use = &cctk_convfac,\ - cctki_use = &cctk_nghostzones,\ - cctki_use = &cctk_iteration,\ - cctki_use = &cctki_use); + enum { \ + cctk_dummyi_dummy_int = sizeof( cctki_dummy_int ), \ + cctk_dummy_dim = sizeof( cctk_dim ), \ + cctk_dummy_gsh = sizeof( cctk_gsh ), \ + cctk_dummy_lsh = sizeof( cctk_lsh ), \ + cctk_dummy_lbnd = sizeof( cctk_lbnd ), \ + cctk_dummy_ubnd = sizeof( cctk_ubnd ), \ + cctk_dummy_lssh = sizeof( cctk_lssh ), \ + cctk_dummy_from = sizeof( cctk_from ), \ + cctk_dummy_to = sizeof( cctk_to ), \ + cctk_dummy_bbox = sizeof( cctk_bbox ), \ + cctk_dummy_delta_time = sizeof( cctk_delta_time ), \ + cctk_dummy_time = sizeof( cctk_time ), \ + cctk_dummy_delta_space = sizeof( cctk_delta_space ), \ + cctk_dummy_origin_space = sizeof( cctk_origin_space ), \ + cctk_dummy_levoff = sizeof( cctk_levoff ), \ + cctk_dummy_levfac = sizeof( cctk_levfac ), \ + cctk_dummy_levoffdenom = sizeof( cctk_levoffdenom ), \ + cctk_dummy_timefac = sizeof( cctk_timefac ), \ + cctk_dummy_convlevel = sizeof( cctk_convlevel ), \ + cctk_dummy_convfac = sizeof( cctk_convfac ), \ + cctk_dummy_nghostzones = sizeof( cctk_nghostzones ), \ + cctk_dummy_iteration = sizeof( cctk_iteration ) \ + }; #define _INITIALISE_CCTK_C2F