aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/alias-16.c
blob: 8f5aa35281b5c8dfa6f99cfade42032b47fa5f3a (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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* { dg-do compile } */
/* { dg-options "-Wstrict-aliasing=1 -fstrict-aliasing" } */

struct incomplete;
struct s1 { int i; };
struct s2 { double d; };

void
f (int *i, double *d, struct s1 *s1, struct s2 *s2, char *c)
{
  (char *) i;
  (char *) d;
  (char *) s1;
  (char *) s2;
  (char *) c;

  (int *) i;
  (int *) d; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */
  (int *) s1; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */
  (int *) s2; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */
  (int *) c;

  (double *) i; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */
  (double *) d;
  (double *) s1; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */
  (double *) s2; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */
  (double *) c;

  (struct incomplete *) i; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */
  (struct incomplete *) d; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */
  (struct incomplete *) s1; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */
  (struct incomplete *) s2; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */
  (struct incomplete *) c; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */

  (struct s1 *) i; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */
  (struct s1 *) d; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */
  (struct s1 *) s1;
  (struct s1 *) s2; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */
  (struct s1 *) c;

  (struct s2 *) i; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */
  (struct s2 *) d; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */
  (struct s2 *) s1; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */
  (struct s2 *) s2;
  (struct s2 *) c;
}