Debian Codegraph @

gcc/testsuite/c-c++-common/torture/attr-persistent-main.inc

raw
1 /* This test checks that data marked with the "persistent" attribute is handled
2 correctly.
3 If data LMA != VMA (e.g. for simulating the copy of data from ROM to RAM),
4 then var_init will always be re-initialized to 2 and this test will loop
5 forever, so it must be skipped for those targets. */
6
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10 extern void _start (void) __attribute__ ((noreturn));
11 #ifdef __cplusplus
12 }
13 #endif
14
15 int var_common;
16 int var_zero = 0;
17 int var_one = 1;
18 int __attribute__((persistent)) var_persistent = 2;
19 int var_init = 2;
20
21 int
22 main (void)
23 {
24 /* Make sure that the C startup code has correctly initialized the ordinary variables. */
25 if (var_common != 0)
26 __builtin_abort ();
27
28 /* Initialized variables are not re-initialized during startup, so
29 check their original values only during the first run of this
30 test. */
31 if (var_init == 2)
32 if (var_zero != 0 || var_one != 1 || var_persistent != 2)
33 __builtin_abort ();
34
35 switch (var_init)
36 {
37 case 2:
38 /* First time through - change all the values. */
39 var_common = var_zero = var_one = var_persistent = var_init = 3;
40 break;
41
42 case 3:
43 /* Second time through - make sure that var_persistent has not been reset. */
44 if (var_persistent != 3)
45 __builtin_abort ();
46 __builtin_exit (0);
47
48 default:
49 /* Any other value for var_init is an error. */
50 __builtin_abort ();
51 }
52
53 /* Simulate a processor reset by calling the C startup code. */
54 _start ();
55
56 /* Should never reach here. */
57 __builtin_abort ();
58 }