From 8d7b6b4cb27d4dec1dd5f7960298c1699275f962 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Sat, 18 May 2024 09:33:19 +0200 Subject: socket: Use may_alias on sockaddr structs (bug 19622) This supports common coding patterns. The GCC C front end before version 7 rejects the may_alias attribute on a struct definition if it was not present in a previous forward declaration, so this attribute can only be conditionally applied. This implements the spirit of the change in Austin Group issue 1641. Suggested-by: Marek Polacek Suggested-by: Jakub Jelinek Reviewed-by: Sam James Reviewed-by: Carlos O'Donell --- misc/sys/cdefs.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'misc') diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h index 2e8279a2c7..ab9620bd0d 100644 --- a/misc/sys/cdefs.h +++ b/misc/sys/cdefs.h @@ -874,4 +874,13 @@ _Static_assert (0, "IEEE 128-bits long double requires redirection on this platf # define __attribute_returns_twice__ /* Ignore. */ #endif +/* Mark struct types as aliasable. Restricted to compilers that + support forward declarations of structs in the presence of the + attribute. */ +#if __GNUC_PREREQ (7, 1) || defined __clang__ +# define __attribute_struct_may_alias__ __attribute__ ((__may_alias__)) +#else +# define __attribute_struct_may_alias__ +#endif + #endif /* sys/cdefs.h */ -- cgit v1.2.3