X-Git-Url: https://granicus.if.org/sourcecode?a=blobdiff_plain;f=gcc_compat.h;h=fe3f9048f7d099eaa63814b4c30501945685c217;hb=3fb78d7305cd5b38bbed2d91b328c3181207b4e9;hp=1f2c8354a065726ae27904ede6301a2f6d7d2d0c;hpb=f32126ba790dd4e61d43a2140b24f02426297bb6;p=strace diff --git a/gcc_compat.h b/gcc_compat.h index 1f2c8354..fe3f9048 100644 --- a/gcc_compat.h +++ b/gcc_compat.h @@ -25,8 +25,8 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef GCC_COMPAT_H_ -#define GCC_COMPAT_H_ +#ifndef STRACE_GCC_COMPAT_H +#define STRACE_GCC_COMPAT_H #if defined __GNUC__ && defined __GNUC_MINOR__ # define GNUC_PREREQ(maj, min) \ @@ -52,6 +52,16 @@ # define ATTRIBUTE_PACKED /* empty */ #endif +#if GNUC_PREREQ(3, 0) +# define SAME_TYPE(x, y) __builtin_types_compatible_p(typeof(x), typeof(y)) +# define FAIL_BUILD_ON_ZERO(expr) (sizeof(int[-1 + 2 * !!(expr)]) * 0) +/* &(a)[0] is a pointer and not an array, shouldn't be treated as the same */ +# define MUST_BE_ARRAY(a) FAIL_BUILD_ON_ZERO(!SAME_TYPE((a), &(a)[0])) +#else +# define SAME_TYPE(x, y) 0 +# define MUST_BE_ARRAY(a) 0 +#endif + #if GNUC_PREREQ(3, 0) # define ATTRIBUTE_MALLOC __attribute__((__malloc__)) #else @@ -64,10 +74,22 @@ # define ATTRIBUTE_NOINLINE /* empty */ #endif +#if GNUC_PREREQ(4, 0) +# define ATTRIBUTE_SENTINEL __attribute__((__sentinel__)) +#else +# define ATTRIBUTE_SENTINEL /* empty */ +#endif + +#if GNUC_PREREQ(4, 1) +# define ALIGNOF(t_) __alignof__(t_) +#else +# define ALIGNOF(t_) (sizeof(struct {char x_; t_ y_;}) - sizeof(t_)) +#endif + #if GNUC_PREREQ(4, 3) # define ATTRIBUTE_ALLOC_SIZE(args) __attribute__((__alloc_size__ args)) #else # define ATTRIBUTE_ALLOC_SIZE(args) /* empty */ #endif -#endif +#endif /* !STRACE_GCC_COMPAT_H */