This short snippet seg faults if compiled -O2 /////////////// #include <string> int isspa(int ch) { return 0; } void foo(std::string& str) { std::string::iterator it = str.begin(); std::string::iterator stop = str.end(); for (; it != stop; ++it ) //for (std::string::iterator it = str.begin(); it != str.end(); ++it ) if ( isspa( *it ) ) break; } int main() { std::string str = "test"; foo(str); } //////////////// Release: 3.1, also 3.2 20020517 Environment: i686-pc-linux-gnu How-To-Repeat: Interestingly, using the alternate form of the for statement makes the problem go away.
From: Paolo Carlini <pcarlini@unitus.it> To: gcc-gnats@gcc.gnu.org, gcc-prs@gcc.gnu.org, mark@ecriticalinc.com, pcarlini@unitus.it, gcc-bugs@gcc.gnu.org Cc: Subject: Re: optimization/6713: Regression wrt 3.0.4: g++ -O2 leads to seg fault at run time Date: Sat, 18 May 2002 11:23:20 +0200 An additional bit of information: the problem also goes away with -O2 -fno-inline, therefore it definitely seems inlining related. Ciao, Paolo. http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6713
From: Glen Nakamura <glen@imodulo.com> To: gcc-gnats@gcc.gnu.org, mark@ecriticalinc.com, pcarlini@unitus.it, gcc-bugs@gcc.gnu.org, nobody@gcc.gnu.org Cc: Subject: Re: optimization/6713: Regression wrt 3.0.4: g++ -O2 leads to seg fault at run time Date: Wed, 22 May 2002 16:31:39 -1000 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6713 FYI: the problem also goes away when compiling w/ -O2 -fno-strength-reduce. I'm not sure how it's supposed to work, but strength_reduce() in loop.c eliminates reg 60 but leaves a REG_EQUAL note referring to it within the loop. I think this REG_EQUAL note is cause of the problem... If I eliminate it, the problem goes away. BTW, changing ++i to i++ in the for loop avoids the problem since the REG_EQUAL note is not emitted in that case. Any thoughts on how to fix this? I'm not familiar enough with the loop optimizer to produce a proper patch. - Glen Nakamura [snip] giv at 482 reduced to (reg 135) giv at 480 reduced to (reg 135) biv 60 was eliminated. Reg 60: biv eliminated [snip] (note 351 591 492 NOTE_INSN_LOOP_BEG) [snip] (note 529 474 482 [bb 6] NOTE_INSN_BASIC_BLOCK) (insn 482 529 588 (set (reg/s/f:SI 111) (reg/f:SI 135)) -1 (nil) (expr_list:REG_EQUAL (plus:SI (reg/v:SI 60) <<< PROBLEM NOTE??? (const_int 1 [0x1])) (nil))) (insn 588 482 489 (set (reg/s/f:SI 111) (reg/f:SI 135)) -1 (nil) (nil)) (note 489 588 490 0x40660980 NOTE_INSN_BLOCK_END) [snip] (note 497 408 499 NOTE_INSN_LOOP_END) [snip]
From: rth@gcc.gnu.org To: gcc-gnats@gcc.gnu.org Cc: Subject: optimization/6713 Date: 17 Jul 2002 18:00:36 -0000 CVSROOT: /cvs/gcc Module name: gcc Changes by: rth@gcc.gnu.org 2002-07-17 11:00:36 Modified files: gcc : ChangeLog loop.c Added files: gcc/testsuite/g++.dg/opt: pr6713.C Log message: PR optimization/6713 * loop.c (loop_givs_rescan): Explicitly delete the insn that sets a non-replaceable giv after issuing the new one. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=1.14868&r2=1.14869 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/loop.c.diff?cvsroot=gcc&r1=1.410&r2=1.411 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/opt/pr6713.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
State-Changed-From-To: open->closed State-Changed-Why: Fixed by rth.
From: jakub@gcc.gnu.org To: gcc-gnats@gcc.gnu.org Cc: Subject: optimization/6713 Date: 9 Oct 2002 11:24:10 -0000 CVSROOT: /cvs/gcc Module name: egcs Branch: gcc-3_2-rhl8-branch Changes by: jakub@gcc.gnu.org 2002-10-09 04:24:10 Modified files: gcc : ChangeLog loop.c Log message: * loop.c (loop_givs_rescan): Delete the REG_EQUAL note, not the insn. PR optimization/6713 * loop.c (loop_givs_rescan): Explicitly delete the insn that sets a non-replaceable giv after issuing the new one. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/egcs/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-rhl8-branch&r1=1.13152.2.657.2.27.2.14&r2=1.13152.2.657.2.27.2.15 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/egcs/gcc/loop.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-rhl8-branch&r1=1.389.2.7.4.2&r2=1.389.2.7.4.3