view gcc/testsuite/gcc.dg/ipa/propmalloc-4.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents
children
line wrap: on
line source

/* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-local-pure-const-details" } */

void *foo(int cond1, int cond2, int cond3)
{
  void *ret;
  void *a;
  void *b;

  if (cond1)
    a = __builtin_malloc (10);
  else
    a = __builtin_malloc (20);

  if (cond2)
    b = __builtin_malloc (30);
  else
    b = __builtin_malloc (40);

  if (cond3)
    ret = a;
  else
    ret = b;

  return ret;
}

void *foo2(int cond1, int cond2, int cond3)
{
  void *ret;
  void *a;
  void *b;
  void bar(void *, void *);

  if (cond1)
    a = __builtin_malloc (10);
  else
    a = __builtin_malloc (20);

  if (cond2)
    b = __builtin_malloc (30);
  else
    b = __builtin_malloc (40);

  bar (a, b);

  if (cond3)
    ret = a;
  else
    ret = b;

  return ret;
}

/* { dg-final { scan-tree-dump "Function found to be malloc: foo" "local-pure-const1" } } */
/* { dg-final { scan-tree-dump-not "Function found to be malloc: foo2" "local-pure-const1" } } */