[gomp4.1] coerce libgomp to build with C++

Aldy Hernandez aldyh@redhat.com
Fri Aug 14 00:55:00 GMT 2015


Ughh... what was supposed to be a short hack turned out to be 2 days of 
pure torture.

So...I'm implementing task priorities as per the 4.1 standard, and 
decided to use a priority queue.  Since we already have splay trees in 
libgomp, I figured these priority queues could be built on top of them. 
  However, our libgomp splay tree adaptation is not exactly generic 
enough, so I started rewriting it to use C++ templates.

I quickly found out that libgomp is built with C, so I said to myself... 
"Self, how bad can it be to convert libgomp to C++?".  Very.

I've pretty much renounced the splay tree in C++ idea, but only because 
I don't want to iron out the remaining automake/configury magic, not to 
mention possible ABI issues I've yet to uncover.  However, throwing 2 
days' worth of work away would be silly, so how about we pass 
-Wc++-compat and avoid further C/C++ divergence?

I have tested this patch as is, as well as with:

	AM_CFLAGS = $(XCFLAGS) -x c++

Using the C++ compiler compiles, but does not link:

/usr/bin/ld: .libs/loop.o: relocation R_X86_64_PC32 against undefined 
symbol `gomp_ialias_GOMP_parallel_end' can not be used when making a 
shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value

I really must get back to task priorities, so I'm not going to pursue 
C++ linking any further.  However, the attached patch should get us 95% 
of the way there, and we can keep it going forward.

I could provide a trunk version of this, but considering gomp4.1 will 
get merged (*crosses fingers*), no sense in doing the work twice.

Most everything is obvious.  The things that are not, or I'm unsure 
about, I have documented throughout.

OK for gomp4.1 branch?
-------------- next part --------------
commit 69a9fc925ecf856057883e49842186e2b412cad2
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Thu Aug 13 13:02:48 2015 -0700

    	* Makefile.am (AM_CFLAGS): Pass -Wc++-compat.
    	* Makefile.in: Regenerate.
    	* config/linux/affinity.c (gomp_affinity_alloc): Fix *alloc cast.
    	(gomp_affinity_init_level): Same.
    	(gomp_affinity_print_place): Fix *signed comparison.
    	(omp_get_place_num_procs): Same.
    	(omp_get_place_proc_ids): Same.
    	* critical.c (GOMP_critical_name_start): Cast pointer assignment.
    	* env.c (gomp_global_icv): Rearrange field initialization.
    	(parse_schedule): Fix *signed comparison.
    	(parse_unsigned_long_list): Cast pointer assignment.
    	(parse_bind_var): Same.
    	(handle_omp_display_env): Fix *signed comparison.
    	Insert space after string concatenation.
    	(omp_set_schedule): Cast enum.
    	(omp_get_schedule): Cast pointer assignment.
    	(omp_proc_bind_t): Cast enum.
    	* fortran.c (gomp_init_nest_lock__30): Add unused attribute.
    	(gomp_destroy_nest_lock__30): Same.
    	(gomp_set_nest_lock__30): Same.
    	(gomp_unset_nest_lock__30): Same.
    	(gomp_test_nest_lock__30): Same.
    	(omp_set_schedule_): Cast pointer.
    	(omp_set_schedule_8_): Cast enum.
    	* iter.c (gomp_iter_static_next): Fix signness issues.
    	* iter_ull.c (gomp_iter_ull_static_next): Same.
    	* libgomp.h: Wrap gomp_*_{25,30} functions in extern "C".
    	* libgomp_g.h: Wrap GOMP_* functions in extern "C".
    	* loop_ull.c: Same.
    	* loop.c (gomp_loop_init): Same.
    	Fix sign issues.
    	* oacc-async.c: Add __GOACC_CXX_NOEXCEPT to all acc_* functions.
    	* oacc-cuda.c: Same.
    	* oacc-init.c (goacc_register): Same.
    	(resolve_device): Fix enum issues.
    	(goacc_new_thread): Fix typo in malloc size.
    	(goacc_destroy_thread): Fix pointer cast.
    	(acc_*): Add __GOACC_CXX_NOEXCEPT.
    	* oacc-host.c (host_dispatch): Rearrange field initialization.
    	* oacc-mem.c (lookup_host): Fix sign problems
    	(acc_*): Add __GOACC_CXX_NOEXCEPT.  Fix sign problems.
    	* oacc-parallel.c (find_pset): Same.
    	(GOACC_parallel): Insert space in between string concat.
    	Add pointer casts.
    	* oacc-plugin.c (GOMP_PLUGIN_async_unmap_vars): Add pointer cast.
    	* omp.h.in (__GOMP_NOTHROW): Remove throw() from C++ definition.
    	* openacc.h (__GOACC_CXX_NOEXCEPT): New.
    	(__GOACC_NOTHROW): Use it.
    	* ordered.c (GOMP_ordered_start): Provide C++ mangling.
    	* parallel.c (omp_get_ancestor_thread_num): Sign sign issues.
    	(omp_get_team_size): Same.
    	* plugin/plugin-host.c (GOMP_OFFLOAD_openacc_parallel): Cast
    	pointer.
    	(GOMP_OFFLOAD_openacc_create_thread_data): Same.
    	* sections.c (gomp_sections_init): Fix sign issues.
    	* target.c (gomp_map_vars): Add pointer casts.
    	Insert space in between string concat.
    	(gomp_offload_image_to_device): Add pointer casts.
    	(GOMP_offload_register): Same.
    	(GOMP_target_41): Same.
    	(gomp_exit_data): Protect variable declaration from goto.
    	(omp_target_associate_ptr): Add pointer casts.
    	(gomp_load_plugin_for_device): Same.
    	(gomp_target_init): Same.
    	Cast enum.
    	* task.c (GOMP_task): Same.
    	(gomp_barrier_handle_tasks): Fix sign issues.
    	(GOMP_taskwait): Same.
    	(gomp_task_maybe_wait_for_dependencies): Same.
    	(GOMP_taskgroup_start): Same.
    	(GOMP_taskgroup_end): Same.
    	* tasklookup.c (GOMP_taskloop): Add pointer casts.
    	* team.c (struct gomp_thread_start_data): Add visibility
    	push/pop's around structure.
    	(gomp_thread_start): Add pointer casts.
    	(gomp_new_team): Same.
    	(gomp_new_thread_pool): Same.
    	(gomp_free_thread): Fix sign issues.
    	(gomp_team_start): Add pointer casts.
    	(gomp_team_end): Same.
    	(gomp_new_icv): Same.
    	* work.c (alloc_work_share): Same.
    	(gomp_init_work_share): Same.

diff --git a/libgomp/ChangeLog.gomp b/libgomp/ChangeLog.gomp
index f54732e..2030d15 100644
--- a/libgomp/ChangeLog.gomp
+++ b/libgomp/ChangeLog.gomp
@@ -1,3 +1,89 @@
+2015-08-13  Aldy Hernandez  <aldyh@redhat.com>
+
+	* Makefile.am (AM_CFLAGS): Pass -Wc++-compat.
+	* Makefile.in: Regenerate.
+	* config/linux/affinity.c (gomp_affinity_alloc): Fix *alloc cast.
+	(gomp_affinity_init_level): Same.
+	(gomp_affinity_print_place): Fix *signed comparison.
+	(omp_get_place_num_procs): Same.
+	(omp_get_place_proc_ids): Same.
+	* critical.c (GOMP_critical_name_start): Cast pointer assignment.
+	* env.c (gomp_global_icv): Rearrange field initialization.
+	(parse_schedule): Fix *signed comparison.
+	(parse_unsigned_long_list): Cast pointer assignment.
+	(parse_bind_var): Same.
+	(handle_omp_display_env): Fix *signed comparison.
+	Insert space after string concatenation.
+	(omp_set_schedule): Cast enum.
+	(omp_get_schedule): Cast pointer assignment.
+	(omp_proc_bind_t): Cast enum.
+	* fortran.c (gomp_init_nest_lock__30): Add unused attribute.
+	(gomp_destroy_nest_lock__30): Same.
+	(gomp_set_nest_lock__30): Same.
+	(gomp_unset_nest_lock__30): Same.
+	(gomp_test_nest_lock__30): Same.
+	(omp_set_schedule_): Cast pointer.
+	(omp_set_schedule_8_): Cast enum.
+	* iter.c (gomp_iter_static_next): Fix signness issues.
+	* iter_ull.c (gomp_iter_ull_static_next): Same.
+	* libgomp.h: Wrap gomp_*_{25,30} functions in extern "C".
+	* libgomp_g.h: Wrap GOMP_* functions in extern "C".
+	* loop_ull.c: Same.
+	* loop.c (gomp_loop_init): Same.
+	Fix sign issues.
+	* oacc-async.c: Add __GOACC_CXX_NOEXCEPT to all acc_* functions.
+	* oacc-cuda.c: Same.
+	* oacc-init.c (goacc_register): Same.
+	(resolve_device): Fix enum issues.
+	(goacc_new_thread): Fix typo in malloc size.
+	(goacc_destroy_thread): Fix pointer cast.
+	(acc_*): Add __GOACC_CXX_NOEXCEPT.
+	* oacc-host.c (host_dispatch): Rearrange field initialization.
+	* oacc-mem.c (lookup_host): Fix sign problems
+	(acc_*): Add __GOACC_CXX_NOEXCEPT.  Fix sign problems.
+	* oacc-parallel.c (find_pset): Same.
+	(GOACC_parallel): Insert space in between string concat.
+	Add pointer casts.
+	* oacc-plugin.c (GOMP_PLUGIN_async_unmap_vars): Add pointer cast.
+	* omp.h.in (__GOMP_NOTHROW): Remove throw() from C++ definition.
+	* openacc.h (__GOACC_CXX_NOEXCEPT): New.
+	(__GOACC_NOTHROW): Use it.
+	* ordered.c (GOMP_ordered_start): Provide C++ mangling.
+	* parallel.c (omp_get_ancestor_thread_num): Sign sign issues.
+	(omp_get_team_size): Same.
+	* plugin/plugin-host.c (GOMP_OFFLOAD_openacc_parallel): Cast
+	pointer.
+	(GOMP_OFFLOAD_openacc_create_thread_data): Same.
+	* sections.c (gomp_sections_init): Fix sign issues.
+	* target.c (gomp_map_vars): Add pointer casts.
+	Insert space in between string concat.
+	(gomp_offload_image_to_device): Add pointer casts.
+	(GOMP_offload_register): Same.
+	(GOMP_target_41): Same.
+	(gomp_exit_data): Protect variable declaration from goto.
+	(omp_target_associate_ptr): Add pointer casts.
+	(gomp_load_plugin_for_device): Same.
+	(gomp_target_init): Same.
+	Cast enum.
+	* task.c (GOMP_task): Same.
+	(gomp_barrier_handle_tasks): Fix sign issues.
+	(GOMP_taskwait): Same.
+	(gomp_task_maybe_wait_for_dependencies): Same.
+	(GOMP_taskgroup_start): Same.
+	(GOMP_taskgroup_end): Same.
+	* tasklookup.c (GOMP_taskloop): Add pointer casts.
+	* team.c (struct gomp_thread_start_data): Add visibility
+	push/pop's around structure.
+	(gomp_thread_start): Add pointer casts.
+	(gomp_new_team): Same.
+	(gomp_new_thread_pool): Same.
+	(gomp_free_thread): Fix sign issues.
+	(gomp_team_start): Add pointer casts.
+	(gomp_team_end): Same.
+	(gomp_new_icv): Same.
+	* work.c (alloc_work_share): Same.
+	(gomp_init_work_share): Same.
+
 2015-07-31  Jakub Jelinek  <jakub@redhat.com>
 
 	* target.c (gomp_map_fields_existing): New function.
diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index 5411278..734553c 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -16,7 +16,7 @@ libsubincludedir = $(libdir)/gcc/$(target_alias)/$(gcc_version)/include
 vpath % $(strip $(search_path))
 
 AM_CPPFLAGS = $(addprefix -I, $(search_path))
-AM_CFLAGS = $(XCFLAGS)
+AM_CFLAGS = $(XCFLAGS) -Wc++-compat
 AM_LDFLAGS = $(XLDFLAGS) $(SECTION_LDFLAGS) $(OPT_LDFLAGS)
 
 toolexeclib_LTLIBRARIES = libgomp.la
diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index 9d07e8d..2cc3300 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -399,7 +399,7 @@ search_path = $(addprefix $(top_srcdir)/config/, $(config_path)) $(top_srcdir) \
 fincludedir = $(libdir)/gcc/$(target_alias)/$(gcc_version)/finclude
 libsubincludedir = $(libdir)/gcc/$(target_alias)/$(gcc_version)/include
 AM_CPPFLAGS = $(addprefix -I, $(search_path))
-AM_CFLAGS = $(XCFLAGS)
+AM_CFLAGS = $(XCFLAGS) -Wc++-compat
 AM_LDFLAGS = $(XLDFLAGS) $(SECTION_LDFLAGS) $(OPT_LDFLAGS)
 toolexeclib_LTLIBRARIES = libgomp.la $(am__append_1) \
 	libgomp-plugin-host_nonshm.la
diff --git a/libgomp/config/linux/affinity.c b/libgomp/config/linux/affinity.c
index 775ee0a..a6b4bb6 100644
--- a/libgomp/config/linux/affinity.c
+++ b/libgomp/config/linux/affinity.c
@@ -83,7 +83,7 @@ gomp_affinity_alloc (unsigned long count, bool quiet)
       return NULL;
     }
 
-  ret = malloc (count * sizeof (void *) + count * gomp_cpuset_size);
+  ret = (void **) malloc (count * sizeof (void *) + count * gomp_cpuset_size);
   if (ret == NULL)
     {
       if (!quiet)
@@ -256,7 +256,7 @@ gomp_affinity_init_level (int level, unsigned long count, bool quiet)
       char name[sizeof ("/sys/devices/system/cpu/cpu/topology/"
 			"thread_siblings_list") + 3 * sizeof (unsigned long)];
       size_t prefix_len = sizeof ("/sys/devices/system/cpu/cpu") - 1;
-      cpu_set_t *copy = gomp_alloca (gomp_cpuset_size);
+      cpu_set_t *copy = (cpu_set_t *) gomp_alloca (gomp_cpuset_size);
       FILE *f;
       char *line = NULL;
       size_t linelen = 0;
@@ -356,7 +356,7 @@ gomp_affinity_print_place (void *p)
 int
 omp_get_place_num_procs (int place_num)
 {
-  if (place_num < 0 || place_num >= gomp_places_list_len)
+  if (place_num < 0 || (unsigned) place_num >= gomp_places_list_len)
     return 0;
 
   cpu_set_t *cpusetp = (cpu_set_t *) gomp_places_list[place_num];
@@ -366,7 +366,7 @@ omp_get_place_num_procs (int place_num)
 void
 omp_get_place_proc_ids (int place_num, int *ids)
 {
-  if (place_num < 0 || place_num >= gomp_places_list_len)
+  if (place_num < 0 || (unsigned) place_num >= gomp_places_list_len)
     return;
 
   cpu_set_t *cpusetp = (cpu_set_t *) gomp_places_list[place_num];
@@ -379,7 +379,7 @@ omp_get_place_proc_ids (int place_num, int *ids)
 void
 gomp_get_place_proc_ids_8 (int place_num, int64_t *ids)
 {
-  if (place_num < 0 || place_num >= gomp_places_list_len)
+  if (place_num < 0 || (unsigned) place_num >= gomp_places_list_len)
     return;
 
   cpu_set_t *cpusetp = (cpu_set_t *) gomp_places_list[place_num];
diff --git a/libgomp/critical.c b/libgomp/critical.c
index 12b23d5..027448f 100644
--- a/libgomp/critical.c
+++ b/libgomp/critical.c
@@ -64,15 +64,17 @@ 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
+	    = (gomp_mutex_t *) __sync_val_compare_and_swap (pptr, NULL, nlock);
 	  if (plock != NULL)
 	    {
 	      gomp_mutex_destroy (nlock);
@@ -110,7 +112,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 65a6851..60e1c04 100644
--- a/libgomp/env.c
+++ b/libgomp/env.c
@@ -57,10 +57,10 @@
 
 struct gomp_task_icv gomp_global_icv = {
   .nthreads_var = 1,
-  .thread_limit_var = UINT_MAX,
   .run_sched_var = GFS_DYNAMIC,
   .run_sched_chunk_size = 1,
   .default_device_var = 0,
+  .thread_limit_var = UINT_MAX,
   .dyn_var = false,
   .nest_var = false,
   .bind_var = omp_proc_bind_false,
@@ -146,7 +146,7 @@ parse_schedule (void)
   if (*end != '\0')
     goto invalid;
 
-  if ((int)value != value)
+  if ((unsigned int) value != value)
     goto invalid;
 
   if (value == 0 && gomp_global_icv.run_sched_var != GFS_STATIC)
@@ -258,7 +258,8 @@ parse_unsigned_long_list (const char *name, unsigned long *p1stvalue,
 		{
 		  unsigned long *n;
 		  nalloced = nalloced ? nalloced * 2 : 16;
-		  n = realloc (values, nalloced * sizeof (unsigned long));
+		  n = (unsigned long *)
+		        realloc (values, nalloced * sizeof (unsigned long));
 		  if (n == NULL)
 		    {
 		      free (values);
@@ -370,7 +371,7 @@ parse_bind_var (const char *name, char *p1stvalue,
 		{
 		  char *n;
 		  nalloced = nalloced ? nalloced * 2 : 16;
-		  n = realloc (values, nalloced);
+		  n = (char *) realloc (values, nalloced);
 		  if (n == NULL)
 		    {
 		      free (values);
@@ -1035,7 +1036,7 @@ handle_omp_display_env (unsigned long stacksize, int wait_policy)
   const char *env;
   bool display = false;
   bool verbose = false;
-  int i;
+  unsigned int i;
 
   env = getenv ("OMP_DISPLAY_ENV");
   if (env == NULL)
@@ -1167,7 +1168,7 @@ handle_omp_display_env (unsigned long stacksize, int wait_policy)
       fputs ("  GOMP_CPU_AFFINITY = ''\n", stderr);
       fprintf (stderr, "  GOMP_STACKSIZE = '%lu'\n", stacksize);
 #ifdef HAVE_INTTYPES_H
-      fprintf (stderr, "  GOMP_SPINCOUNT = '%"PRIu64"'\n",
+      fprintf (stderr, "  GOMP_SPINCOUNT = '%" PRIu64 "'\n",
 	       (uint64_t) gomp_spin_count_var);
 #else
       fprintf (stderr, "  GOMP_SPINCOUNT = '%lu'\n",
@@ -1363,14 +1364,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;
 }
 
@@ -1417,7 +1418,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;
 }
 
 void
diff --git a/libgomp/fortran.c b/libgomp/fortran.c
index ceff9ac..b5d86ed 100644
--- a/libgomp/fortran.c
+++ b/libgomp/fortran.c
@@ -106,11 +106,13 @@ gomp_init_lock__30 (omp_lock_arg_t lock)
   gomp_init_lock_30 (omp_lock_arg (lock));
 }
 
+__attribute__((unused))
 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));
 }
@@ -125,6 +127,7 @@ gomp_destroy_lock__30 (omp_lock_arg_t lock)
 #endif
 }
 
+__attribute__((unused))
 void
 gomp_destroy_nest_lock__30 (omp_nest_lock_arg_t lock)
 {
@@ -141,6 +144,7 @@ gomp_set_lock__30 (omp_lock_arg_t lock)
   gomp_set_lock_30 (omp_lock_arg (lock));
 }
 
+__attribute__((unused))
 void
 gomp_set_nest_lock__30 (omp_nest_lock_arg_t lock)
 {
@@ -153,6 +157,7 @@ gomp_unset_lock__30 (omp_lock_arg_t lock)
   gomp_unset_lock_30 (omp_lock_arg (lock));
 }
 
+__attribute__((unused))
 void
 gomp_unset_nest_lock__30 (omp_nest_lock_arg_t lock)
 {
@@ -165,6 +170,7 @@ gomp_test_lock__30 (omp_lock_arg_t lock)
   return gomp_test_lock_30 (omp_lock_arg (lock));
 }
 
+__attribute__((unused))
 int32_t
 gomp_test_nest_lock__30 (omp_nest_lock_arg_t lock)
 {
@@ -353,13 +359,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
diff --git a/libgomp/iter.c b/libgomp/iter.c
index 0ceb41d..0a79404 100644
--- a/libgomp/iter.c
+++ b/libgomp/iter.c
@@ -43,7 +43,7 @@ gomp_iter_static_next (long *pstart, long *pend)
   struct gomp_work_share *ws = thr->ts.work_share;
   unsigned long nthreads = team ? team->nthreads : 1;
 
-  if (thr->ts.static_trip == -1)
+  if (thr->ts.static_trip == ~0UL)
     return -1;
 
   /* Quick test for degenerate teams and orphaned constructs.  */
@@ -274,7 +274,7 @@ gomp_iter_guided_next_locked (long *pstart, long *pend)
   n = (ws->end - start) / ws->incr;
   q = (n + nthreads - 1) / nthreads;
 
-  if (q < ws->chunk_size)
+  if (q < (unsigned long) ws->chunk_size)
     q = ws->chunk_size;
   if (q <= n)
     end = start + q * ws->incr;
diff --git a/libgomp/iter_ull.c b/libgomp/iter_ull.c
index b1cad84..aeb735f 100644
--- a/libgomp/iter_ull.c
+++ b/libgomp/iter_ull.c
@@ -44,7 +44,7 @@ gomp_iter_ull_static_next (gomp_ull *pstart, gomp_ull *pend)
   struct gomp_work_share *ws = thr->ts.work_share;
   unsigned long nthreads = team ? team->nthreads : 1;
 
-  if (thr->ts.static_trip == -1)
+  if (thr->ts.static_trip == ~0UL)
     return -1;
 
   /* Quick test for degenerate teams and orphaned constructs.  */
diff --git a/libgomp/libgomp.h b/libgomp/libgomp.h
index 9031649..3bc20bb 100644
--- a/libgomp/libgomp.h
+++ b/libgomp/libgomp.h
@@ -847,6 +847,11 @@ gomp_work_share_init_done (void)
 #endif
 
 #ifdef LIBGOMP_GNU_SYMBOL_VERSIONING
+#ifdef __cplusplus
+/* The strongalias uses below will have an alias expecting the C
+   mangling.  */
+extern "C" {
+#endif
 extern void gomp_init_lock_30 (omp_lock_t *) __GOMP_NOTHROW;
 extern void gomp_destroy_lock_30 (omp_lock_t *) __GOMP_NOTHROW;
 extern void gomp_set_lock_30 (omp_lock_t *) __GOMP_NOTHROW;
@@ -868,6 +873,9 @@ extern void gomp_destroy_nest_lock_25 (omp_nest_lock_25_t *) __GOMP_NOTHROW;
 extern void gomp_set_nest_lock_25 (omp_nest_lock_25_t *) __GOMP_NOTHROW;
 extern void gomp_unset_nest_lock_25 (omp_nest_lock_25_t *) __GOMP_NOTHROW;
 extern int gomp_test_nest_lock_25 (omp_nest_lock_25_t *) __GOMP_NOTHROW;
+#ifdef __cplusplus
+}
+#endif
 
 # define strong_alias(fn, al) \
   extern __typeof (fn) al __attribute__ ((alias (#fn)));
diff --git a/libgomp/libgomp_g.h b/libgomp/libgomp_g.h
index bc635d3..df9b528 100644
--- a/libgomp/libgomp_g.h
+++ b/libgomp/libgomp_g.h
@@ -32,6 +32,10 @@
 #include <stdbool.h>
 #include <stddef.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* barrier.c */
 
 extern void GOMP_barrier (void);
@@ -245,4 +249,8 @@ extern void GOACC_wait (int, int, ...);
 extern int GOACC_get_num_threads (void);
 extern int GOACC_get_thread_num (void);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* LIBGOMP_G_H */
diff --git a/libgomp/loop.c b/libgomp/loop.c
index 4339ee5..b493c9f 100644
--- a/libgomp/loop.c
+++ b/libgomp/loop.c
@@ -53,7 +53,7 @@ gomp_loop_init (struct gomp_work_share *ws, long start, long end, long incr,
 	   faster.  */
 	struct gomp_thread *thr = gomp_thread ();
 	struct gomp_team *team = thr->ts.team;
-	long nthreads = team ? team->nthreads : 1;
+	unsigned long nthreads = team ? team->nthreads : 1;
 
 	if (__builtin_expect (incr > 0, 1))
 	  {
@@ -63,7 +63,7 @@ gomp_loop_init (struct gomp_work_share *ws, long start, long end, long incr,
 					     * __CHAR_BIT__ / 2 - 1), 0))
 	      ws->mode = 0;
 	    else
-	      ws->mode = ws->end < (LONG_MAX
+	      ws->mode = ws->end < (long) (LONG_MAX
 				    - (nthreads + 1) * ws->chunk_size);
 	  }
 	/* Cheap overflow protection.  */
@@ -72,7 +72,7 @@ gomp_loop_init (struct gomp_work_share *ws, long start, long end, long incr,
 					      * __CHAR_BIT__ / 2 - 1), 0))
 	  ws->mode = 0;
 	else
-	  ws->mode = ws->end > (nthreads + 1) * -ws->chunk_size - LONG_MAX;
+	  ws->mode = ws->end > (long) (nthreads + 1) * -ws->chunk_size - LONG_MAX;
       }
 #endif
     }
@@ -94,6 +94,11 @@ gomp_loop_init (struct gomp_work_share *ws, long start, long end, long incr,
    allocated to this thread.  Returns false if all work was assigned to
    other threads prior to this thread's arrival.  */
 
+#ifdef __cplusplus
+/* Aliases below expects C mangling.  */
+extern "C" {
+#endif
+
 static bool
 gomp_loop_static_start (long start, long end, long incr, long chunk_size,
 			long *istart, long *iend)
@@ -560,6 +565,9 @@ GOMP_loop_end_nowait (void)
   gomp_work_share_end_nowait ();
 }
 
+#ifdef __cplusplus
+}
+#endif
 
 /* We use static functions above so that we're sure that the "runtime"
    function can defer to the proper routine without interposition.  We
diff --git a/libgomp/loop_ull.c b/libgomp/loop_ull.c
index c09b0d4..20fd601 100644
--- a/libgomp/loop_ull.c
+++ b/libgomp/loop_ull.c
@@ -31,6 +31,11 @@
 
 typedef unsigned long long gomp_ull;
 
+#ifdef __cplusplus
+/* Aliases below expects C mangling.  */
+extern "C" {
+#endif
+
 /* Initialize the given work share construct from the given arguments.  */
 
 static inline void
@@ -446,6 +451,10 @@ GOMP_loop_ull_ordered_runtime_next (gomp_ull *istart, gomp_ull *iend)
     }
 }
 
+#ifdef __cplusplus
+}
+#endif
+
 /* We use static functions above so that we're sure that the "runtime"
    function can defer to the proper routine without interposition.  We
    export the static function with a strong alias when possible, or with
diff --git a/libgomp/oacc-async.c b/libgomp/oacc-async.c
index 1f5827e..1272e3e 100644
--- a/libgomp/oacc-async.c
+++ b/libgomp/oacc-async.c
@@ -32,7 +32,7 @@
 #include "oacc-int.h"
 
 int
-acc_async_test (int async)
+acc_async_test (int async) __GOACC_CXX_NOEXCEPT
 {
   if (async < acc_async_sync)
     gomp_fatal ("invalid async argument: %d", async);
@@ -46,7 +46,7 @@ acc_async_test (int async)
 }
 
 int
-acc_async_test_all (void)
+acc_async_test_all (void) __GOACC_CXX_NOEXCEPT
 {
   struct goacc_thread *thr = goacc_thread ();
 
@@ -57,7 +57,7 @@ acc_async_test_all (void)
 }
 
 void
-acc_wait (int async)
+acc_wait (int async) __GOACC_CXX_NOEXCEPT
 {
   if (async < acc_async_sync)
     gomp_fatal ("invalid async argument: %d", async);
@@ -71,7 +71,7 @@ acc_wait (int async)
 }
 
 void
-acc_wait_async (int async1, int async2)
+acc_wait_async (int async1, int async2) __GOACC_CXX_NOEXCEPT
 {
   struct goacc_thread *thr = goacc_thread ();
 
@@ -82,7 +82,7 @@ acc_wait_async (int async1, int async2)
 }
 
 void
-acc_wait_all (void)
+acc_wait_all (void) __GOACC_CXX_NOEXCEPT
 {
   struct goacc_thread *thr = goacc_thread ();
 
@@ -93,7 +93,7 @@ acc_wait_all (void)
 }
 
 void
-acc_wait_all_async (int async)
+acc_wait_all_async (int async) __GOACC_CXX_NOEXCEPT
 {
   if (async < acc_async_sync)
     gomp_fatal ("invalid async argument: %d", async);
diff --git a/libgomp/oacc-cuda.c b/libgomp/oacc-cuda.c
index 4aab422..110641c 100644
--- a/libgomp/oacc-cuda.c
+++ b/libgomp/oacc-cuda.c
@@ -32,7 +32,7 @@
 #include "oacc-int.h"
 
 void *
-acc_get_current_cuda_device (void)
+acc_get_current_cuda_device (void) __GOACC_CXX_NOEXCEPT
 {
   struct goacc_thread *thr = goacc_thread ();
 
@@ -43,7 +43,7 @@ acc_get_current_cuda_device (void)
 }
 
 void *
-acc_get_current_cuda_context (void)
+acc_get_current_cuda_context (void) __GOACC_CXX_NOEXCEPT
 {
   struct goacc_thread *thr = goacc_thread ();
 
@@ -54,7 +54,7 @@ acc_get_current_cuda_context (void)
 }
 
 void *
-acc_get_cuda_stream (int async)
+acc_get_cuda_stream (int async) __GOACC_CXX_NOEXCEPT
 {
   struct goacc_thread *thr = goacc_thread ();
 
@@ -68,7 +68,7 @@ acc_get_cuda_stream (int async)
 }
 
 int
-acc_set_cuda_stream (int async, void *stream)
+acc_set_cuda_stream (int async, void *stream) __GOACC_CXX_NOEXCEPT
 {
   struct goacc_thread *thr;
 
diff --git a/libgomp/oacc-host.c b/libgomp/oacc-host.c
index 6dcdbf3..dbd4e8c 100644
--- a/libgomp/oacc-host.c
+++ b/libgomp/oacc-host.c
@@ -51,23 +51,28 @@ static struct gomp_device_descr host_dispatch =
     .free_func = GOMP_OFFLOAD_free,
     .dev2host_func = GOMP_OFFLOAD_dev2host,
     .host2dev_func = GOMP_OFFLOAD_host2dev,
+    .dev2dev_func = NULL,
     .run_func = GOMP_OFFLOAD_run,
 
+    .mem_map = { NULL },
+    .lock = 0,
+
     .is_initialized = false,
 
     .openacc = {
+      .data_environ = NULL,
       .exec_func = GOMP_OFFLOAD_openacc_parallel,
 
       .register_async_cleanup_func
         = GOMP_OFFLOAD_openacc_register_async_cleanup,
 
-      .async_set_async_func = GOMP_OFFLOAD_openacc_async_set_async,
       .async_test_func = GOMP_OFFLOAD_openacc_async_test,
       .async_test_all_func = GOMP_OFFLOAD_openacc_async_test_all,
       .async_wait_func = GOMP_OFFLOAD_openacc_async_wait,
       .async_wait_async_func = GOMP_OFFLOAD_openacc_async_wait_async,
       .async_wait_all_func = GOMP_OFFLOAD_openacc_async_wait_all,
       .async_wait_all_async_func = GOMP_OFFLOAD_openacc_async_wait_all_async,
+      .async_set_async_func = GOMP_OFFLOAD_openacc_async_set_async,
 
       .create_thread_data_func = GOMP_OFFLOAD_openacc_create_thread_data,
       .destroy_thread_data_func = GOMP_OFFLOAD_openacc_destroy_thread_data,
diff --git a/libgomp/oacc-init.c b/libgomp/oacc-init.c
index c91731e..5748a83 100644
--- a/libgomp/oacc-init.c
+++ b/libgomp/oacc-init.c
@@ -66,7 +66,7 @@ static gomp_mutex_t goacc_thread_lock;
 static struct gomp_device_descr *dispatchers[_ACC_device_hwm] = { 0 };
 
 attribute_hidden void
-goacc_register (struct gomp_device_descr *disp)
+goacc_register (struct gomp_device_descr *disp) __GOACC_CXX_NOEXCEPT
 {
   /* Only register the 0th device here.  */
   if (disp->target_id != 0)
@@ -114,18 +114,19 @@ name_of_acc_device_t (enum acc_device_t type)
    otherwise it returns NULL in that case.  */
 
 static struct gomp_device_descr *
-resolve_device (acc_device_t d, bool fail_is_error)
+resolve_device (acc_device_t dev, bool fail_is_error)
 {
-  acc_device_t d_arg = d;
+  acc_device_t d_arg = dev;
 
+  int d = (int) dev;
   switch (d)
     {
-    case acc_device_default:
+    case (int) acc_device_default:
       {
 	if (goacc_device_type)
 	  {
 	    /* Lookup the named device.  */
-	    while (++d != _ACC_device_hwm)
+	    while (++d != (int)_ACC_device_hwm)
 	      if (dispatchers[d]
 		  && !strcasecmp (goacc_device_type,
 				  get_openacc_name (dispatchers[d]->name))
@@ -143,7 +144,7 @@ resolve_device (acc_device_t d, bool fail_is_error)
 
 	/* No default device specified, so start scanning for any non-host
 	   device that is available.  */
-	d = acc_device_not_host;
+	d = (int) acc_device_not_host;
       }
       /* FALLTHROUGH */
 
@@ -170,7 +171,7 @@ resolve_device (acc_device_t d, bool fail_is_error)
       break;
 
     default:
-      if (d > _ACC_device_hwm)
+      if (d > (int) _ACC_device_hwm)
 	{
 	  if (fail_is_error)
 	    goto unsupported_device;
@@ -181,15 +182,16 @@ resolve_device (acc_device_t d, bool fail_is_error)
     }
  found:
 
-  assert (d != acc_device_none
-	  && d != acc_device_default
-	  && d != acc_device_not_host);
+  assert (d != (int) acc_device_none
+	  && d != (int) acc_device_default
+	  && d != (int) acc_device_not_host);
 
   if (dispatchers[d] == NULL && fail_is_error)
     {
     unsupported_device:
       gomp_mutex_unlock (&acc_device_lock);
-      gomp_fatal ("device type %s not supported", name_of_acc_device_t (d));
+      gomp_fatal ("device type %s not supported",
+		  name_of_acc_device_t ((acc_device_t) d));
     }
 
   return dispatchers[d];
@@ -312,7 +314,13 @@ acc_shutdown_1 (acc_device_t d)
 static struct goacc_thread *
 goacc_new_thread (void)
 {
-  struct goacc_thread *thr = gomp_malloc (sizeof (struct gomp_thread));
+  /* ????????? */
+  /* ????????? */
+  /* ????????? */
+  /* ????????? */
+  /* ?? I have fixed this seemingly incorrect sizeof.  */
+  struct goacc_thread *thr
+    = (struct goacc_thread *) gomp_malloc (sizeof (struct goacc_thread));
 
 #if defined HAVE_TLS || defined USE_EMUTLS
   goacc_tls_data = thr;
@@ -333,7 +341,7 @@ goacc_new_thread (void)
 static void
 goacc_destroy_thread (void *data)
 {
-  struct goacc_thread *thr = data, *walk, *prev;
+  struct goacc_thread *thr = (struct goacc_thread *) data, *walk, *prev;
 
   gomp_mutex_lock (&goacc_thread_lock);
 
@@ -421,7 +429,7 @@ goacc_attach_host_thread_to_device (int ord)
    init/shutdown is per-process or per-thread.  We choose per-process.  */
 
 void
-acc_init (acc_device_t d)
+acc_init (acc_device_t d) __GOACC_CXX_NOEXCEPT
 {
   if (!cached_base_dev)
     gomp_init_targets_once ();
@@ -438,7 +446,7 @@ acc_init (acc_device_t d)
 ialias (acc_init)
 
 void
-acc_shutdown (acc_device_t d)
+acc_shutdown (acc_device_t d) __GOACC_CXX_NOEXCEPT
 {
   gomp_mutex_lock (&acc_device_lock);
 
@@ -450,7 +458,7 @@ acc_shutdown (acc_device_t d)
 ialias (acc_shutdown)
 
 int
-acc_get_num_devices (acc_device_t d)
+acc_get_num_devices (acc_device_t d) __GOACC_CXX_NOEXCEPT
 {
   int n = 0;
   struct gomp_device_descr *acc_dev;
@@ -481,7 +489,7 @@ ialias (acc_get_num_devices)
    default device type for new threads to D.  */
 
 void
-acc_set_device_type (acc_device_t d)
+acc_set_device_type (acc_device_t d) __GOACC_CXX_NOEXCEPT
 {
   struct gomp_device_descr *base_dev, *acc_dev;
   struct goacc_thread *thr = goacc_thread ();
@@ -516,7 +524,7 @@ acc_set_device_type (acc_device_t d)
 ialias (acc_set_device_type)
 
 acc_device_t
-acc_get_device_type (void)
+acc_get_device_type (void) __GOACC_CXX_NOEXCEPT
 {
   acc_device_t res = acc_device_none;
   struct gomp_device_descr *dev;
@@ -543,7 +551,7 @@ acc_get_device_type (void)
 ialias (acc_get_device_type)
 
 int
-acc_get_device_num (acc_device_t d)
+acc_get_device_num (acc_device_t d) __GOACC_CXX_NOEXCEPT
 {
   const struct gomp_device_descr *dev;
   struct goacc_thread *thr = goacc_thread ();
@@ -567,7 +575,7 @@ acc_get_device_num (acc_device_t d)
 ialias (acc_get_device_num)
 
 void
-acc_set_device_num (int ord, acc_device_t d)
+acc_set_device_num (int ord, acc_device_t d) __GOACC_CXX_NOEXCEPT
 {
   struct gomp_device_descr *base_dev, *acc_dev;
   int num_devices;
@@ -612,7 +620,7 @@ acc_set_device_num (int ord, acc_device_t d)
 ialias (acc_set_device_num)
 
 int
-acc_on_device (acc_device_t dev)
+acc_on_device (acc_device_t dev) __GOACC_CXX_NOEXCEPT
 {
   struct goacc_thread *thr = goacc_thread ();
 
diff --git a/libgomp/oacc-mem.c b/libgomp/oacc-mem.c
index af067d6..4ec991d 100644
--- a/libgomp/oacc-mem.c
+++ b/libgomp/oacc-mem.c
@@ -61,7 +61,6 @@ lookup_host (struct gomp_device_descr *dev, void *h, size_t s)
 static splay_tree_key
 lookup_dev (struct target_mem_desc *tgt, void *d, size_t s)
 {
-  int i;
   struct target_mem_desc *t;
 
   if (!tgt)
@@ -76,14 +75,14 @@ lookup_dev (struct target_mem_desc *tgt, void *d, size_t s)
   if (!t)
     return NULL;
 
-  for (i = 0; i < t->list_count; i++)
+  for (unsigned i = 0; i < t->list_count; i++)
     {
       void * offset;
 
       splay_tree_key k = &t->array[i].key;
-      offset = d - t->tgt_start + k->tgt_offset;
+      offset = (void *) ((uintptr_t) d - t->tgt_start + k->tgt_offset);
 
-      if (k->host_start + offset <= (void *) k->host_end)
+      if (k->host_start + (uintptr_t) offset <= k->host_end)
         return k;
     }
 
@@ -94,7 +93,7 @@ lookup_dev (struct target_mem_desc *tgt, void *d, size_t s)
    NULL.  */
 
 void *
-acc_malloc (size_t s)
+acc_malloc (size_t s) __GOACC_CXX_NOEXCEPT
 {
   if (!s)
     return NULL;
@@ -112,7 +111,7 @@ acc_malloc (size_t s)
    the device address is mapped. We choose to check if it mapped,
    and if it is, to unmap it. */
 void
-acc_free (void *d)
+acc_free (void *d) __GOACC_CXX_NOEXCEPT
 {
   splay_tree_key k;
 
@@ -134,11 +133,11 @@ acc_free (void *d)
     {
       void *offset;
 
-      offset = d - k->tgt->tgt_start + k->tgt_offset;
+      offset = (void *) ((uintptr_t) d - k->tgt->tgt_start + k->tgt_offset);
 
       gomp_mutex_unlock (&acc_dev->lock);
 
-      acc_unmap_data ((void *)(k->host_start + offset));
+      acc_unmap_data ((void *)(k->host_start + (uintptr_t) offset));
     }
   else
     gomp_mutex_unlock (&acc_dev->lock);
@@ -147,7 +146,7 @@ acc_free (void *d)
 }
 
 void
-acc_memcpy_to_device (void *d, void *h, size_t s)
+acc_memcpy_to_device (void *d, void *h, size_t s) __GOACC_CXX_NOEXCEPT
 {
   /* No need to call lazy open here, as the device pointer must have
      been obtained from a routine that did that.  */
@@ -159,7 +158,7 @@ acc_memcpy_to_device (void *d, void *h, size_t s)
 }
 
 void
-acc_memcpy_from_device (void *h, void *d, size_t s)
+acc_memcpy_from_device (void *h, void *d, size_t s) __GOACC_CXX_NOEXCEPT
 {
   /* No need to call lazy open here, as the device pointer must have
      been obtained from a routine that did that.  */
@@ -174,7 +173,7 @@ acc_memcpy_from_device (void *h, void *d, size_t s)
    if no mapping.  */
 
 void *
-acc_deviceptr (void *h)
+acc_deviceptr (void *h) __GOACC_CXX_NOEXCEPT
 {
   splay_tree_key n;
   void *d;
@@ -195,9 +194,9 @@ acc_deviceptr (void *h)
       return NULL;
     }
 
-  offset = h - n->host_start;
+  offset = (void *) ((uintptr_t) h - n->host_start);
 
-  d = n->tgt->tgt_start + n->tgt_offset + offset;
+  d = (void *) (n->tgt->tgt_start + n->tgt_offset + (uintptr_t) offset);
 
   gomp_mutex_unlock (&dev->lock);
 
@@ -208,7 +207,7 @@ acc_deviceptr (void *h)
    if no mapping.  */
 
 void *
-acc_hostptr (void *d)
+acc_hostptr (void *d) __GOACC_CXX_NOEXCEPT
 {
   splay_tree_key n;
   void *h;
@@ -229,9 +228,9 @@ acc_hostptr (void *d)
       return NULL;
     }
 
-  offset = d - n->tgt->tgt_start + n->tgt_offset;
+  offset = (void *) ((uintptr_t) d - n->tgt->tgt_start + n->tgt_offset);
 
-  h = n->host_start + offset;
+  h = (void *) (n->host_start + (uintptr_t) offset);
 
   gomp_mutex_unlock (&acc_dev->lock);
 
@@ -241,7 +240,7 @@ acc_hostptr (void *d)
 /* Return 1 if host data [H,+S] is present on the device.  */
 
 int
-acc_is_present (void *h, size_t s)
+acc_is_present (void *h, size_t s) __GOACC_CXX_NOEXCEPT
 {
   splay_tree_key n;
 
@@ -270,7 +269,7 @@ acc_is_present (void *h, size_t s)
 /* Create a mapping for host [H,+S] -> device [D,+S] */
 
 void
-acc_map_data (void *h, void *d, size_t s)
+acc_map_data (void *h, void *d, size_t s) __GOACC_CXX_NOEXCEPT
 {
   struct target_mem_desc *tgt;
   size_t mapnum = 1;
@@ -329,7 +328,7 @@ acc_map_data (void *h, void *d, size_t s)
 }
 
 void
-acc_unmap_data (void *h)
+acc_unmap_data (void *h) __GOACC_CXX_NOEXCEPT
 {
   struct goacc_thread *thr = goacc_thread ();
   struct gomp_device_descr *acc_dev = thr->dev;
@@ -420,7 +419,7 @@ present_create_copy (unsigned f, void *h, size_t s)
           gomp_fatal ("[%p,+%d] already mapped to [%p,+%d]",
         	      (void *)h, (int)s, (void *)d, (int)s);
 	}
-      if ((h + s) > (void *)n->host_end)
+      if (((uintptr_t) h + s) > n->host_end)
 	{
 	  gomp_mutex_unlock (&acc_dev->lock);
 	  gomp_fatal ("[%p,+%d] not mapped", (void *)h, (int)s);
@@ -463,25 +462,25 @@ present_create_copy (unsigned f, void *h, size_t s)
 }
 
 void *
-acc_create (void *h, size_t s)
+acc_create (void *h, size_t s) __GOACC_CXX_NOEXCEPT
 {
   return present_create_copy (FLAG_CREATE, h, s);
 }
 
 void *
-acc_copyin (void *h, size_t s)
+acc_copyin (void *h, size_t s) __GOACC_CXX_NOEXCEPT
 {
   return present_create_copy (FLAG_CREATE | FLAG_COPY, h, s);
 }
 
 void *
-acc_present_or_create (void *h, size_t s)
+acc_present_or_create (void *h, size_t s) __GOACC_CXX_NOEXCEPT
 {
   return present_create_copy (FLAG_PRESENT | FLAG_CREATE, h, s);
 }
 
 void *
-acc_present_or_copyin (void *h, size_t s)
+acc_present_or_copyin (void *h, size_t s) __GOACC_CXX_NOEXCEPT
 {
   return present_create_copy (FLAG_PRESENT | FLAG_CREATE | FLAG_COPY, h, s);
 }
@@ -532,12 +531,12 @@ delete_copyout (unsigned f, void *h, size_t s)
 }
 
 void
-acc_delete (void *h , size_t s)
+acc_delete (void *h , size_t s) __GOACC_CXX_NOEXCEPT
 {
   delete_copyout (0, h, s);
 }
 
-void acc_copyout (void *h, size_t s)
+void acc_copyout (void *h, size_t s) __GOACC_CXX_NOEXCEPT
 {
   delete_copyout (FLAG_COPYOUT, h, s);
 }
@@ -574,13 +573,13 @@ update_dev_host (int is_dev, void *h, size_t s)
 }
 
 void
-acc_update_device (void *h, size_t s)
+acc_update_device (void *h, size_t s) __GOACC_CXX_NOEXCEPT
 {
   update_dev_host (1, h, s);
 }
 
 void
-acc_update_self (void *h, size_t s)
+acc_update_self (void *h, size_t s) __GOACC_CXX_NOEXCEPT
 {
   update_dev_host (0, h, s);
 }
@@ -611,7 +610,7 @@ gomp_acc_remove_pointer (void *h, bool force_copyfrom, int async, int mapnum)
   struct gomp_device_descr *acc_dev = thr->dev;
   splay_tree_key n;
   struct target_mem_desc *t;
-  int minrefs = (mapnum == 1) ? 2 : 3;
+  unsigned int minrefs = (mapnum == 1) ? 2 : 3;
 
   gomp_mutex_lock (&acc_dev->lock);
 
diff --git a/libgomp/oacc-parallel.c b/libgomp/oacc-parallel.c
index 38c4770..aaa854e 100644
--- a/libgomp/oacc-parallel.c
+++ b/libgomp/oacc-parallel.c
@@ -41,7 +41,7 @@
 static int
 find_pset (int pos, size_t mapnum, unsigned short *kinds)
 {
-  if (pos + 1 >= mapnum)
+  if (pos + 1 >= (int) mapnum)
     return 0;
 
   unsigned char kind = kinds[pos+1] & 0xff;
@@ -77,7 +77,7 @@ GOACC_parallel (int device, void (*fn) (void *),
 		num_workers);
 
 #ifdef HAVE_INTTYPES_H
-  gomp_debug (0, "%s: mapnum=%"PRIu64", hostaddrs=%p, size=%p, kinds=%p, "
+  gomp_debug (0, "%s: mapnum=%" PRIu64 ", hostaddrs=%p, size=%p, kinds=%p, "
 		 "async = %d\n",
 	      __FUNCTION__, (uint64_t) mapnum, hostaddrs, sizes, kinds, async);
 #else
@@ -133,14 +133,15 @@ GOACC_parallel (int device, void (*fn) (void *),
   tgt = gomp_map_vars (acc_dev, mapnum, hostaddrs, NULL, sizes, kinds, true,
 		       GOMP_MAP_VARS_OPENACC);
 
-  devaddrs = gomp_alloca (sizeof (void *) * mapnum);
+  devaddrs = (typeof (devaddrs)) gomp_alloca (sizeof (void *) * mapnum);
   for (i = 0; i < mapnum; i++)
     devaddrs[i] = (void *) (tgt->list[i].key->tgt->tgt_start
 			    + tgt->list[i].key->tgt_offset);
 
-  acc_dev->openacc.exec_func (tgt_fn, mapnum, hostaddrs, devaddrs, sizes, kinds,
+  acc_dev->openacc.exec_func ((void (*) (void *)) tgt_fn,
+			      mapnum, hostaddrs, devaddrs, sizes, kinds,
 			      num_gangs, num_workers, vector_length, async,
-			      tgt);
+			      (void *) tgt);
 
   /* If running synchronously, unmap immediately.  */
   if (async < acc_async_noval)
@@ -162,7 +163,7 @@ GOACC_data_start (int device, size_t mapnum,
   struct target_mem_desc *tgt;
 
 #ifdef HAVE_INTTYPES_H
-  gomp_debug (0, "%s: mapnum=%"PRIu64", hostaddrs=%p, size=%p, kinds=%p\n",
+  gomp_debug (0, "%s: mapnum=%" PRIu64 ", hostaddrs=%p, size=%p, kinds=%p\n",
 	      __FUNCTION__, (uint64_t) mapnum, hostaddrs, sizes, kinds);
 #else
   gomp_debug (0, "%s: mapnum=%lu, hostaddrs=%p, sizes=%p, kinds=%p\n",
diff --git a/libgomp/oacc-plugin.c b/libgomp/oacc-plugin.c
index 44cd6d6..9e037ce 100644
--- a/libgomp/oacc-plugin.c
+++ b/libgomp/oacc-plugin.c
@@ -33,7 +33,7 @@
 void
 GOMP_PLUGIN_async_unmap_vars (void *ptr)
 {
-  struct target_mem_desc *tgt = ptr;
+  struct target_mem_desc *tgt = (typeof (tgt)) ptr;
 
   gomp_unmap_vars (tgt, false);
 }
diff --git a/libgomp/omp.h.in b/libgomp/omp.h.in
index e62f146..28e9d86 100644
--- a/libgomp/omp.h.in
+++ b/libgomp/omp.h.in
@@ -73,7 +73,7 @@ typedef enum omp_lock_hint_t
 
 #ifdef __cplusplus
 extern "C" {
-# define __GOMP_NOTHROW throw ()
+# define __GOMP_NOTHROW
 #else
 # define __GOMP_NOTHROW __attribute__((__nothrow__))
 #endif
diff --git a/libgomp/openacc.h b/libgomp/openacc.h
index 44a1526..2b4c8f6 100644
--- a/libgomp/openacc.h
+++ b/libgomp/openacc.h
@@ -39,10 +39,13 @@ extern "C" {
 #endif
 
 #if __cplusplus >= 201103
-# define __GOACC_NOTHROW noexcept
+# define __GOACC_CXX_NOEXCEPT noexcept
+# define __GOACC_NOTHROW __GOACC_CXX_NOEXCEPT
 #elif __cplusplus
-# define __GOACC_NOTHROW throw ()
+# define __GOACC_CXX_NOEXCEPT
+# define __GOACC_NOTHROW
 #else /* Not C++ */
+# define __GOACC_CXX_NOEXCEPT
 # define __GOACC_NOTHROW __attribute__ ((__nothrow__))
 #endif
 
diff --git a/libgomp/ordered.c b/libgomp/ordered.c
index 69ca217..f891f75 100644
--- a/libgomp/ordered.c
+++ b/libgomp/ordered.c
@@ -228,7 +228,12 @@ gomp_ordered_sync (void)
 
 #ifdef HAVE_ATTRIBUTE_ALIAS
 extern void GOMP_ordered_start (void)
+#ifdef __cplusplus
+// ?? Errr, either do this or set `extern "C"' on gomp_ordered_*.
+	__attribute__((alias ("_Z17gomp_ordered_syncv")));
+#else
 	__attribute__((alias ("gomp_ordered_sync")));
