Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: removed some extra spaces

...

Code Block
bgColor#FFCCCC
langc
int * restrict a;
int * restrict b;

extern int c[];
 
int main(void) {
  c[0] = 17; 
  c[1] = 18;
  a = &c[0]; 
  b = &c[1];
  a = b; /* Undefined behavior */

  /* ... */
}

...

Code Block
bgColor#ccccff
langc
int * a;
int * b;

extern int c[];
 
int main(void) {
  c[0] = 17; 
  c[1] = 18;
  a = &c[0]; 
  b = &c[1];
  a = b; /* Valid defined behavior */

  /* ... */
}

...

Code Block
bgColor#FFCCCC
langc
#include <stddef.h>
void f(size_t n, int * restrict p, int * restrict q) {
  while (n-- > 0) {
    *p++ = *q++;
  }
}
 
void g(void) {
  extern int d[100];

  /* ... */
  f(50, d + 1, d); /* Undefined behavior */
}

...

Code Block
bgColor#ccccff
langc
#include <stdlib.h>
void f(size_t n, int * restrict p, int * restrict q) {
  while (n-- > 0) {
    *p++ = *q++;
  } 
}
 
void g(void) {
  extern int d[100];

  /* ... */
  f(50, d + 50, d); /* Valid defined behavior  */
}

...

Code Block
bgColor#FFCCCC
langc
#include <stddef.h>
 
void add(size_t n, int * restrict res, int * restrict lhs,
       int * restrict rhs) {
  for (size_t i = 0; i < n; ++i) {
    res[i] = lhs[i] + rhs[i];
  }
}
 
void f(void) {
  int a[100]; 
  add(100, a, a, a); /* Undefined behavior */
}

...

Code Block
bgColor#ccccff
langc
#include <stddef.h>
void add(size_t n, int * restrict res, int * restrict lhs,
         int * restrict rhs) {
  for (size_t i = 0; i < n; ++i) {
    res[i] = lhs[i] + rhs[i];
  }
}
 
void f(void) {
   int a[100]; 
   int b[100];
   add(100, a, b, b); /* Valid defined behavior  */
}

...

Code Block
bgColor#FFCCCC
langc
void func(void) {
  int * restrict p1;
  int * restrict q1;

  int * restrict p2 = p1; /* Undefined behavior */ 
  int * restrict q2 = q1; /* Undefined behavior */ 
 }

...

Code Block
bgColor#ccccff
langc
void func(void) {
  int * restrict p1;   
  int * restrict q1;
  {  /* Added inner block */
    int * restrict p2 = p1;  /* Valid defined behavior  */    
    int * restrict q2 = q1;  /* Valid defined behavior  */ 
  }
}

...