]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Import offsetof and vg_alignof from VEX (tracking VEX r3049).
authorFlorian Krohm <florian@eich-krohm.de>
Mon, 29 Dec 2014 22:19:24 +0000 (22:19 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Mon, 29 Dec 2014 22:19:24 +0000 (22:19 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14839

include/pub_tool_basics.h

index cb6beb26c38498b4ce9e119cce96b281a168b869..ebb75d20f6a5317a3edba3e5c7b3d557bcbbd82d 100644 (file)
@@ -294,6 +294,33 @@ static inline Bool sr_EQ ( SysRes sr1, SysRes sr2 ) {
 #  error Unknown arch
 #endif
 
+/* Offsetof */
+#if !defined(offsetof)
+#   define offsetof(type,memb) ((SizeT)(HWord)&((type*)0)->memb)
+#endif
+
+/* Alignment */
+/* We use a prefix vg_ for vg_alignof as its behaviour slightly
+   differs from the standard alignof/gcc defined __alignof__
+
+   vg_alignof returns a "safe" alignement.
+   "safe" is defined as the alignment chosen by the compiler in
+   a struct made of a char followed by this type.
+
+      Note that this is not necessarily the "preferred" alignment
+      for a platform. This preferred alignment is returned by the gcc
+       __alignof__ and by the standard (in recent standard) alignof.
+      Compared to __alignof__, vg_alignof gives on some platforms (e.g.
+      amd64, ppc32, ppc64) a bigger alignment for long double (16 bytes
+      instead of 8).
+      On some platforms (e.g. x86), vg_alignof gives a smaller alignment
+      than __alignof__ for long long and double (4 bytes instead of 8). 
+      If we want to have the "preferred" alignment for the basic types,
+      then either we need to depend on gcc __alignof__, or on a (too)
+      recent standard and compiler (implementing <stdalign.h>).
+*/
+#define vg_alignof(_type) (sizeof(struct {char c;_type _t;})-sizeof(_type))
+
 /* Regparmness */
 #if defined(VGA_x86)
 #  define VG_REGPARM(n)            __attribute__((regparm(n)))