Project

General

Profile

Bug #11979

gcc-6 fails to optimize regcomp.c:compile_length_quantifier_node()

Added by t-nissie (Takeshi Nishimatsu) over 3 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:72819]

Description

This may be a GCC version specific issue.
gcc-6, an experimental snapshot from http://ftp.tsukuba.wide.ad.jp/software/gcc/snapshots/6-20160110/ ,
fails to compile ruby-2.2.4 and ruby-2.3.0 with an error of
template/encdb.h.tmpl:63:in `block (4 levels) in ': x_emoji.h:8: ENC_REPLICATE: UTF-8 is not defined yet. (replica UTF8-DoCoMo) (ArgumentError) .
I confirmed it both on Linux and Mac OS X.

gcc-4.9.2 could compile ruby-2.3.0.
/usr/bin/gcc of Mac OS X (Apple LLVM version 7.0.2 (clang-700.1.81)) could compile ruby-2.3.0, too.

Maybe, I should report it to https://gcc.gnu.org/bugzilla/ .
Could you tell me how to make small reproducible code?
(Or, please report it to the bugzilla with small code ;-)

Compile log:

$ uname -a
Linux emerald01 2.6.32-573.12.1.el6.x86_64 #1 SMP Tue Dec 15 21:19:08 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
$ tar xf ruby-2.3.0.tar.xz
$ mkdir ruby-2.3.0/Linux-x86_64-gcc-6-20160110-emerald01
$ cd    ruby-2.3.0/Linux-x86_64-gcc-6-20160110-emerald01
$ pwd
$ ../configure
$ make -j16
$ make
$ make V=1
    CC = gcc
    LD = ld
    LDSHARED = gcc -shared
    CFLAGS = -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat -std=iso9899:1999
    XCFLAGS = -D_FORTIFY_SOURCE=2 -fstack-protector -fno-strict-overflow -fvisibility=hidden -DRUBY_EXPORT -fPIE
    CPPFLAGS =   -I. -I.ext/include/x86_64-linux -I../include -I..
    DLDFLAGS = -fstack-protector -pie
    SOLIBS = -lgmp
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/6.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --enable-languages=c,c++,fortran,go,objc --with-gmp-include=/usr/local/include --with-gmp-lib=/usr/local/lib64 --with-mpfr-include=/usr/local/include --with-mpfr-lib=/usr/local/lib64 --with-mpc-include=/usr/local/include --with-mpc-lib=/usr/local/lib64
Thread model: posix
gcc version 6.0.0 20160110 (experimental) (GCC)
./miniruby -I../lib -I. -I.ext/common  ../enc/make_encmake.rb --builtin-encs="enc/ascii.o enc/us_ascii.o enc/unicode.o enc/utf_8.o" --builtin-transes="enc/trans/newline.o" --module  enc.mk
./miniruby -I../lib -I. -I.ext/common  ../tool/generic_erb.rb -c -o encdb.h ../template/encdb.h.tmpl ../enc enc
../template/encdb.h.tmpl:63:in `block (4 levels) in <main>': x_emoji.h:8: ENC_REPLICATE: UTF-8 is not defined yet. (replica UTF8-DoCoMo) (ArgumentError)
    from ../template/encdb.h.tmpl:43:in `each_line'
    from ../template/encdb.h.tmpl:43:in `block (3 levels) in <main>'
    from ../template/encdb.h.tmpl:41:in `open'
    from ../template/encdb.h.tmpl:41:in `block (2 levels) in <main>'
    from ../template/encdb.h.tmpl:38:in `each'
    from ../template/encdb.h.tmpl:38:in `block in <main>'
    from ../template/encdb.h.tmpl:34:in `each'
    from ../template/encdb.h.tmpl:34:in `<main>'
    from /home002/t-nissie/COMMON/work/ruby/ruby/ruby-2.3.0/lib/erb.rb:864:in `eval'
    from /home002/t-nissie/COMMON/work/ruby/ruby/ruby-2.3.0/lib/erb.rb:864:in `result'
    from ../tool/generic_erb.rb:38:in `<main>'
make: *** [encdb.h] Error 1

Related issues

Related to Ruby trunk - Bug #11831: Undefined behavior issuesClosedActions

Associated revisions

Revision b888ee25
Added by naruse (Yui NARUSE) about 3 years ago

revert UNALIGNED_WORD_ACCESS for GCC6

Released GCC 6.0 fixed the issue.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69291
[ruby-core:72211] [Bug #11831] [Bug #11979]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54855 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 54855
Added by naruse (Yui NARUSE) about 3 years ago

revert UNALIGNED_WORD_ACCESS for GCC6

Released GCC 6.0 fixed the issue.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69291
[ruby-core:72211] [Bug #11831] [Bug #11979]

Revision 54855
Added by naruse (Yui NARUSE) about 3 years ago

revert UNALIGNED_WORD_ACCESS for GCC6

Released GCC 6.0 fixed the issue.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69291
[ruby-core:72211] [Bug #11831] [Bug #11979]

Revision 54855
Added by naruse (Yui NARUSE) about 3 years ago

revert UNALIGNED_WORD_ACCESS for GCC6

Released GCC 6.0 fixed the issue.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69291
[ruby-core:72211] [Bug #11831] [Bug #11979]

Revision 54855
Added by naruse (Yui NARUSE) about 3 years ago

revert UNALIGNED_WORD_ACCESS for GCC6

Released GCC 6.0 fixed the issue.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69291
[ruby-core:72211] [Bug #11831] [Bug #11979]

History

Updated by t-nissie (Takeshi Nishimatsu) over 3 years ago

This IS a GCC version specific issue.

make -j16 optflags="-O0 -fno-fast-math"

can compile ruby-2.3.0, but

make -j16 optflags="-O1 -fno-fast-math"

cannot.

I want to know which file in ruby-2.3.0 reveals this issue of GCC-6.

Updated by t-nissie (Takeshi Nishimatsu) over 3 years ago

  • Subject changed from with gcc-6, template/encdb.h.tmpl:63:in `block (4 levels) in <main>': x_emoji.h:8: ENC_REPLICATE: UTF-8 is not defined yet. (replica UTF8-DoCoMo) (ArgumentError) to gcc-6 fails to optimize regcomp.c

