[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[Bug tree-optimization/33826] [4.1/4.2/4.3 Regression] GCC generates wrong code for infinitely recursive functions




------- Comment #1 from rguenth at gcc dot gnu dot org  2007-10-20 10:03 -------
foo is analyzed to be const by ipa-pure-const and so the self-recursive call
is DCEd.  Now one could argue that foo indeed _is_ const, for example

unsigned foo(unsigned i)
{
  if (i == 1)
    return 1;
  return foo(i-1) + 1; 
}

is a perfectly const tail-recursive way of returning i.  We'd no longer DCE

void bar(void)
{
  foo(5);
}

I'd argue that a stack overflow is nothing that the C standard describes and
that we are of course not supposed to solve the halting problem to decide
that non-halting functions are not pure/const.  As we handle simple
non-terminating cases like

void foo(void)
{
  while (1) ;
}

we probably can handle the simple self-recursion as well.  Even if this
wouldn't be a complete solution.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |NEW
          Component|target                      |tree-optimization
     Ever Confirmed|0                           |1
           Keywords|                            |wrong-code
   Last reconfirmed|0000-00-00 00:00:00         |2007-10-20 10:03:01
               date|                            |
            Summary|GCC generates wrong code for|[4.1/4.2/4.3 Regression] GCC
                   |infinitely recursive        |generates wrong code for
                   |functions                   |infinitely recursive
                   |                            |functions
   Target Milestone|---                         |4.2.3


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33826

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.



Reply to: