Thanks for fixing that, Bruno. Some other complications:
* ICC defines __EDG__ (at least, ICC 2021.3 does), so the underlying
issue seems to be EDG-based not ICC-specific, which means intprops.h
should look at __EDG__ and not bother with __ICC. (Perhaps this should
be true elsewhere in Gnulib?)
* In September, Intel's 2021.4 release moved from EDG to Clang. This no
longer defines __ICC or __EDG__, though it does define __clang__. There
is no longer a compiler called "icc"; I suppose people should use
"clang" now.
* The Clang folks installed a patch for Clang bug 16404 and this should
be part of Clang 14 when it comes out.
I installed the attached to try to modernize intprops.h in the light of
these developments. I haven't tested ICC 2021.3 much though, since
Fedora 35 glibc is too new for ICC 2021.3.From b33bf44931ec459cf2934bc83595d1399a83bfc3 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 6 Dec 2021 10:29:54 -0800
Subject: [PATCH] intprops: streamline and get ready for Clang 14
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* lib/intprops.h (_GL_HAS_BUILTIN_ADD_OVERFLOW):
Rely on __has_builtin first, since GCC didn’t introduce it until
GCC 9 so we don’t need to special-case GCC first.
(_GL_HAS_BUILTIN_ADD_OVERFLOW, _GL_HAS_BUILTIN_OVERFLOW_P):
Look at __EDG__ rather than __ICC, since icc defines __EDG__ too.
(_GL_HAS_BUILTIN_MUL_OVERFLOW): Define to 1 in Clang 14 and later,
as a bug fix is scheduled for Clang 14.
(_GL_HAS_BUILTIN_OVERFLOW_P): Do not bother to special-case
__clang__, since __has_builtin should do the right thing anyway.
---
ChangeLog | 13 +++++++++++++
lib/intprops.h | 20 +++++++++-----------
2 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 52068d2aa7..105918b2bb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2021-12-06 Paul Eggert <[email protected]>
+
+ intprops: streamline and get ready for Clang 14
+ * lib/intprops.h (_GL_HAS_BUILTIN_ADD_OVERFLOW):
+ Rely on __has_builtin first, since GCC didn’t introduce it until
+ GCC 9 so we don’t need to special-case GCC first.
+ (_GL_HAS_BUILTIN_ADD_OVERFLOW, _GL_HAS_BUILTIN_OVERFLOW_P):
+ Look at __EDG__ rather than __ICC, since icc defines __EDG__ too.
+ (_GL_HAS_BUILTIN_MUL_OVERFLOW): Define to 1 in Clang 14 and later,
+ as a bug fix is scheduled for Clang 14.
+ (_GL_HAS_BUILTIN_OVERFLOW_P): Do not bother to special-case
+ __clang__, since __has_builtin should do the right thing anyway.
+
2021-12-06 Bruno Haible <[email protected]>
intprops: Treat EDG-based compilers like Intel compilers.
diff --git a/lib/intprops.h b/lib/intprops.h
index b36e0bbed9..7f20f09fa0 100644
--- a/lib/intprops.h
+++ b/lib/intprops.h
@@ -229,18 +229,18 @@
/* True if __builtin_add_overflow (A, B, P) and __builtin_sub_overflow
(A, B, P) work when P is non-null. */
+#if defined __has_builtin
+# define _GL_HAS_BUILTIN_ADD_OVERFLOW __has_builtin (__builtin_add_overflow)
/* __builtin_{add,sub}_overflow exists but is not reliable in GCC 5.x and 6.x,
see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98269>. */
-#if 7 <= __GNUC__ && !defined __ICC
+#elif 7 <= __GNUC__ && !defined __EDG__
# define _GL_HAS_BUILTIN_ADD_OVERFLOW 1
-#elif defined __has_builtin
-# define _GL_HAS_BUILTIN_ADD_OVERFLOW __has_builtin (__builtin_add_overflow)
#else
# define _GL_HAS_BUILTIN_ADD_OVERFLOW 0
#endif
/* True if __builtin_mul_overflow (A, B, P) works when P is non-null. */
-#ifdef __clang__
+#if defined __clang_major_ && __clang_major__ < 14
/* Work around Clang bug <https://bugs.llvm.org/show_bug.cgi?id=16404>. */
# define _GL_HAS_BUILTIN_MUL_OVERFLOW 0
#else
@@ -249,12 +249,10 @@
/* True if __builtin_add_overflow_p (A, B, C) works, and similarly for
__builtin_sub_overflow_p and __builtin_mul_overflow_p. */
-#if defined __clang__ || defined __ICC || defined __EDG__
-/* Clang 11 lacks __builtin_mul_overflow_p, and even if it did it
- would presumably run afoul of Clang bug 16404. In ICC 2021.1 and
- the EDG-based MCST Elbrus LCC compiler, __builtin_add_overflow_p etc.
- are not treated as integral constant expressions even when all
- arguments are. */
+#ifdef __EDG__
+/* In EDG-based compilers like ICC 2021.3 and earlier,
+ __builtin_add_overflow_p etc. are not treated as integral constant
+ expressions even when all arguments are. */
# define _GL_HAS_BUILTIN_OVERFLOW_P 0
#elif defined __has_builtin
# define _GL_HAS_BUILTIN_OVERFLOW_P __has_builtin (__builtin_mul_overflow_p)
@@ -401,7 +399,7 @@
#if _GL_HAS_BUILTIN_MUL_OVERFLOW
# if ((9 < __GNUC__ + (3 <= __GNUC_MINOR__) \
|| (__GNUC__ == 8 && 4 <= __GNUC_MINOR__)) \
- && !defined __ICC)
+ && !defined __EDG__)
# define INT_MULTIPLY_WRAPV(a, b, r) __builtin_mul_overflow (a, b, r)
# else
/* Work around GCC bug 91450. */
--
2.33.1