Bug 41805 - possible LTO termination bug
Summary: possible LTO termination bug
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: 4.5.0
Assignee: Richard Biener
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2009-10-23 02:48 UTC by John Regehr
Modified: 2009-10-23 13:16 UTC (History)
3 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2009-10-23 10:17:09


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Regehr 2009-10-23 02:48:15 UTC
Using r153474 with LTO, the compilation units below appear to be improperly turned into a terminating executable.

regehr@john-home:~$ current-gcc -g -Wall -O3 -flto -c rnd_output0.c
regehr@john-home:~$ current-gcc -g -Wall -O3 -flto -c rnd_output1.c
regehr@john-home:~$ current-gcc -g -Wall -O3 -flto rnd_output1.o rnd_output0.o -o rand 
regehr@john-home:~$ ./rand
Done
regehr@john-home:~$ 
regehr@john-home:~$ cat rnd_output0.c
#include <assert.h>
#include <stdio.h>

int func_5();

int i = 0;

int func_2()
{
    func_5();
    assert(i == 0);
    assert(i == 0);
    assert(i == 0);
    assert(i == 0);
    assert(i == 0);
    assert(i == 0);
    assert(i == 0);
    return 0;
}

int func_1(int p)
{
    func_2();
    return 0;
}

int main(void)
{
    func_1(func_2());
    printf ("Done\n");
    return 0;
}
regehr@john-home:~$ cat rnd_output1.c
int func_5()
{
    while(1)
      ;
    return 0;
}
Comment 1 John Regehr 2009-10-23 02:50:08 UTC
Forgot to add gcc details:

regehr@john-home:~$ current-gcc -v
Using built-in specs.
COLLECT_GCC=current-gcc
COLLECT_LTO_WRAPPER=/home/regehr/z/tmp/gcc-r153474-install/libexec/gcc/i686-pc-linux-gnu/4.5.0/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: ../configure --with-libelf=/usr/local --enable-lto --prefix=/home/regehr/z/tmp/gcc-r153474-install --program-prefix=r153474- --enable-languages=c,c++
Thread model: posix
gcc version 4.5.0 20091022 (experimental) (GCC) 
Comment 2 Andrew Pinski 2009-10-23 02:56:12 UTC
Sounds like pure/const pass is messing up.
Comment 3 Richard Biener 2009-10-23 10:04:23 UTC
It is RTL expansion that drops the calls to func_2 () from main.
Comment 4 Richard Biener 2009-10-23 10:17:09 UTC
I have a patch.
Comment 5 Richard Biener 2009-10-23 10:20:50 UTC
Non-LTO testcase:

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

int main()
{
  foo ();
  return 0;
}
Comment 6 Richard Biener 2009-10-23 12:01:38 UTC
Subject: Bug 41805

Author: rguenth
Date: Fri Oct 23 12:01:21 2009
New Revision: 153495

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=153495
Log:
2009-10-23  Richard Guenther  <rguenther@suse.de>

	PR middle-end/41805
	* cfgexpand.c (expand_call_stmt): Use gimple_has_side_effects and
	gimple_call_nothrow_p.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/cfgexpand.c

Comment 7 Richard Biener 2009-10-23 13:16:38 UTC
Fixed.