Bug 55005 - [4.8 Regression] gcc.c-torture/execute/loop-3.c FAILs with -fPIC
Summary: [4.8 Regression] gcc.c-torture/execute/loop-3.c FAILs with -fPIC
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: 4.8.0
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2012-10-21 05:25 UTC by Zdenek Sojka
Modified: 2012-10-23 15:05 UTC (History)
2 users (show)

See Also:
Host: x86_64-pc-linux-gnu
Target: x86_64-pc-linux-gnu
Build:
Known to work: 4.7.3
Known to fail: 4.8.0
Last reconfirmed: 2012-10-21 00:00:00


Attachments
reduced testcase (155 bytes, text/x-csrc)
2012-10-21 05:25 UTC, Zdenek Sojka
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Zdenek Sojka 2012-10-21 05:25:02 UTC
Created attachment 28498 [details]
reduced testcase

There are various compiler flags that cause the FAIL.

Output:
$ gcc -O3 -fPIC testcase.c && ./a.out 
Aborted
$ gcc -O2 -funroll-loops -fPIC testcase.c && ./a.out 
Aborted
$ gcc -O2 -fpeel-loops -fPIC testcase.c && ./a.out 
Aborted
$ gcc -O2 -flto -fPIC testcase.c && ./a.out 
Aborted

Tested revisions:
r192641 - fail
r191586 - OK
4.7 r191640 - OK
Comment 1 Zdenek Sojka 2012-10-21 12:14:59 UTC
This isn't the only testcase that started failing recently.

One interesting flag combination:
$ gcc -O2 -fno-tree-ccp -fno-tree-copy-prop -fno-tree-dce testcase.c && ./a.out Segmentation fault

In this case, the body of main() isn't generated at all, so the code runs away immediatelly after jumping to main().

main:
.LFB2:
	.cfi_startproc
	.cfi_endproc
.LFE2:
	.size	main, .-main
Comment 2 Marek Polacek 2012-10-21 16:10:30 UTC
Started with http://gcc.gnu.org/viewcvs?view=revision&revision=192538
Comment 3 Zdenek Sojka 2012-10-21 16:14:53 UTC
(In reply to comment #2)
> Started with http://gcc.gnu.org/viewcvs?view=revision&revision=192538

Thanks for bisecting. The testcase from comment #1 was failing even before that (though instead of segfaulting, the code ended in an endless loop), so it might be a bit different problem.
Comment 4 Marek Polacek 2012-10-22 12:53:47 UTC
$ gcc -O2 -funroll-loops -fPIC testcase.c && ./a.out
$ gcc -O2 -fpeel-loops -fPIC testcase.c && ./a.out 

seem to be fine with current trunk.  The others are failing though.
Comment 5 Marek Polacek 2012-10-22 13:08:40 UTC
In .jump there's
;; Function main (main, funcdef_no=2, decl_uid=1727, cgraph_uid=2) (executed once)

Deleted 22 trivially dead insns

3 basic blocks, 1 edges.

(note 5 0 4 2 [bb 2] NOTE_INSN_BASIC_BLOCK)
(note 4 5 0 2 NOTE_INSN_FUNCTION_BEG)

Doesn't look right.
Comment 6 Jan Hubicka 2012-10-23 14:32:02 UTC
This is similar case as do-1.f90.  We have:

Statement _6 = m_5 * 2147483647;
 is executed at most 2 (bounded by 2) + 1 times in loop 1.

coming from:
  while (i--)
    {
      g (i * 2147483647);
    }
This overflows for i==4 and leads to undefined effect.
So I think the testcase is invalid. 

Honza
Comment 7 Jakub Jelinek 2012-10-23 15:05:46 UTC
Yeah, the undefined behavior is reached on the testcase unconditionally, so it is definitely invalid.