summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authorJustus Winter <4winter@informatik.uni-hamburg.de>2015-02-15 13:29:30 +0100
committerJustus Winter <4winter@informatik.uni-hamburg.de>2015-02-15 14:33:33 +0100
commit44753cf5a30b9324d2c4ac9021843674bde5cc3c (patch)
tree743687464c6e13941fdf2cb4691843c6864fe2db /utils.c
parentf573a84faeb902f74b5f4b6fc1a67e7579012a9e (diff)
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.
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/utils.c b/utils.c
index 396e743..4c2a87b 100644
--- a/utils.c
+++ b/utils.c
@@ -239,10 +239,16 @@ WriteFieldDeclPrim(FILE *file, const argument_t *arg,
* use the element type and maximum size specified.
* Note arg->argCount->argMultiplier == btype->itNumber.
*/
- fprintf(file, "\t\t%s %s[%d];",
+ fprintf(file, "\t\tunion {\n");
+ fprintf(file, "\t\t\t%s %s[%d];\n",
(*tfunc)(btype),
arg->argMsgField,
it->itNumber/btype->itNumber);
+ fprintf(file, "\t\t\t%s *%s%s;\n",
+ (*tfunc)(btype),
+ arg->argMsgField,
+ OOLPostfix);
+ fprintf(file, "\t\t};");
}
else
fprintf(file, "\t\t%s %s;", (*tfunc)(it), arg->argMsgField);