2018-03-15 Steven G. Kargl <kargl@gcc.gnu.org>
[official-gcc.git] / gcc / testsuite / gcc.target / msp430 / data-attributes.c
blob10dd1714d72eb137fa2d316c7882ca4e3b1bd658
1 /* { dg-do run } */
2 /* { dg-options "-O2" } */
4 /* This test checks that persistent and noinit data are handled correctly. */
6 extern void __crt0_start (void) __attribute__ ((noreturn));
7 extern void abort (void) __attribute__ ((noreturn));
8 extern void exit (int) __attribute__ ((noreturn));
10 int a;
11 int b = 0;
12 int c = 1;
13 int __attribute__((noinit)) d;
14 int __attribute__((persistent)) e = 2;
16 int
17 main (void)
19 /* Make sure that the C startup code has correctly initialised the ordinary variables. */
20 if (a != 0)
21 abort ();
23 #ifndef __MSP430X_LARGE__
24 /* For non-large targets we use the ordinary msp430-sim.ld linker script.
25 This does not support FLASH, and as a side effect it does not support
26 reinitialising initialised data. Hence we only test b and c if this
27 is the first time through this test, or large support has been enabled. */
28 if (e == 2)
29 #endif
30 if (b != 0 || c != 1)
31 abort ();
33 switch (e)
35 case 2:
36 /* First time through - change all the values. */
37 a = b = c = d = e = 3;
38 break;
40 case 3:
41 /* Second time through - make sure that d has not been reset. */
42 if (d != 3)
43 abort ();
44 exit (0);
46 default:
47 /* Any other value for e is an error. */
48 abort ();
51 /* Simulate a processor reset by calling the C startup code. */
52 __crt0_start ();
54 /* Should never reach here. */
55 abort ();