summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/ipa/pr70306.c
blob: f9327073ac8dc6f22987b6a92f6ddb6864c77f6b (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
/* { dg-options "-O2 -fdump-ipa-icf" } */
/* { dg-do run } */
/* { dg-require-effective-target global_constructor } */

int ctor_counter = 1;
int dtor_counter;

__attribute__((constructor))
void A()
{
  ctor_counter++;
}

__attribute__((destructor))
void B()
{
  if (dtor_counter == 0)
    __builtin_abort ();

  dtor_counter--;
}

__attribute__((constructor))
static void C() {
    ctor_counter++;
}

__attribute__((destructor))
static void D() {
  if (dtor_counter == 0)
    __builtin_abort ();

  dtor_counter--;
}

int main()
{
    if (ctor_counter != 3)
        __builtin_abort ();

    dtor_counter = 2;

    return 0;
}

/* { dg-final { scan-ipa-dump "Equal symbols: 0" "icf"  } } */