From: TODO <>

This is a preview of the changes that we're working on integrating for GCC 17.
---
 libgomp/Makefile.am                    |   3 +
 libgomp/Makefile.in                    |   4 +-
 libgomp/affinity-fmt.c                 |  12 +-
 libgomp/alloc_cache.h                  |   2 +-
 libgomp/allocator.c                    |  14 +--
 libgomp/basic-allocator.c              |  16 +--
 libgomp/config/accel/target-indirect.c |   2 +-
 libgomp/config/bsd/proc.c              |   3 +-
 libgomp/config/gcn/allocator.c         |   8 +-
 libgomp/config/gcn/team.c              |   8 +-
 libgomp/config/linux/affinity.c        |   4 +-
 libgomp/config/linux/futex_waitv/bar.c |  16 +--
 libgomp/config/linux/numa.c            |   6 +-
 libgomp/config/nvptx/atomic.c          |   2 +-
 libgomp/config/nvptx/team.c            |   6 +-
 libgomp/config/posix/pool.h            |   2 +-
 libgomp/config/rtems/pool.h            |   4 +-
 libgomp/config/rtems/proc.c            |   4 +-
 libgomp/critical.c                     |  12 +-
 libgomp/env.c                          |  44 ++++---
 libgomp/fortran.c                      |  27 ++--
 libgomp/icv.c                          |   6 +-
 libgomp/libgomp-plugin.h               |   2 +-
 libgomp/libgomp.h                      |  12 +-
 libgomp/loop.c                         |  16 +--
 libgomp/loop_ull.c                     |   8 +-
 libgomp/oacc-async.c                   |   4 +-
 libgomp/oacc-host.c                    | 168 ++++++++++++++-----------
 libgomp/oacc-init.c                    |  12 +-
 libgomp/oacc-mem.c                     |   2 +
 libgomp/oacc-parallel.c                |  14 ++-
 libgomp/oacc-profiling.c               |  10 +-
 libgomp/ordered.c                      |   8 +-
 libgomp/plugin/plugin-gcn.c            |  71 ++++++-----
 libgomp/plugin/plugin-nvptx.c          |  43 ++++---
 libgomp/priority_queue.h               |   4 +-
 libgomp/sections.c                     |   2 +-
 libgomp/simple-allocator.c             |  10 +-
 libgomp/target.c                       | 113 +++++++++--------
 libgomp/task.c                         |  22 ++--
 libgomp/taskloop.c                     |   2 +-
 libgomp/team.c                         |  22 ++--
 libgomp/work.c                         |  12 +-
 43 files changed, 424 insertions(+), 338 deletions(-)

diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index 37422e19b5c9..3def3c6d3b9f 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -20,6 +20,9 @@ AM_CPPFLAGS = $(addprefix -I, $(search_path))
 AM_CFLAGS = $(XCFLAGS)
 AM_LDFLAGS = $(XLDFLAGS) $(SECTION_LDFLAGS) $(OPT_LDFLAGS)
 
+#TODO
+AM_CFLAGS += -Wc++-compat
+
 toolexeclib_LTLIBRARIES = libgomp.la
 nodist_toolexeclib_HEADERS = libgomp.spec
 
diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index d1e0f6593b28..3104831443b3 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -519,7 +519,9 @@ search_path = $(addprefix $(top_srcdir)/config/, 
$(config_path)) $(top_srcdir) \
 fincludedir = 
$(libdir)/gcc/$(target_alias)/$(gcc_version)$(MULTISUBDIR)/finclude
 libsubincludedir = $(libdir)/gcc/$(target_alias)/$(gcc_version)/include
 AM_CPPFLAGS = $(addprefix -I, $(search_path))
-AM_CFLAGS = $(XCFLAGS)
+
+#TODO
+AM_CFLAGS = $(XCFLAGS) -Wc++-compat
 AM_LDFLAGS = $(XLDFLAGS) $(SECTION_LDFLAGS) $(OPT_LDFLAGS)
 toolexeclib_LTLIBRARIES = libgomp.la $(am__append_1) $(am__append_2)
 nodist_toolexeclib_HEADERS = libgomp.spec
diff --git a/libgomp/affinity-fmt.c b/libgomp/affinity-fmt.c
index c5d324fdbad8..0ef69b7a56a0 100644
--- a/libgomp/affinity-fmt.c
+++ b/libgomp/affinity-fmt.c
@@ -55,9 +55,9 @@ gomp_set_affinity_format (const char *format, size_t len)
     {
       char *p;
       if (gomp_affinity_format_len)
-       p = gomp_realloc (gomp_affinity_format_var, len + 1);
+       p = (char *) gomp_realloc (gomp_affinity_format_var, len + 1);
       else
-       p = gomp_malloc (len + 1);
+       p = (char *) gomp_malloc (len + 1);
       memcpy (p, format, len);
       gomp_affinity_format_var = p;
       gomp_affinity_format_len = len + 1;
@@ -217,9 +217,9 @@ gomp_display_hostname (char *buffer, size_t size, size_t 
*ret,
          break;
        len = len * 2;
        if (len == 512)
-         b = gomp_malloc (len);
+         b = (char *) gomp_malloc (len);
        else
-         b = gomp_realloc (b, len);
+         b = (char *) gomp_realloc (b, len);
       }
     while (1);
     if (b != buf)
@@ -468,7 +468,7 @@ omp_display_affinity (const char *format)
       gomp_print_string (buf, ret + 1);
       return;
     }
-  b = gomp_malloc (ret + 1);
+  b = (char *) gomp_malloc (ret + 1);
   ialias_call (omp_capture_affinity) (b, ret + 1, format);
   b[ret] = '\n';
   gomp_print_string (b, ret + 1);
@@ -489,7 +489,7 @@ gomp_display_affinity_thread (gomp_thread_handle handle,
       gomp_print_string (buf, ret + 1);
       return;
     }
-  b = gomp_malloc (ret + 1);
+  b = (char *) gomp_malloc (ret + 1);
   gomp_display_affinity (b, ret + 1, gomp_affinity_format_var,
                         handle, ts, place);
   b[ret] = '\n';
diff --git a/libgomp/alloc_cache.h b/libgomp/alloc_cache.h
index 782569c1faec..b3ecb02097a3 100644
--- a/libgomp/alloc_cache.h
+++ b/libgomp/alloc_cache.h
@@ -98,7 +98,7 @@ alloc_cache_add_taken_node (struct alloc_cache *cache,
                            void *allocation,
                            size_t size)
 {
-  struct alloc_cache_node *new_node = malloc (sizeof (*new_node));
+  struct alloc_cache_node *new_node = (typeof (new_node)) malloc (sizeof 
(*new_node));
 
   if (!new_node)
     return NULL;
diff --git a/libgomp/allocator.c b/libgomp/allocator.c
index dc1b79d9b83a..a0741e285746 100644
--- a/libgomp/allocator.c
+++ b/libgomp/allocator.c
@@ -73,7 +73,7 @@ GOMP_add_alloc (void *ptr)
   if (ptr == NULL)
     return;
   fort_alloc_splay_tree_node item;
-  item = gomp_malloc (sizeof (struct splay_tree_node_s));
+  item = (typeof (item)) gomp_malloc (sizeof (struct splay_tree_node_s));
   item->key.ptr = ptr;
   item->left = NULL;
   item->right = NULL;
@@ -251,7 +251,7 @@ struct omp_allocator_data
      this field unconditionally when offload is enabled.  */
   #if defined(LIBGOMP_USE_MEMKIND) || defined(LIBGOMP_USE_LIBNUMA) ||  \
     defined(LIBGOMP_OFFLOAD_HOST) || defined(LIBGOMP_OFFLOADED_ONLY)
-  unsigned int memkind : 8;
+  enum gomp_numa_memkind_kind memkind : 8;
 #endif
   /* Note: we now require __sync builtins for offload host/accelerator,
      checked during configuration. This lock should never be enabled
@@ -302,7 +302,7 @@ gomp_init_libnuma (void)
   void *handle = dlopen ("libnuma.so.1", RTLD_LAZY);
   struct gomp_libnuma_data *data;
 
-  data = calloc (1, sizeof (struct gomp_libnuma_data));
+  data = (typeof (data)) calloc (1, sizeof (struct gomp_libnuma_data));
   if (data == NULL)
     {
       if (handle)
@@ -364,7 +364,7 @@ gomp_init_memkind (void)
 #undef GOMP_MEMKIND_KIND
   };
 
-  data = calloc (1, sizeof (struct gomp_memkind_data));
+  data = (typeof (data)) calloc (1, sizeof (struct gomp_memkind_data));
   if (data == NULL)
     {
       if (handle)
@@ -423,7 +423,7 @@ gomp_init_allocator_data (struct omp_allocator_data *data,
   data->alignment = 1;
   data->pool_size = ~(uintptr_t) 0;
   data->used_pool_size = 0;
-  data->fb_data = 0;
+  data->fb_data = omp_null_allocator;
   data->sync_hint = omp_atv_contended;
   data->access = omp_atv_all;
   data->fallback = omp_atv_default_mem_fb;
@@ -507,7 +507,7 @@ gomp_init_allocator_data (struct omp_allocator_data *data,
          }
        break;
       case omp_atk_fb_data:
-       data->fb_data = traits[i].value;
+       data->fb_data = (typeof (data->fb_data)) traits[i].value;
        break;
       case omp_atk_pinned:
        switch (traits[i].value)
@@ -601,7 +601,7 @@ omp_init_allocator (omp_memspace_handle_t memspace, int 
ntraits,
                    const omp_alloctrait_t traits[])
 {
   struct omp_allocator_data *data
-    = gomp_malloc (sizeof (struct omp_allocator_data));
+    = (typeof (data)) gomp_malloc (sizeof (struct omp_allocator_data));
 
   omp_allocator_handle_t ret
     = gomp_init_allocator_data (data, memspace, ntraits, traits);
diff --git a/libgomp/basic-allocator.c b/libgomp/basic-allocator.c
index 15914a82e3a4..751df393e3c4 100644
--- a/libgomp/basic-allocator.c
+++ b/libgomp/basic-allocator.c
@@ -73,7 +73,7 @@ typedef struct {
 } heapdesc;
 
 void
-basic_alloc_init (char *heap, size_t limit)
+basic_alloc_init (void *heap, size_t limit)
 {
   if (heap == NULL)
     return;
@@ -90,7 +90,7 @@ basic_alloc_init (char *heap, size_t limit)
 }
 
 static void *
-basic_alloc_alloc (char *heap, size_t size)
+basic_alloc_alloc (void *heap, size_t size)
 {
   if (heap == NULL)
     return NULL;
@@ -161,12 +161,12 @@ basic_alloc_alloc (char *heap, size_t size)
 }
 
 static void *
-basic_alloc_calloc (char *heap, size_t size)
+basic_alloc_calloc (void *heap, size_t size)
 {
   /* Memory is allocated in N-byte granularity.  */
   size = ALIGN (size);
 
-  uint64_t *result = basic_alloc_alloc (heap, size);
+  uint64_t *result = (typeof (result)) basic_alloc_alloc (heap, size);
   if (result)
     /* Inline memset in which we know size is a multiple of 8.  */
     for (unsigned i = 0; i < (unsigned) size / 8; i++)
@@ -176,7 +176,7 @@ basic_alloc_calloc (char *heap, size_t size)
 }
 
 static void
-basic_alloc_free (char *heap, void *addr, size_t size)
+basic_alloc_free (void *heap, void *addr, size_t size)
 {
   /* Memory is allocated in N-byte granularity.  */
   size = ALIGN (size);
@@ -251,7 +251,7 @@ basic_alloc_free (char *heap, void *addr, size_t size)
 }
 
 static void *
-basic_alloc_realloc (char *heap, void *addr, size_t oldsize,
+basic_alloc_realloc (void *heap, void *addr, size_t oldsize,
                                      size_t size)
 {
   /* Memory is allocated in N-byte granularity.  */
@@ -301,7 +301,7 @@ basic_alloc_realloc (char *heap, void *addr, size_t oldsize,
 
       /* Update the free chain.  */
       heapdesc nowfree;
-      nowfree.offset = (char *) nowfreeptr - heap;
+      nowfree.offset = (void *) nowfreeptr - heap;
       nowfree.size = oldsize - size;
 
       if (nowfree.offset + size == chunk.offset)
@@ -367,7 +367,7 @@ basic_alloc_realloc (char *heap, void *addr, size_t oldsize,
       if (result != NULL)
        {
          /* Inline memcpy in which we know oldsize is a multiple of 8.  */
-         uint64_t *from = addr, *to = result;
+         uint64_t *from = (typeof (from)) addr, *to = (typeof (to)) result;
          for (unsigned i = 0; i < (unsigned) oldsize / 8; i++)
            to[i] = from[i];
 
diff --git a/libgomp/config/accel/target-indirect.c 
b/libgomp/config/accel/target-indirect.c
index a5695b3790ff..f3e196c48fca 100644
--- a/libgomp/config/accel/target-indirect.c
+++ b/libgomp/config/accel/target-indirect.c
@@ -104,7 +104,7 @@ build_indirect_map (void)
   htab_t indirect_htab = htab_create (num_ind_funcs);
   GOMP_INDIRECT_ADDR_HMAP = (void *) indirect_htab;
 
-  map_entry = GOMP_INDIRECT_ADDR_MAP;
+  map_entry = (uint64_t *) GOMP_INDIRECT_ADDR_MAP;
   for (int i = 0; i < num_ind_funcs; i++, map_entry += 2)
     {
       hash_entry_type element;
diff --git a/libgomp/config/bsd/proc.c b/libgomp/config/bsd/proc.c
index 13efb0786bdb..ddcb963f6435 100644
--- a/libgomp/config/bsd/proc.c
+++ b/libgomp/config/bsd/proc.c
@@ -49,7 +49,8 @@ get_num_procs (void)
 #elif defined HW_NCPU
   int ncpus = 1;
   size_t len = sizeof(ncpus);
-  sysctl((int[2]) {CTL_HW, HW_NCPU}, 2, &ncpus, &len, NULL, 0);
+  int mib[] = {CTL_HW, HW_NCPU};
+  sysctl (mib, 2, &ncpus, &len, NULL, 0);
   return ncpus;
 #else
   return 0;
diff --git a/libgomp/config/gcn/allocator.c b/libgomp/config/gcn/allocator.c
index f09d19cc755e..054a74a0d527 100644
--- a/libgomp/config/gcn/allocator.c
+++ b/libgomp/config/gcn/allocator.c
@@ -52,7 +52,7 @@ gcn_memspace_alloc (omp_memspace_handle_t memspace, size_t 
size)
 {
   if (memspace == omp_low_lat_mem_space)
     {
-      char *shared_pool = FLAT_HEAP_PTR;
+      void *shared_pool = FLAT_HEAP_PTR;
 
       return __gcn_lowlat_alloc (shared_pool, size);
     }
@@ -69,7 +69,7 @@ gcn_memspace_calloc (omp_memspace_handle_t memspace, size_t 
size)
 {
   if (memspace == omp_low_lat_mem_space)
     {
-      char *shared_pool = FLAT_HEAP_PTR;
+      void *shared_pool = FLAT_HEAP_PTR;
 
       return __gcn_lowlat_calloc (shared_pool, size);
     }
@@ -85,7 +85,7 @@ gcn_memspace_free (omp_memspace_handle_t memspace, void 
*addr, size_t size)
 {
   if (memspace == omp_low_lat_mem_space)
     {
-      char *shared_pool = FLAT_HEAP_PTR;
+      void *shared_pool = FLAT_HEAP_PTR;
 
       __gcn_lowlat_free (shared_pool, addr, size);
     }
@@ -99,7 +99,7 @@ gcn_memspace_realloc (omp_memspace_handle_t memspace, void 
*addr,
 {
   if (memspace == omp_low_lat_mem_space)
     {
-      char *shared_pool = FLAT_HEAP_PTR;
+      void *shared_pool = FLAT_HEAP_PTR;
 
       return __gcn_lowlat_realloc (shared_pool, addr, oldsize, size);
     }
diff --git a/libgomp/config/gcn/team.c b/libgomp/config/gcn/team.c
index f9bfa93fe631..7b94e708d7c8 100644
--- a/libgomp/config/gcn/team.c
+++ b/libgomp/config/gcn/team.c
@@ -90,20 +90,20 @@ gomp_gcn_enter_kernel (void)
 
       /* Initialize the low-latency heap.  The header is the size.  */
       void __lds *lowlat = (void __lds *)GCN_LOWLAT_HEAP;
-      hsa_kernel_dispatch_packet_t *queue_ptr = __builtin_gcn_dispatch_ptr ();
+      hsa_kernel_dispatch_packet_t *queue_ptr = (typeof (queue_ptr)) 
__builtin_gcn_dispatch_ptr ();
       __gcn_lowlat_init ((void*)(uintptr_t)(void __flat*)lowlat,
                         queue_ptr->group_segment_size - GCN_LOWLAT_HEAP);
 
       /* Allocate and initialize the team-local-storage data.  */
-      struct gomp_thread *thrs = team_malloc_cleared (sizeof (*thrs)
+      struct gomp_thread *thrs = (typeof (thrs)) team_malloc_cleared (sizeof 
(*thrs)
                                                      * numthreads);
       set_gcn_thrs (thrs);
 
       /* Allocate and initialize a pool of threads in the team.
          The threads are already running, of course, we just need to manage
          the communication between them.  */
-      struct gomp_thread_pool *pool = team_malloc (sizeof (*pool));
-      pool->threads = team_malloc (sizeof (void *) * numthreads);
+      struct gomp_thread_pool *pool = (typeof (pool)) team_malloc (sizeof 
(*pool));
+      pool->threads = (typeof (pool->threads)) team_malloc (sizeof (void *) * 
numthreads);
       for (int tid = 0; tid < numthreads; tid++)
        pool->threads[tid] = &thrs[tid];
       pool->threads_size = numthreads;
diff --git a/libgomp/config/linux/affinity.c b/libgomp/config/linux/affinity.c
index d30187b60643..798172eaaaf5 100644
--- a/libgomp/config/linux/affinity.c
+++ b/libgomp/config/linux/affinity.c
@@ -84,7 +84,7 @@ gomp_affinity_alloc (unsigned long count, bool quiet)
       return NULL;
     }
 
-  ret = malloc (count * sizeof (void *) + count * gomp_cpuset_size);
+  ret = (typeof (ret)) malloc (count * sizeof (void *) + count * 
gomp_cpuset_size);
   if (ret == NULL)
     {
       if (!quiet)
@@ -482,7 +482,7 @@ gomp_affinity_init_level (int level, unsigned long count, 
bool quiet)
   if (gomp_places_list == NULL)
     return false;
 
-  copy = gomp_alloca (gomp_cpuset_size);
+  copy = (typeof (copy)) gomp_alloca (gomp_cpuset_size);
   strcpy (name, "/sys/devices/system/cpu/cpu");
   memcpy (copy, gomp_cpusetp, gomp_cpuset_size);
   if (level == 5)
diff --git a/libgomp/config/linux/futex_waitv/bar.c 
b/libgomp/config/linux/futex_waitv/bar.c
index ffb27e0cc8a2..2e4a372d6bbc 100644
--- a/libgomp/config/linux/futex_waitv/bar.c
+++ b/libgomp/config/linux/futex_waitv/bar.c
@@ -149,8 +149,8 @@ gomp_assert_and_increment_flag (gomp_barrier_t *bar, 
unsigned id, unsigned gens)
      observe.  We are the only thread writing to this value, so we only need an
      atomic store for publishing and do not need __atomic_fetch_add.  */
   unsigned orig = bar->threadgens[id].gen;
-  unsigned new = orig + BAR_INCR;
-  gomp_assert_and_store_flag (&bar->threadgens[id].gen, new, orig, gens, id);
+  unsigned new_gen = orig + BAR_INCR;
+  gomp_assert_and_store_flag (&bar->threadgens[id].gen, new_gen, orig, gens, 
id);
 }
 
 static inline gomp_barrier_state_t
@@ -789,8 +789,8 @@ gomp_assert_and_increment_cancel_flag (gomp_barrier_t *bar, 
unsigned id,
                                       unsigned gens)
 {
   unsigned orig = bar->threadgens[id].gen;
-  unsigned new = BAR_INCREMENT_CANCEL (orig);
-  gomp_assert_and_store_flag (&bar->threadgens[id].gen, new, orig, gens, id);
+  unsigned new_gen = BAR_INCREMENT_CANCEL (orig);
+  gomp_assert_and_store_flag (&bar->threadgens[id].gen, new_gen, orig, gens, 
id);
 }
 
 static inline bool
@@ -999,12 +999,12 @@ gomp_team_barrier_wait_cancel_end_impl (gomp_barrier_t 
*bar,
           */
          unsigned *cgen = &bar->threadgens[id].gen;
          unsigned orig = *cgen;
-         unsigned new = ((orig - BAR_CANCEL_INCR) & BAR_CANCEL_GEN_MASK)
-                        | (orig & ~BAR_CANCEL_GEN_MASK);
-         __atomic_store_n (cgen, new, MEMMODEL_RELAXED);
+         unsigned new_gen = (((orig - BAR_CANCEL_INCR) & BAR_CANCEL_GEN_MASK)
+                             | (orig & ~BAR_CANCEL_GEN_MASK));
+         __atomic_store_n (cgen, new_gen, MEMMODEL_RELAXED);
 #if _LIBGOMP_CHECKING_
          unsigned global_gen = gen & BAR_BOTH_GENS_MASK;
-         gomp_assert (new == global_gen,
+         gomp_assert (new_gen == global_gen,
                       "thread-local generation %u unknown modification:"
                       " expected %u seen %u",
                       id, BAR_INCREMENT_CANCEL (global_gen), orig);
diff --git a/libgomp/config/linux/numa.c b/libgomp/config/linux/numa.c
index 82711f6e885e..7ded9803896f 100644
--- a/libgomp/config/linux/numa.c
+++ b/libgomp/config/linux/numa.c
@@ -101,9 +101,10 @@ retry:
 
   /* Create mapping array between the node number and contiguous
      n-th online node count. */
+  { //TODO indentation
   unsigned constexpr UNSET_REMAP = (unsigned) -1;
   num_remap = 8;
-  remap = malloc (sizeof (*remap) * num_remap);
+  remap = (typeof (remap)) malloc (sizeof (*remap) * num_remap);
   if (!remap)
     goto fail;
   for (int i = 0; i < num_remap; i++)
@@ -131,7 +132,7 @@ retry:
       if (num_remap <= nlast)
        {
          int n = nlast > 2 * num_remap ? nlast + 1 : num_remap * 2;
-         remap = realloc (remap, sizeof (*remap) * n);
+         remap = (typeof (remap)) realloc (remap, sizeof (*remap) * n);
          if (!remap || n <= nlast)
            goto fail;
          for (int i = num_remap; i < n; i++)
@@ -184,6 +185,7 @@ retry:
   __asm volatile ("" : : : "memory");
   __atomic_store_n (&num_numa_nodes, num, MEMMODEL_RELAXED);
   goto retry;
+  }
 
 fail:
   free (lineptr);
diff --git a/libgomp/config/nvptx/atomic.c b/libgomp/config/nvptx/atomic.c
index 2e13b09b4973..371fc596e861 100644
--- a/libgomp/config/nvptx/atomic.c
+++ b/libgomp/config/nvptx/atomic.c
@@ -10,7 +10,7 @@ unsigned __int128
 __sync_val_compare_and_swap_16 (volatile void *vptr, unsigned __int128 oldval,
                                unsigned __int128 newval)
 {
-  volatile __int128 *ptr = vptr;
+  volatile __int128 *ptr = (typeof (ptr)) vptr;
   __int128 expected = oldval;
   __atomic_compare_exchange_n (ptr, &expected, newval, false,
                               MEMMODEL_SEQ_CST, MEMMODEL_SEQ_CST);
diff --git a/libgomp/config/nvptx/team.c b/libgomp/config/nvptx/team.c
index 5ec4d7819069..9f21be55a881 100644
--- a/libgomp/config/nvptx/team.c
+++ b/libgomp/config/nvptx/team.c
@@ -75,7 +75,7 @@ gomp_nvptx_main (void (*fn) (void *), void *fn_data)
       gomp_global_icv.dyn_var = true;
 
       __gomp_team_num = 0;
-      nvptx_thrs = alloca (ntids * sizeof (*nvptx_thrs));
+      nvptx_thrs = (typeof (nvptx_thrs)) alloca (ntids * sizeof (*nvptx_thrs));
       memset (nvptx_thrs, 0, ntids * sizeof (*nvptx_thrs));
 
       /* Initialize indirect function support for older libgomp.  */
@@ -96,8 +96,8 @@ gomp_nvptx_main (void (*fn) (void *), void *fn_data)
 #endif
 
       /* Initialize the thread pool.  */
-      struct gomp_thread_pool *pool = alloca (sizeof (*pool));
-      pool->threads = alloca (ntids * sizeof (*pool->threads));
+      struct gomp_thread_pool *pool = (typeof (pool)) alloca (sizeof (*pool));
+      pool->threads = (typeof (pool->threads)) alloca (ntids * sizeof 
(*pool->threads));
       for (tid = 0; tid < ntids; tid++)
        pool->threads[tid] = nvptx_thrs + tid;
       pool->threads_size = ntids;
diff --git a/libgomp/config/posix/pool.h b/libgomp/config/posix/pool.h
index 385f339fd1fe..0b71bd4d0f6e 100644
--- a/libgomp/config/posix/pool.h
+++ b/libgomp/config/posix/pool.h
@@ -39,7 +39,7 @@ gomp_get_thread_pool (struct gomp_thread *thr, unsigned 
nthreads)
   struct gomp_thread_pool *pool = thr->thread_pool;
   if (__builtin_expect (pool == NULL, 0))
     {
-      pool = gomp_malloc (sizeof (*pool));
+      pool = (typeof (pool)) gomp_malloc (sizeof (*pool));
       pool->threads = NULL;
       pool->threads_size = 0;
       pool->threads_used = 0;
diff --git a/libgomp/config/rtems/pool.h b/libgomp/config/rtems/pool.h
index ca36e2a99d66..3e6a83fc215a 100644
--- a/libgomp/config/rtems/pool.h
+++ b/libgomp/config/rtems/pool.h
@@ -62,7 +62,7 @@ gomp_get_thread_pool_reservoir (void)
   if (res == NULL && gomp_thread_pool_reservoirs != NULL)
     {
       struct gomp_thread *thr = gomp_thread ();
-      thr->thread_pool = gomp_malloc_cleared (sizeof (*thr->thread_pool));
+      thr->thread_pool = (typeof (thr->thread_pool)) gomp_malloc_cleared 
(sizeof (*thr->thread_pool));
       res = gomp_thread_pool_reservoirs[_Sched_Index ()];
       gomp_tls_rtems_data.thread_pool_reservoir = res;
     }
@@ -76,7 +76,7 @@ gomp_get_own_thread_pool (struct gomp_thread *thr, unsigned 
nthreads)
   struct gomp_thread_pool *pool = thr->thread_pool;
   if (__builtin_expect (pool == NULL, 0))
     {
-      pool = gomp_malloc_cleared (sizeof (*pool));
+      pool = (typeof (pool)) gomp_malloc_cleared (sizeof (*pool));
       pool->threads_busy = nthreads;
       thr->thread_pool = pool;
     }
diff --git a/libgomp/config/rtems/proc.c b/libgomp/config/rtems/proc.c
index dc6912795098..160eca175546 100644
--- a/libgomp/config/rtems/proc.c
+++ b/libgomp/config/rtems/proc.c
@@ -42,7 +42,7 @@ allocate_thread_pool_reservoirs (void)
 {
   struct gomp_thread_pool_reservoir **reservoirs;
   size_t size = _Sched_Count () * sizeof (*reservoirs);
-  reservoirs = gomp_malloc (size);
+  reservoirs = (typeof (reservoirs)) gomp_malloc (size);
   gomp_thread_pool_reservoirs = reservoirs;
   memset (reservoirs, 0, size);
 }
@@ -60,7 +60,7 @@ allocate_thread_pool_reservoir (unsigned long count, unsigned 
long priority,
   if (res != NULL)
     gomp_fatal ("Multiple thread pool reservoir initialization");
   size = sizeof (*res) + count * (sizeof(pools) + sizeof(*pools));
-  pools = gomp_malloc (size);
+  pools = (typeof (pools)) gomp_malloc (size);
   memset (pools, 0, size);
   res = (struct gomp_thread_pool_reservoir *) (pools + count);
   res->index = count;
diff --git a/libgomp/critical.c b/libgomp/critical.c
index 1a45ceb4b850..6dcec438a7da 100644
--- a/libgomp/critical.c
+++ b/libgomp/critical.c
@@ -64,15 +64,15 @@ GOMP_critical_name_start (void **pptr)
   /* Otherwise we have to be prepared to malloc storage.  */
   else
     {
-      plock = *pptr;
+      plock = *(gomp_mutex_t **) pptr;
 
       if (plock == NULL)
        {
 #ifdef HAVE_SYNC_BUILTINS
-         gomp_mutex_t *nlock = gomp_malloc (sizeof (gomp_mutex_t));
+         gomp_mutex_t *nlock = (gomp_mutex_t *) gomp_malloc (sizeof 
(gomp_mutex_t));
          gomp_mutex_init (nlock);
 
-         plock = __sync_val_compare_and_swap (pptr, NULL, nlock);
+         plock = __sync_val_compare_and_swap ((gomp_mutex_t **) pptr, NULL, 
nlock);
          if (plock != NULL)
            {
              gomp_mutex_destroy (nlock);
@@ -82,10 +82,10 @@ GOMP_critical_name_start (void **pptr)
            plock = nlock;
 #else
          gomp_mutex_lock (&create_lock_lock);
-         plock = *pptr;
+         plock = *(gomp_mutex_t **) pptr;
          if (plock == NULL)
            {
-             plock = gomp_malloc (sizeof (gomp_mutex_t));
+             plock = (typeof (plock)) gomp_malloc (sizeof (gomp_mutex_t));
              gomp_mutex_init (plock);
              __sync_synchronize ();
              *pptr = plock;
@@ -110,7 +110,7 @@ GOMP_critical_name_end (void **pptr)
       && __alignof (gomp_mutex_t) <= sizeof (void *))
     plock = (gomp_mutex_t *)pptr;
   else
-    plock = *pptr;
+    plock = *(gomp_mutex_t **) pptr;
 
   gomp_mutex_unlock (plock);
 }
diff --git a/libgomp/env.c b/libgomp/env.c
index 9dcbbd72ad01..c5e9dd84bf8b 100644
--- a/libgomp/env.c
+++ b/libgomp/env.c
@@ -52,6 +52,7 @@
 # endif
 #endif
 #include <errno.h>
+#include <assert.h>
 #include "thread-stacksize.h"
 
 #ifndef HAVE_STRTOULL
@@ -201,7 +202,7 @@ parse_schedule (const char *env, const char *val, void 
*const params[])
 
   if (monotonic == 1
       || (monotonic == 0 && *schedule == GFS_STATIC))
-    *schedule |= GFS_MONOTONIC;
+    *schedule = (enum gomp_schedule_type) (*schedule | GFS_MONOTONIC);
 
   while (isspace ((unsigned char) *val))
     ++val;
@@ -387,7 +388,7 @@ parse_unsigned_long_list (const char *env, const char *val,
                {
                  unsigned long *n;
                  nalloced = nalloced ? nalloced * 2 : 16;
-                 n = realloc (values, nalloced * sizeof (unsigned long));
+                 n = (typeof (n)) realloc (values, nalloced * sizeof (unsigned 
long));
                  if (n == NULL)
                    {
                      free (values);
@@ -473,7 +474,7 @@ parse_target_offload (const char *env, const char *val, 
void *const params[])
     ++val;
   if (new_offload != -1 && *val == '\0')
     {
-      *(enum gomp_target_offload_t *) params[0] = new_offload;
+      *(enum gomp_target_offload_t *) params[0] = (enum gomp_target_offload_t) 
new_offload;
       return true;
     }
 
@@ -495,7 +496,20 @@ parse_bind_var (const char *env, const char *val, void 
*const params[])
   int i;
   static struct proc_bind_kinds
   {
+#if 0 //TODO C++
     const char name[7];
+#else
+    //TODO For "primary":
+    //TODO     error: initializer-string for array of ‘char’ is too long for 
C++ (8 chars into 7 available) [-Werror=c++-compat]
+    //TODO ..., which is the correct diagnostic for "old" C++ -- but this 
should again be valid as-was for C++11?
+    /*TODO ..., but is still diagnosed with '-std=gnu++11':
+../../../source-gcc/libgomp/env.cc: In function ‘bool parse_bind_var(const 
char*, const char*, void* const*)’:
+../../../source-gcc/libgomp/env.cc:528:7: error: initializer-string for ‘const 
char [7]’ is too long [-fpermissive]
+  528 |     { "primary", 7, omp_proc_bind_primary },
+      |       ^~~~~~~~~
+     */
+    const char name[/*7*/ 8];
+#endif
     const char len;
     omp_proc_bind_t kind;
   } kinds[] =
@@ -545,7 +559,7 @@ parse_bind_var (const char *env, const char *val, void 
*const params[])
                {
                  char *n;
                  nalloced = nalloced ? nalloced * 2 : 16;
-                 n = realloc (values, nalloced);
+                 n = (char *) realloc (values, nalloced);
                  if (n == NULL)
                    {
                      free (values);
@@ -1379,7 +1393,7 @@ parse_allocator (const char *env, const char *val, void 
*const params[])
            ++ntraits;
          ++cp;
        }
-      traits = gomp_alloca (ntraits * sizeof (omp_alloctrait_t));
+      traits = (typeof (traits)) gomp_alloca (ntraits * sizeof 
(omp_alloctrait_t));
       size_t n = 0;
       while (*val != '\0')
        {
@@ -1489,7 +1503,8 @@ parse_allocator (const char *env, const char *val, void 
*const params[])
     {
       if (ntraits)
        {
-         *ret = omp_init_allocator (*ret, ntraits, traits);
+         assert (memspace);
+         *ret = omp_init_allocator ((omp_memspace_handle_t) *ret, ntraits, 
traits);
          if (*ret == omp_null_allocator)
            {
              gomp_error ("Allocator of environment variable %.*s cannot be "
@@ -1664,7 +1679,7 @@ static const struct envvar
 {
   const char *name;
   int name_len;
-  uint8_t flag_vars[3];
+  enum gomp_icvs flag_vars[3];
   uint8_t flag;
   bool (*parse_func) (const char *, const char *, void *const[]);
 } envvars[] = {
@@ -1729,7 +1744,7 @@ static const struct envvar
 
 static const struct host_envvar
 {
-  unsigned char flag_var;
+  enum gomp_icvs flag_var;
   void *dest[3];
   int type_code;
 } host_envvars[] = {
@@ -2315,7 +2330,7 @@ cleanup_env (void)
   if (gomp_def_allocator_envvar != NULL)
     {
       free (gomp_def_allocator_envvar);
-      omp_destroy_allocator (gomp_def_allocator);
+      omp_destroy_allocator ((omp_allocator_handle_t) gomp_def_allocator);
     }
 }
 
@@ -2495,7 +2510,8 @@ initialize_env (void)
       const char *env = getenv ("OMP_NESTED");
 
       /* OMP_NESTED is deprecated in OpenMP 5.0.  */
-      if (parse_boolean ("OMP_NESTED", env, (void *[]) {&nested}))
+      void *const params[] = {&nested};
+      if (parse_boolean ("OMP_NESTED", env, params))
        gomp_global_icv.max_active_levels_var
          = nested ? gomp_supported_active_levels : 1;
       else if (gomp_nthreads_var_list_len > 1 || gomp_bind_var_list_len > 1)
@@ -2581,9 +2597,9 @@ initialize_env (void)
   if (!(none != NULL && gomp_get_icv_flag (none->flags, GOMP_ICV_STACKSIZE)))
     {
       const char *env = getenv ("GOMP_STACKSIZE");
+      void *const params[] = {&none->icvs.stacksize};
       if (env != NULL
-         && parse_stacksize ("GOMP_STACKSIZE", env,
-                             (void *[]) {&none->icvs.stacksize}))
+         && parse_stacksize ("GOMP_STACKSIZE", env, params))
        gomp_set_icv_flag (&none->flags, GOMP_ICV_STACKSIZE);
     }
   if (none != NULL && gomp_get_icv_flag (none->flags, GOMP_ICV_STACKSIZE))
@@ -2624,8 +2640,8 @@ initialize_env (void)
 
   /* OpenACC.  */
 
-  if (!parse_int ("ACC_DEVICE_NUM", getenv ("ACC_DEVICE_NUM"),
-                 (void *[]) {&goacc_device_num, (void *) true}))
+  void *const adn_params[] = {&goacc_device_num, (void *) true};
+  if (!parse_int ("ACC_DEVICE_NUM", getenv ("ACC_DEVICE_NUM"), adn_params))
     goacc_device_num = 0;
 
   parse_acc_device_type ();
diff --git a/libgomp/fortran.c b/libgomp/fortran.c
index 3af77c6c7ba8..d342cd11dddf 100644
--- a/libgomp/fortran.c
+++ b/libgomp/fortran.c
@@ -126,7 +126,7 @@ void
 gomp_init_lock__30 (omp_lock_arg_t lock)
 {
 #ifndef OMP_LOCK_DIRECT
-  omp_lock_arg (lock) = malloc (sizeof (omp_lock_t));
+  omp_lock_arg (lock) = (omp_lock_t *) malloc (sizeof (omp_lock_t));
 #endif
   gomp_init_lock_30 (omp_lock_arg (lock));
 }
@@ -135,7 +135,7 @@ void
 gomp_init_nest_lock__30 (omp_nest_lock_arg_t lock)
 {
 #ifndef OMP_NEST_LOCK_DIRECT
-  omp_nest_lock_arg (lock) = malloc (sizeof (omp_nest_lock_t));
+  omp_nest_lock_arg (lock) = (omp_nest_lock_t *) malloc (sizeof 
(omp_nest_lock_t));
 #endif
   gomp_init_nest_lock_30 (omp_nest_lock_arg (lock));
 }
@@ -201,7 +201,7 @@ void
 gomp_init_lock__25 (omp_lock_25_arg_t lock)
 {
 #ifndef OMP_LOCK_25_DIRECT
-  omp_lock_25_arg (lock) = malloc (sizeof (omp_lock_25_t));
+  omp_lock_25_arg (lock) = (omp_lock_25_t *) malloc (sizeof (omp_lock_25_t));
 #endif
   gomp_init_lock_25 (omp_lock_25_arg (lock));
 }
@@ -210,7 +210,7 @@ void
 gomp_init_nest_lock__25 (omp_nest_lock_25_arg_t lock)
 {
 #ifndef OMP_NEST_LOCK_25_DIRECT
-  omp_nest_lock_25_arg (lock) = malloc (sizeof (omp_nest_lock_25_t));
+  omp_nest_lock_25_arg (lock) = (omp_nest_lock_25_t *) malloc (sizeof 
(omp_nest_lock_25_t));
 #endif
   gomp_init_nest_lock_25 (omp_nest_lock_25_arg (lock));
 }
@@ -378,13 +378,13 @@ omp_get_wtime_ (void)
 void
 omp_set_schedule_ (const int32_t *kind, const int32_t *chunk_size)
 {
-  omp_set_schedule (*kind, *chunk_size);
+  omp_set_schedule ((omp_sched_t) *kind, *chunk_size);
 }
 
 void
 omp_set_schedule_8_ (const int32_t *kind, const int64_t *chunk_size)
 {
-  omp_set_schedule (*kind, TO_INT (*chunk_size));
+  omp_set_schedule ((omp_sched_t) *kind, TO_INT (*chunk_size));
 }
 
 void
@@ -695,7 +695,7 @@ omp_display_affinity_ (const char *format, size_t 
format_len)
   char buf[512];
   if (format_len)
     {
-      fmt = format_len < 256 ? fmt_buf : gomp_malloc (format_len + 1);
+      fmt = format_len < 256 ? fmt_buf : (char *) gomp_malloc (format_len + 1);
       memcpy (fmt, format, format_len);
       fmt[format_len] = '\0';
     }
@@ -711,7 +711,7 @@ omp_display_affinity_ (const char *format, size_t 
format_len)
     }
   else
     {
-      char *b = gomp_malloc (ret + 1);
+      char *b = (char *) gomp_malloc (ret + 1);
       gomp_display_affinity (buf, sizeof buf,
                             format_len ? fmt : gomp_affinity_format_var,
                             gomp_thread_self (), &thr->ts, thr->place);
@@ -730,7 +730,7 @@ omp_capture_affinity_ (char *buffer, const char *format,
   char *fmt = NULL, fmt_buf[256];
   if (format_len)
     {
-      fmt = format_len < 256 ? fmt_buf : gomp_malloc (format_len + 1);
+      fmt = format_len < 256 ? fmt_buf : (char *) gomp_malloc (format_len + 1);
       memcpy (fmt, format, format_len);
       fmt[format_len] = '\0';
     }
@@ -749,13 +749,13 @@ omp_capture_affinity_ (char *buffer, const char *format,
 int32_t
 omp_pause_resource_ (const int32_t *kind, const int32_t *device_num)
 {
-  return omp_pause_resource (*kind, *device_num);
+  return omp_pause_resource ((omp_pause_resource_t) *kind, *device_num);
 }
 
 int32_t
 omp_pause_resource_all_ (const int32_t *kind)
 {
-  return omp_pause_resource_all (*kind);
+  return omp_pause_resource_all ((omp_pause_resource_t) *kind);
 }
 
 intptr_t
@@ -833,7 +833,7 @@ int
 omp_get_device_from_uid_ (const char *uid, size_t uid_len)
 {
 #ifndef LIBGOMP_OFFLOADED_ONLY
-  char *str = __builtin_alloca ((uid_len + 1) * sizeof (char));
+  char *str = (char *) __builtin_alloca ((uid_len + 1) * sizeof (char));
   memcpy (str, uid, uid_len * sizeof (char));
   str[uid_len] = '\0';
   return omp_get_device_from_uid (str);
@@ -877,8 +877,9 @@ omp_get_supported_active_league_dims_ (int *device_num, int 
*native_support)
 }
 
 size_t
-omp_get_gprivate_limit_ (int device_num, int access_group, bool present_agrp)
+omp_get_gprivate_limit_ (int device_num, int access_group_, bool present_agrp)
 {
+  omp_access_t access_group = (typeof (access_group)) access_group_;
   if (!present_agrp)
     access_group = omp_access_cgroup;
   return omp_get_gprivate_limit (device_num, access_group);
diff --git a/libgomp/icv.c b/libgomp/icv.c
index 6c331451983a..56131905f20e 100644
--- a/libgomp/icv.c
+++ b/libgomp/icv.c
@@ -93,14 +93,14 @@ omp_set_schedule (omp_sched_t kind, int chunk_size)
     default:
       return;
     }
-  icv->run_sched_var = kind;
+  icv->run_sched_var = (enum gomp_schedule_type) kind;
 }
 
 void
 omp_get_schedule (omp_sched_t *kind, int *chunk_size)
 {
   struct gomp_task_icv *icv = gomp_icv (false);
-  *kind = icv->run_sched_var;
+  *kind = (omp_sched_t) icv->run_sched_var;
   *chunk_size = icv->run_sched_chunk_size;
 }
 
@@ -169,7 +169,7 @@ omp_proc_bind_t
 omp_get_proc_bind (void)
 {
   struct gomp_task_icv *icv = gomp_icv (false);
-  return icv->bind_var;
+  return (omp_proc_bind_t) icv->bind_var;
 }
 
 int
diff --git a/libgomp/libgomp-plugin.h b/libgomp/libgomp-plugin.h
index c67eeec6978f..489e87a0cbc9 100644
--- a/libgomp/libgomp-plugin.h
+++ b/libgomp/libgomp-plugin.h
@@ -326,7 +326,7 @@ typedef struct gomp_simple_alloc_context 
*gomp_simple_alloc_ctx_p;
 
 gomp_simple_alloc_ctx_p gomp_simple_alloc_init_context ();
 void gomp_simple_alloc_register_memory (gomp_simple_alloc_ctx_p ctx,
-                                       char *base, size_t size);
+                                       void *base, size_t size);
 void *gomp_simple_alloc (gomp_simple_alloc_ctx_p ctx, size_t size);
 void gomp_simple_free (gomp_simple_alloc_ctx_p ctx, void *addr);
 void *gomp_simple_realloc (gomp_simple_alloc_ctx_p ctx, void *addr,
diff --git a/libgomp/libgomp.h b/libgomp/libgomp.h
index dd0669b9a49f..847e21348a54 100644
--- a/libgomp/libgomp.h
+++ b/libgomp/libgomp.h
@@ -153,7 +153,7 @@ team_malloc (size_t size)
 static inline void * __attribute__((malloc))
 team_malloc_cleared (size_t size)
 {
-  char *result = team_malloc (size);
+  void *result = team_malloc (size);
 
   /* Clear the allocated memory.  */
   __builtin_memset (result, 0, size);
@@ -1146,7 +1146,13 @@ extern void gomp_display_string (char *, size_t, size_t 
*, const char *,
 #ifdef LIBGOMP_USE_PTHREADS
 typedef pthread_t gomp_thread_handle;
 #else
+//TODO     error: empty struct has size 0 in C, size 1 in C++ 
[-Werror=c++-compat]
+# pragma GCC diagnostic push
+//TODO     error: option ‘-Wc++-compat’ is valid for C/ObjC but not for C++ 
[-Werror=pragmas]
+# pragma GCC diagnostic warning "-Wpragmas"
+# pragma GCC diagnostic warning "-Wc++-compat"
 typedef struct {} gomp_thread_handle;
+# pragma GCC diagnostic pop
 #endif
 extern size_t gomp_display_affinity (char *, size_t, const char *,
                                     gomp_thread_handle,
@@ -1595,7 +1601,8 @@ struct gomp_device_descr
    ALLOC. */
 #define gomp_offload_session_new(devicep, alloc)               \
   ({                                                           \
-    void *session = alloc (devicep->session.size);     \
+    struct gomp_offload_session *session                       \
+      = (typeof (session)) alloc (devicep->session.size);      \
     devicep->session.start_func (session, devicep->target_id); \
     session;                                                   \
   })
@@ -1603,6 +1610,7 @@ struct gomp_device_descr
 /* Kind of the pragma, for which gomp_map_vars () is called.  */
 enum gomp_map_vars_kind
 {
+  GOMP_MAP_VARS_NONE       = 0,
   GOMP_MAP_VARS_OPENACC    = 1,
   GOMP_MAP_VARS_TARGET     = 2,
   GOMP_MAP_VARS_DATA       = 4,
diff --git a/libgomp/loop.c b/libgomp/loop.c
index ce0073966582..2c1ab854ece8 100644
--- a/libgomp/loop.c
+++ b/libgomp/loop.c
@@ -257,7 +257,7 @@ GOMP_loop_start (long start, long end, long incr, long 
sched,
     {
       sched = gomp_adjust_sched (sched, &chunk_size);
       gomp_loop_init (thr->ts.work_share, start, end, incr,
-                     sched, chunk_size);
+                     (enum gomp_schedule_type) sched, chunk_size);
       if (reductions)
        {
          GOMP_taskgroup_reduction_register (reductions);
@@ -277,7 +277,7 @@ GOMP_loop_start (long start, long end, long incr, long 
sched,
                        - INLINE_ORDERED_TEAM_IDS_OFF))
            *mem
              = (void *) (thr->ts.work_share->ordered_team_ids
-                         = gomp_malloc_cleared (size));
+                         = (unsigned *) gomp_malloc_cleared (size));
          else
            *mem = memset (((char *) thr->ts.work_share)
                           + INLINE_ORDERED_TEAM_IDS_OFF, '\0', size);
@@ -430,7 +430,7 @@ GOMP_loop_ordered_start (long start, long end, long incr, 
long sched,
     {
       sched = gomp_adjust_sched (sched, &chunk_size);
       gomp_loop_init (thr->ts.work_share, start, end, incr,
-                     sched, chunk_size);
+                     (enum gomp_schedule_type) sched, chunk_size);
       if (reductions)
        {
          GOMP_taskgroup_reduction_register (reductions);
@@ -609,7 +609,7 @@ GOMP_loop_doacross_start (unsigned ncounts, long *counts, 
long sched,
        extra = (uintptr_t) *mem;
       sched = gomp_adjust_sched (sched, &chunk_size);
       gomp_loop_init (thr->ts.work_share, 0, counts[0], 1,
-                     sched, chunk_size);
+                     (enum gomp_schedule_type) sched, chunk_size);
       gomp_doacross_init (ncounts, counts, chunk_size, extra);
       if (reductions)
        {
@@ -834,7 +834,7 @@ GOMP_parallel_loop_runtime_start (void (*fn) (void *), void 
*data,
 {
   struct gomp_task_icv *icv = gomp_icv (false);
   gomp_parallel_loop_start (fn, data, num_threads, start, end, incr,
-                           icv->run_sched_var & ~GFS_MONOTONIC,
+                           (enum gomp_schedule_type) (icv->run_sched_var & 
~GFS_MONOTONIC),
                            icv->run_sched_chunk_size, 0);
 }
 
@@ -880,7 +880,7 @@ GOMP_parallel_loop_runtime (void (*fn) (void *), void *data,
 {
   struct gomp_task_icv *icv = gomp_icv (false);
   gomp_parallel_loop_start (fn, data, num_threads, start, end, incr,
-                           icv->run_sched_var & ~GFS_MONOTONIC,
+                           (enum gomp_schedule_type) (icv->run_sched_var & 
~GFS_MONOTONIC),
                            icv->run_sched_chunk_size, flags);
   fn (data);
   GOMP_parallel_end ();
@@ -927,7 +927,7 @@ GOMP_parallel_loop_nonmonotonic_runtime (void (*fn) (void 
*), void *data,
 {
   struct gomp_task_icv *icv = gomp_icv (false);
   gomp_parallel_loop_start (fn, data, num_threads, start, end, incr,
-                           icv->run_sched_var & ~GFS_MONOTONIC,
+                           (enum gomp_schedule_type) (icv->run_sched_var & 
~GFS_MONOTONIC),
                            icv->run_sched_chunk_size, flags);
   fn (data);
   GOMP_parallel_end ();
@@ -941,7 +941,7 @@ GOMP_parallel_loop_maybe_nonmonotonic_runtime (void (*fn) 
(void *), void *data,
 {
   struct gomp_task_icv *icv = gomp_icv (false);
   gomp_parallel_loop_start (fn, data, num_threads, start, end, incr,
-                           icv->run_sched_var & ~GFS_MONOTONIC,
+                           (enum gomp_schedule_type) (icv->run_sched_var & 
~GFS_MONOTONIC),
                            icv->run_sched_chunk_size, flags);
   fn (data);
   GOMP_parallel_end ();
diff --git a/libgomp/loop_ull.c b/libgomp/loop_ull.c
index cb110c785deb..86f99a62c440 100644
--- a/libgomp/loop_ull.c
+++ b/libgomp/loop_ull.c
@@ -256,7 +256,7 @@ GOMP_loop_ull_start (bool up, gomp_ull start, gomp_ull end,
     {
       sched = gomp_adjust_sched (sched, &chunk_size);
       gomp_loop_ull_init (thr->ts.work_share, up, start, end, incr,
-                         sched, chunk_size);
+                         (enum gomp_schedule_type) sched, chunk_size);
       if (reductions)
        {
          GOMP_taskgroup_reduction_register (reductions);
@@ -276,7 +276,7 @@ GOMP_loop_ull_start (bool up, gomp_ull start, gomp_ull end,
                        - INLINE_ORDERED_TEAM_IDS_OFF))
            *mem
              = (void *) (thr->ts.work_share->ordered_team_ids
-                         = gomp_malloc_cleared (size));
+                         = (unsigned *) gomp_malloc_cleared (size));
          else
            *mem = memset (((char *) thr->ts.work_share)
                           + INLINE_ORDERED_TEAM_IDS_OFF, '\0', size);
@@ -432,7 +432,7 @@ GOMP_loop_ull_ordered_start (bool up, gomp_ull start, 
gomp_ull end,
     {
       sched = gomp_adjust_sched (sched, &chunk_size);
       gomp_loop_ull_init (thr->ts.work_share, up, start, end, incr,
-                         sched, chunk_size);
+                         (enum gomp_schedule_type) sched, chunk_size);
       if (reductions)
        {
          GOMP_taskgroup_reduction_register (reductions);
@@ -615,7 +615,7 @@ GOMP_loop_ull_doacross_start (unsigned ncounts, gomp_ull 
*counts,
        extra = (uintptr_t) *mem;
       sched = gomp_adjust_sched (sched, &chunk_size);
       gomp_loop_ull_init (thr->ts.work_share, true, 0, counts[0], 1,
-                         sched, chunk_size);
+                         (enum gomp_schedule_type) sched, chunk_size);
       gomp_doacross_ull_init (ncounts, counts, chunk_size, extra);
       if (reductions)
        {
diff --git a/libgomp/oacc-async.c b/libgomp/oacc-async.c
index 41563d737bea..55ab5132fcac 100644
--- a/libgomp/oacc-async.c
+++ b/libgomp/oacc-async.c
@@ -91,7 +91,7 @@ lookup_goacc_asyncqueue (struct goacc_thread *thr, bool 
create, int async)
     {
       int diff = async + 1 - dev->openacc.async.nasyncqueue;
       dev->openacc.async.asyncqueue
-       = gomp_realloc (dev->openacc.async.asyncqueue,
+       = (typeof (dev->openacc.async.asyncqueue)) gomp_realloc 
(dev->openacc.async.asyncqueue,
                        sizeof (goacc_aq) * (async + 1));
       memset (dev->openacc.async.asyncqueue + dev->openacc.async.nasyncqueue,
              0, sizeof (goacc_aq) * diff);
@@ -110,7 +110,7 @@ lookup_goacc_asyncqueue (struct goacc_thread *thr, bool 
create, int async)
        }
       
       /* Link new async queue into active list.  */
-      goacc_aq_list n = gomp_malloc (sizeof (struct goacc_asyncqueue_list));
+      goacc_aq_list n = (typeof (n)) gomp_malloc (sizeof (struct 
goacc_asyncqueue_list));
       n->aq = dev->openacc.async.asyncqueue[async];
       n->next = dev->openacc.async.active;
       dev->openacc.async.active = n;
diff --git a/libgomp/oacc-host.c b/libgomp/oacc-host.c
index ef552888cb52..f30b40d4bfc6 100644
--- a/libgomp/oacc-host.c
+++ b/libgomp/oacc-host.c
@@ -45,7 +45,104 @@ struct host_offload_session
 _Static_assert (_Alignof (struct host_offload_session) <= 
__BIGGEST_ALIGNMENT__,
                "gomp_offload_session requires too high alignment");
 
-static struct gomp_device_descr host_dispatch;
+static const char *host_get_name (void);
+static unsigned int host_get_caps (void);
+static int host_get_type (void);
+static int host_get_num_devices (void);
+static bool host_init_device (int);
+static bool host_fini_device (int);
+static unsigned host_version (void);
+static int host_load_image (int, unsigned, const void *, struct addr_pair **, 
uint64_t **, uint64_t *);
+static bool host_unload_image (int, unsigned, const void *);
+static void *host_alloc (int, size_t);
+static bool host_free (int, void *);
+static bool host_dev2host (int, void *, const void *, size_t);
+static bool host_host2dev (int, void *, const void *, size_t);
+static void host_session_start (struct gomp_offload_session *, int);
+static void host_session_set_target_var_table (struct gomp_offload_session *, 
void **);
+static void host_run (struct gomp_offload_session *, void *, void **);
+static void host_openacc_exec (struct gomp_offload_session *, void (*) (void 
*), size_t, void **, unsigned *, void *);
+static void host_openacc_async_exec (struct gomp_offload_session *, void (*) 
(void *), size_t, void **, unsigned *, void *, struct goacc_asyncqueue *);
+static int host_openacc_async_test (struct goacc_asyncqueue *);
+static bool host_openacc_async_synchronize (struct goacc_asyncqueue *);
+static bool host_openacc_async_serialize (struct goacc_asyncqueue *, struct 
goacc_asyncqueue *);
+static bool host_openacc_async_host2dev (int, void *, const void *, size_t, 
struct goacc_asyncqueue *);
+static bool host_openacc_async_dev2host (int, void *, const void *, size_t, 
struct goacc_asyncqueue *);
+static void host_openacc_async_queue_callback (struct goacc_asyncqueue *, void 
(*)(void *), void *);
+static struct goacc_asyncqueue *host_openacc_async_construct (int);
+static bool host_openacc_async_destruct (struct goacc_asyncqueue *);
+static union goacc_property_value host_openacc_get_property (int, enum 
goacc_property);
+static void *host_openacc_create_thread_data (int);
+static void host_openacc_destroy_thread_data (void *);
+
+static struct gomp_device_descr host_dispatch =
+  {
+    .name = "host",
+    .uid = NULL,
+    .capabilities = (GOMP_OFFLOAD_CAP_SHARED_MEM
+                    | GOMP_OFFLOAD_CAP_NATIVE_EXEC
+                    | GOMP_OFFLOAD_CAP_OPENACC_200),
+    .target_id = 0,
+    .type = OFFLOAD_TARGET_TYPE_HOST,
+
+    .get_name_func = host_get_name,
+    .get_uid_func = NULL,
+    .get_caps_func = host_get_caps,
+    .get_type_func = host_get_type,
+    .get_num_devices_func = host_get_num_devices,
+    .init_device_func = host_init_device,
+    .fini_device_func = host_fini_device,
+    .version_func = host_version,
+    .load_image_func = host_load_image,
+    .unload_image_func = host_unload_image,
+    .alloc_func = host_alloc,
+    .free_func = host_free,
+    .dev2host_func = host_dev2host,
+    .host2dev_func = host_host2dev,
+    .memcpy2d_func = NULL,
+    .memcpy3d_func = NULL,
+    .memspace_validate_func = NULL,
+    .run_func = host_run,
+
+    .session = {
+      .start_func = host_session_start,
+      .set_tvt_func = host_session_set_target_var_table,
+      .size = sizeof (struct host_offload_session),
+    },
+
+    .mem_map = { NULL },
+    .mem_map_rev = { NULL },
+    /* .lock initialized in goacc_host_init.  */
+    .state = GOMP_DEVICE_UNINITIALIZED,
+
+    .openacc = {
+      .exec_func = host_openacc_exec,
+
+      .create_thread_data_func = host_openacc_create_thread_data,
+      .destroy_thread_data_func = host_openacc_destroy_thread_data,
+
+      .async = {
+       .construct_func = host_openacc_async_construct,
+       .destruct_func = host_openacc_async_destruct,
+       .test_func = host_openacc_async_test,
+       .synchronize_func = host_openacc_async_synchronize,
+       .serialize_func = host_openacc_async_serialize,
+       .queue_callback_func = host_openacc_async_queue_callback,
+       .exec_func = host_openacc_async_exec,
+       .dev2host_func = host_openacc_async_dev2host,
+       .host2dev_func = host_openacc_async_host2dev,
+      },
+
+      .get_property_func = host_openacc_get_property,
+
+      .cuda = {
+       .get_current_device_func = NULL,
+       .get_current_context_func = NULL,
+       .get_stream_func = NULL,
+       .set_stream_func = NULL,
+      }
+    }
+  };
 
 static const char *
 host_get_name (void)
@@ -294,75 +391,6 @@ host_openacc_destroy_thread_data (void *tls_data 
__attribute__ ((unused)))
 {
 }
 
-static struct gomp_device_descr host_dispatch =
-  {
-    .name = "host",
-    .uid = NULL,
-    .capabilities = (GOMP_OFFLOAD_CAP_SHARED_MEM
-                    | GOMP_OFFLOAD_CAP_NATIVE_EXEC
-                    | GOMP_OFFLOAD_CAP_OPENACC_200),
-    .target_id = 0,
-    .type = OFFLOAD_TARGET_TYPE_HOST,
-
-    .get_name_func = host_get_name,
-    .get_uid_func = NULL,
-    .get_caps_func = host_get_caps,
-    .get_type_func = host_get_type,
-    .get_num_devices_func = host_get_num_devices,
-    .init_device_func = host_init_device,
-    .fini_device_func = host_fini_device,
-    .version_func = host_version,
-    .load_image_func = host_load_image,
-    .unload_image_func = host_unload_image,
-    .alloc_func = host_alloc,
-    .free_func = host_free,
-    .dev2host_func = host_dev2host,
-    .host2dev_func = host_host2dev,
-    .memcpy2d_func = NULL,
-    .memcpy3d_func = NULL,
-    .memspace_validate_func = NULL,
-    .run_func = host_run,
-
-    .session = {
-      .start_func = host_session_start,
-      .set_tvt_func = host_session_set_target_var_table,
-      .size = sizeof (struct host_offload_session),
-    },
-
-    .mem_map = { NULL },
-    .mem_map_rev = { NULL },
-    /* .lock initialized in goacc_host_init.  */
-    .state = GOMP_DEVICE_UNINITIALIZED,
-
-    .openacc = {
-      .exec_func = host_openacc_exec,
-
-      .create_thread_data_func = host_openacc_create_thread_data,
-      .destroy_thread_data_func = host_openacc_destroy_thread_data,
-
-      .async = {
-       .construct_func = host_openacc_async_construct,
-       .destruct_func = host_openacc_async_destruct,
-       .test_func = host_openacc_async_test,
-       .synchronize_func = host_openacc_async_synchronize,
-       .serialize_func = host_openacc_async_serialize,
-       .queue_callback_func = host_openacc_async_queue_callback,
-       .exec_func = host_openacc_async_exec,
-       .dev2host_func = host_openacc_async_dev2host,
-       .host2dev_func = host_openacc_async_host2dev,
-      },
-
-      .get_property_func = host_openacc_get_property,
-
-      .cuda = {
-       .get_current_device_func = NULL,
-       .get_current_context_func = NULL,
-       .get_stream_func = NULL,
-       .set_stream_func = NULL,
-      }
-    }
-  };
-
 /* Initialize and register this device type.  */
 void
 goacc_host_init (void)
diff --git a/libgomp/oacc-init.c b/libgomp/oacc-init.c
index 9c5b8774c9ca..79aef79b66ef 100644
--- a/libgomp/oacc-init.c
+++ b/libgomp/oacc-init.c
@@ -148,7 +148,7 @@ resolve_device (acc_device_t d, bool fail_is_error)
        if (goacc_device_type)
          {
            /* Lookup the named device.  */
-           while (known_device_type_p (++d))
+           while (known_device_type_p (/* ++d */ d = (typeof (d)) ((size_t) d 
+ 1)))
              if (dispatchers[d]
                  && !strcasecmp (goacc_device_type,
                                  get_openacc_name (dispatchers[d]->name))
@@ -172,7 +172,7 @@ resolve_device (acc_device_t d, bool fail_is_error)
 
     case acc_device_not_host:
       /* Find the first available device after acc_device_not_host.  */
-      while (known_device_type_p (++d))
+      while (known_device_type_p (/* ++d */ d = (typeof (d)) ((size_t) d + 1)))
        if (dispatchers[d] && dispatchers[d]->get_num_devices_func () > 0)
          goto found;
       if (d_arg == acc_device_default)
@@ -480,7 +480,7 @@ acc_shutdown_1 (acc_device_t d, int dev_num)
 static struct goacc_thread *
 goacc_new_thread (void)
 {
-  struct goacc_thread *thr = gomp_malloc (sizeof (struct goacc_thread));
+  struct goacc_thread *thr = (typeof (thr)) gomp_malloc (sizeof (struct 
goacc_thread));
 
 #if defined HAVE_TLS || defined USE_EMUTLS
   goacc_tls_data = thr;
@@ -501,7 +501,7 @@ goacc_new_thread (void)
 static void
 goacc_destroy_thread (void *data)
 {
-  struct goacc_thread *thr = data, *walk, *prev;
+  struct goacc_thread *thr = (typeof (thr)) data, *walk, *prev;
 
   gomp_mutex_lock (&goacc_thread_lock);
 
@@ -937,8 +937,10 @@ acc_set_device_num (int ord, acc_device_t d)
 }
 
 static union goacc_property_value
-get_property_any (int ord, acc_device_t d, acc_device_property_t prop)
+get_property_any (int ord, acc_device_t d, acc_device_property_t prop_)
 {
+  enum goacc_property prop = (typeof (prop)) prop_;
+
   goacc_lazy_initialize ();
   struct goacc_thread *thr = goacc_thread ();
 
diff --git a/libgomp/oacc-mem.c b/libgomp/oacc-mem.c
index f9ceb094d156..3a596ff30e37 100644
--- a/libgomp/oacc-mem.c
+++ b/libgomp/oacc-mem.c
@@ -1476,12 +1476,14 @@ goacc_enter_exit_data_internal (int flags_m, size_t 
mapnum, void **hostaddrs,
   if (num_waits)
     goacc_wait (async, num_waits, ap);
 
+  {
   goacc_aq aq = get_goacc_asyncqueue (async);
 
   if (data_enter)
     goacc_enter_data_internal (acc_dev, mapnum, hostaddrs, sizes, kinds, aq);
   else
     goacc_exit_data_internal (acc_dev, mapnum, hostaddrs, sizes, kinds, aq);
+  }
 
  out_prof:
   if (profiling_p)
diff --git a/libgomp/oacc-parallel.c b/libgomp/oacc-parallel.c
index 3770af510f29..515905d4cae6 100644
--- a/libgomp/oacc-parallel.c
+++ b/libgomp/oacc-parallel.c
@@ -111,7 +111,7 @@ GOACC_parallel_keyed (int flags_m, void (*fn) (void *),
   unsigned int i;
   struct splay_tree_key_s k;
   splay_tree_key tgt_fn_key;
-  void (*tgt_fn);
+  typeof (fn) tgt_fn;
   int async = GOMP_ASYNC_SYNC;
   unsigned dims[GOMP_DIM_MAX];
   unsigned tag;
@@ -268,10 +268,10 @@ GOACC_parallel_keyed (int flags_m, void (*fn) (void *),
       if (tgt_fn_key == NULL)
        gomp_fatal ("target function wasn't mapped");
 
-      tgt_fn = (void (*)) tgt_fn_key->tgt_offset;
+      tgt_fn = (typeof (tgt_fn)) tgt_fn_key->tgt_offset;
     }
   else
-    tgt_fn = (void (*)) fn;
+    tgt_fn = fn;
 
   acc_event_info enter_exit_data_event_info;
   if (profiling_p)
@@ -289,6 +289,7 @@ GOACC_parallel_keyed (int flags_m, void (*fn) (void *),
                                &api_info);
     }
 
+  {
   goacc_aq aq = get_goacc_asyncqueue (async);
 
   /* Prepare an offload session.  */
@@ -331,6 +332,7 @@ GOACC_parallel_keyed (int flags_m, void (*fn) (void *),
     /* We need to clean up the above-allocated session later if executing
        asynchronously. */
     acc_dev->openacc.async.queue_callback_func (aq, free, session);
+  }
 
   if (profiling_p)
     {
@@ -462,7 +464,7 @@ GOACC_data_start (int flags_m, size_t mapnum,
     {
       prof_info.device_type = acc_device_host;
       api_info.device_type = prof_info.device_type;
-      tgt = goacc_map_vars (NULL, NULL, 0, NULL, NULL, NULL, NULL, true, 0, 
NULL);
+      tgt = goacc_map_vars (NULL, NULL, 0, NULL, NULL, NULL, NULL, true, 
GOMP_MAP_VARS_NONE, NULL);
       tgt->prev = thr->mapped_data;
       thr->mapped_data = tgt;
 
@@ -471,7 +473,7 @@ GOACC_data_start (int flags_m, size_t mapnum,
 
   gomp_debug (0, "  %s: prepare mappings\n", __FUNCTION__);
   tgt = goacc_map_vars (acc_dev, NULL, mapnum, hostaddrs, NULL, sizes, kinds,
-                       true, 0, NULL);
+                       true, GOMP_MAP_VARS_NONE, NULL);
   gomp_debug (0, "  %s: mappings prepared\n", __FUNCTION__);
   tgt->prev = thr->mapped_data;
   thr->mapped_data = tgt;
@@ -643,6 +645,7 @@ GOACC_update (int flags_m, size_t mapnum,
       va_end (ap);
     }
 
+  {
   bool update_device = false;
   for (i = 0; i < mapnum; ++i)
     {
@@ -704,6 +707,7 @@ GOACC_update (int flags_m, size_t mapnum,
          break;
        }
     }
+  }
 
  out_prof:
   if (profiling_p)
diff --git a/libgomp/oacc-profiling.c b/libgomp/oacc-profiling.c
index 7213aa6f26e4..94b16cbf6e30 100644
--- a/libgomp/oacc-profiling.c
+++ b/libgomp/oacc-profiling.c
@@ -122,7 +122,7 @@ goacc_profiling_initialize (void)
          if (acc_proflibs_sep != NULL)
            {
              /* Single out the first library.  */
-             acc_proflib = gomp_malloc (acc_proflibs_sep - acc_proflibs + 1);
+             acc_proflib = (char *) gomp_malloc (acc_proflibs_sep - 
acc_proflibs + 1);
              memcpy (acc_proflib, acc_proflibs,
                      acc_proflibs_sep - acc_proflibs);
              acc_proflib[acc_proflibs_sep - acc_proflibs] = '\0';
@@ -138,7 +138,7 @@ goacc_profiling_initialize (void)
          if (dl_handle != NULL)
            {
              typeof (&acc_register_library) a_r_l
-               = dlsym (dl_handle, "acc_register_library");
+               = (typeof (a_r_l)) dlsym (dl_handle, "acc_register_library");
              if (a_r_l == NULL)
                goto dl_fail;
              gomp_debug (0, "  %s: calling %s:acc_register_library\n",
@@ -313,7 +313,7 @@ acc_prof_register (acc_event_t ev, acc_prof_callback cb, 
acc_register_t reg)
       else
        {
          struct goacc_prof_callback_entry *e
-           = gomp_malloc (sizeof (struct goacc_prof_callback_entry));
+           = (typeof (e)) gomp_malloc (sizeof (struct 
goacc_prof_callback_entry));
          e->cb = cb;
          e->ref = 1;
          e->enabled = true;
@@ -585,7 +585,7 @@ _goacc_profiling_setup_p (struct goacc_thread *thr,
 
   /* Fill in some defaults.  */
 
-  prof_info->event_type = -1; /* Must be set later.  */
+  prof_info->event_type = (acc_event_t) -1; /* Must be set later.  */
   prof_info->valid_bytes = _ACC_PROF_INFO_VALID_BYTES;
   prof_info->version = _ACC_PROF_INFO_VERSION;
   if (thr->dev)
@@ -595,7 +595,7 @@ _goacc_profiling_setup_p (struct goacc_thread *thr,
     }
   else
     {
-      prof_info->device_type = -1;
+      prof_info->device_type = (acc_device_t) -1;
       prof_info->device_number = -1;
     }
   prof_info->thread_id = -1;
diff --git a/libgomp/ordered.c b/libgomp/ordered.c
index aa432f692ac1..53b02db6046b 100644
--- a/libgomp/ordered.c
+++ b/libgomp/ordered.c
@@ -276,7 +276,7 @@ gomp_doacross_init (unsigned ncounts, long *counts, long 
chunk_size,
        ws->doacross = NULL;
       else
        {
-         doacross = gomp_malloc_cleared (sizeof (*doacross) + extra);
+         doacross = (typeof (doacross)) gomp_malloc_cleared (sizeof 
(*doacross) + extra);
          doacross->extra = (void *) (doacross + 1);
          ws->doacross = doacross;
        }
@@ -325,7 +325,7 @@ gomp_doacross_init (unsigned ncounts, long *counts, long 
chunk_size,
     }
   elt_sz = (elt_sz + 63) & ~63UL;
 
-  doacross = gomp_malloc (sizeof (*doacross) + 63 + num_ents * elt_sz
+  doacross = (typeof (doacross)) gomp_malloc (sizeof (*doacross) + 63 + 
num_ents * elt_sz
                          + shift_sz + extra);
   doacross->chunk_size = chunk_size;
   doacross->elt_sz = elt_sz;
@@ -526,7 +526,7 @@ gomp_doacross_ull_init (unsigned ncounts, gomp_ull *counts,
        ws->doacross = NULL;
       else
        {
-         doacross = gomp_malloc_cleared (sizeof (*doacross) + extra);
+         doacross = (typeof (doacross)) gomp_malloc_cleared (sizeof 
(*doacross) + extra);
          doacross->extra = (void *) (doacross + 1);
          ws->doacross = doacross;
        }
@@ -580,7 +580,7 @@ gomp_doacross_ull_init (unsigned ncounts, gomp_ull *counts,
     }
   elt_sz = (elt_sz + 63) & ~63UL;
 
-  doacross = gomp_malloc (sizeof (*doacross) + 63 + num_ents * elt_sz
+  doacross = (typeof (doacross)) gomp_malloc (sizeof (*doacross) + 63 + 
num_ents * elt_sz
                          + shift_sz);
   doacross->chunk_size_ull = chunk_size;
   doacross->elt_sz = elt_sz;
diff --git a/libgomp/plugin/plugin-gcn.c b/libgomp/plugin/plugin-gcn.c
index 3ffbe88925c7..0f2556ff118d 100644
--- a/libgomp/plugin/plugin-gcn.c
+++ b/libgomp/plugin/plugin-gcn.c
@@ -435,9 +435,7 @@ struct gcn_image_desc
   const unsigned global_variable_count;
 };
 
-/* Enum values corresponding to the the ELF architecture codes.
-   Only 'special' values are actually referenced in this file, but having them
-   all may aid debugging.  */
+/* Enum values corresponding to the the ELF architecture codes.  */
 
 typedef enum {
   EF_AMDGPU_MACH_UNSUPPORTED = -1,
@@ -1006,7 +1004,7 @@ dump_hsa_agent_info (hsa_agent_t agent, void *data 
__attribute__((unused)))
 
   uint32_t cu_count;
   status = hsa_fns.hsa_agent_get_info_fn
-    (agent, HSA_AMD_AGENT_INFO_COMPUTE_UNIT_COUNT, &cu_count);
+    (agent, (hsa_agent_info_t) HSA_AMD_AGENT_INFO_COMPUTE_UNIT_COUNT, 
&cu_count);
   if (status == HSA_STATUS_SUCCESS)
     GCN_DEBUG ("HSA_AMD_AGENT_INFO_COMPUTE_UNIT_COUNT: %u\n", cu_count);
   else
@@ -1231,7 +1229,7 @@ get_executable_symbol_name (hsa_executable_symbol_t 
symbol)
       return NULL;
     }
 
-  res = GOMP_PLUGIN_malloc (len + 1);
+  res = (typeof (res)) GOMP_PLUGIN_malloc (len + 1);
 
   const hsa_executable_symbol_info_t info_name
     = HSA_EXECUTABLE_SYMBOL_INFO_NAME;
@@ -1257,7 +1255,7 @@ get_cu_count (struct agent_info *agent)
 {
   uint32_t cu_count;
   hsa_status_t status = hsa_fns.hsa_agent_get_info_fn
-    (agent->id, HSA_AMD_AGENT_INFO_COMPUTE_UNIT_COUNT, &cu_count);
+    (agent->id, (hsa_agent_info_t) HSA_AMD_AGENT_INFO_COMPUTE_UNIT_COUNT, 
&cu_count);
   if (status == HSA_STATUS_SUCCESS)
     return cu_count;
   else
@@ -1486,11 +1484,11 @@ static bool
 init_hsa_runtime_functions (void)
 {
 #define DLSYM_FN(function) \
-  hsa_fns.function##_fn = dlsym (handle, #function); \
+  hsa_fns.function##_fn = (typeof (hsa_fns.function##_fn)) dlsym (handle, 
#function); \
   if (hsa_fns.function##_fn == NULL) \
     GOMP_PLUGIN_fatal ("'%s' is missing '%s'", hsa_runtime_lib, #function);
 #define DLSYM_OPT_FN(function) \
-  hsa_fns.function##_fn = dlsym (handle, #function);
+  hsa_fns.function##_fn = (typeof (hsa_fns.function##_fn)) dlsym (handle, 
#function);
 
   void *handle = dlopen (hsa_runtime_lib, RTLD_LAZY);
   if (handle == NULL)
@@ -1659,7 +1657,7 @@ init_hsa_context (bool probe)
   GCN_DEBUG ("There are %i GCN GPU devices.\n", hsa_context.agent_count);
 
   hsa_context.agents
-    = GOMP_PLUGIN_malloc_cleared (hsa_context.agent_count
+    = (typeof (hsa_context.agents)) GOMP_PLUGIN_malloc_cleared 
(hsa_context.agent_count
                                  * sizeof (struct agent_info));
   status = hsa_fns.hsa_iterate_agents_fn (assign_agent_ids, &agent_index);
   if (status != HSA_STATUS_SUCCESS)
@@ -1810,8 +1808,8 @@ isa_name (int isa) {
 
 static gcn_isa
 isa_code(const char *isa) {
-#define GCN_DEVICE(name, NAME, ELF, ...) \
-  if (!strcmp (isa, #name)) return ELF;
+#define GCN_DEVICE(name, NAME, ...) \
+  if (!strcmp (isa, #name)) return EF_AMDGPU_MACH_AMDGCN_ ## NAME;
 #include "../../gcc/config/gcn/gcn-devices.def"
 
   return EF_AMDGPU_MACH_UNSUPPORTED;
@@ -1824,13 +1822,13 @@ static gcn_isa
 generic_isa_code (int isa) {
   switch(isa)
     {
-#define EF_AMDGPU_MACH_AMDGCN_NONE 0
+#define EF_AMDGPU_MACH_AMDGCN_NONE ((EF_AMDGPU_MACH) 0)
 #define GCN_DEVICE(name, NAME, ELF, GCCISA, XNACK, SRAM, WAVE64, CUMODE, \
                   VGPRS, CO, ARCH, GENERIC_ISA, ...) \
     case ELF: return EF_AMDGPU_MACH_AMDGCN_ ## GENERIC_ISA;
 #include "../../gcc/config/gcn/gcn-devices.def"
     }
-  return 0;
+  return EF_AMDGPU_MACH_AMDGCN_NONE;
 }
 
 /* CDNA2 devices have twice as many VGPRs compared to older devices.  */
@@ -1935,7 +1933,7 @@ allocate_session_kernargs (struct gomp_offload_session 
*session,
        GOMP_PLUGIN_fatal ("Could not allocate cache node for kernel 
arguments");
     }
 
-  return session->kernarg_cache_node->allocation;
+  return (struct kernargs *) session->kernarg_cache_node->allocation;
 }
 
 void **
@@ -2012,7 +2010,7 @@ configure_ephemeral_memories (struct kernel_info *kernel,
          GOMP_PLUGIN_error ("Could not lock a GCN agent program mutex");
          return;
        }
-      item = malloc (sizeof (*item));
+      item = (typeof (item)) malloc (sizeof (*item));
       item->size = size;
       item->next = NULL;
       *next_ptr = item;
@@ -2274,7 +2272,10 @@ console_output (struct kernel_info *kernel, struct 
kernargs *kernargs,
   unsigned int i;
   for (i = from; i < to; i++)
     {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic warning "-Wc++-compat"
       struct printf_data *data = &kernargs->output_data.queue[i%limit];
+#pragma GCC diagnostic pop
 
       if (!data->written && !final)
        break;
@@ -2324,7 +2325,7 @@ init_kernel_properties (struct kernel_info *kernel)
   hsa_status_t status;
   struct agent_info *agent = kernel->agent;
   hsa_executable_symbol_t kernel_symbol;
-  char *buf = alloca (strlen (kernel->name) + 4);
+  char *buf = (typeof (buf)) alloca (strlen (kernel->name) + 4);
   sprintf (buf, "%s.kd", kernel->name);
   status = hsa_fns.hsa_executable_get_symbol_fn (agent->executable, NULL,
                                                 buf, agent->id,
@@ -2501,7 +2502,8 @@ run_kernel (struct gomp_offload_session *session,
                                             packet->grid_size_x,
                                             kla->wdims[0]);
 
-  struct kernargs *kernargs = session->kernarg_cache_node->allocation;
+  struct kernargs *kernargs
+    = (typeof (kernargs)) session->kernarg_cache_node->allocation;
   packet->kernarg_address = kernargs;
 
   if (kla->ndim >= 2)
@@ -2767,8 +2769,7 @@ create_and_finalize_hsa_program (struct agent_info *agent)
     }
 
   /* Load any GCN modules.  */
-  struct module_info *module = agent->module;
-  if (module)
+  if (struct module_info *module = agent->module)
     {
       Elf64_Ehdr *image = (Elf64_Ehdr *)module->image_desc->gcn_image->image;
 
@@ -2999,7 +3000,7 @@ execute_queue_entry (struct goacc_asyncqueue *aq, int 
index)
 static void *
 drain_queue (void *thread_arg)
 {
-  struct goacc_asyncqueue *aq = thread_arg;
+  struct goacc_asyncqueue *aq = (typeof (aq)) thread_arg;
 
   if (DRAIN_QUEUE_SYNCHRONOUS_P)
     {
@@ -3322,7 +3323,7 @@ hsa_memory_copy_wrapper (void *dst, const void *src, 
size_t len)
   GCN_WARNING ("Read-only data transfer bug workaround triggered for "
               "[%p:+%d]\n", (void *) src, (int) len);
 
-  void *src_copy = malloc (len);
+  void *src_copy = (typeof (src_copy)) malloc (len);
   memcpy (src_copy, src, len);
   status = hsa_fns.hsa_memory_copy_fn (dst, (const void *) src_copy, len);
   free (src_copy);
@@ -3686,8 +3687,8 @@ GOMP_OFFLOAD_get_uid (int ord)
   struct agent_info *agent = get_agent_info (ord);
 
   /* HSA documentation states: maximally 21 characters including NUL.  */
-  str = GOMP_PLUGIN_malloc (21 * sizeof (char));
-  status = hsa_fns.hsa_agent_get_info_fn (agent->id, HSA_AMD_AGENT_INFO_UUID,
+  str = (typeof (str)) GOMP_PLUGIN_malloc (21 * sizeof (char));
+  status = hsa_fns.hsa_agent_get_info_fn (agent->id, (hsa_agent_info_t) 
HSA_AMD_AGENT_INFO_UUID,
                                          str);
   if (status != HSA_STATUS_SUCCESS)
     {
@@ -3715,9 +3716,11 @@ GOMP_OFFLOAD_get_numa_node (int ord)
 
   agent->numa_node = -1;
 
-  status = hsa_fns.hsa_agent_get_info_fn (agent->id, HSA_AMD_AGENT_INFO_DOMAIN,
+  status = hsa_fns.hsa_agent_get_info_fn (agent->id,
+                                         (hsa_agent_info_t) 
HSA_AMD_AGENT_INFO_DOMAIN,
                                          &domain);
-  status2 = hsa_fns.hsa_agent_get_info_fn (agent->id, HSA_AMD_AGENT_INFO_BDFID,
+  status2 = hsa_fns.hsa_agent_get_info_fn (agent->id,
+                                          (hsa_agent_info_t) 
HSA_AMD_AGENT_INFO_BDFID,
                                           &bdfid);
   if (status != HSA_STATUS_SUCCESS || status2 != HSA_STATUS_SUCCESS)
     return -1;
@@ -4087,7 +4090,7 @@ GOMP_OFFLOAD_load_image (int ord, unsigned version, const 
void *target_data,
   GCN_DEBUG ("Encountered %d indirect functions in an image\n", 
ind_func_count);
   GCN_DEBUG ("Encountered %u global variables in an image\n", var_count);
   GCN_DEBUG ("Expect %d other variables in an image\n", other_count);
-  pair = GOMP_PLUGIN_malloc ((kernel_count + var_count + other_count - 2)
+  pair = (typeof (pair)) GOMP_PLUGIN_malloc ((kernel_count + var_count + 
other_count - 2)
                             * sizeof (struct addr_pair));
   *target_table = pair;
   module = (struct module_info *)
@@ -4354,7 +4357,7 @@ GOMP_OFFLOAD_load_image (int ord, unsigned version, const 
void *target_data,
         &fn_table_addr);
       if (status != HSA_STATUS_SUCCESS)
        hsa_fatal ("Could not extract a variable from its symbol", status);
-      *rev_fn_table = GOMP_PLUGIN_malloc (kernel_count * sizeof (uint64_t));
+      *rev_fn_table = (typeof (*rev_fn_table)) GOMP_PLUGIN_malloc 
(kernel_count * sizeof (uint64_t));
       GOMP_OFFLOAD_dev2host (agent->device_id, *rev_fn_table,
                             (void*) fn_table_addr,
                             kernel_count * sizeof (uint64_t));
@@ -4978,7 +4981,7 @@ init_hip_runtime_functions (void)
     return false;
 
 #define DLSYM_OPT_FN(function) \
-  hip_fns.function##_fn = dlsym (handle, #function)
+  hip_fns.function##_fn = (typeof (hip_fns.function##_fn)) dlsym (handle, 
#function)
 
   DLSYM_OPT_FN (hipStreamCreate);
   DLSYM_OPT_FN (hipStreamDestroy);
@@ -5048,9 +5051,9 @@ GOMP_OFFLOAD_memset (int ord, void *ptr, int val, size_t 
count)
     {
       void *data;
       if (before > alloca_size)
-       data = malloc (before * sizeof (uint8_t));
+       data = (typeof (data)) malloc (before * sizeof (uint8_t));
       else
-       data = alloca (before * sizeof (uint8_t));
+       data = (typeof (data)) alloca (before * sizeof (uint8_t));
       memset (data, val, before);
       status = hsa_fns.hsa_memory_copy_fn (ptr, data, before);
       if (before > alloca_size)
@@ -5065,6 +5068,7 @@ GOMP_OFFLOAD_memset (int ord, void *ptr, int val, size_t 
count)
 
   ptr += before;
 
+  { //TODO indentation
   uint32_t values = v8 | (v8 << 8) | (v8 << 16) | (v8 << 24);
   status = hsa_fns.hsa_amd_memory_fill_fn (ptr, values, count / 4);
   if (tail && status == HSA_STATUS_SUCCESS)
@@ -5072,6 +5076,7 @@ GOMP_OFFLOAD_memset (int ord, void *ptr, int val, size_t 
count)
       ptr += count - tail;
       status = hsa_fns.hsa_memory_copy_fn (ptr, &values, tail);
     }
+  }
   if (status == HSA_STATUS_SUCCESS)
     return true;
 
@@ -5705,7 +5710,7 @@ GOMP_OFFLOAD_openacc_async_construct (int device)
 
   pthread_mutex_lock (&agent->async_queues_mutex);
 
-  struct goacc_asyncqueue *aq = GOMP_PLUGIN_malloc (sizeof (*aq));
+  struct goacc_asyncqueue *aq = (typeof (aq)) GOMP_PLUGIN_malloc (sizeof 
(*aq));
   aq->agent = get_agent_info (device);
   aq->prev = NULL;
   aq->next = agent->async_queues;
@@ -5787,12 +5792,14 @@ GOMP_OFFLOAD_openacc_async_destruct (struct 
goacc_asyncqueue *aq)
       GOMP_PLUGIN_error ("Failed to destroy a GCN async queue cond");
       goto fail;
     }
+  { //TODO indentation
   hsa_status_t status = hsa_fns.hsa_queue_destroy_fn (aq->hsa_queue);
   if (status != HSA_STATUS_SUCCESS)
     {
       hsa_error ("Error destroying command queue", status);
       goto fail;
     }
+  }
 
   if (aq->prev)
     aq->prev->next = aq->next;
@@ -5930,7 +5937,7 @@ void *
 GOMP_OFFLOAD_openacc_create_thread_data (int ord __attribute__((unused)))
 {
   struct gcn_thread *thread_data
-    = GOMP_PLUGIN_malloc (sizeof (struct gcn_thread));
+    = (typeof (thread_data)) GOMP_PLUGIN_malloc (sizeof (struct gcn_thread));
 
   thread_data->async = GOMP_ASYNC_SYNC;
 
diff --git a/libgomp/plugin/plugin-nvptx.c b/libgomp/plugin/plugin-nvptx.c
index bdbcfddc98e5..83ae7f134d27 100644
--- a/libgomp/plugin/plugin-nvptx.c
+++ b/libgomp/plugin/plugin-nvptx.c
@@ -125,7 +125,7 @@ init_cuda_lib (void)
 # define CUDA_ONE_CALL(call) CUDA_ONE_CALL_1 (call, false)
 # define CUDA_ONE_CALL_MAYBE_NULL(call) CUDA_ONE_CALL_1 (call, true)
 # define CUDA_ONE_CALL_1(call, allow_null)             \
-  cuda_lib.call = dlsym (h, #call);    \
+  cuda_lib.call = (typeof (cuda_lib.call)) dlsym (h, #call); \
   if (!allow_null && cuda_lib.call == NULL)            \
     GOMP_PLUGIN_fatal ("'%s' is missing '%s'", cuda_runtime_lib, #call);
 #include "cuda-lib.def"
@@ -164,7 +164,7 @@ static void notify_var (const char *, const char *);
 
 #define CUDA_CALL_ERET(ERET, FN, ...)          \
   do {                                         \
-    unsigned __r                               \
+    CUresult __r                               \
       = CUDA_CALL_PREFIX FN (__VA_ARGS__);     \
     if (__r != CUDA_SUCCESS)                   \
       {                                                \
@@ -179,7 +179,7 @@ static void notify_var (const char *, const char *);
 
 #define CUDA_CALL_ASSERT(FN, ...)              \
   do {                                         \
-    unsigned __r                               \
+    CUresult __r                               \
       = CUDA_CALL_PREFIX FN (__VA_ARGS__);     \
     if (__r != CUDA_SUCCESS)                   \
       {                                                \
@@ -386,7 +386,7 @@ nvptx_init (void)
            cuda_driver_version / 1000, cuda_driver_version % 1000 / 10);
 
   CUDA_CALL (cuDeviceGetCount, &ndevs);
-  ptx_devices = GOMP_PLUGIN_malloc_cleared (sizeof (struct ptx_device *)
+  ptx_devices = (typeof (ptx_devices)) GOMP_PLUGIN_malloc_cleared (sizeof 
(struct ptx_device *)
                                            * ndevs);
 
   return true;
@@ -450,7 +450,7 @@ nvptx_open_device (int n)
 
   CUDA_CALL_ERET (NULL, cuDeviceGet, &dev, n);
 
-  ptx_dev = GOMP_PLUGIN_malloc (sizeof (struct ptx_device));
+  ptx_dev = (typeof (ptx_dev)) GOMP_PLUGIN_malloc (sizeof (struct ptx_device));
 
   ptx_dev->ord = n;
   ptx_dev->dev = dev;
@@ -1187,7 +1187,7 @@ nvptx_free (void *p, struct ptx_device *ptx_dev)
         documentation for description). Arrange to free this piece of device
         memory later.  */
       struct ptx_free_block *n
-       = GOMP_PLUGIN_malloc (sizeof (struct ptx_free_block));
+       = (typeof (n)) GOMP_PLUGIN_malloc (sizeof (struct ptx_free_block));
       n->ptr = p;
       pthread_mutex_lock (&ptx_dev->free_blocks_lock);
       n->next = ptx_dev->free_blocks;
@@ -1584,7 +1584,7 @@ nvptx_do_global_cdtors (CUmodule module, struct 
ptx_device *ptx_dev,
       const char *mgomp_suffix = "__mgomp";
       size_t mgomp_suffix_len = strlen (mgomp_suffix);
       funcname_mgomp
-       = GOMP_PLUGIN_malloc (funcname_len + mgomp_suffix_len + 1);
+       = (typeof (funcname_mgomp)) GOMP_PLUGIN_malloc (funcname_len + 
mgomp_suffix_len + 1);
       memcpy (funcname_mgomp, funcname, funcname_len);
       memcpy (funcname_mgomp + funcname_len,
              mgomp_suffix, mgomp_suffix_len + 1);
@@ -1698,14 +1698,14 @@ GOMP_OFFLOAD_load_image (int ord, unsigned version, 
const void *target_data,
   /* Currently, other_entries contains only the struct of ICVs.  */
   other_entries = 1;
 
-  targ_tbl = GOMP_PLUGIN_malloc (sizeof (struct addr_pair)
+  targ_tbl = (typeof (targ_tbl)) GOMP_PLUGIN_malloc (sizeof (struct addr_pair)
                                 * (fn_entries + var_entries + other_entries));
-  targ_fns = GOMP_PLUGIN_malloc (sizeof (struct targ_fn_descriptor)
+  targ_fns = (typeof (targ_fns)) GOMP_PLUGIN_malloc (sizeof (struct 
targ_fn_descriptor)
                                 * fn_entries);
 
   *target_table = targ_tbl;
 
-  new_image = GOMP_PLUGIN_malloc (sizeof (struct ptx_image_data));
+  new_image = (typeof (new_image)) GOMP_PLUGIN_malloc (sizeof (struct 
ptx_image_data));
   new_image->target_data = target_data;
   new_image->module = module;
   new_image->fns = targ_fns;
@@ -1856,7 +1856,7 @@ GOMP_OFFLOAD_load_image (int ord, unsigned version, const 
void *target_data,
       if (r != CUDA_SUCCESS)
        GOMP_PLUGIN_fatal ("cuModuleGetGlobal error: %s", cuda_error (r));
       assert (bytes == sizeof (uint64_t) * fn_entries);
-      *rev_fn_table = GOMP_PLUGIN_malloc (sizeof (uint64_t) * fn_entries);
+      *rev_fn_table = (typeof (*rev_fn_table)) GOMP_PLUGIN_malloc (sizeof 
(uint64_t) * fn_entries);
       r = CUDA_CALL_NOCHECK (cuMemcpyDtoH, *rev_fn_table, var, bytes);
       if (r != CUDA_SUCCESS)
        GOMP_PLUGIN_fatal ("cuMemcpyDtoH error: %s", cuda_error (r));
@@ -2131,7 +2131,7 @@ GOMP_OFFLOAD_openacc_create_thread_data (int ord)
 {
   struct ptx_device *ptx_dev;
   struct nvptx_thread *nvthd
-    = GOMP_PLUGIN_malloc (sizeof (struct nvptx_thread));
+    = (typeof (nvthd)) GOMP_PLUGIN_malloc (sizeof (struct nvptx_thread));
   CUcontext thd_ctx;
 
   ptx_dev = ptx_devices[ord];
@@ -2196,7 +2196,7 @@ nvptx_goacc_asyncqueue_construct (unsigned int flags)
   CUDA_CALL_ERET (NULL, cuStreamCreate, &stream, flags);
 
   struct goacc_asyncqueue *aq
-    = GOMP_PLUGIN_malloc (sizeof (struct goacc_asyncqueue));
+    = (typeof (aq)) GOMP_PLUGIN_malloc (sizeof (struct goacc_asyncqueue));
   aq->cuda_stream = stream;
   return aq;
 }
@@ -2273,7 +2273,7 @@ GOMP_OFFLOAD_openacc_async_queue_callback (struct 
goacc_asyncqueue *aq,
                                           void (*callback_fn)(void *),
                                           void *userptr)
 {
-  struct nvptx_callback *b = GOMP_PLUGIN_malloc (sizeof (*b));
+  struct nvptx_callback *b = (typeof (b)) GOMP_PLUGIN_malloc (sizeof (*b));
   b->fn = callback_fn;
   b->ptr = userptr;
   b->aq = aq;
@@ -2776,14 +2776,16 @@ GOMP_OFFLOAD_interop (struct interop_obj_t *obj, int 
ord,
 
   if (action == gomp_interop_flag_destroy)
     {
-      if (obj->stream)
-       CUDA_CALL_ASSERT (cuStreamDestroy, obj->stream);
+      CUstream stream = (typeof (stream)) obj->stream;
+      if (stream)
+       CUDA_CALL_ASSERT (cuStreamDestroy, stream);
       return;
     }
   if (action == gomp_interop_flag_use)
     {
-      if (obj->stream)
-       CUDA_CALL_ASSERT (cuStreamSynchronize, obj->stream);
+      CUstream stream = (typeof (stream)) obj->stream;
+      if (stream)
+       CUDA_CALL_ASSERT (cuStreamSynchronize, stream);
       return;
     }
 
@@ -2823,7 +2825,8 @@ GOMP_OFFLOAD_interop (struct interop_obj_t *obj, int ord,
          break;
       }
 
-  struct ptx_device *ptx_dev = obj->device_data = ptx_devices[ord];
+  struct ptx_device *ptx_dev = ptx_devices[ord];
+  obj->device_data = ptx_dev;
 
   if (targetsync)
     {
@@ -3113,7 +3116,7 @@ GOMP_OFFLOAD_run (struct gomp_offload_session *session, 
void *tgt_fn, void **arg
       else if (id == GOMP_TARGET_ARG_THREAD_LIMIT)
        threads = val;
     }
-  nvptx_adjust_launch_bounds (tgt_fn, ptx_dev, &teams, &threads);
+  nvptx_adjust_launch_bounds (tgt_fn_desc, ptx_dev, &teams, &threads);
 
   bool reverse_offload = ptx_dev->rev_data != NULL;
   struct goacc_asyncqueue *reverse_offload_aq = NULL;
diff --git a/libgomp/priority_queue.h b/libgomp/priority_queue.h
index 6d914111e606..e24ee8c223a9 100644
--- a/libgomp/priority_queue.h
+++ b/libgomp/priority_queue.h
@@ -306,7 +306,7 @@ priority_tree_insert (enum priority_queue_type type,
         tree.  */
       if (head->l.tasks != NULL)
        {
-         prio_splay_tree_node k = gomp_malloc (sizeof (*k));
+         prio_splay_tree_node k = (prio_splay_tree_node) gomp_malloc (sizeof 
(*k));
          k->left = NULL;
          k->right = NULL;
          k->key.l.priority = 0;
@@ -320,7 +320,7 @@ priority_tree_insert (enum priority_queue_type type,
     = priority_queue_lookup_priority (head, priority);
   if (!list)
     {
-      prio_splay_tree_node k = gomp_malloc (sizeof (*k));
+      prio_splay_tree_node k = (prio_splay_tree_node) gomp_malloc (sizeof 
(*k));
       k->left = NULL;
       k->right = NULL;
       k->key.l.priority = priority;
diff --git a/libgomp/sections.c b/libgomp/sections.c
index f47a4483f8f2..8e3d4394e956 100644
--- a/libgomp/sections.c
+++ b/libgomp/sections.c
@@ -128,7 +128,7 @@ GOMP_sections2_start (unsigned count, uintptr_t 
*reductions, void **mem)
                        - INLINE_ORDERED_TEAM_IDS_OFF))
            *mem
              = (void *) (thr->ts.work_share->ordered_team_ids
-                         = gomp_malloc_cleared (size));
+                         = (unsigned *) gomp_malloc_cleared (size));
          else
            *mem = memset (((char *) thr->ts.work_share)
                           + INLINE_ORDERED_TEAM_IDS_OFF, '\0', size);
diff --git a/libgomp/simple-allocator.c b/libgomp/simple-allocator.c
index 199c4c3d4219..b8f9378013bd 100644
--- a/libgomp/simple-allocator.c
+++ b/libgomp/simple-allocator.c
@@ -72,7 +72,7 @@ struct gomp_simple_alloc_context {
 gomp_simple_alloc_ctx_p
 gomp_simple_alloc_init_context ()
 {
-  return calloc (1, sizeof (struct gomp_simple_alloc_context));
+  return (gomp_simple_alloc_ctx_p) calloc (1, sizeof (struct 
gomp_simple_alloc_context));
 }
 
 /* Coalesce contiguous free space into one entry.  This considers the entries
@@ -114,7 +114,7 @@ simple_alloc_coalesce_free_space (gomp_simple_alloc_ctx_p 
ctx)
    will be coalesced.  */
 
 void
-gomp_simple_alloc_register_memory (gomp_simple_alloc_ctx_p ctx, char *base,
+gomp_simple_alloc_register_memory (gomp_simple_alloc_ctx_p ctx, void *base,
                                   size_t size)
 {
   if (base == NULL || ctx == NULL)
@@ -123,7 +123,7 @@ gomp_simple_alloc_register_memory (gomp_simple_alloc_ctx_p 
ctx, char *base,
   gomp_mutex_lock (&ctx->lock);
 
   simple_alloc_splay_tree_node node;
-  node = malloc (sizeof (struct simple_alloc_splay_tree_node_s));
+  node = (typeof (node)) malloc (sizeof (struct 
simple_alloc_splay_tree_node_s));
   node->key.base = base;
   node->key.size = size;
   node->left = NULL;
@@ -190,7 +190,7 @@ gomp_simple_alloc (gomp_simple_alloc_ctx_p ctx, size_t size)
     {
       /* Allocation successful.  */
       result = freenode->key.base;
-      simple_alloc_splay_tree_node allocnode = malloc (sizeof (*allocnode));
+      simple_alloc_splay_tree_node allocnode = (typeof (allocnode)) malloc 
(sizeof (*allocnode));
       allocnode->key.base = result;
       allocnode->key.size = size;
       allocnode->left = NULL;
@@ -265,7 +265,7 @@ gomp_simple_realloc (gomp_simple_alloc_ctx_p ctx, void 
*addr, size_t newsize)
   else if (newsize < found->size)
     {
       /* We're reducing the allocation size.  */
-      simple_alloc_splay_tree_node newfree = malloc (sizeof (*newfree));
+      simple_alloc_splay_tree_node newfree = (typeof (newfree)) malloc (sizeof 
(*newfree));
       newfree->key.base = found->base + newsize;
       newfree->key.size = found->size - newsize;
       newfree->left = NULL;
diff --git a/libgomp/target.c b/libgomp/target.c
index 2bd1d573de45..8d8ca1e9aa79 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -850,11 +850,11 @@ gomp_attach_pointer (struct gomp_device_descr *devicep,
   idx = (attach_to - n->host_start) / sizeof (void *);
 
   if (!n->aux)
-    n->aux = gomp_malloc_cleared (sizeof (struct splay_tree_aux));
+    n->aux = (typeof (n->aux)) gomp_malloc_cleared (sizeof (struct 
splay_tree_aux));
 
   if (!n->aux->attach_count)
     n->aux->attach_count
-      = gomp_malloc_cleared (sizeof (*n->aux->attach_count) * size);
+      = (typeof (n->aux->attach_count)) gomp_malloc_cleared (sizeof 
(*n->aux->attach_count) * size);
 
   if (n->aux->attach_count[idx] < UINTPTR_MAX)
     n->aux->attach_count[idx]++;
@@ -1068,7 +1068,7 @@ gomp_add_map (size_t idx, size_t *new_idx,
 {
   if ((*sizes)[idx] == SIZE_MAX)
     {
-      uintptr_t *iterator_array = (*hostaddrs)[idx];
+      uintptr_t *iterator_array = (typeof (iterator_array)) (*hostaddrs)[idx];
       size_t count = *iterator_array++;
       for (size_t i = 0; i < count; i++)
        {
@@ -1133,7 +1133,7 @@ gomp_merge_iterator_maps (size_t *mapnum, void 
***hostaddrs, size_t **sizes,
   for (size_t i = 0; i < *mapnum; i++)
     if ((*sizes)[i] == SIZE_MAX)
       {
-       uintptr_t *iterator_array = (*hostaddrs)[i];
+       uintptr_t *iterator_array = (typeof (iterator_array)) (*hostaddrs)[i];
        map_count += iterator_array[0];
        iterator_p = true;
       }
@@ -1169,7 +1169,8 @@ gomp_merge_iterator_maps (size_t *mapnum, void 
***hostaddrs, size_t **sizes,
            {
              if ((*sizes)[j] == SIZE_MAX)
                {
-                 uintptr_t *iterator_array = (*hostaddrs)[j];
+                 uintptr_t *iterator_array
+                   = (typeof (iterator_array)) (*hostaddrs)[j];
                  size_t count = iterator_array[0];
                  new_sizes[idx_i] += count - 1;
                }
@@ -1246,7 +1247,7 @@ gomp_map_vars_internal (struct gomp_device_descr *devicep,
     iterators_p = gomp_merge_iterator_maps (&mapnum, &hostaddrs, &sizes,
                                            &kinds, &iterator_count);
   struct target_mem_desc *tgt
-    = gomp_malloc (sizeof (*tgt) + sizeof (tgt->list[0]) * mapnum);
+    = (typeof (tgt)) gomp_malloc (sizeof (*tgt) + sizeof (tgt->list[0]) * 
mapnum);
   tgt->list_count = mapnum;
   tgt->refcount = (pragma_kind & GOMP_MAP_VARS_ENTER_DATA) ? 0 : 1;
   tgt->device_descr = devicep;
@@ -1608,7 +1609,7 @@ gomp_map_vars_internal (struct gomp_device_descr *devicep,
       if (cbuf.chunk_cnt > 0)
        {
          cbuf.buf
-           = malloc (cbuf.chunks[cbuf.chunk_cnt - 1].end - 
cbuf.chunks[0].start);
+           = (typeof (cbuf.buf)) malloc (cbuf.chunks[cbuf.chunk_cnt - 1].end - 
cbuf.chunks[0].start);
          if (cbuf.buf)
            {
              cbuf.tgt = tgt;
@@ -1631,7 +1632,7 @@ gomp_map_vars_internal (struct gomp_device_descr *devicep,
   if (not_found_cnt || has_firstprivate || has_always_ptrset)
     {
       if (not_found_cnt)
-       tgt->array = gomp_malloc (not_found_cnt * sizeof (*tgt->array));
+       tgt->array = (typeof (tgt->array)) gomp_malloc (not_found_cnt * sizeof 
(*tgt->array));
       splay_tree_node array = tgt->array;
       size_t j, field_tgt_offset = 0, field_tgt_clear = FIELD_TGT_EMPTY;
       uintptr_t field_tgt_base = 0;
@@ -1776,6 +1777,7 @@ gomp_map_vars_internal (struct gomp_device_descr *devicep,
                tgt_size = (tgt_size + align - 1) & ~(align - 1);
                tgt->list[i].offset = tgt_size;
 
+               { //TODO indentation
                void *descr_ptr = hostaddrs[i];
                void *devaddr = (void *) (tgt->tgt_start + tgt_size);
                uintptr_t dev_allocator
@@ -1784,6 +1786,7 @@ gomp_map_vars_internal (struct gomp_device_descr *devicep,
                hostaddrs[i] = (void *) dev_allocator;
                tgt_size += gomp_omp_allocator_data_size;
                continue;
+               }
 
              case GOMP_MAP_STRUCT_UNORD:
                if (sizes[i] > 1)
@@ -1988,7 +1991,7 @@ gomp_map_vars_internal (struct gomp_device_descr *devicep,
                       of mapped object in the splay tree.  */
                    splay_tree_remove (mem_map, n);
                    k->aux
-                     = gomp_malloc_cleared (sizeof (struct splay_tree_aux));
+                     = (typeof (k->aux)) gomp_malloc_cleared (sizeof (struct 
splay_tree_aux));
                    k->aux->link_key = n;
                  }
                size_t align = (size_t) 1 << (kind >> rshift);
@@ -2282,7 +2285,7 @@ goacc_map_vars (struct gomp_device_descr *devicep,
 {
   return gomp_map_vars_internal (devicep, aq, mapnum, hostaddrs, devaddrs,
                                 sizes, kinds, short_mapkind, NULL,
-                                GOMP_MAP_VARS_OPENACC | pragma_kind,
+                                (enum gomp_map_vars_kind) 
(GOMP_MAP_VARS_OPENACC | pragma_kind),
                                 session);
 }
 
@@ -2666,49 +2669,49 @@ get_gomp_offload_icvs (int dev_num)
   if (offload_icvs != NULL)
     return &offload_icvs->icvs;
 
-  struct gomp_offload_icv_list *new
+  struct gomp_offload_icv_list *goil_new
     = (struct gomp_offload_icv_list *) gomp_malloc (sizeof (struct 
gomp_offload_icv_list));
 
-  new->device_num = dev_num;
-  new->icvs.device_num = dev_num;
-  new->next = gomp_offload_icv_list;
+  goil_new->device_num = dev_num;
+  goil_new->icvs.device_num = dev_num;
+  goil_new->next = gomp_offload_icv_list;
 
   if (dev_x != NULL && gomp_get_icv_flag (dev_x->flags, GOMP_ICV_NTEAMS))
-    new->icvs.nteams = dev_x->icvs.nteams_var;
+    goil_new->icvs.nteams = dev_x->icvs.nteams_var;
   else if (dev != NULL && gomp_get_icv_flag (dev->flags, GOMP_ICV_NTEAMS))
-    new->icvs.nteams = dev->icvs.nteams_var;
+    goil_new->icvs.nteams = dev->icvs.nteams_var;
   else if (all != NULL && gomp_get_icv_flag (all->flags, GOMP_ICV_NTEAMS))
-    new->icvs.nteams = all->icvs.nteams_var;
+    goil_new->icvs.nteams = all->icvs.nteams_var;
   else
-    new->icvs.nteams = gomp_default_icv_values.nteams_var;
+    goil_new->icvs.nteams = gomp_default_icv_values.nteams_var;
 
   if (dev_x != NULL
       && gomp_get_icv_flag (dev_x->flags, GOMP_ICV_TEAMS_THREAD_LIMIT))
-    new->icvs.teams_thread_limit = dev_x->icvs.teams_thread_limit_var;
+    goil_new->icvs.teams_thread_limit = dev_x->icvs.teams_thread_limit_var;
   else if (dev != NULL
           && gomp_get_icv_flag (dev->flags, GOMP_ICV_TEAMS_THREAD_LIMIT))
-    new->icvs.teams_thread_limit = dev->icvs.teams_thread_limit_var;
+    goil_new->icvs.teams_thread_limit = dev->icvs.teams_thread_limit_var;
   else if (all != NULL
           && gomp_get_icv_flag (all->flags, GOMP_ICV_TEAMS_THREAD_LIMIT))
-    new->icvs.teams_thread_limit = all->icvs.teams_thread_limit_var;
+    goil_new->icvs.teams_thread_limit = all->icvs.teams_thread_limit_var;
   else
-    new->icvs.teams_thread_limit
+    goil_new->icvs.teams_thread_limit
       = gomp_default_icv_values.teams_thread_limit_var;
 
   if (dev_x != NULL
       && gomp_get_icv_flag (dev_x->flags, GOMP_ICV_DEFAULT_DEVICE))
-    new->icvs.default_device = dev_x->icvs.default_device_var;
+    goil_new->icvs.default_device = dev_x->icvs.default_device_var;
   else if (dev != NULL
           && gomp_get_icv_flag (dev->flags, GOMP_ICV_DEFAULT_DEVICE))
-    new->icvs.default_device = dev->icvs.default_device_var;
+    goil_new->icvs.default_device = dev->icvs.default_device_var;
   else if (all != NULL
           && gomp_get_icv_flag (all->flags, GOMP_ICV_DEFAULT_DEVICE))
-    new->icvs.default_device = all->icvs.default_device_var;
+    goil_new->icvs.default_device = all->icvs.default_device_var;
   else
-    new->icvs.default_device = gomp_default_icv_values.default_device_var;
+    goil_new->icvs.default_device = gomp_default_icv_values.default_device_var;
 
-  gomp_offload_icv_list = new;
-  return &new->icvs;
+  gomp_offload_icv_list = goil_new;
+  return &goil_new->icvs;
 }
 
 /* Load image pointed by TARGET_DATA to the device, specified by DEVICEP.
@@ -2767,12 +2770,12 @@ gomp_load_image_to_device (struct gomp_device_descr 
*devicep, unsigned version,
     }
 
   /* Insert host-target address mapping into splay tree.  */
-  struct target_mem_desc *tgt = gomp_malloc (sizeof (*tgt));
+  struct target_mem_desc *tgt = (typeof (tgt)) gomp_malloc (sizeof (*tgt));
   /* "+1" due to the additional ICV struct.  */
-  tgt->array = gomp_malloc ((num_funcs + num_vars + 1)
+  tgt->array = (typeof (tgt->array)) gomp_malloc ((num_funcs + num_vars + 1)
                            * sizeof (*tgt->array));
   if (rev_target_fn_table)
-    tgt->rev_array = gomp_malloc (num_funcs * sizeof (*tgt->rev_array));
+    tgt->rev_array = (typeof (tgt->rev_array)) gomp_malloc (num_funcs * sizeof 
(*tgt->rev_array));
   else
     tgt->rev_array = NULL;
   tgt->refcount = REFCOUNT_INFINITY;
@@ -3065,11 +3068,11 @@ GOMP_offload_register_ver (unsigned version, const void 
*host_table,
 
   /* Insert image to array of pending images.  */
   offload_images
-    = gomp_realloc_unlock (offload_images,
+    = (typeof (offload_images)) gomp_realloc_unlock (offload_images,
                           (num_offload_images + 1)
                           * sizeof (struct offload_image_descr));
   offload_images[num_offload_images].version = version;
-  offload_images[num_offload_images].type = target_type;
+  offload_images[num_offload_images].type = (enum offload_target_type) 
target_type;
   offload_images[num_offload_images].host_table = host_table;
   offload_images[num_offload_images].target_data = target_data;
 
@@ -3717,7 +3720,7 @@ GOMP_target_ext (int device, void (*fn) (void *), size_t 
mapnum,
                                               &tgt_align, &tgt_size);
          if (tgt_align)
            {
-             char *tgt = gomp_alloca (tgt_size + tgt_align - 1);
+             char *tgt = (char *) gomp_alloca (tgt_size + tgt_align - 1);
              copy_firstprivate_data (tgt, mapnum, hostaddrs, sizes, kinds,
                                      tgt_align, tgt_size);
            }
@@ -3738,7 +3741,7 @@ GOMP_target_ext (int device, void (*fn) (void *), size_t 
mapnum,
                                               &tgt_align, &tgt_size);
          if (tgt_align)
            {
-             char *tgt = gomp_alloca (tgt_size + tgt_align - 1);
+             char *tgt = (char *) gomp_alloca (tgt_size + tgt_align - 1);
              copy_firstprivate_data (tgt, mapnum, hostaddrs, sizes, kinds,
                                      tgt_align, tgt_size);
            }
@@ -3789,7 +3792,7 @@ GOMP_target_ext (int device, void (*fn) (void *), size_t 
mapnum,
                                               &tgt_align, &tgt_size);
          if (tgt_align)
            {
-             char *tgt = gomp_alloca (tgt_size + tgt_align - 1);
+             char *tgt = (char *) gomp_alloca (tgt_size + tgt_align - 1);
              copy_firstprivate_data (tgt, mapnum, hostaddrs, sizes, kinds,
                                      tgt_align, tgt_size);
            }
@@ -4008,13 +4011,13 @@ gomp_target_rev (uint64_t fn_ptr, uint64_t mapnum, 
uint64_t devaddrs_ptr,
 
   /* If actually executed on 32bit systems, the casts lead to wrong code;
      but 32bit with offloading is not supported; see top of this function.  */
-  calculate_firstprivate_requirements (mapnum, (void *) (uintptr_t) sizes,
-                                      (void *) (uintptr_t) kinds,
+  calculate_firstprivate_requirements (mapnum, (size_t *) (uintptr_t) sizes,
+                                      (unsigned short *) (uintptr_t) kinds,
                                       &tgt_align, &tgt_size);
 
   if (tgt_align)
     {
-      char *tgt = gomp_alloca (tgt_size + tgt_align - 1);
+      char *tgt = (char *) gomp_alloca (tgt_size + tgt_align - 1);
       uintptr_t al = (uintptr_t) tgt & (tgt_align - 1);
       if (al)
        tgt += tgt_align - al;
@@ -4054,7 +4057,7 @@ gomp_target_rev (uint64_t fn_ptr, uint64_t mapnum, 
uint64_t devaddrs_ptr,
     {
       size_t j, struct_cpy = 0;
       splay_tree_key n2;
-      cdata = gomp_alloca (sizeof (*cdata) * mapnum);
+      cdata = (typeof (cdata)) gomp_alloca (sizeof (*cdata) * mapnum);
       memset (cdata, '\0', sizeof (*cdata) * mapnum);
       gomp_mutex_lock (&devicep->lock);
       for (uint64_t i = 0; i < mapnum; i++)
@@ -4090,6 +4093,7 @@ gomp_target_rev (uint64_t fn_ptr, uint64_t mapnum, 
uint64_t devaddrs_ptr,
              case GOMP_MAP_ALWAYS_PRESENT_TO:
              case GOMP_MAP_ALWAYS_PRESENT_TOFROM:
              case GOMP_MAP_ZERO_LEN_ARRAY_SECTION:
+               { //TODO indentation
                cdata[i].devaddr = devaddrs[i];
                bool zero_len = (kind == GOMP_MAP_DELETE_ZERO_LEN_ARRAY_SECTION
                                 || kind == GOMP_MAP_ZERO_LEN_ARRAY_SECTION);
@@ -4158,6 +4162,7 @@ gomp_target_rev (uint64_t fn_ptr, uint64_t mapnum, 
uint64_t devaddrs_ptr,
                if (struct_cpy)
                  struct_cpy--;
                break;
+               } //TODO indentation
              case GOMP_MAP_ATTACH:
              case GOMP_MAP_POINTER:
              case GOMP_MAP_ALWAYS_POINTER:
@@ -4626,6 +4631,7 @@ gomp_exit_data (struct gomp_device_descr *devicep, size_t 
mapnum,
        case GOMP_MAP_RELEASE:
        case GOMP_MAP_ZERO_LEN_ARRAY_SECTION:
        case GOMP_MAP_DELETE_ZERO_LEN_ARRAY_SECTION:
+         { //TODO indentation
          cur_node.host_start = (uintptr_t) hostaddrs[i];
          cur_node.host_end = cur_node.host_start + sizes[i];
          splay_tree_key k = (kind == GOMP_MAP_DELETE_ZERO_LEN_ARRAY_SECTION
@@ -4682,6 +4688,7 @@ gomp_exit_data (struct gomp_device_descr *devicep, size_t 
mapnum,
          if (do_remove)
            remove_vars[nrmvars++] = k;
          break;
+         } //TODO indentation
 
        case GOMP_MAP_DETACH:
          break;
@@ -5151,7 +5158,7 @@ gomp_managed_free (void *device_ptr)
    the process.  */
 
 static struct gomp_device_descr *device_for_page_locked
-  = /* uninitialized */ (void *) -1;
+  = /* uninitialized */ (typeof (device_for_page_locked)) -1;
 
 static struct gomp_device_descr *
 get_device_for_page_locked (void)
@@ -5411,7 +5418,7 @@ typedef struct
 static void
 omp_target_memcpy_async_helper (void *args)
 {
-  omp_target_memcpy_data *a = args;
+  omp_target_memcpy_data *a = (typeof (a)) args;
   if (omp_target_memcpy_copy (a->dst, a->src, a->length, a->dst_offset,
                              a->src_offset, a->dst_devicep, a->src_devicep))
     gomp_fatal ("omp_target_memcpy failed");
@@ -5707,7 +5714,7 @@ typedef struct
 static void
 omp_target_memcpy_rect_async_helper (void *args)
 {
-  omp_target_memcpy_rect_data *a = args;
+  omp_target_memcpy_rect_data *a = (typeof (a)) args;
   int ret = omp_target_memcpy_rect_copy (a->dst, a->src, a->element_size,
                                         a->num_dims, a->volume, a->dst_offsets,
                                         a->src_offsets, a->dst_dimensions,
@@ -5816,7 +5823,7 @@ typedef struct
 static void
 omp_target_memset_async_helper (void *args)
 {
-  omp_target_memset_data *a = args;
+  omp_target_memset_data *a = (typeof (a)) args;
   omp_target_memset_int (a->ptr, a->val, a->count, a->devicep);
 }
 
@@ -5894,8 +5901,8 @@ omp_target_associate_ptr (const void *host_ptr, const 
void *device_ptr,
     }
   else
     {
-      struct target_mem_desc *tgt = gomp_malloc (sizeof (*tgt));
-      tgt->array = gomp_malloc (sizeof (*tgt->array));
+      struct target_mem_desc *tgt = (typeof (tgt)) gomp_malloc (sizeof (*tgt));
+      tgt->array = (typeof (tgt->array)) gomp_malloc (sizeof (*tgt->array));
       tgt->refcount = 1;
       tgt->tgt_start = 0;
       tgt->tgt_end = 0;
@@ -6474,7 +6481,7 @@ gomp_get_uid_for_device (struct gomp_device_descr 
*devicep, int device_num)
     {
       size_t ln = strlen (STR_OMP_DEV_PREFIX) + 10 + 1;
       char *uid;
-      uid = gomp_malloc (ln);
+      uid = (typeof (uid)) gomp_malloc (ln);
       snprintf (uid, ln, "%s%d", STR_OMP_DEV_PREFIX, device_num);
       devicep->uid = uid;
     }
@@ -6631,12 +6638,12 @@ gomp_load_plugin_for_device (struct gomp_device_descr 
*device,
      so we don't need to check dlerror all the time.  */
 #define DLSYM(f) DLSYM2(f, f)
 #define DLSYM2(f, n)                                                   \
-  if (!(device->f##_func = dlsym (plugin_handle, "GOMP_OFFLOAD_" #n))) \
+  if (!(device->f##_func = (typeof (device->f##_func)) dlsym (plugin_handle, 
"GOMP_OFFLOAD_" #n)))     \
     goto dl_fail
   /* Similar, but missing functions are not an error.  Return false if
      failed, true otherwise.  */
 #define DLSYM_OPT(f, n)                                                        
\
-  ((device->f##_func = dlsym (plugin_handle, "GOMP_OFFLOAD_" #n))      \
+  ((device->f##_func = (typeof (device->f##_func)) dlsym (plugin_handle, 
"GOMP_OFFLOAD_" #n)) \
    || (last_missing = #n, 0))
 
   DLSYM (version);
@@ -6685,7 +6692,7 @@ gomp_load_plugin_for_device (struct gomp_device_descr 
*device,
   if (device->capabilities & GOMP_OFFLOAD_CAP_OPENMP_400)
     {
       __typeof (GOMP_OFFLOAD_session_size) *size_func
-       = dlsym (plugin_handle, "GOMP_OFFLOAD_session_size");
+       = (typeof (size_func)) dlsym (plugin_handle, 
"GOMP_OFFLOAD_session_size");
       device->session.size = size_func ();
       DLSYM2 (session.start, session_start);
       DLSYM_OPT (session.alloc_tvt, session_allocate_target_var_table);
@@ -6825,7 +6832,7 @@ gomp_target_init (void)
            if (new_num_devs >= 1)
              {
                /* Augment DEVICES and NUM_DEVICES.  */
-               devs = realloc (devs, (num_devs + new_num_devs)
+               devs = (typeof (devs)) realloc (devs, (num_devs + new_num_devs)
                                      * sizeof (struct gomp_device_descr));
                if (!devs)
                  {
@@ -6838,7 +6845,7 @@ gomp_target_init (void)
                /* Defer UID setting until needed + after gomp_init_device.  */
                current_device.uid = NULL;
                /* current_device.capabilities has already been set.  */
-               current_device.type = current_device.get_type_func ();
+               current_device.type = (typeof (current_device.type)) 
current_device.get_type_func ();
                current_device.mem_map.root = NULL;
                current_device.mem_map_rev.root = NULL;
                current_device.state = GOMP_DEVICE_UNINITIALIZED;
@@ -6907,7 +6914,7 @@ gomp_target_init (void)
   /* In DEVICES, sort the GOMP_OFFLOAD_CAP_OPENMP_400 ones first, and set
      NUM_DEVICES_OPENMP.  */
   struct gomp_device_descr *devs_s
-    = malloc (num_devs * sizeof (struct gomp_device_descr));
+    = (typeof (devs_s)) malloc (num_devs * sizeof (struct gomp_device_descr));
   if (!devs_s)
     {
       num_devs = 0;
diff --git a/libgomp/task.c b/libgomp/task.c
index 9ff300d576a3..248d88dacbbf 100644
--- a/libgomp/task.c
+++ b/libgomp/task.c
@@ -244,7 +244,7 @@ gomp_task_handle_depend (struct gomp_task *task, struct 
gomp_task *parent,
       if (tsk->dependers == NULL)
        {
          tsk->dependers
-           = gomp_malloc (sizeof (struct gomp_dependers_vec)
+           = (typeof (tsk->dependers)) gomp_malloc (sizeof (struct 
gomp_dependers_vec)
                           + 6 * sizeof (struct gomp_task *));
          tsk->dependers->n_elem = 1;
          tsk->dependers->allocated = 6;
@@ -257,7 +257,7 @@ gomp_task_handle_depend (struct gomp_task *task, struct 
gomp_task *parent,
              tsk->dependers->allocated
                = tsk->dependers->allocated * 2 + 2;
              tsk->dependers
-               = gomp_realloc (tsk->dependers,
+               = (typeof (tsk->dependers)) gomp_realloc (tsk->dependers,
                                sizeof (struct gomp_dependers_vec)
                                + (tsk->dependers->allocated
                                   * sizeof (struct gomp_task *)));
@@ -303,7 +303,7 @@ gomp_task_handle_depend (struct gomp_task *task, struct 
gomp_task *parent,
                      if (tsk->dependers == NULL)
                        {
                          tsk->dependers
-                           = gomp_malloc (sizeof (struct gomp_dependers_vec)
+                           = (typeof (tsk->dependers)) gomp_malloc (sizeof 
(struct gomp_dependers_vec)
                                           + 6 * sizeof (struct gomp_task *));
                          tsk->dependers->n_elem = 1;
                          tsk->dependers->allocated = 6;
@@ -323,7 +323,7 @@ gomp_task_handle_depend (struct gomp_task *task, struct 
gomp_task *parent,
                          tsk->dependers->allocated
                            = tsk->dependers->allocated * 2 + 2;
                          tsk->dependers
-                           = gomp_realloc (tsk->dependers,
+                           = (typeof (tsk->dependers)) gomp_realloc 
(tsk->dependers,
                                            sizeof (struct gomp_dependers_vec)
                                            + (tsk->dependers->allocated
                                               * sizeof (struct gomp_task *)));
@@ -400,7 +400,7 @@ gomp_task_handle_depend (struct gomp_task *task, struct 
gomp_task *parent,
              if (tsk->dependers == NULL)
                {
                  tsk->dependers
-                   = gomp_malloc (sizeof (struct gomp_dependers_vec)
+                   = (typeof (tsk->dependers)) gomp_malloc (sizeof (struct 
gomp_dependers_vec)
                                   + 6 * sizeof (struct gomp_task *));
                  tsk->dependers->n_elem = 1;
                  tsk->dependers->allocated = 6;
@@ -419,7 +419,7 @@ gomp_task_handle_depend (struct gomp_task *task, struct 
gomp_task *parent,
                  tsk->dependers->allocated
                    = tsk->dependers->allocated * 2 + 2;
                  tsk->dependers
-                   = gomp_realloc (tsk->dependers,
+                   = (typeof (tsk->dependers)) gomp_realloc (tsk->dependers,
                                    sizeof (struct gomp_dependers_vec)
                                    + (tsk->dependers->allocated
                                       * sizeof (struct gomp_task *)));
@@ -618,7 +618,7 @@ GOMP_task (void (*fn) (void *), void *data, void (*cpyfn) 
(void *, void *),
       if (flags & GOMP_TASK_FLAG_DEPEND)
        depend_size = ((uintptr_t) (depend[0] ? depend[0] : depend[1])
                       * sizeof (struct gomp_task_depend_entry));
-      task = gomp_malloc (sizeof (*task) + depend_size
+      task = (typeof (task)) gomp_malloc (sizeof (*task) + depend_size
                          + arg_size + arg_align - 1);
       arg = (char *) (((uintptr_t) (task + 1) + depend_size + arg_align - 1)
                      & ~(uintptr_t) (arg_align - 1));
@@ -776,7 +776,7 @@ priority_queue_move_task_first (enum priority_queue_type 
type,
     }
   else
     list = &head->l;
-  priority_list_remove (list, task_to_priority_node (type, task), 0);
+  priority_list_remove (list, task_to_priority_node (type, task), 
MEMMODEL_RELAXED);
   priority_list_insert (type, list, task, task->priority,
                        PRIORITY_INSERT_BEGIN, type == PQ_CHILDREN,
                        task->parent_depends_on);
@@ -954,7 +954,7 @@ gomp_create_target_task (struct gomp_device_descr *devicep,
       /* ... and reserve enough room.  */
       task_alloc_size += devicep->session.size;
     }
-  task = gomp_malloc (task_alloc_size);
+  task = (typeof (task)) gomp_malloc (task_alloc_size);
   gomp_init_task (task, parent, gomp_icv (false));
   task->priority = 0;
   task->kind = GOMP_TASK_WAITING;
@@ -969,7 +969,7 @@ gomp_create_target_task (struct gomp_device_descr *devicep,
   if (session_start_offset)
     {
       uintptr_t session_ptr = (uintptr_t) task + session_start_offset;
-      ttask->offload_session = (void *) session_ptr;
+      ttask->offload_session = (typeof (ttask->offload_session)) session_ptr;
     }
 
   memcpy (ttask->hostaddrs, hostaddrs, mapnum * sizeof (void *));
@@ -2244,7 +2244,7 @@ static inline struct gomp_taskgroup *
 gomp_taskgroup_init (struct gomp_taskgroup *prev)
 {
   struct gomp_taskgroup *taskgroup
-    = gomp_malloc (sizeof (struct gomp_taskgroup));
+    = (struct gomp_taskgroup *) gomp_malloc (sizeof (struct gomp_taskgroup));
   taskgroup->prev = prev;
   priority_queue_init (&taskgroup->taskgroup_queue);
   taskgroup->reductions = prev ? prev->reductions : NULL;
diff --git a/libgomp/taskloop.c b/libgomp/taskloop.c
index 2b661e583ccc..3815928d7021 100644
--- a/libgomp/taskloop.c
+++ b/libgomp/taskloop.c
@@ -301,7 +301,7 @@ GOMP_taskloop (void (*fn) (void *), void *data, void 
(*cpyfn) (void *, void *),
       for (i = 0; i < num_tasks; i++)
        {
          struct gomp_task *task
-           = gomp_malloc (sizeof (*task) + arg_size + arg_align - 1);
+           = (typeof (task)) gomp_malloc (sizeof (*task) + arg_size + 
arg_align - 1);
          tasks[i] = task;
          arg = (char *) (((uintptr_t) (task + 1) + arg_align - 1)
                          & ~(uintptr_t) (arg_align - 1));
diff --git a/libgomp/team.c b/libgomp/team.c
index 3d38b7f95873..c6cfa4194a0e 100644
--- a/libgomp/team.c
+++ b/libgomp/team.c
@@ -106,7 +106,7 @@ gomp_init_team_state (struct gomp_team_state *ts, struct 
gomp_team *team,
 static void *
 gomp_thread_start (void *xdata)
 {
-  struct gomp_thread_start_data *data = xdata;
+  struct gomp_thread_start_data *data = (typeof (data)) xdata;
   struct gomp_thread *thr;
   struct gomp_thread_pool *pool;
   void (*local_fn) (void *);
@@ -312,10 +312,10 @@ gomp_new_team (unsigned nthreads)
       size_t alloc_extra
        = team_extra + barrier_padding + barrier_extra_alloc.size;
 #ifdef GOMP_USE_ALIGNED_WORK_SHARES
-      team = gomp_aligned_alloc (__alignof (struct gomp_team),
+      team = (typeof (team)) gomp_aligned_alloc (__alignof (struct gomp_team),
                                 sizeof (*team) + alloc_extra);
 #else
-      team = team_malloc (sizeof (*team) + alloc_extra);
+      team = (typeof (team)) team_malloc (sizeof (*team) + alloc_extra);
 #endif
 
 #ifndef HAVE_SYNC_BUILTINS
@@ -345,7 +345,7 @@ gomp_new_team (unsigned nthreads)
   team->work_shares[i].next_free = NULL;
 
   gomp_sem_init (&team->master_release, 0);
-  team->ordered_release = (void *) &team->implicit_task[nthreads];
+  team->ordered_release = (typeof (team->ordered_release)) 
&team->implicit_task[nthreads];
   team->ordered_release[0] = &team->master_release;
 
   priority_queue_init (&team->task_queue);
@@ -725,7 +725,7 @@ gomp_team_start (void (*fn) (void *), void *data, unsigned 
nthreads,
        {
          pool->threads_size = nthreads + 1;
          pool->threads
-           = gomp_realloc (pool->threads,
+           = (typeof (pool->threads)) gomp_realloc (pool->threads,
                            pool->threads_size
                            * sizeof (struct gomp_thread *));
          /* Add current (master) thread to threads[].  */
@@ -811,11 +811,11 @@ gomp_team_start (void (*fn) (void *), void *data, 
unsigned nthreads,
 
                      if (team->prev_ts.place_partition_len > 64)
                        affinity_thr
-                         = gomp_malloc (team->prev_ts.place_partition_len
+                         = (typeof (affinity_thr)) gomp_malloc 
(team->prev_ts.place_partition_len
                                         * sizeof (struct gomp_thread *));
                      else
                        affinity_thr
-                         = gomp_alloca (team->prev_ts.place_partition_len
+                         = (typeof (affinity_thr)) gomp_alloca 
(team->prev_ts.place_partition_len
                                         * sizeof (struct gomp_thread *));
                      memset (affinity_thr, '\0',
                              team->prev_ts.place_partition_len
@@ -1051,7 +1051,7 @@ gomp_team_start (void (*fn) (void *), void *data, 
unsigned nthreads,
 
   if (i >= nthreads)
     __builtin_unreachable ();
-  start_data = gomp_alloca (sizeof (struct gomp_thread_start_data)
+  start_data = (typeof (start_data)) gomp_alloca (sizeof (struct 
gomp_thread_start_data)
                            * (nthreads - i));
 
   /* Launch new threads.  */
@@ -1287,7 +1287,7 @@ gomp_team_end (void)
       struct gomp_work_share *ws = team->work_shares_to_free;
       do
        {
-         struct gomp_work_share *next_ws = gomp_ptrlock_get (&ws->next_ws);
+         struct gomp_work_share *next_ws = (typeof (next_ws)) gomp_ptrlock_get 
(&ws->next_ws);
          if (next_ws == NULL)
            gomp_ptrlock_set (&ws->next_ws, ws);
          gomp_fini_work_share (ws);
@@ -1431,7 +1431,7 @@ gomp_pause_host (void)
        {
          int i;
          pthread_t *thrs
-           = gomp_alloca (sizeof (pthread_t) * pool->threads_used);
+           = (typeof (thrs)) gomp_alloca (sizeof (pthread_t) * 
pool->threads_used);
          for (i = 1; i < pool->threads_used; i++)
            {
              struct gomp_thread *nthr = pool->threads[i];
@@ -1476,7 +1476,7 @@ struct gomp_task_icv *
 gomp_new_icv (void)
 {
   struct gomp_thread *thr = gomp_thread ();
-  struct gomp_task *task = gomp_malloc (sizeof (struct gomp_task));
+  struct gomp_task *task = (typeof (task)) gomp_malloc (sizeof (struct 
gomp_task));
   gomp_init_task (task, NULL, &gomp_global_icv);
   thr->task = task;
 #ifdef LIBGOMP_USE_PTHREADS
diff --git a/libgomp/work.c b/libgomp/work.c
index 280fa242fd53..701f773aa069 100644
--- a/libgomp/work.c
+++ b/libgomp/work.c
@@ -79,11 +79,11 @@ alloc_work_share (struct gomp_team *team)
   /* Allocating gomp_work_share structures aligned is just an
      optimization, don't do it when using the fallback method.  */
 #ifdef GOMP_USE_ALIGNED_WORK_SHARES
-  ws = gomp_aligned_alloc (__alignof (struct gomp_work_share),
+  ws = (typeof (ws)) gomp_aligned_alloc (__alignof (struct gomp_work_share),
                           team->work_share_chunk
                           * sizeof (struct gomp_work_share));
 #else
-  ws = gomp_malloc (team->work_share_chunk * sizeof (struct gomp_work_share));
+  ws = (typeof (ws)) gomp_malloc (team->work_share_chunk * sizeof (struct 
gomp_work_share));
 #endif
   ws->next_alloc = team->work_shares[0].next_alloc;
   team->work_shares[0].next_alloc = ws;
@@ -122,7 +122,7 @@ gomp_init_work_share (struct gomp_work_share *ws, size_t 
ordered,
       else
        ordered = nthreads * sizeof (*ws->ordered_team_ids);
       if (ordered > INLINE_ORDERED_TEAM_IDS_SIZE)
-       ws->ordered_team_ids = team_malloc (ordered);
+       ws->ordered_team_ids = (typeof (ws->ordered_team_ids)) team_malloc 
(ordered);
       else
        ws->ordered_team_ids = ws->inline_ordered_team_ids;
       memset (ws->ordered_team_ids, '\0', ordered);
@@ -194,10 +194,10 @@ gomp_work_share_start (size_t ordered)
   if (team == NULL)
     {
 #ifdef GOMP_USE_ALIGNED_WORK_SHARES
-      ws = gomp_aligned_alloc (__alignof (struct gomp_work_share),
+      ws = (typeof (ws)) gomp_aligned_alloc (__alignof (struct 
gomp_work_share),
                               sizeof (*ws));
 #else
-      ws = gomp_malloc (sizeof (*ws));
+      ws = (typeof (ws)) gomp_malloc (sizeof (*ws));
 #endif
       gomp_init_work_share (ws, ordered, 1);
       thr->ts.work_share = ws;
@@ -206,7 +206,7 @@ gomp_work_share_start (size_t ordered)
 
   ws = thr->ts.work_share;
   thr->ts.last_work_share = ws;
-  ws = gomp_ptrlock_get (&ws->next_ws);
+  ws = (typeof (ws)) gomp_ptrlock_get (&ws->next_ws);
   if (ws == NULL)
     {
       /* This thread encountered a new ws first.  */
-- 
2.53.0

Reply via email to