gcc-6 fails to optimize regcomp.c.

$ ../configure CC=/usr/local/bin/gcc
$ make -j4 encdb.h   # => ArgumentError
$ rm regcomp.o
$ make optflags="-O0 -fno-fast-math" V=1 encdb.h
    :
gcc version 6.0.0 20151115 (experimental) (GCC)
    :
encdb.h updated
$ make -j4
$ make check
    :
# Running tests:

Finished tests in 451.167437s, 34.9227 tests/s, 4957.5298 assertions/s.
15756 tests, 2236676 assertions, 0 failures, 0 errors, 53 skips

ruby -v: ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]
check succeeded
$

I want to know where I should put #pragma optimization_level 0 .

Updated by t-nissie (Takeshi Nishimatsu) over 3 years ago

  • Subject changed from gcc-6 fails to optimize regcomp.c to gcc-6 fails to optimize regcomp.c:compile_length_quantifier_node()

gcc-6 fails to optimize ruby-2.3.0/regcomp.c:compile_length_quantifier_node()
and cannot build the ruby. Even the -O1 optimization option fails.
Adding __attribute__((optimize("O0"))) before the function can evade this issue.
I confirmed this issue both on GNU/Linux and Mac OS X.

Please note that there are two compile_length_quantifier_node() in ruby-2.3.0/regcomp.c.
gcc-6 fails to optimize second one at the line 985.

gcc-4.9.2 could build ruby-2.3.0.
/usr/bin/gcc of Mac OS X (Apple LLVM version 7.0.2 (clang-700.1.81)) could
build ruby-2.3.0, too.

I will report this issue to https://gcc.gnu.org/bugzilla/ tomorrow.

