Debian Codegraph @

gcc/testsuite/gcc.target/msp430/data-attributes.c

raw
1 /* { dg-do run } */
2 /* { dg-options "-O2" } */
3
4 /* This test checks that persistent and noinit data are handled correctly. */
5
6 extern void __crt0_start (void) __attribute__ ((noreturn));
7 extern void abort (void) __attribute__ ((noreturn));
8 extern void exit (int) __attribute__ ((noreturn));
9
10 int a;
11 int b = 0;
12 int c = 1;
13 int __attribute__((noinit)) d;
14 int __attribute__((persistent)) e = 2;
15
16 int
17 main (void)
18 {
19 /* Make sure that the C startup code has correctly initialised the ordinary variables. */
20 if (a != 0)
21 abort ();
22
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 ();
32
33 switch (e)
34 {
35 case 2:
36 /* First time through - change all the values. */
37 a = b = c = d = e = 3;
38 break;
39
40 case 3:
41 /* Second time through - make sure that d has not been reset. */
42 if (d != 3)
43 abort ();
44 exit (0);
45
46 default:
47 /* Any other value for e is an error. */
48 abort ();
49 }
50
51 /* Simulate a processor reset by calling the C startup code. */
52 __crt0_start ();
53
54 /* Should never reach here. */
55 abort ();
56 }