summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/msp430/data-attributes.c
blob: 10dd1714d72eb137fa2d316c7882ca4e3b1bd658 (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
47
48
49
50
51
52
53
54
55
56
/* { dg-do run } */
/* { dg-options "-O2" } */

/* This test checks that persistent and noinit data are handled correctly.  */

extern void __crt0_start (void) __attribute__ ((noreturn));
extern void abort (void) __attribute__ ((noreturn));
extern void exit (int) __attribute__ ((noreturn));

int a;
int b = 0;
int c = 1;
int __attribute__((noinit)) d;
int __attribute__((persistent)) e = 2;

int
main (void)
{
  /* Make sure that the C startup code has correctly initialised the ordinary variables.  */
  if (a != 0)
    abort ();

#ifndef __MSP430X_LARGE__
  /* For non-large targets we use the ordinary msp430-sim.ld linker script.
     This does not support FLASH, and as a side effect it does not support
     reinitialising initialised data.  Hence we only test b and c if this
     is the first time through this test, or large support has been enabled.  */
  if (e == 2)
#endif
  if (b != 0 || c != 1)
    abort ();
  
  switch (e)
    {
    case 2:
      /* First time through - change all the values.  */
      a = b = c = d = e = 3;
      break;

    case 3:
      /* Second time through - make sure that d has not been reset.  */
      if (d != 3)
	abort ();
      exit (0);

    default:
      /* Any other value for e is an error.  */
      abort ();
    }

  /* Simulate a processor reset by calling the C startup code.  */
  __crt0_start ();

  /* Should never reach here.  */
  abort ();
}