Bug 80067 - [6/7 Regression] ICE in fold_comparison with -fsanitize=undefined
Summary: [6/7 Regression] ICE in fold_comparison with -fsanitize=undefined
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: sanitizer (show other bugs)
Version: 7.0.1
: P2 normal
Target Milestone: 6.4
Assignee: Marek Polacek
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks: yarpgen
  Show dependency treegraph
 
Reported: 2017-03-16 14:41 UTC by Vsevolod Livinskii
Modified: 2021-11-01 23:07 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-03-16 00:00:00


Attachments
Reproducer. (72 bytes, text/plain)
2017-03-16 14:41 UTC, Vsevolod Livinskii
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Vsevolod Livinskii 2017-03-16 14:41:51 UTC
Created attachment 40984 [details]
Reproducer.

GCC crashes with with -fsanitize=undefined option.

Reproducer:
extern signed char a;
void foo () { 
    0 << ((647 > a) - 1); 
}

Error:
>$ g++ -fsanitize=undefined -c repr.cpp 
repr.cpp: In function ‘void foo()’:
repr.cpp:3:24: internal compiler error: tree check: expected class ‘expression’, have ‘constant’ (integer_cst) in fold_comparison, at fold-const.c:8707
     0 << ((647 > a) - 1);
                        ^
0x10100b7 tree_class_check_failed(tree_node const*, tree_code_class, char const*, int, char const*)
	/home/vsevolod/workspace/gcc-dev/trunk/gcc/tree.c:9867
0xa94317 expr_check(tree_node*, char const*, int, char const*)
	/home/vsevolod/workspace/gcc-dev/trunk/gcc/tree.h:3233
0xa94317 fold_comparison
	(...)

GCC version:
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/home/vsevolod/workspace/gcc-dev/bin-trunk/libexec/gcc/x86_64-pc-linux-gnu/7.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /home/vsevolod/workspace/gcc-dev/trunk/configure --prefix=/home/vsevolod/workspace/gcc-dev/bin-trunk
Thread model: posix
gcc version 7.0.1 20170315 (experimental) (GCC)
Comment 1 Marek Polacek 2017-03-16 16:36:44 UTC
Mine.
Comment 2 Marek Polacek 2017-03-16 17:05:32 UTC
Started with r230365 - Merge C++ delayed folding branch.
Comment 3 Marek Polacek 2017-03-28 08:13:35 UTC
Author: mpolacek
Date: Tue Mar 28 08:13:04 2017
New Revision: 246521

URL: https://gcc.gnu.org/viewcvs?rev=246521&root=gcc&view=rev
Log:
	PR sanitizer/80067
	* fold-const.c (fold_comparison): Use protected_set_expr_location
	instead of SET_EXPR_LOCATION.

	* c-c++-common/ubsan/shift-10.c: New test.

Added:
    trunk/gcc/testsuite/c-c++-common/ubsan/shift-10.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fold-const.c
    trunk/gcc/testsuite/ChangeLog
Comment 4 Marek Polacek 2017-03-28 08:16:59 UTC
Author: mpolacek
Date: Tue Mar 28 08:16:27 2017
New Revision: 246522

URL: https://gcc.gnu.org/viewcvs?rev=246522&root=gcc&view=rev
Log:
	PR sanitizer/80067
	* fold-const.c (fold_comparison): Use protected_set_expr_location
	instead of SET_EXPR_LOCATION.

	* c-c++-common/ubsan/shift-10.c: New test.

Added:
    branches/gcc-6-branch/gcc/testsuite/c-c++-common/ubsan/shift-10.c
Modified:
    branches/gcc-6-branch/gcc/ChangeLog
    branches/gcc-6-branch/gcc/fold-const.c
    branches/gcc-6-branch/gcc/testsuite/ChangeLog
Comment 5 Marek Polacek 2017-03-28 08:19:03 UTC
Fixed.