Bug 6713 - Regression wrt 3.0.4: g++ -O2 leads to seg fault at run time
|
Bug#:
6713
|
Product: gcc
|
Version: 3.2
|
|
Host:
|
Target:
|
Build:
|
|
Status: RESOLVED
|
Severity: normal
|
Priority: P3
|
|
Resolution: FIXED
|
Assigned To: unassigned@gcc.gnu.org
|
Reported By: pcarlini@unitus.it
|
|
Component: rtl-optimization
|
Target Milestone: ---
|
|
Summary: Regression wrt 3.0.4: g++ -O2 leads to seg fault at run time
|
|
Keywords:
|
|
Opened: 2002-05-18 01:46
|
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: 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]
State-Changed-From-To: open->closed
State-Changed-Why: Fixed by rth.