epsilon-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 6/7] Simplify __attribute__ tests, less porting hassle


From: Paul Eggert
Subject: [PATCH 6/7] Simplify __attribute__ tests, less porting hassle
Date: Thu, 26 Jan 2023 14:17:37 -0800

This would have prevented the build problem with
GNU poke 2.90.1 on CLFS for LoongArch64 7.2 with
GCC 13.0.0 20221018 (experimental) as described in
https://lists.gnu.org/r/bug-gnulib/2023-01/msg00207.html
* configure.ac (ac_cv_have_gnu_c_attribute)
(JITTER_HAVE_GNU_C_ATTRIBUTE):
Test whether __attribute__ works with both no_reorder and
returns_nonnull.  This is simpler, and avoids the need for things
like '#define __returns_nonnull__' that infringe on the system
namespace.  A downside might be slightly worse diagnostics and/or
code generated by GCC 5 and earlier, but these older compilers are
not that important nowadays.
(ac_cv_have_no_reorder, JITTER_HAVE_ATTRIBUTE_NO_REORDER)
(ac_cv_have_returns_nonnull, JITTER_HAVE_ATTRIBUTE_RETURNS_NONNULL):
Remove.  All uses removed.  When checking whether to use
-fno-toplevel-reorder, simply test ac_cv_have_gnu_c_attribute.
* jitter/jitter-missing.h (no_reorder, __no_reorder)
(returns_nonnull, __returns_nonnull__):
Remove; no longer needed.
---
 configure.ac              | 68 ++++++++-------------------------------
 jitter/jitter-config.h.in |  8 ++---
 jitter/jitter-missing.h   | 21 ------------
 3 files changed, 15 insertions(+), 82 deletions(-)

diff --git a/configure.ac b/configure.ac
index b4db5b8..12ad6cf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1174,77 +1174,35 @@ fi
 # Check for GCC attributes.
 ################################################################
 
-# Check if the GNU C attribute syntax is recognized at all.
-AC_CACHE_CHECK([for GNU C attributes], [ac_cv_have_gnu_c_attribute],
-  [AC_COMPILE_IFELSE(
-     [AC_LANG_PROGRAM(
-        [[__attribute__ (())
-          int
-          f (int x)
-          {
-            return x;
-          }]],
-        [[return f (0);]])],
-     [ac_cv_have_gnu_c_attribute=yes],
-     [ac_cv_have_gnu_c_attribute=no])])
-if test "x$ac_cv_have_gnu_c_attribute" = "xyes"; then
-  AC_DEFINE([JITTER_HAVE_GNU_C_ATTRIBUTE], [1],
-            [Define if the compiler supports __attribute__.])
-fi
-
-# Check for specific attributes not supported by older versions of GCC;
-# and possibly by other compilers.  Notice that we have to temporarily
+# Check if the GNU C attribute syntax is recognized and supports
+# the attributes that Jitter uses.  While checking, emporarily
 # change CFLAGS to force -Werror.  If -Werror is not supported than the tests
 # will all fail, which is the correct conservative behavior.
 
-# FIXME: I should factor the following with M4.
-
 jitter_save_CFLAGS=$CFLAGS
 CFLAGS="$CFLAGS -Werror"
-
-# Check for attribute no_reorder .
-AC_CACHE_CHECK([for the no_reorder attribute],
-  [ac_cv_have_no_reorder],
-  [AC_COMPILE_IFELSE(
-     [AC_LANG_PROGRAM(
-        [[long n = 7;
-          __attribute__ ((no_reorder))
-          long *
-          f (void)
-          {
-            return & n;
-          }]],
-        [[return * f () != 0;]])],
-     [ac_cv_have_no_reorder=yes],
-     [ac_cv_have_no_reorder=no])])
-if test "x$ac_cv_have_no_reorder" = "xyes"; then
-  AC_DEFINE([JITTER_HAVE_ATTRIBUTE_NO_REORDER], [1],
-            [Define if the no_reorder attribute works])
-fi
-
-# Check for attribute returns_nonnull .
-AC_CACHE_CHECK([for the returns_nonnull attribute],
-  [ac_cv_have_returns_nonnull],
+AC_CACHE_CHECK([for GNU C attributes that Jitter uses],
+  [ac_cv_have_gnu_c_attribute],
   [AC_COMPILE_IFELSE(
      [AC_LANG_PROGRAM(
         [[long n = 7;
-          __attribute__ ((returns_nonnull))
+          __attribute__ ((no_reorder, returns_nonnull))
           long *
           f (void)
           {
             return & n;
           }]],
         [[return * f () != 0;]])],
-     [ac_cv_have_returns_nonnull=yes],
-     [ac_cv_have_returns_nonnull=no])])
-if test "x$ac_cv_have_returns_nonnull" = "xyes"; then
-  AC_DEFINE([JITTER_HAVE_ATTRIBUTE_RETURNS_NONNULL], [1],
-            [Define if the returns_nonnull attribute works])
+     [ac_cv_have_gnu_c_attribute=yes],
+     [ac_cv_have_gnu_c_attribute=no])])
+if test "x$ac_cv_have_gnu_c_attribute" = "xyes"; then
+  AC_DEFINE([JITTER_HAVE_GNU_C_ATTRIBUTE], [1],
+            [Define if the compiler supports __attribute__.])
 fi
