rpcgen: drop type-puning workarounds

The current RPC code is post-processed to introduce an
intermediate variable, rather than casting directly
to char ** at time of use. This is said to be a workaround
for type-puning warnings that the compiler emitted.

Neither GCC or CLang emit any warnings for the code in
question today, across any of the architectures we
test in CI. Thus it is presumed that somewhere in the
15 years since the workaround was done, the compilers
have got smarter and do the right thing.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2022-12-20 12:14:07 -05:00
parent 3d9019e64f
commit 07e18c18a4

View File

@ -85,29 +85,6 @@ while (<RPCGEN>) {
@uses = grep /[^.>]\bi\b/, @function;
@function = grep !/[^.>]\bi\b/, @function if @uses == 1;
# (char **)&objp->... gives:
# warning: dereferencing type-punned pointer will break
# strict-aliasing rules
# so rewrite it.
my %uses = ();
my $i = 0;
foreach (@function) {
$uses{$1} = $i++ if m/\(char \*\*\)\&(objp->[a-z_.]+_val)/i;
}
if (keys %uses >= 1) {
my $i = 1;
foreach (sort(keys %uses)) {
$i = $uses{$_};
unshift @function,
(" char **objp_cpp$i = (char **) (void *) &$_;\n");
$i++;
}
@function =
map { s{\(char \*\*\)\&(objp->[a-z_.]+_val)}
{objp_cpp$uses{$1}}gi; $_ } @function;
}
# The code uses 'IXDR_PUT_{U_,}LONG' but it's wrong in two
# ways: Firstly these functions are deprecated and don't
# work on 64 bit platforms. Secondly the return value should