This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: forcing tail/sibling call optimization


Fergus Henderson writes:
> I did attempt to test the exact patch that I posted in the ways that
> I described, but the GCC tests passed anyway (none of them test that
> sibcall optimization is applied, apparently)

Can DejaGNU set RLIMIT_STACK?  If so, checking that sibcall optimization is
working should be easy, I'd think -- just write a tail-recursive program
that'll use up all the stack without it.

I've attached a trivial one below.  Compiled with gcc-3.1, it runs
successfully with -O2 and -Os on sparc-sun-solaris2.8, but dies with a
segmentation fault with -O0 and -O1.

Presumably a real test ought to have sibcalled functions that test all the
patterns the compiler's supposed to recognize.

extern void exit(int);

int tr(int x) {
  if (x == 1000000) {
    return x;
  }
  return tr(x+1);
}

int main()
{
  int foo = tr(0);
  
  if (foo != 1000000) {
    exit(1);
  }

  exit(0);
}
-- 
Jonathan Lennox
lennox@cs.columbia.edu

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]