Bug 67920 - [6 Regression] wrong code with -O3
Summary: [6 Regression] wrong code with -O3
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: 6.0
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2015-10-10 19:46 UTC by James Almer
Modified: 2015-10-14 09:37 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work: 5.2.0
Known to fail: 6.0
Last reconfirmed: 2015-10-12 00:00:00


Attachments
-save-temps output for all three files (519.62 KB, application/gzip)
2015-10-13 00:18 UTC, James Almer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description James Almer 2015-10-10 19:46:51 UTC
Some change to trunk made in the last 18 days is making gcc miscompile the files libavcodec/jpeg2000dec.c libavcodec/j2kenc.c and libavcodec/avuidec.c from ffmpeg git head when -O3 is used. This doesn't happen with -O2.
I tested with x86_64-pc-linux-gnu only.

How to reproduce:
git clone git://git.videolan.org/ffmpeg.git && cd ffmpeg && ./configure
make fate-vsynth1-jpeg2000 fate-vsynth1-avui

The tests will fail, the former showing both the encoder and decoder are producing garbage, and the latter only the decoder. Adding -fno-strict-aliasing -fwrapv does not make a difference.

The command Makefile uses to compile all three files looks like this:
gcc -I. -I/home/jamrial/ffmpeg/ -D_ISOC99_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -DZLIB_CONST -DHAVE_AV_CONFIG_H -std=c99 -fomit-frame-pointer -pthread -g -Wdeclaration-after-statement -Wall -Wdisabled-optimization -Wpointer-arith -Wredundant-decls -Wwrite-strings -Wtype-limits -Wundef -Wmissing-prototypes -Wno-pointer-to-int-cast -Wstrict-prototypes -Wempty-body -Wno-parentheses -Wno-switch -Wno-format-zero-length -Wno-pointer-sign -O3 -fno-math-errno -fno-signed-zeros -fno-tree-vectorize -Werror=format-security -Werror=implicit-function-declaration -Werror=missing-prototypes -Werror=return-type -Werror=vla -Wformat -fdiagnostics-color=auto -Wno-maybe-uninitialized -c -o OUTPUT.o INPUT.c

You can get that kind of verbose output by running make with V=1.
Keep in mind you'll probably run into pr67794 while bisecting gcc trunk to find the commit that introduced this regression.

Apologizes for not having a simpler test case.
Comment 1 James Almer 2015-10-10 20:01:06 UTC
For reference you can also check http://fate.ffmpeg.org/report.cgi?time=20151010052205&slot=x86_64-archlinux-gcc-experimental
Comment 2 Andrew Pinski 2015-10-10 20:08:16 UTC
Can you also compile with -fsanitize=undefined and try that?  Can you also try -fsanitize=address ?

This might detect if it is a bug in the code vs a bug in GCC.
Comment 3 James Almer 2015-10-10 21:00:26 UTC
(In reply to Andrew Pinski from comment #2)
> Can you also compile with -fsanitize=undefined and try that?  Can you also
> try -fsanitize=address ?
> 
> This might detect if it is a bug in the code vs a bug in GCC.

Can't check with gcc 6 because of pr67921, but asan/ubsan in gcc 5.2.0 and clang 3.1 apparently don't complain about the code.

ubsan gcc 5.2.0: http://fate.ffmpeg.org/report.cgi?time=20151010033356&slot=x86_64-archlinux-gcc-ubsan
asan gcc 5.2.0: http://fate.ffmpeg.org/report.cgi?time=20151010181435&slot=x86_64-archlinux-gcc-asan
Clang 3.1 asan: http://fate.ffmpeg.org/report.cgi?time=20151010171909&slot=x86_64-debian-asan-144800
Comment 4 Richard Biener 2015-10-12 07:43:48 UTC
Waiting for sth like a testcase.
Comment 5 James Almer 2015-10-13 00:16:57 UTC
This is a regression introduced by r228599.
I'm attaching the output of -save-temps for all three files, the good assembly from r228598 (last good commit) and the bad assembly from r228599.

I can't generate a better or simpler testcase, sorry.
Comment 6 James Almer 2015-10-13 00:18:55 UTC
Created attachment 36491 [details]
-save-temps output for all three files
Comment 7 Marek Polacek 2015-10-13 10:42:58 UTC
This should be the same as PR67947 which has a testcase.
Comment 8 Yuri Rumyantsev 2015-10-13 13:11:13 UTC
Please check that revision 228760 will cure your issue.
Comment 9 James Almer 2015-10-13 17:00:13 UTC
(In reply to Yuri Rumyantsev from comment #8)
> Please check that revision 228760 will cure your issue.

Looks like it did. Thanks.
Comment 10 Ilya Enkovich 2015-10-14 09:37:17 UTC
(In reply to James Almer from comment #9)
> Looks like it did. Thanks.

Fixed then