https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116977
Bug ID: 116977 Summary: Analyzer: track OpenACC "host" vs. "device" pointers Product: gcc Version: 15.0 Status: UNCONFIRMED Keywords: openacc Severity: normal Priority: P3 Component: analyzer Assignee: vedanttewari2000 at gmail dot com Reporter: tschwinge at gcc dot gnu.org CC: dmalcolm at gcc dot gnu.org Target Milestone: --- Vedant is working on adding to the GCC Static Analyzer checks for programs using OpenACC, mentored by me. This idea goes back to my 2019 email <https://inbox.sourceware.org/yxfpy2wfv9hq....@hertz.schwinge.homeip.net> "Re: [PATCH 00/49] RFC: Add a static analysis framework to GCC", see "OpenACC in there. As a first step, we would like advice on the general implementation approach for tracking OpenACC "host" vs. "device" pointers. For example, we'd like '-fanalyzer' to diagnose: #include <stdlib.h> // Via '#include <openacc.h>': #include <stddef.h> # define __GOACC_NOTHROW __attribute__ ((__nothrow__)) void *acc_malloc (size_t) __GOACC_NOTHROW; int main() { float *a = acc_malloc(sizeof *a); free(a); // { dg-error {'a' is a device pointer} TODO { xfail *-*-* } .-1 } return 0; } Currently, this doesn’t emit any diagnostic (thus, "TODO", XFAILed); the goal is to get a diagnostic for such code, as indicated (or similar). This code will execute fine in a standard GCC configuration without offloading enabled (because 'acc_malloc' in that case just does 'return malloc(n);'), but running this code in a GCC configuration with offloading enabled and a GPU available, you get: $ ./a.out Segmentation fault (core dumped) ('acc_free' needs to be used with 'acc_malloc'.) Relevant OpenACC specification sections: - OpenACC 2.6, 3.2. "Runtime Library Routines" and specifically 3.2.18. "acc_malloc" We're of course happy to supply any further information.