On 3/2/21 7:09 PM, Bruno Haible wrote:
+   /* On TinyCC, make sure that the macros that indicate the special invocation
+      convention get undefined.  */
+#  ifdef __TINYC__
+#   undef __need_wchar_t
+#   undef __need_size_t

Would it be more robust to omit the "#ifdef __TINYC__" line, and unconditionally undef those macros? That won't hurt GCC, and it should help with any compiler (not just tcc) that is incompatible with GCC in this respect.

Also, test-stdalign failed on Ubuntu 20.10 with tcc, since tcc's <stdalign.h> has a broken alignof when glibc headers like <stdint.h> are used. Glibc <stdint.h> defines __attribute__(x) to empty for compilers like tcc that do not define __GNUC__, but tcc's alignof relies on __attribute__. I installed the attached patch to try to work around that problem.
From 7955dc93ef02c0cb90a8c4966abf142a3813ff48 Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Thu, 4 Mar 2021 00:47:19 -0800
Subject: [PATCH] stdalign: port to tcc + glibc
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lib/stdalign.in.h (_Alignas): Do not define using __attribute__
if __attribute__ is defined as a macro, as __attribute__ surely a
no-op in that case and this is an area where __attribute__ cannot
simply be ignored.
* m4/stdalign.m4 (gl_STDALIGN_H): Include <stdint.h> so that
it #defines __attribute__(x) to nothing on glibc-based systems
when non-GNU-C-compatible compilers are used.
This exposes a bug in Tiny C Compiler 0.9.27’s implementation
of _Alignas on glibc platforms.
---
 ChangeLog         | 13 +++++++++++++
 lib/stdalign.in.h | 13 +++++++------
 m4/stdalign.m4    |  4 +++-
 3 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9f6818c17..50d247fac 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2021-03-04  Paul Eggert  <egg...@cs.ucla.edu>
+
+	stdalign: port to tcc + glibc
+	* lib/stdalign.in.h (_Alignas): Do not define using __attribute__
+	if __attribute__ is defined as a macro, as __attribute__ surely a
+	no-op in that case and this is an area where __attribute__ cannot
+	simply be ignored.
+	* m4/stdalign.m4 (gl_STDALIGN_H): Include <stdint.h> so that
+	it #defines __attribute__(x) to nothing on glibc-based systems
+	when non-GNU-C-compatible compilers are used.
+	This exposes a bug in Tiny C Compiler 0.9.27’s implementation
+	of _Alignas on glibc platforms.
+
 2021-03-03  Bruno Haible  <br...@clisp.org>
 
 	asyncsafe-spin, simple-atomic: Add support for tcc/x86.
diff --git a/lib/stdalign.in.h b/lib/stdalign.in.h
index e7a7402ee..52a4a7b6e 100644
--- a/lib/stdalign.in.h
+++ b/lib/stdalign.in.h
@@ -104,12 +104,13 @@
 #if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112
 # if defined __cplusplus && 201103 <= __cplusplus
 #  define _Alignas(a) alignas (a)
-# elif ((defined __APPLE__ && defined __MACH__                  \
-         ? 4 < __GNUC__ + (1 <= __GNUC_MINOR__)                 \
-         : __GNUC__ && !defined __ibmxl__)                      \
-        || (4 <= __clang_major__)                               \
-        || (__ia64 && (61200 <= __HP_cc || 61200 <= __HP_aCC))  \
-        || __ICC || 0x590 <= __SUNPRO_C || 0x0600 <= __xlC__)
+# elif (!defined __attribute__ \
+        && ((defined __APPLE__ && defined __MACH__ \
+             ? 4 < __GNUC__ + (1 <= __GNUC_MINOR__) \
+             : __GNUC__ && !defined __ibmxl__) \
+            || (4 <= __clang_major__) \
+            || (__ia64 && (61200 <= __HP_cc || 61200 <= __HP_aCC)) \
+            || __ICC || 0x590 <= __SUNPRO_C || 0x0600 <= __xlC__))
 #  define _Alignas(a) __attribute__ ((__aligned__ (a)))
 # elif 1300 <= _MSC_VER
 #  define _Alignas(a) __declspec (align (a))
diff --git a/m4/stdalign.m4 b/m4/stdalign.m4
index 8dcb634d5..e22d7f78c 100644
--- a/m4/stdalign.m4
+++ b/m4/stdalign.m4
@@ -13,7 +13,8 @@ AC_DEFUN([gl_STDALIGN_H],
     [gl_cv_header_working_stdalign_h],
     [AC_COMPILE_IFELSE(
        [AC_LANG_PROGRAM(
-          [[#include <stdalign.h>
+          [[#include <stdint.h>
+            #include <stdalign.h>
             #include <stddef.h>
 
             /* Test that alignof yields a result consistent with offsetof.
@@ -32,6 +33,7 @@ AC_DEFUN([gl_STDALIGN_H],
             /* Test _Alignas only on platforms where gnulib can help.  */
             #if \
                 ((defined __cplusplus && 201103 <= __cplusplus) \
+                 || (__TINYC__ && defined __attribute__) \
                  || (defined __APPLE__ && defined __MACH__ \
                      ? 4 < __GNUC__ + (1 <= __GNUC_MINOR__) \
                      : __GNUC__) \
-- 
2.27.0

Reply via email to