bug-gnulib
[Top][All Lists]
Advanced

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

stdalign: Ensure alignof is actually defined on FreeBSD


From: Bruno Haible
Subject: stdalign: Ensure alignof is actually defined on FreeBSD
Date: Sat, 28 Jan 2023 02:30:27 +0100

Building a testdir of all of Gnulib on FreeBSD 11.0/x86 or FreeBSD 12.0/x86,
I get this compilation error:

depbase=`echo rawmemchr.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`; cc 
-ferror-limit=0 -DHAVE_CONFIG_H -DEXEEXT=\"\" -DEXEEXT=\"\" -DNO_XMALLOC  
-DEXEEXT=\"\" -I. -I../../gllib -I..  -DGNULIB_STRICT_CHECKING=1  
-I/home/bruno/include -Wall -D_THREAD_SAFE -fvisibility=hidden -g -O2 -MT 
rawmemchr.o -MD -MP -MF $depbase.Tpo -c -o rawmemchr.o ../../gllib/rawmemchr.c 
&& mv -f $depbase.Tpo $depbase.Po
../../gllib/rawmemchr.c:45:31: warning: implicit declaration of function 
'alignof' is invalid in C99 [-Wimplicit-function-declaration]
       (uintptr_t) char_ptr % alignof (longword) != 0;
                              ^
../../gllib/rawmemchr.c:45:40: error: unexpected type name 'longword': expected 
expression
       (uintptr_t) char_ptr % alignof (longword) != 0;
                                       ^
1 warning and 1 error generated.


The cause is that alignof is not defined, neither as a keyword or compiler
built-in (since the compiler is clang 3.8.0 or 6.0.1, respectively), nor
as a macro by Gnulib's stdalign.h override. alignof *is* defined as a macro
in /usr/include/stdalign.h, but since Gnulib's stdalign.h overrides it,
it gets never included.

This is a regression from 2023-01-15 (since I am not seeing this error
on the stable-201301 branch).

This patch fixes it.


2023-01-27  Bruno Haible  <bruno@clisp.org>

        stdalign: Ensure alignof is defined on FreeBSD (regression 2023-01-15).
        * lib/stdalign.in.h: Include the system's <stdalign.h> when it exists.
        * m4/stdalign.m4 (gl_ALIGNASOF): Invoke gl_CHECK_NEXT_HEADERS. Set
        HAVE_STDALIGN_H.
        * modules/stdalign (Makefile.am): Substitute GUARD_PREFIX,
        HAVE_STDALIGN_H, INCLUDE_NEXT, PRAGMA_SYSTEM_HEADER, PRAGMA_COLUMNS,
        NEXT_STDALIGN_H.

diff --git a/lib/stdalign.in.h b/lib/stdalign.in.h
index 6523546f16..b616c100fd 100644
--- a/lib/stdalign.in.h
+++ b/lib/stdalign.in.h
@@ -20,8 +20,22 @@
 /* Define two obsolescent C11 macros, assuming alignas and alignof are
    either keywords or alignasof-defined macros.  */
 
-#ifndef _GL_STDALIGN_H
-#define _GL_STDALIGN_H
+#ifndef _@GUARD_PREFIX@_STDALIGN_H
+
+#if __GNUC__ >= 3
+@PRAGMA_SYSTEM_HEADER@
+#endif
+@PRAGMA_COLUMNS@
+
+/* We need to include the system's <stdalign.h> when it exists, because it 
might
+   define 'alignof' as a macro when it's not a keyword or compiler built-in.  
*/
+#if @HAVE_STDALIGN_H@
+/* The include_next requires a split double-inclusion guard.  */
+# @INCLUDE_NEXT@ @NEXT_STDALIGN_H@
+#endif
+
+#ifndef _@GUARD_PREFIX@_STDALIGN_H
+#define _@GUARD_PREFIX@_STDALIGN_H
 
 #if (defined alignas \
      || (defined __STDC_VERSION__ && 202311 <= __STDC_VERSION__) \
@@ -31,4 +45,5 @@
 
 #define __alignof_is_defined 1
 
-#endif /* _GL_STDALIGN_H */
+#endif /* _@GUARD_PREFIX@_STDALIGN_H */
+#endif /* _@GUARD_PREFIX@_STDALIGN_H */
diff --git a/m4/stdalign.m4 b/m4/stdalign.m4
index 6a0ab2c102..3e83a2ca58 100644
--- a/m4/stdalign.m4
+++ b/m4/stdalign.m4
@@ -179,9 +179,17 @@ AC_DEFUN([gl_ALIGNASOF],
 AC_DEFUN([gl_STDALIGN_H],
 [
   AC_REQUIRE([gl_ALIGNASOF])
-  GL_GENERATE_STDALIGN_H=false
-  AS_IF([test "$gl_cv_header_working_stdalign_h" = no],
-    [GL_GENERATE_STDALIGN_H=true])
-
-  AC_CHECK_HEADERS_ONCE([stdalign.h])
+  if test "$gl_cv_header_working_stdalign_h" = no; then
+    GL_GENERATE_STDALIGN_H=true
+  else
+    GL_GENERATE_STDALIGN_H=false
+  fi
+
+  gl_CHECK_NEXT_HEADERS([stdalign.h])
+  if test $ac_cv_header_stdalign_h = yes; then
+    HAVE_STDALIGN_H=1
+  else
+    HAVE_STDALIGN_H=0
+  fi
+  AC_SUBST([HAVE_STDALIGN_H])
 ])
diff --git a/modules/stdalign b/modules/stdalign
index c5c29d3088..ceeab546a2 100644
--- a/modules/stdalign
+++ b/modules/stdalign
@@ -26,7 +26,14 @@ BUILT_SOURCES += $(STDALIGN_H)
 if GL_GENERATE_STDALIGN_H
 stdalign.h: stdalign.in.h $(top_builddir)/config.status
 @NMD@  $(AM_V_GEN)$(MKDIR_P) '%reldir%'
-       $(gl_V_at)$(SED_HEADER_TO_AT_t) $(srcdir)/stdalign.in.h
+       $(gl_V_at)$(SED_HEADER_STDOUT) \
+             -e 's|@''GUARD_PREFIX''@|${gl_include_guard_prefix}|g' \
+             -e 's|@''HAVE_STDALIGN_H''@|$(HAVE_STDALIGN_H)|g' \
+             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+             -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+             -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+             -e 's|@''NEXT_STDALIGN_H''@|$(NEXT_STDALIGN_H)|g' \
+             $(srcdir)/stdalign.in.h > $@-t
        $(AM_V_at)mv $@-t $@
 else
 stdalign.h: $(top_builddir)/config.status






reply via email to

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