Subject: bug#53256: closed (Re: [bug-diffutils] bug#53256: Compiling 3.8 with nvhpc 22.1 : malloca.c 64 bits operations with signed and unsigned operands are currently unsupported by __builtin_add_overflow)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 15 Jan 2022 03:54:01 +0000

Your bug report

#53256: Compiling 3.8 with nvhpc 22.1 : malloca.c 64 bits operations with signed and unsigned operands are currently unsupported by __builtin_add_overflow

which was filed against the diffutils package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
53256: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=53256
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: [bug-diffutils] bug#53256: Compiling 3.8 with nvhpc 22.1 : malloca.c 64 bits operations with signed and unsigned operands are currently unsupported by __builtin_add_overflow
From: Paul Eggert <[email-masked]>
To: Olivier Cessenat <[email-masked]>
Cc: Gnulib bugs <[email-masked]>, [email-masked]
Date: Fri, 14 Jan 2022 19:53:39 -0800
List-Id: <debbugs-submit.debbugs.gnu.org>

On 1/14/22 03:33, Olivier Cessenat wrote:
> "diffutils-3.8/lib/malloca.c", line 52: error: 64 bits operations with 
> signed and unsigned operands are currently unsupported by 
> __builtin_add_overflow

Thanks for the bug report. Although nvc 22.1 defines __GNUC__ to be 11 
which means it supports GNU C as of GCC 11, that's obviously untrue for 
__builtin_add_overflow. That's unfortunate. Perhaps you could report 
this as a bug to NVIDIA, as their compiler shouldn't claim to support 
GNU C features that it lacks. nvc can set __GNUC__ to be the version of 
GNU C that it actually does support.

To work around the bug I installed the attached into Gnulib and this 
should appear in the next diffutils release. In the meantime you can 
compile with gcc.

From f0b5cdf9a1fdb5c991cf3e1bdffb55e31126dffc Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Fri, 14 Jan 2022 18:50:48 -0800
Subject: [PATCH] intprops: work around nvc 22.1 bug
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Problem reported by Olivier Cessenat (Bug#53256).
* lib/intprops.h (_GL_HAS_BUILTIN_ADD_OVERFLOW) [__EDG__]:
Define to 0, since __builtin_add_overflow doesn’t work
on NVIDIA HPC SDK 22.1.
---
 ChangeLog      | 6 ++++++
 lib/intprops.h | 8 ++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a900fec78d..cf22140d44 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2022-01-14  Paul Eggert  <[email-masked]>
 
+	intprops: work around nvc 22.1 bug
+	Problem reported by Olivier Cessenat (Bug#53256).
+	* lib/intprops.h (_GL_HAS_BUILTIN_ADD_OVERFLOW) [__EDG__]:
+	Define to 0, since __builtin_add_overflow doesn’t work
+	on NVIDIA HPC SDK 22.1.
+
 	copy-file-range: work around Linux kernel bug
 	This workaround is adapted from Coreutils.
 	* lib/copy-file-range.c [__linux__ && HAVE_COPY_FILE_RANGE]:
diff --git a/lib/intprops.h b/lib/intprops.h
index 68d6daa570..d4a917f72a 100644
--- a/lib/intprops.h
+++ b/lib/intprops.h
@@ -229,11 +229,15 @@
 
 /* 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
+#ifdef __EDG__
+/* EDG-based compilers like nvc 22.1 cannot add 64-bit signed to unsigned
+   <https://bugs.gnu.org/53256>.  */
+# define _GL_HAS_BUILTIN_ADD_OVERFLOW 0
+#elif 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>.  */
-#elif 7 <= __GNUC__ && !defined __EDG__
+#elif 7 <= __GNUC__
 # define _GL_HAS_BUILTIN_ADD_OVERFLOW 1
 #else
 # define _GL_HAS_BUILTIN_ADD_OVERFLOW 0
-- 
2.32.0

Subject: Compiling 3.8 with nvhpc 22.1 : malloca.c 64 bits operations with signed and unsigned operands are currently unsupported by __builtin_add_overflow
From: Olivier Cessenat <[email-masked]>
To: [email-masked]
Date: Fri, 14 Jan 2022 12:33:40 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

Hello,

I'm trying to compile diffutils 3.8 with nvc 22.1.

I get an error:

<<

"diffutils-3.8/lib/malloca.c", line 52: error: 64 bits operations with 
signed and unsigned operands are currently unsupported by 
__builtin_add_overflow
     if (!INT_ADD_WRAPV (n, plus, &nplus) && !xalloc_oversized (nplus, 1))
          ^

1 error detected in the compilation of "diffutils-3.8/lib/malloca.c".

It was fine with 3.7.

Thanks for your help.

Olivier Cessenat

Ubuntu 20.04 - compilation still fine with gcc 9.3.0