$ wget https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.0.tar.xz
$ shasum ruby-2.3.0.tar.xz | grep 96e620e38af351c8da63e40cfe217ec79f912ba1
$ tar xf ruby-2.3.0.tar.xz
$ mkdir  ruby-2.3.0/build_on_MacOSX
$ cd     ruby-2.3.0/build_on_MacOSX
$ /usr/local/bin/gcc --version
gcc (GCC) 6.0.0 20151115 (experimental)
$ ../configure CC=/usr/local/bin/gcc
$ make -j4
    :
generating encdb.h
../template/encdb.h.tmpl:63:in `block (4 levels) in <main>': x_emoji.h:8: ENC_REPLICATE: UTF-8 is not defined yet. (replica UTF8-DoCoMo) (ArgumentError)
    :
$ sed -e '984 a\
> __attribute__((optimize("O0")))' ../regcomp.c > regcomp.c
$ diff -u ../regcomp.c .
--- ../regcomp.c        2015-12-09 16:30:44.000000000 +0900
+++ ./regcomp.c 2016-01-14 08:21:52.798816125 +0900
@@ -982,6 +982,7 @@
 #else /* USE_COMBINATION_EXPLOSION_CHECK */
 static int
+__attribute__((optimize("O0")))
 compile_length_quantifier_node(QtfrNode* qn, regex_t* reg)
 {
   int len, mod_tlen;
$ make V=1 encdb.h
    :
./miniruby -I../lib -I. -I.ext/common  ../tool/generic_erb.rb -c -o encdb.h ../template/encdb.h.tmpl ../enc enc
encdb.h updated
$ make -j4
$ make check
    :
# Running tests:

Finished tests in 453.556568s, 34.7388 tests/s, 4931.0101 assertions/s.
15756 tests, 2236492 assertions, 0 failures, 0 errors, 53 skips

ruby -v: ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]
check succeeded
$

Updated by t-nissie (Takeshi Nishimatsu) over 3 years ago

I reported this issue as https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69291 with new info of:

I found strange behavior. If I built the ruby in /tmp on CentOS 6.7,
this issue does not stop to make encdb.h. But anyway, it stops to make rdoc
with Segmentation fault. Adding attribute((optimize("O0"))) can eliminate
the Segmentation fault, too.

Currently I got one comment:

Markus Trippelsdorf 2016-01-15 05:50:50 UTC
I think this bug is invalid, because ruby invokes undefined behavior, see:
https://bugs.ruby-lang.org/issues/11831

Updated by t-nissie (Takeshi Nishimatsu) over 3 years ago

Sorry, but GCC developers judged my bug report as INVALID.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69291

On the other hand, the same build error is reported in Ubuntu:
amd64 build of ruby2.2 2.2.3-2 in ubuntu xenial RELEASE
https://launchpad.net/ubuntu/+archive/test-rebuild-20151218.1-gcc6/+build/8718227

#6

Updated by naruse (Yui NARUSE) over 3 years ago

  • Related to Bug #11831: Undefined behavior issues added

Updated by octoploid (octoploid octoploid) over 3 years ago

Takeshi Nishimatsu wrote:

Sorry, but GCC developers judged my bug report as INVALID.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69291

On the other hand, the same build error is reported in Ubuntu:
amd64 build of ruby2.2 2.2.3-2 in ubuntu xenial RELEASE
https://launchpad.net/ubuntu/+archive/test-rebuild-20151218.1-gcc6/+build/8718227

I changed the resolution to "fixed". Today's gcc trunk compiles ruby without any issues.

Updated by naruse (Yui NARUSE) over 3 years ago

  • Status changed from Open to Closed

octoploid octoploid wrote:

Takeshi Nishimatsu wrote:

Sorry, but GCC developers judged my bug report as INVALID.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69291

On the other hand, the same build error is reported in Ubuntu:
amd64 build of ruby2.2 2.2.3-2 in ubuntu xenial RELEASE
https://launchpad.net/ubuntu/+archive/test-rebuild-20151218.1-gcc6/+build/8718227

I changed the resolution to "fixed". Today's gcc trunk compiles ruby without any issues.

Thank you for notice that, I close this.

Updated by t-nissie (Takeshi Nishimatsu) over 3 years ago

FYI, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69291 was REOPENED,
because the "Issue still happens on i586 and fails the ruby build".

Also available in: Atom PDF