From d041d90629f26b071fb71bebda785eb0b262f806 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 16 Sep 2022 07:34:32 -0700 Subject: nan-boxing: build on older gcc. Older GCC 4.x versions do not support diagnostic pragmas in functions and don't have push pragmas for diagnostics. * arith.c (flo): Put the diagnostic disabling pragma stuff outside of the function. Instead saving and restoring the status with push and pop, we just disable the aliasing warning and re-instate it as a warning. * lib.h (c_f): Likewise. --- arith.c | 15 ++++++++------- lib.h | 15 ++++++++------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/arith.c b/arith.c index d135e2a4..fad3e15b 100644 --- a/arith.c +++ b/arith.c @@ -4268,20 +4268,17 @@ INLINE int bad_float(double d) #define bad_float(d) (0) #endif +#if CONFIG_NAN_BOXING && defined __GNUC__ +#pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif + val flo(double n) { if (bad_float(n)) { uw_throw(numeric_error_s, lit("out-of-range floating-point result")); } else { #if CONFIG_NAN_BOXING -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstrict-aliasing" -#endif ucnum u = *(ucnum *) &n + NAN_FLNUM_DELTA; -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif return coerce(val, u); #else val obj = make_obj(); @@ -4292,6 +4289,10 @@ val flo(double n) } } +#if CONFIG_NAN_BOXING && defined __GNUC__ +#pragma GCC diagnostic warning "-Wstrict-aliasing" +#endif + double c_flo(val num, val self) { #if CONFIG_NAN_BOXING diff --git a/lib.h b/lib.h index c2f42408..c15e1ff5 100644 --- a/lib.h +++ b/lib.h @@ -621,23 +621,24 @@ INLINE ucnum c_u(val num) #endif } +#if CONFIG_NAN_BOXING && defined __GNUC__ +#pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif + INLINE double c_f(val num) { #if CONFIG_NAN_BOXING ucnum u = coerce(ucnum, num) - NAN_FLNUM_DELTA; -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstrict-aliasing" -#endif return *coerce(double *, &u); -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif #else return num->fl.n; #endif } +#if CONFIG_NAN_BOXING && defined __GNUC__ +#pragma GCC diagnostic warning "-Wstrict-aliasing" +#endif + #if SIZEOF_WCHAR_T < 4 && !CONFIG_NAN_BOXING #define lit_noex(strlit) coerce(obj_t *,\ coerce(cnum, L"\0" L ## strlit L"\0" + 1) | \ -- cgit v1.2.3