[gcc/devel/omp/gcc-10] [nvptx, libgcc] Fix Wbuiltin-declaration-mismatch in atomic.c

Tobias Burnus burnus@gcc.gnu.org
Fri Sep 11 12:00:13 GMT 2020


https://gcc.gnu.org/g:21fc67c95a47f8bb349492943dc0d05618db2cfd

commit 21fc67c95a47f8bb349492943dc0d05618db2cfd
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Fri Sep 11 13:53:21 2020 +0200

    [nvptx, libgcc] Fix Wbuiltin-declaration-mismatch in atomic.c
    
    When building for target nvptx, we get this and similar warnings for libgcc:
    ...
    src/libgcc/config/nvptx/atomic.c:39:1: warning: conflicting types for \
      built-in function ‘__sync_val_compare_and_swap_1’; expected \
      ‘unsigned char(volatile void *, unsigned char,  unsigned char)’ \
      [-Wbuiltin-declaration-mismatch]
    ...
    
    Fix this by making sure in atomic.c that the pointers used are of type
    'volatile void *'.
    
    Tested by rebuilding atomic.c.
    
    libgcc/ChangeLog:
    
            * config/nvptx/atomic.c (__SYNC_SUBWORD_COMPARE_AND_SWAP): Fix
            Wbuiltin-declaration-mismatch.
    
    (cherry picked from commit 7b9c26519e6aa07a0709c5c6fcc2b9a6ba050e7a)

Diff:
---
 libgcc/ChangeLog.omp         |  8 ++++++++
 libgcc/config/nvptx/atomic.c | 12 ++++++++----
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/libgcc/ChangeLog.omp b/libgcc/ChangeLog.omp
index 2009c3ec68e..e17e83aff7c 100644
--- a/libgcc/ChangeLog.omp
+++ b/libgcc/ChangeLog.omp
@@ -1,3 +1,11 @@
+2020-09-11  Tobias Burnus  <tobias@codesourcery.com>
+
+	Backport from mainline
+	2020-09-09  Tom de Vries  <tdevries@suse.de>
+
+	* config/nvptx/atomic.c (__SYNC_SUBWORD_COMPARE_AND_SWAP): Fix
+	Wbuiltin-declaration-mismatch.
+
 2020-08-12  Kwok Cheung Yeung  <kcy@codesourcery.com>
 
 	* config/nvptx/atomic.c: New.
diff --git a/libgcc/config/nvptx/atomic.c b/libgcc/config/nvptx/atomic.c
index 25a34fb5f2c..3b2ce34d4ad 100644
--- a/libgcc/config/nvptx/atomic.c
+++ b/libgcc/config/nvptx/atomic.c
@@ -33,10 +33,13 @@
 #define __SYNC_SUBWORD_COMPARE_AND_SWAP(TYPE, SIZE)			     \
 									     \
 TYPE									     \
-__sync_val_compare_and_swap_##SIZE (TYPE *ptr, TYPE oldval, TYPE newval)     \
+__sync_val_compare_and_swap_##SIZE (volatile void *vptr, TYPE oldval,	     \
+				    TYPE newval)			     \
 {									     \
-  unsigned int *wordptr = (unsigned int *)((__UINTPTR_TYPE__ ) ptr & ~3UL);  \
-  int shift = ((__UINTPTR_TYPE__ ) ptr & 3UL) * 8;			     \
+  volatile TYPE *ptr = vptr;						     \
+  volatile unsigned int *wordptr					     \
+    = (volatile unsigned int *)((__UINTPTR_TYPE__) ptr & ~3UL);	     \
+  int shift = ((__UINTPTR_TYPE__) ptr & 3UL) * 8;			     \
   unsigned int valmask = (1 << (SIZE * 8)) - 1;				     \
   unsigned int wordmask = ~(valmask << shift);				     \
   unsigned int oldword = *wordptr;					     \
@@ -61,7 +64,8 @@ __sync_val_compare_and_swap_##SIZE (TYPE *ptr, TYPE oldval, TYPE newval)     \
 }									     \
 									     \
 bool									     \
-__sync_bool_compare_and_swap_##SIZE (TYPE *ptr, TYPE oldval, TYPE newval)    \
+__sync_bool_compare_and_swap_##SIZE (volatile void *ptr, TYPE oldval,	     \
+				     TYPE newval)			     \
 {									     \
   return __sync_val_compare_and_swap_##SIZE (ptr, oldval, newval) == oldval; \
 }


More information about the Gcc-cvs mailing list