https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69291
Bug ID: 69291 Summary: [6 Regression] wrong code at -O1 for ruby-2.3.0/regcomp.c:985:compile_length_quantifier_nod e() Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: t_nissie at yahoo dot co.jp Target Milestone: --- gcc-6 gives wrong code at -O1 for ruby-2.3.0/regcomp.c:985: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 on CentOS 6.7 (x86_64-pc-linux-gnu) and Mac OS X 10.11.2 (x86_64-apple-darwin15.0.0). However, 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. 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. This may be a regression, because gcc-4.9.2 could build ruby-2.3.0. clang of Mac OS X (Apple LLVM version 7.0.2 (clang-700.1.81)) could build ruby-2.3.0, too. ================================ $ 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 '985 i\ > __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 $ ================================ Tank you for your constant efforts on GCC, Takeshi