From 44753cf5a30b9324d2c4ac9021843674bde5cc3c Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Sun, 15 Feb 2015 13:29:30 +0100 Subject: Do not generate code dereferencing type-punned pointers For variable-length arrays, up to 2048 bytes are transmitted inline. If the array is larger, the data is transmitted out-of-line, and a pointer to a vm_allocated region is stored at the beginning of the array. Previously, the generated code casted the field. Use a union instead. This fixes the gcc warning `dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]'. * global.c (OOLPostfix): New variable. * global.h (OOLPostfix): New declaration. * server.c (WriteServerCallArg): Avoid cast. (WriteDestroyArg): Likewise. (WritePackArgValue): Likewise. (WritePackArg): Likewise. * user.c (WriteExtractArgValue): Likewise. * utils.c (WriteFieldDeclPrim): Generate a union with an additional pointer field for variable-length arrays. --- server.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'server.c') diff --git a/server.c b/server.c index 56ccfc7..15fc128 100644 --- a/server.c +++ b/server.c @@ -777,9 +777,9 @@ WriteServerCallArg(FILE *file, const argument_t *arg) arg->argTTName, arg->argLongForm ? ".msgtl_header" : ""); fprintf(file, "? %s ", InArgMsgField(arg)); - fprintf(file, ": *((%s **)%s)", - FetchServerType(arg->argType->itElement), - InArgMsgField(arg)); + fprintf(file, ": %s%s", + InArgMsgField(arg), + OOLPostfix); } else fprintf(file, "%s", InArgMsgField(arg)); @@ -816,8 +816,8 @@ WriteDestroyArg(FILE *file, const argument_t *arg) arg->argRequestPos, arg->argTTName, arg->argLongForm ? ".msgtl_header" : ""); - fprintf(file, "\t\t\t%smig_deallocate(* (vm_offset_t *) %s, ", - SubrPrefix, InArgMsgField(arg)); + fprintf(file, "\t\t\t%smig_deallocate((vm_offset_t) %s%s, ", + SubrPrefix, InArgMsgField(arg), OOLPostfix); if (multiplier > 1) fprintf(file, "%d * ", multiplier); fprintf(file, " %s);\n", InArgMsgField(count)); @@ -978,9 +978,9 @@ WritePackArgValue(FILE *file, const argument_t *arg) arg->argTTName, arg->argLongForm ? ".msgtl_header" : "", arg->argDealloc->argVarName); - fprintf(file, "\t\t*((%s **)OutP->%s) = %sP;\n", - FetchServerType(btype), + fprintf(file, "\t\tOutP->%s%s = %sP;\n", arg->argMsgField, + OOLPostfix, arg->argVarName); if (!arg->argRoutine->rtSimpleFixedReply) fprintf(file, "\t\tmsgh_simple = FALSE;\n"); @@ -1203,9 +1203,9 @@ WritePackArg(FILE *file, const argument_t *arg) arg->argTTName, arg->argLongForm ? ".msgtl_header" : "", arg->argDealloc->argVarName); - fprintf(file, "\t\t*((%s **)OutP->%s) = %sP;\n", - FetchServerType(it->itElement), + fprintf(file, "\t\tOutP->%s%s = %sP;\n", arg->argMsgField, + OOLPostfix, arg->argVarName); if (!arg->argRoutine->rtSimpleFixedReply) fprintf(file, "\t\tmsgh_simple = FALSE;\n"); -- cgit v1.2.3