https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115574
Bug ID: 115574 Summary: [OpenMP] Nested C function – 'declare target link(var)' leads to "referenced in offloaded code but hasn't been marked to be included in the offloaded code" Product: gcc Version: 15.0 Status: UNCONFIRMED Keywords: openmp, rejects-valid Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: burnus at gcc dot gnu.org CC: jakub at gcc dot gnu.org Target Milestone: --- C variant for the issue PR 115559. [Nested functions are a GNU extension - thus, we may decide not to fix this.] Nonetheless, the following compiles but fails during device LTO: foo.c:2:13: error: variable 'a' has been referenced in offloaded code but hasn't been marked to be included in the offloaded code 2 | static int a, b[5]; | ^ foo.c:2:16: error: variable 'b' has been referenced in offloaded code but hasn't been marked to be included in the offloaded code 2 | static int a, b[5]; void f() { static int a, b[5]; #pragma declare target link(a,b) void g() { a = 7; b[3] = 3; } // #pragma omp declare target enter(g) #pragma omp target map(tofrom: a, b) g(); } The problem is the global-var check in c/c-parser.cc (and cp/parser.cc): id = get_identifier ("omp declare target link"); std::swap (at1, at2); } ... if (!at1) { DECL_ATTRIBUTES (t) = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t)); if (TREE_CODE (t) != FUNCTION_DECL && !is_global_var (t)) continue; symtab_node *node = symtab_node::get (t); if (node != NULL) { node->offloadable = 1; ... vec_safe_push (offload_vars, t); As neither is a global var, it is not added.