aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.c-torture/execute/noinit-attribute.c
blob: c8fa22bf38b888af916df9b2ba8e1fb667b7c204 (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
57
58
59
60
61
62
63
/* { dg-do run } */
/* { dg-require-effective-target noinit } */
/* { dg-options "-Wattributes" } */
/* { dg-skip-if "data LMA != VMA" { msp430-*-* } { "-mlarge" } } */

/* This test checks that noinit data is handled correctly.
   If data LMA != VMA (e.g. for simulating the copy of data from ROM to RAM),
   then var_init will always be re-initialized to 2 and this test will loop
   forever.  */

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

int var_common;
int var_zero = 0;
int var_one = 1;
int __attribute__((noinit)) var_noinit;
int var_init = 2;

int __attribute__((noinit)) func(); /* { dg-warning "attribute only applies to variables" } */
int __attribute__((section ("mysection"), noinit)) var_section1; /* { dg-warning "because it conflicts with attribute" } */
int __attribute__((noinit, section ("mysection"))) var_section2; /* { dg-warning "because it conflicts with attribute" } */


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

  /* Initialized variables are not re-initialized during startup, so
     check their original values only during the first run of this
     test.  */
  if (var_init == 2)
    if (var_zero != 0 || var_one != 1)
      abort ();

  switch (var_init)
    {
    case 2:
      /* First time through - change all the values.  */
      var_common = var_zero = var_one = var_noinit = var_init = 3;
      break;

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

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

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

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