https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118157
Bug ID: 118157 Summary: [OpenMP] Variant function - build failed due to auto-tagged as 'declare target' but uncalled + not callable 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: sandra at gcc dot gnu.org Target Milestone: --- The following code is rejected with: var.c:1:5: error: variable 'x' has been referenced in offloaded code but hasn't been marked to be included in the offbut uncalledloaded code 1 | int x = 123; | ^ lto1: fatal error: errors during merging of translation units The problem is that 'f' is has: __attribute__((omp declare target, omp declare variant variant)) However, the condition device={isa("avx512f")} can never be true for devices, but it still gets the 'declare target' attribute. Note that during gimplify, it is already resolved to: #pragma omp target num_teams(-2) thread_limit(0) map(from:y [len: 4]) { int y.0; y.0 = h (); y = y.0; } Thus, there is no need for 'f' getting the 'declare target'. ******************* int x = 123; int f() { return (int) x; } int h() { return 12; } #pragma omp declare variant(f) match(device={isa("avx512f")}) #pragma omp declare variant (h) match (user={condition(score(20): 1)}) int foo() { return 3; } int main() { int y; #pragma omp target map(from: y) y = foo(); __builtin_printf("y = %d\n", y); }