https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84991

            Bug ID: 84991
           Summary: [openacc] Misleading error message for function static
                    var in routine
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vries at gcc dot gnu.org
  Target Milestone: ---

The openacc spec tells us at 2.15.1. Routine Directive:
...
In C and C++, function static variables are not supported in functions to which
a routine directive applies.
...

When compiling such an example with -fopenacc:
...
#include <stdio.h>

#pragma acc routine seq
static int __attribute__((noinline)) foo (int n)
{
  static const int test[] = {1,2,3,4};
  return test[n];
}

int
main (void)
{
  int n[1];
  n[0] = 3;
#pragma acc parallel copy(n)
  {
    n[0] = foo (n[0]);
  }
  printf ("n: %d\n", n[0]);

  return 0;
}
...

we get
...
static.c: In function 'foo':
static.c:6:20: error: 'test' requires a 'declare' directive for use in a
'routine' function
static.c:6:20: error: 'test' requires a 'declare' directive for use in a
'routine' function
...

The error message is somewhat misleading. Adding a declare directive here does
not change the example into valid openacc.

Reply via email to