Bug 80097 - internal compiler error in c_fully_fold_internal with std=c89 and -fsanitize=float-divide-by-zero
Summary: internal compiler error in c_fully_fold_internal with std=c89 and -fsanitize=...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 6.3.1
: P3 normal
Target Milestone: ---
Assignee: Jakub Jelinek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-03-19 14:02 UTC by Max Bruckner
Modified: 2017-05-30 09:28 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 5.4.0, 6.3.1
Last reconfirmed: 2017-03-19 00:00:00


Attachments
C file to reproduce the bug (65 bytes, text/plain)
2017-03-19 14:02 UTC, Max Bruckner
Details
Makefile with the compiler options necessary to reproduce the bug (72 bytes, text/plain)
2017-03-19 14:03 UTC, Max Bruckner
Details
gcc7-pr80097.patch (661 bytes, patch)
2017-03-20 11:19 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Max Bruckner 2017-03-19 14:02:36 UTC
Created attachment 40999 [details]
C file to reproduce the bug

When building the attached C source file with GCC 6.3.1 or GCC 5.4.0 on an x86 (32bit) system and the compiler flags '-std=c89 -fsanitize=float-divide-by-zero', an internal compiler error happens. It doesn't happen on x86_64, ppc or armv7 from what I tested.

Output for GCC 5.4.0:

gcc-5 -std=c89 -fsanitize=float-divide-by-zero bug.c -c
bug.c: In function ‘bug’:
bug.c:3:2: internal compiler error: in c_fully_fold_internal, at c-family/c-common.c:1545
int test = (1 / number >= 1);
^
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://bugs.archlinux.org/> for instructions.
make: *** [Makefile:2: bug] Error 1


Output for GCC 6.0.3:

cc -std=c89 -fsanitize=float-divide-by-zero bug.c -c
bug.c: In function ‘bug’:
bug.c:3:2: internal compiler error: in c_fully_fold_internal, at c/c-fold.c:558
int test = (1 / number >= 1);
^~~
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://bugs.archlinux.org/> for instructions.
make: *** [Makefile:2: bug] Error 1
Comment 1 Max Bruckner 2017-03-19 14:03:22 UTC
Created attachment 41000 [details]
Makefile with the compiler options necessary to reproduce the bug
Comment 2 Max Bruckner 2017-03-19 14:04:53 UTC
I already created a bug report in the Archlinux bug tracker here: https://bugs.archlinux.org/task/53368 but I could also reproduce the bug on Ubuntu 16.04.2 with GCC 5.4.0
Comment 3 Max Bruckner 2017-03-19 14:05:24 UTC
I already created a bug report in the Archlinux bug tracker here: https://bugs.archlinux.org/task/53368 but I could also reproduce the bug on Ubuntu 16.04.2 with GCC 5.4.0
Comment 4 Jakub Jelinek 2017-03-19 17:09:58 UTC
Looking into this.
Comment 5 Jakub Jelinek 2017-03-20 11:19:42 UTC
Created attachment 41002 [details]
gcc7-pr80097.patch

Untested fix.
Comment 6 Jakub Jelinek 2017-03-21 07:01:37 UTC
Author: jakub
Date: Tue Mar 21 07:01:05 2017
New Revision: 246302

URL: https://gcc.gnu.org/viewcvs?rev=246302&root=gcc&view=rev
Log:
	PR c/80097
	* c-typeck.c (build_binary_op): Add EXCESS_PRECISION_EXPR only around
	optional COMPOUND_EXPR with ubsan instrumentation.

	* gcc.dg/ubsan/pr80097.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/ubsan/pr80097.c
Modified:
    trunk/gcc/c/ChangeLog
    trunk/gcc/c/c-typeck.c
    trunk/gcc/testsuite/ChangeLog
Comment 7 Jakub Jelinek 2017-03-21 07:53:39 UTC
Fixed on the trunk so far.
Comment 8 Jakub Jelinek 2017-05-05 21:42:37 UTC
Author: jakub
Date: Fri May  5 21:42:05 2017
New Revision: 247687

URL: https://gcc.gnu.org/viewcvs?rev=247687&root=gcc&view=rev
Log:
	Backported from mainline
	2017-03-21  Jakub Jelinek  <jakub@redhat.com>

	PR c/80097
	* c-typeck.c (build_binary_op): Add EXCESS_PRECISION_EXPR only around
	optional COMPOUND_EXPR with ubsan instrumentation.

	* gcc.dg/ubsan/pr80097.c: New test.

Added:
    branches/gcc-6-branch/gcc/testsuite/gcc.dg/ubsan/pr80097.c
Modified:
    branches/gcc-6-branch/gcc/c/ChangeLog
    branches/gcc-6-branch/gcc/c/c-typeck.c
    branches/gcc-6-branch/gcc/testsuite/ChangeLog
Comment 9 Jakub Jelinek 2017-05-30 08:17:03 UTC
Author: jakub
Date: Tue May 30 08:16:31 2017
New Revision: 248661

URL: https://gcc.gnu.org/viewcvs?rev=248661&root=gcc&view=rev
Log:
	Backported from mainline
	2017-03-21  Jakub Jelinek  <jakub@redhat.com>

	PR c/80097
	* c-typeck.c (build_binary_op): Add EXCESS_PRECISION_EXPR only around
	optional COMPOUND_EXPR with ubsan instrumentation.

	* gcc.dg/ubsan/pr80097.c: New test.

Added:
    branches/gcc-5-branch/gcc/testsuite/gcc.dg/ubsan/pr80097.c
Modified:
    branches/gcc-5-branch/gcc/c/ChangeLog
    branches/gcc-5-branch/gcc/c/c-typeck.c
    branches/gcc-5-branch/gcc/testsuite/ChangeLog
Comment 10 Jakub Jelinek 2017-05-30 09:28:30 UTC
Fixed.