From c7826af5a0403b48eeeb6c18532dc076146b1966 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Mon, 27 Aug 2012 20:52:15 +0200 Subject: [PATCH] FFI: Detect type punning through unions. --- doc/ext_ffi_semantics.html | 12 +++++++++--- src/lj_opt_mem.c | 36 ++++++++++++++++++++---------------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/doc/ext_ffi_semantics.html b/doc/ext_ffi_semantics.html index afe7e613..56b3f62e 100644 --- a/doc/ext_ffi_semantics.html +++ b/doc/ext_ffi_semantics.html @@ -192,8 +192,8 @@ a typedef, except re-declarations will be ignored):

-You're encouraged to use these types in preference to the -compiler-specific extensions or the target-dependent standard types. +You're encouraged to use these types in preference to +compiler-specific extensions or target-dependent standard types. E.g. char differs in signedness and long differs in size, depending on the target architecture and platform ABI.

@@ -660,12 +660,18 @@ initialization. The JIT compiler benefits from this fact when applying certain optimizations.

-As a consequence of this, the elements of complex numbers and +As a consequence, the elements of complex numbers and vectors are immutable. But the elements of an aggregate holding these types may be modified of course. I.e. you cannot assign to foo.c.im, but you can assign a (newly created) complex number to foo.c.

+

+The JIT compiler implements strict aliasing rules: accesses to different +types do not alias, except for differences in signedness (this +applies even to char pointers, unlike C99). Type punning +through unions is explicitly detected and allowed. +

Calling a cdata object