-
-# End of -Werror section.
 CFLAGS=$jitter_save_CFLAGS
 
+# When JITTER_HAVE_GNU_C_ATTRIBUTE is not defined, jitter-missing.h
+# #defines __attribute__(X) to nothing.
 # Many people like to compile with -Werror.  This is a way of redefining
 # attributes not supported by the compiler so that they expand to nothing.
 
@@ -2650,7 +2608,7 @@ for dispatch in $jitter_enabled_dispatches; do
   # But GCCs older then version 5 do not suport the attribute.  In that case
   # can fall back to a more brutal solution, preventing the reordering of
   # any function:
-  if test "x$ac_cv_have_no_reorder" = 'xno'; then
+  if test "x$ac_cv_have_gnu_c_attribute" = 'xno'; then
     jitter_check_cc_options JITTER_FLAGS_CFLAGS -fno-toplevel-reorder
   fi
 
diff --git a/jitter/jitter-config.h.in b/jitter/jitter-config.h.in
index 5a419e5..4fbc5ad 100644
--- a/jitter/jitter-config.h.in
+++ b/jitter/jitter-config.h.in
@@ -100,7 +100,7 @@
    for both when the 64-bit variant is a very similar clean extension, as
    is the case for example with RISC-V, MIPS and PowerPC; the user may then
    conditionalise on JITTER_BYTES_PER_WORD (which is a CPP-time constant) if
-   needed. 
+   needed.
    When the two variants of an architecture are radically different and
    incompatible two different macros are used here. */
 
@@ -397,13 +397,9 @@
 /* Define if __builtin_choose_expr is available. */
 #undef JITTER_HAVE_GCC_BUILTIN_CHOOSE_EXPR
 
-/* Define if the C compilers supports GNU C attributes. */
+/* Define if the C compilers supports GNU C attributes that Jitter needs. */
 #undef JITTER_HAVE_GNU_C_ATTRIBUTE
 
-/* Define for specific GNU C attributes. */
-#undef JITTER_HAVE_ATTRIBUTE_NO_REORDER
-#undef JITTER_HAVE_ATTRIBUTE_RETURNS_NONNULL
-
 /* Define if the compiler supports #pragma GCC diagnostic inside functions.
    Some old versions of GCC 4 do not but, annoyingly, others versions do which
    are less recent than others which do not. */
diff --git a/jitter/jitter-missing.h b/jitter/jitter-missing.h
index 6aebf78..d68c7a9 100644
--- a/jitter/jitter-missing.h
+++ b/jitter/jitter-missing.h
@@ -66,27 +66,6 @@
 # define __attribute__(ignored_attributes)  /* Nothing. */
 #endif /* ! defined (JITTER_HAVE_GNU_C_ATTRIBUTE) */
 
-/* After the previous definition, non-GNU C compilers will not have any 
problem,
-   since every attribute use will be macroexpanded away; therefore it would be
-   useless, in the following, to conditionalize over the attribute syntax
-   availability.  What remains to be solved is older GNU C compilers not 
knowing
-   about more recently introduced attributes. */
-#if ! defined (JITTER_HAVE_ATTRIBUTE_NO_REORDER)
-# define no_reorder      /* Nothing. */
-# define __no_reorder__  /* Nothing. */
-  /* On configurations where no_reorder is not defined, which will be the case
-     for very old GCCs, configure tries to add -fno-toplevel-reorder to CFLAGS 
.
-     That is a more brutal, global way of enforcing ordering. */
-#endif /* #if ! defined (JITTER_HAVE_ATTRIBUTE_NO_REORDER) */
-#if ! defined (JITTER_HAVE_ATTRIBUTE_RETURNS_NONNULL)                   \
-    && /* Redefining these two macros does not play well with Gnulib's  \
-          workaround definitions for Clang. */                          \
-       ! defined (JITTER_HAVE_CLANG)
-# define returns_nonnull      /* Nothing. */
-# define __returns_nonnull__  /* Nothing. */
-#endif /* #if ! defined (JITTER_HAVE_ATTRIBUTE_RETURNS_NONNULL) */
-
-
 
 
 /* GCC builtins.
-- 
2.39.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]