From 2f34598297074b67eb54dd6c5a1a84f51c837a4a Mon Sep 17 00:00:00 2001 From: Luca Bacci Date: Tue, 4 Feb 2025 11:34:20 +0100 Subject: [PATCH] Add STDC FENV_ACCESS ON pragma This is required by the C99 standard, even though it's not needed by the compilers we support. --- src/cairo-compiler-private.h | 24 ++++++++++++++++++++++++ test/cairo-test.c | 2 ++ test/invalid-matrix.c | 2 ++ 3 files changed, 28 insertions(+) diff --git a/src/cairo-compiler-private.h b/src/cairo-compiler-private.h index 1aaced394..26cb1fca3 100644 --- a/src/cairo-compiler-private.h +++ b/src/cairo-compiler-private.h @@ -153,6 +153,30 @@ #define __attribute__(x) #endif +#if defined(__clang__) +# if __clang_major__ >= 12 +# define CAIRO_FENV_ACCESS_ON _Pragma ("STDC FENV_ACCESS ON") +# else +# define CAIRO_FENV_ACCESS_ON +# endif +#elif defined(__GNUC__) + /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118838 */ +# if __GNUC__ >= 16 + /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=34678 */ +# define CAIRO_FENV_ACCESS_ON \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wunknown-pragmas\"") \ + _Pragma ("STDC FENV_ACCESS ON") \ + _Pragma ("GCC diagnostic pop") +# else +# define CAIRO_FENV_ACCESS_ON +# endif +#elif defined(_MSC_VER) +# define CAIRO_FENV_ACCESS_ON __pragma (fenv_access (on)) +#else +# define CAIRO_FENV_ACCESS_ON _Pragma ("STDC FENV_ACCESS ON") +#endif + #if (defined(__WIN32__) && !defined(__WINE__)) || defined(_MSC_VER) #define access _access #ifndef R_OK diff --git a/test/cairo-test.c b/test/cairo-test.c index 49dfadb15..28c35e204 100644 --- a/test/cairo-test.c +++ b/test/cairo-test.c @@ -83,6 +83,8 @@ #define alarm(X); #endif +CAIRO_FENV_ACCESS_ON + static const cairo_user_data_key_t _cairo_test_context_key; static void diff --git a/test/invalid-matrix.c b/test/invalid-matrix.c index df0dff0f1..81cce5edc 100644 --- a/test/invalid-matrix.c +++ b/test/invalid-matrix.c @@ -33,6 +33,8 @@ #define INFINITY HUGE_VAL #endif +CAIRO_FENV_ACCESS_ON + static cairo_test_status_t draw (cairo_t *cr, int width, int height) {