https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106316
Bug ID: 106316 Summary: [OpenMP] Auto "declare target" should honor 'declare variant' kind(nohost) Product: gcc Version: 13.0 Status: UNCONFIRMED Keywords: openmp 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: --- The following fails during device lto1 with: ld: error: undefined symbol: external >>> referenced by decl-var.c:3 >>> /tmp/cc6C3J6T.o:(onhost) However, 'external' is never executed on the device. This seems to be more a 'declare variant' tagging issue than a symbol issue as it works when keeping only int onhost(void); /* Only declaration, no definition */ in the second file (and having the definition alongside 'external' in the first). → omp_discover_declare_target_tgt_fn_r, omp_discover_declare_target_fn_r functions. ---- First file. Compile with 'gcc -c first.c' ------ void external(void) { __builtin_printf("Hello World\n"); } /* See remark: int onhost(void) { external(); return 5; } */ ----------------------------------------------------- ---- Second file. Compile with 'gcc -fopenmp second.c first.o' ------ void external(void); int onhost(void) { external(); return 5; } int ondevice(void) { return 7; } #pragma omp declare variant (onhost) match (device={kind(host)}) #pragma omp declare variant (ondevice) match (device={kind(nohost)}) int stub (void) { return 9; } #pragma omp declare target int caller(void) { return stub(); } #pragma omp end declare target int main() { __builtin_printf("On host: %d (expected: 5)\n", caller()); #pragma omp target __builtin_printf("On device: %d (expected: 7)\n", caller()); return 0; } --------------------------------------------------------------------- * * * A variant would be: #pragma omp declare variant (ondevice) match (device={kind(nohost)}) int stub (void) { external(); return 9; } where the 'stub();' is called in the target region but is still unreachable because of the 'nohost'. * * * While some generic solution would be good - i.e. if offload host is only GCN, it would be nice if the following works - even if it will fail once -foffload=nvptx is used #pragma omp declare variant (ondevice) match (construct={target},device={arch(gcn)}) int stub (void) { external(); return 9; } handling an explicit 'kind(host)' is very useful.