aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/ext/attr-malloc-2.C
blob: 600d430468c508992dd1ef4a56cce4a3a5a2ef56 (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
// Bug c++/83503 - bogus -Wattributes for const and pure on function template
// specialization
// Test to verify that attribute malloc on multiple declarations of
// the same ordinary function are merged.
// { dg-do compile }
// { dg-options "-O -Wall -fdump-tree-optimized" }

void* __attribute__ ((malloc))
fmalloc_none (unsigned);

void*
fmalloc_none (unsigned);

static char a[8];

void fmalloc_none_failed ();

void test_fmalloc_none (void)
{
  void *p = fmalloc_none (1);
  if (!p)
    return;

  if (p == a)                     // must be false
    fmalloc_none_failed ();       // should be eliminated

  // Verify that the call to fmalloc_none() is eliminated.
  // { dg-final { scan-tree-dump-not "fmalloc_none_failed" "optimized" } }
}

void* fnone_malloc (unsigned);

void* __attribute__ ((malloc))
fnone_malloc (unsigned);

void fnone_malloc_failed ();

void test_fnone_malloc (void)
{
  void *p = fnone_malloc (1);
  if (!p)
    return;

  if (p == a)                     // must be false
    fnone_malloc_failed ();       // should be eliminated

  // Verify that the call to fnone_malloc() is eliminated.
  // { dg-final { scan-tree-dump-not "fnone_malloc_failed" "optimized" } }
}