view gcc/testsuite/gcc.dg/torture/pr67828.c @ 131:84e7813d76e9

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

/* Check that we don't misoptimize the final value of d.  We used to
   apply loop unswitching on if(j), introducing undefined behavior
   that the original code wouldn't exercise, and this undefined
   behavior would get later passes to misoptimize the loop.  */

/* { dg-do run } */

#include <stdio.h>
#include <stdlib.h>

int x;

int __attribute__ ((noinline, noclone))
xprintf (int d) {
  if (d)
    {
      if (x)
	printf ("%d", d);
      abort ();
    }
}

int a, b;
short c;

int
main ()
{
  int j, d = 1;
  for (; c >= 0; c++)
    {
      a = d;
      d = 0;
      if (b)
	{
	  xprintf (0);
	  if (j)
	    xprintf (0);
	}
    }
  xprintf (d);
  exit (0);
}