summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/opt/alias1.C
blob: 4836c5be06ab565c7045e9c5b49dc93d9abf4561 (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
// Test that type punning using an anonymous union works with strict aliasing.
// { dg-do run }
// { dg-options "-O2 -fstrict-aliasing" }

extern "C" void abort ();

void f (long i)
{
  union
  {
    long ui;
    float uf[20];
  };

  ui = i;
  if (uf[0] != 42.0)
    abort ();
}

int main ()
{
  union U { long i; float f[20]; } u;
  u.f[0] = 42.0;
  f (u.i);
}