From 1c0fdaf79e3618fd7512608a2e5c62b6b306e9e8 Mon Sep 17 00:00:00 2001 From: Tobias Burnus Date: Mon, 8 Jun 2020 23:24:57 +0200 Subject: openmp: ensure variables in offload table are streamed out (PRs 94848 + 95551) gcc/ChangeLog: PR lto/94848 PR middle-end/95551 * omp-offload.c (add_decls_addresses_to_decl_constructor, omp_finish_file): Skip removed items. * lto-cgraph.c (output_offload_tables): Likewise; set force_output to this node for variables and functions. libgomp/ChangeLog: PR lto/94848 PR middle-end/95551 * testsuite/libgomp.fortran/target-var.f90: New test. --- gcc/lto-cgraph.c | 8 ++++++++ gcc/omp-offload.c | 12 +++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'gcc') diff --git a/gcc/lto-cgraph.c b/gcc/lto-cgraph.c index a671c67..93a99f3 100644 --- a/gcc/lto-cgraph.c +++ b/gcc/lto-cgraph.c @@ -1069,6 +1069,10 @@ output_offload_tables (void) for (unsigned i = 0; i < vec_safe_length (offload_funcs); i++) { + symtab_node *node = symtab_node::get ((*offload_funcs)[i]); + if (!node) + continue; + node->force_output = true; streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag, LTO_symtab_unavail_node); lto_output_fn_decl_ref (ob->decl_state, ob->main_stream, @@ -1077,6 +1081,10 @@ output_offload_tables (void) for (unsigned i = 0; i < vec_safe_length (offload_vars); i++) { + symtab_node *node = symtab_node::get ((*offload_vars)[i]); + if (!node) + continue; + node->force_output = true; streamer_write_enum (ob->main_stream, LTO_symtab_tags, LTO_symtab_last_tag, LTO_symtab_variable); lto_output_var_decl_ref (ob->decl_state, ob->main_stream, diff --git a/gcc/omp-offload.c b/gcc/omp-offload.c index b2df91a..4e44cfc 100644 --- a/gcc/omp-offload.c +++ b/gcc/omp-offload.c @@ -125,6 +125,10 @@ add_decls_addresses_to_decl_constructor (vec *v_decls, #endif && lookup_attribute ("omp declare target link", DECL_ATTRIBUTES (it)); + /* See also omp_finish_file and output_offload_tables in lto-cgraph.c. */ + if (!symtab_node::get (it)) + continue; + tree size = NULL_TREE; if (is_var) size = fold_convert (const_ptr_type_node, DECL_SIZE_UNIT (it)); @@ -341,7 +345,7 @@ omp_finish_file (void) add_decls_addresses_to_decl_constructor (offload_vars, v_v); tree vars_decl_type = build_array_type_nelts (pointer_sized_int_node, - num_vars * 2); + vec_safe_length (v_v)); tree funcs_decl_type = build_array_type_nelts (pointer_sized_int_node, num_funcs); SET_TYPE_ALIGN (vars_decl_type, TYPE_ALIGN (pointer_sized_int_node)); @@ -376,11 +380,17 @@ omp_finish_file (void) for (unsigned i = 0; i < num_funcs; i++) { tree it = (*offload_funcs)[i]; + /* See also add_decls_addresses_to_decl_constructor + and output_offload_tables in lto-cgraph.c. */ + if (!symtab_node::get (it)) + continue; targetm.record_offload_symbol (it); } for (unsigned i = 0; i < num_vars; i++) { tree it = (*offload_vars)[i]; + if (!symtab_node::get (it)) + continue; #ifdef ACCEL_COMPILER if (DECL_HAS_VALUE_EXPR_P (it) && lookup_attribute ("omp declare target link", -- cgit v1.1