aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/msp430/pr87691.c
blob: c00425d2452c6a613dab60526e4cf85a83702861 (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
/* PR 87691 - Test that a union containing __int20 and a float is not treated as
   20-bits in size.  */

/* { dg-do compile } */
/* { dg-skip-if "no __int20 for mcpu=msp430" { *-*-* } { "-mcpu=msp430" } { "" } } */
/* { dg-final { scan-assembler-not "MOVX.A" } } */

/* To move a 20-bit value from memory (using indexed or indirect register
   mode), onto the stack (also addressed using indexed or indirect register
   mode), MOVX.A must be used. MOVA does not support these addressing modes.
   Therefore, to check that the union is not manipulated as a 20-bit type,
   test that no MOVX.A instructions are present in the assembly.

   MOVA is used to fill/spill u.i, but if the union is treated as 20 bits in
   size, MOVX.A would be used. No other __int20 operations are present
   in the source, so there will be no valid uses of MOVX.A in the resulting
   assembly.  */

union U1
{
  float f;
  __int20 i;
};

union U2
{
  __int20 i;
  float f;
};

float foo1 (union U1 u)
{
  u.i += 42;
  return u.f;
}

float foo2 (union U2 u)
{
  u.i += 42;
  return u.f;
}