Chiel
Chiel

Reputation: 6194

Compiler error using restrict qualifier on certain C++ compilers

I have a function that has pointers of double as argument that are qualified as restrict. Note that the Intel compiler uses restrict, but we replace the qualifier by __restrict__ in case of GCC.

void Stats::calc_flux_2nd(double* restrict data,
                          double* restrict datamean,
                          double* restrict w)
{
    // ...

    // Set a pointer to the field that contains w,
    // either interpolated or the original
    double* restrict calcw = w;

    // ...

This code compiles without any problems using GCC or Clang, but the IBM BlueGene compiler gives the following error:

(W) Incorrect assignment of a restrict qualified pointer.
Only outer-to-inner scope assignments between restrict pointers are 
allowed.  This may result in incorrect program behavior.

I do not understand how to interpret this error as I do not change the signature of the variable, nor do I know whether I am introducing undefined behavior or whether the IBM BlueGene compiler is wrong.

Upvotes: 3

Views: 1018

Answers (1)

Leandros
Leandros

Reputation: 16825

Your construct is not supported by IBM's XL C/C++ compiler, it's also stated in their documentation. You cannot assign restricted pointers to each other. You can fix this, by creating a new block scope and a new set of pointers.

{
  int * restrict  x;
  int * restrict  y;
  x = y; /* undefined */
  {
     int * restrict  x1 = x; /* okay */
     int * restrict  y1 = y; /* okay */
     x = y1;  /* undefined */
  }
}

Upvotes: 6

Related Questions