+#endif
 #else
 void
 GOMP_ordered_start (void)
diff --git a/libgomp/parallel.c b/libgomp/parallel.c
index 6d5ef05..624684b2d 100644
--- a/libgomp/parallel.c
+++ b/libgomp/parallel.c
@@ -266,7 +266,7 @@ int
 omp_get_ancestor_thread_num (int level)
 {
   struct gomp_team_state *ts = &gomp_thread ()->ts;
-  if (level < 0 || level > ts->level)
+  if (level < 0 || level > (int) ts->level)
     return -1;
   for (level = ts->level - level; level > 0; --level)
     ts = &ts->team->prev_ts;
@@ -277,7 +277,7 @@ int
 omp_get_team_size (int level)
 {
   struct gomp_team_state *ts = &gomp_thread ()->ts;
-  if (level < 0 || level > ts->level)
+  if (level < 0 || level > (int) ts->level)
     return -1;
   for (level = ts->level - level; level > 0; --level)
     ts = &ts->team->prev_ts;
diff --git a/libgomp/plugin/plugin-host.c b/libgomp/plugin/plugin-host.c
index 3cb4dab..6808fc1 100644
--- a/libgomp/plugin/plugin-host.c
+++ b/libgomp/plugin/plugin-host.c
@@ -179,7 +179,7 @@ GOMP_OFFLOAD_openacc_parallel (void (*fn) (void *),
 			       void *targ_mem_desc __attribute__ ((unused)))
 {
 #ifdef HOST_NONSHM_PLUGIN
-  struct nonshm_thread *thd = GOMP_PLUGIN_acc_thread ();
+  struct nonshm_thread *thd = (typeof (thd)) GOMP_PLUGIN_acc_thread ();
   thd->nonshm_exec = true;
   fn (devaddrs);
   thd->nonshm_exec = false;
@@ -242,7 +242,7 @@ GOMP_OFFLOAD_openacc_create_thread_data (int ord
 {
 #ifdef HOST_NONSHM_PLUGIN
   struct nonshm_thread *thd
-    = GOMP_PLUGIN_malloc (sizeof (struct nonshm_thread));
+    = (typeof (thd)) GOMP_PLUGIN_malloc (sizeof (struct nonshm_thread));
   thd->nonshm_exec = false;
   return thd;
 #else
diff --git a/libgomp/sections.c b/libgomp/sections.c
index f3a1725..6ac5083 100644
--- a/libgomp/sections.c
+++ b/libgomp/sections.c
@@ -49,7 +49,7 @@ gomp_sections_init (struct gomp_work_share *ws, unsigned count)
       long nthreads = team ? team->nthreads : 1;
 
       ws->mode = ((nthreads | ws->end)
-		  < 1UL << (sizeof (long) * __CHAR_BIT__ / 2 - 1));
+		  < 1L << (sizeof (long) * __CHAR_BIT__ / 2 - 1));
     }
 #else
   ws->mode = 0;
diff --git a/libgomp/target.c b/libgomp/target.c
index 946fdc0..3be2d19 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -317,7 +317,8 @@ gomp_map_vars (struct gomp_device_descr *devicep, size_t mapnum,
   struct splay_tree_s *mem_map = &devicep->mem_map;
   struct splay_tree_key_s cur_node;
   struct target_mem_desc *tgt
-    = gomp_malloc (sizeof (*tgt) + sizeof (tgt->list[0]) * mapnum);
+    = (struct target_mem_desc *)
+    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;
@@ -495,7 +496,8 @@ gomp_map_vars (struct gomp_device_descr *devicep, size_t mapnum,
   if (not_found_cnt || has_firstprivate)
     {
       if (not_found_cnt)
-	tgt->array = gomp_malloc (not_found_cnt * sizeof (*tgt->array));
+	tgt->array = (splay_tree_node)
+	  gomp_malloc (not_found_cnt * sizeof (*tgt->array));
       splay_tree_node array = tgt->array;
       size_t j, field_tgt_offset = 0, field_tgt_clear = ~(size_t) 0;
       uintptr_t field_tgt_base = 0;
@@ -663,7 +665,7 @@ gomp_map_vars (struct gomp_device_descr *devicep, size_t mapnum,
 		      gomp_mutex_unlock (&devicep->lock);
 #ifdef HAVE_INTTYPES_H
 		      gomp_fatal ("present clause: !acc_is_present (%p, "
-				  "%"PRIu64" (0x%"PRIx64"))",
+				  "%" PRIu64 " (0x%" PRIx64 "))",
 				  (void *) k->host_start,
 				  (uint64_t) size, (uint64_t) size);
 #else
@@ -942,8 +944,9 @@ gomp_offload_image_to_device (struct gomp_device_descr *devicep,
     }
 
   /* Insert host-target address mapping into splay tree.  */
-  struct target_mem_desc *tgt = gomp_malloc (sizeof (*tgt));
-  tgt->array = gomp_malloc ((num_funcs + num_vars) * sizeof (*tgt->array));
+  struct target_mem_desc *tgt = (typeof (tgt)) gomp_malloc (sizeof (*tgt));
+  tgt->array = (typeof (tgt->array))
+    gomp_malloc ((num_funcs + num_vars) * sizeof (*tgt->array));
   tgt->refcount = REFCOUNT_INFINITY;
   tgt->tgt_start = 0;
   tgt->tgt_end = 0;
@@ -1019,9 +1022,10 @@ GOMP_offload_register (void *host_table, enum offload_target_type target_type,
 
   /* Insert image to array of pending images.  */
   offload_images
-    = gomp_realloc_unlock (offload_images,
-			   (num_offload_images + 1)
-			   * sizeof (struct offload_image_descr));
+    = (typeof (offload_images))
+    gomp_realloc_unlock (offload_images,
+			 (num_offload_images + 1)
+			 * sizeof (struct offload_image_descr));
   offload_images[num_offload_images].type = target_type;
   offload_images[num_offload_images].host_table = host_table;
   offload_images[num_offload_images].target_data = target_data;
@@ -1267,7 +1271,7 @@ GOMP_target_41 (int device, void (*fn) (void *), size_t mapnum,
 	  }
       if (tgt_align)
 	{
-	  tgt = gomp_alloca (tgt_size + tgt_align - 1);
+	  tgt = (typeof (tgt)) gomp_alloca (tgt_size + tgt_align - 1);
 	  uintptr_t al = (uintptr_t) tgt & (tgt_align - 1);
 	  if (al)
 	    tgt += tgt_align - al;
@@ -1404,6 +1408,7 @@ gomp_exit_data (struct gomp_device_descr *devicep, size_t mapnum,
 	case GOMP_MAP_DELETE:
 	case GOMP_MAP_RELEASE:
 	case GOMP_MAP_ZERO_LEN_ARRAY_SECTION:
+	  {
 	  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_ZERO_LEN_ARRAY_SECTION
@@ -1433,6 +1438,7 @@ gomp_exit_data (struct gomp_device_descr *devicep, size_t mapnum,
 	      else
 		gomp_unmap_tgt (k->tgt);
 	    }
+	  }
 
 	  break;
 	default:
@@ -1811,8 +1817,9 @@ omp_target_associate_ptr (void *host_ptr, void *device_ptr, size_t size,
     }
   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;
@@ -1908,7 +1915,8 @@ gomp_load_plugin_for_device (struct gomp_device_descr *device,
 #define DLSYM(f)							\
   do									\
     {									\
-      device->f##_func = dlsym (plugin_handle, "GOMP_OFFLOAD_" #f);	\
+      device->f##_func = (typeof (device->f##_func))			\
+	dlsym (plugin_handle, "GOMP_OFFLOAD_" #f);			\
       err = dlerror ();							\
       if (err != NULL)							\
 	goto out;							\
@@ -1919,7 +1927,8 @@ gomp_load_plugin_for_device (struct gomp_device_descr *device,
   do									\
     {									\
       const char *tmp_err;						\
-      device->f##_func = dlsym (plugin_handle, "GOMP_OFFLOAD_" #n);	\
+      device->f##_func = (typeof (device->f##_func))			\
+	dlsym (plugin_handle, "GOMP_OFFLOAD_" #n);			\
       tmp_err = dlerror ();						\
       if (tmp_err == NULL)						\
         optional_present++;						\
@@ -2044,8 +2053,9 @@ gomp_target_init (void)
 	      {
 		/* Augment DEVICES and NUM_DEVICES.  */
 
-		devices = realloc (devices, (num_devices + new_num_devices)
-				   * sizeof (struct gomp_device_descr));
+		devices = (typeof (devices))
+		  realloc (devices, (num_devices + new_num_devices)
+			   * sizeof (struct gomp_device_descr));
 		if (!devices)
 		  {
 		    num_devices = 0;
@@ -2055,7 +2065,8 @@ gomp_target_init (void)
 
 		current_device.name = current_device.get_name_func ();
 		/* current_device.capabilities has already been set.  */
-		current_device.type = current_device.get_type_func ();
+		current_device.type
+		  = (enum offload_target_type) current_device.get_type_func ();
 		current_device.mem_map.root = NULL;
 		current_device.is_initialized = false;
 		current_device.openacc.data_environ = NULL;
@@ -2077,7 +2088,8 @@ gomp_target_init (void)
   /* In DEVICES, sort the GOMP_OFFLOAD_CAP_OPENMP_400 ones first, and set
      NUM_DEVICES_OPENMP.  */
   struct gomp_device_descr *devices_s
-    = malloc (num_devices * sizeof (struct gomp_device_descr));
+    = (typeof (devices_s)) malloc (num_devices
+				   * sizeof (struct gomp_device_descr));
   if (!devices_s)
     {
       num_devices = 0;
diff --git a/libgomp/task.c b/libgomp/task.c
index f2a0fae..3abbd8e 100644
--- a/libgomp/task.c
+++ b/libgomp/task.c
@@ -206,8 +206,8 @@ GOMP_task (void (*fn) (void *), void *data, void (*cpyfn) (void *, void *),
       if (flags & GOMP_TASK_FLAG_DEPEND)
 	depend_size = ((uintptr_t) depend[0]
 		       * sizeof (struct gomp_task_depend_entry));
-      task = gomp_malloc (sizeof (*task) + depend_size
-			  + arg_size + arg_align - 1);
+      task = (struct gomp_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));
       gomp_init_task (task, parent, gomp_icv (false));
@@ -298,7 +298,8 @@ GOMP_task (void (*fn) (void *), void *data, void (*cpyfn) (void *, void *),
 		      if (tsk->dependers == NULL)
 			{
 			  tsk->dependers
-			    = gomp_malloc (sizeof (struct gomp_dependers_vec)
+			    = (struct gomp_dependers_vec *)
+			      gomp_malloc (sizeof (struct gomp_dependers_vec)
 					   + 6 * sizeof (struct gomp_task *));
 			  tsk->dependers->n_elem = 1;
 			  tsk->dependers->allocated = 6;
@@ -319,7 +320,8 @@ GOMP_task (void (*fn) (void *), void *data, void (*cpyfn) (void *, void *),
 			  tsk->dependers->allocated
 			    = tsk->dependers->allocated * 2 + 2;
 			  tsk->dependers
-			    = gomp_realloc (tsk->dependers,
+			    = (struct gomp_dependers_vec *)
+			       gomp_realloc (tsk->dependers,
 					    sizeof (struct gomp_dependers_vec)
 					    + (tsk->dependers->allocated
 					       * sizeof (struct gomp_task *)));
@@ -705,7 +707,7 @@ gomp_barrier_handle_tasks (gomp_barrier_state_t state)
   struct gomp_task *task = thr->task;
   struct gomp_task *child_task = NULL;
   struct gomp_task *to_free = NULL;
-  int do_wake = 0;
+  unsigned int do_wake = 0;
 
   gomp_mutex_lock (&team->task_lock);
   if (gomp_barrier_last_thread (state))
@@ -803,7 +805,7 @@ GOMP_taskwait (void)
   struct gomp_task *child_task = NULL;
   struct gomp_task *to_free = NULL;
   struct gomp_taskwait taskwait;
-  int do_wake = 0;
+  unsigned int do_wake = 0;
 
   /* The acquire barrier on load of task->children here synchronizes
      with the write of a NULL in gomp_task_run_post_remove_parent.  It is
@@ -932,7 +934,7 @@ gomp_task_maybe_wait_for_dependencies (void **depend)
   size_t num_awaited = 0;
   struct gomp_task *child_task = NULL;
   struct gomp_task *to_free = NULL;
-  int do_wake = 0;
+  unsigned int do_wake = 0;
 
   gomp_mutex_lock (&team->task_lock);
   for (i = 0; i < ndepend; i++)
@@ -1101,7 +1103,8 @@ GOMP_taskgroup_start (void)
      by the time GOMP_taskgroup_end is called.  */
   if (team == NULL)
     return;
-  taskgroup = gomp_malloc (sizeof (struct gomp_taskgroup));
+  taskgroup
+    = (struct gomp_taskgroup *) gomp_malloc (sizeof (struct gomp_taskgroup));
   taskgroup->prev = task->taskgroup;
   taskgroup->children = NULL;
   taskgroup->in_taskgroup_wait = false;
@@ -1120,7 +1123,7 @@ GOMP_taskgroup_end (void)
   struct gomp_taskgroup *taskgroup;
   struct gomp_task *child_task = NULL;
   struct gomp_task *to_free = NULL;
-  int do_wake = 0;
+  unsigned int do_wake = 0;
 
   if (team == NULL)
     return;
diff --git a/libgomp/taskloop.c b/libgomp/taskloop.c
index 1a2b85d..21cb500 100644
--- a/libgomp/taskloop.c
+++ b/libgomp/taskloop.c
@@ -249,7 +249,8 @@ 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);
+	    = (struct gomp_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 b98b233..e8547cd 100644
--- a/libgomp/team.c
+++ b/libgomp/team.c
@@ -47,6 +47,13 @@ pthread_key_t gomp_tls_key;
 
 /* This structure is used to communicate across pthread_create.  */
 
+#ifdef HAVE_ATTRIBUTE_VISIBILITY
+/* This visibility push silences the following error in C++:
+
+   error: ‘gomp_thread_start_data’ declared with greater visibility
+   than the type of its field ‘gomp_thread_start_data::ts’.  */
+#pragma GCC visibility push(hidden)
+#endif
 struct gomp_thread_start_data
 {
   void (*fn) (void *);
@@ -57,6 +64,9 @@ struct gomp_thread_start_data
   unsigned int place;
   bool nested;
 };
+#ifdef HAVE_ATTRIBUTE_VISIBILITY
+#pragma GCC visibility pop
+#endif
 
 
 /* This function is a pthread_create entry point.  This contains the idle
@@ -65,7 +75,7 @@ struct gomp_thread_start_data
 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 *);
@@ -146,7 +156,7 @@ gomp_new_team (unsigned nthreads)
 
   size = sizeof (*team) + nthreads * (sizeof (team->ordered_release[0])
 				      + sizeof (team->implicit_task[0]));
-  team = gomp_malloc (size);
+  team = (struct gomp_team *) gomp_malloc (size);
 
   team->work_share_chunk = 8;
 #ifdef HAVE_SYNC_BUILTINS
@@ -167,7 +177,8 @@ gomp_new_team (unsigned nthreads)
   gomp_barrier_init (&team->barrier, nthreads);
 
   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;
 
   gomp_mutex_init (&team->task_lock);
@@ -197,7 +208,7 @@ free_team (struct gomp_team *team)
 static struct gomp_thread_pool *gomp_new_thread_pool (void)
 {
   struct gomp_thread_pool *pool
-    = gomp_malloc (sizeof(struct gomp_thread_pool));
+    = (typeof (pool)) gomp_malloc (sizeof(struct gomp_thread_pool));
   pool->threads = NULL;
   pool->threads_size = 0;
   pool->threads_used = 0;
@@ -229,7 +240,7 @@ gomp_free_thread (void *arg __attribute__((unused)))
     {
       if (pool->threads_used > 0)
 	{
-	  int i;
+	  unsigned int i;
 	  for (i = 1; i < pool->threads_used; i++)
 	    {
 	      struct gomp_thread *nthr = pool->threads[i];
@@ -443,9 +454,10 @@ gomp_team_start (void (*fn) (void *), void *data, unsigned nthreads,
 	{
 	  pool->threads_size = nthreads + 1;
 	  pool->threads
-	    = gomp_realloc (pool->threads,
-			    pool->threads_size
-			    * sizeof (struct gomp_thread_data *));
+	    = (typeof (pool->threads)) gomp_realloc
+					(pool->threads,
+					 pool->threads_size
+					 * sizeof (struct gomp_thread_data *));
 	}
 
       /* Release existing idle threads.  */
@@ -526,12 +538,14 @@ 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
-					 * sizeof (struct gomp_thread *));
+			  = (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
 			      * sizeof (struct gomp_thread *));
@@ -698,8 +712,8 @@ gomp_team_start (void (*fn) (void *), void *data, unsigned nthreads,
       attr = &thread_attr;
     }
 
-  start_data = gomp_alloca (sizeof (struct gomp_thread_start_data)
-			    * (nthreads-i));
+  start_data = (typeof (start_data))
+    gomp_alloca (sizeof (struct gomp_thread_start_data) * (nthreads-i));
 
   /* Launch new threads.  */
   for (; i < nthreads; ++i)
@@ -855,7 +869,8 @@ 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
+	    = (struct gomp_work_share *) gomp_ptrlock_get (&ws->next_ws);
 	  if (next_ws == NULL)
 	    gomp_ptrlock_set (&ws->next_ws, ws);
 	  gomp_fini_work_share (ws);
@@ -940,7 +955,8 @@ 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
+    = (struct gomp_task *) gomp_malloc (sizeof (struct gomp_task));
   gomp_init_task (task, NULL, &gomp_global_icv);
   thr->task = task;
   pthread_setspecific (gomp_thread_destructor, thr);
diff --git a/libgomp/work.c b/libgomp/work.c
index 0570b90..0dc1695 100644
--- a/libgomp/work.c
+++ b/libgomp/work.c
@@ -76,7 +76,8 @@ alloc_work_share (struct gomp_team *team)
 #endif
 
   team->work_share_chunk *= 2;
-  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));
   ws->next_alloc = team->work_shares[0].next_alloc;
   team->work_shares[0].next_alloc = ws;
   team->work_share_list_alloc = &ws[1];
@@ -103,7 +104,8 @@ gomp_init_work_share (struct gomp_work_share *ws, bool ordered,
 
       if (nthreads > INLINE_ORDERED_TEAM_IDS_CNT)
 	ws->ordered_team_ids
-	  = gomp_malloc (nthreads * sizeof (*ws->ordered_team_ids));
+	  = (typeof (ws->ordered_team_ids))
+	  gomp_malloc (nthreads * sizeof (*ws->ordered_team_ids));
       else
 	ws->ordered_team_ids = ws->inline_ordered_team_ids;
       memset (ws->ordered_team_ids, '\0',
@@ -175,7 +177,7 @@ gomp_work_share_start (bool ordered)
   /* Work sharing constructs can be orphaned.  */
   if (team == NULL)
     {
-      ws = gomp_malloc (sizeof (*ws));
+      ws = (typeof (ws)) gomp_malloc (sizeof (*ws));
       gomp_init_work_share (ws, ordered, 1);
       thr->ts.work_share = ws;
       return ws;
@@ -183,7 +185,7 @@ gomp_work_share_start (bool 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.  */


More information about the Gcc-patches mailing list