aboutsummaryrefslogtreecommitdiff
blob: 8a8b9794f7f4a2f076736178080fb34059b9ab30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#define MY_MACRO(a) do { \
  __builtin_warning(!__builtin_safe_p(a), "Macro argument with side effects: " #a); \
    a;	\
  } while (0)

int g(int);
int h(int) __attribute__((pure));
int i(int) __attribute__((const));

static int foo(int x, int y)
{
  /* unsafe: */
  MY_MACRO(x++);
  MY_MACRO(x+=1);
  MY_MACRO(x=x+1);
  MY_MACRO(x%=y);
  MY_MACRO(x=y);
  MY_MACRO(g(x));
  MY_MACRO((y,g(x)));
  /* safe: */
  MY_MACRO(x+1);
  MY_MACRO(h(x));
  MY_MACRO(i(x));
  return x;
}