Bug 28553 - [4.1 Regression] string processing -O3 optimization bug under GCC 4.1.1
Summary: [4.1 Regression] string processing -O3 optimization bug under GCC 4.1.1
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.1.1
: P1 normal
Target Milestone: 4.2.0
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2006-07-31 17:55 UTC by Peter Naulls
Modified: 2008-07-04 15:46 UTC (History)
3 users (show)

See Also:
Host: i486-linux-gnu
Target:
Build:
Known to work: 4.0.3 4.2.0 4.3.0
Known to fail: 4.1.0 4.1.1 4.1.2 4.1.3
Last reconfirmed: 2006-08-24 01:52:50


Attachments
Preprocessed C++ demonstrating problem (61.27 KB, text/plain)
2006-07-31 17:56 UTC, Peter Naulls
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Naulls 2006-07-31 17:55:44 UTC
Note, the following is in reference to this Debian version of GCC:

gcc version 4.1.2 20060729 (prerelease) (Debian 4.1.1-10)

However, it also occurs under a version I have built myself:

Target: i686-pc-linux-gnu
Configured with: ../configure --prefix=/usr/local/gcc-4.1 --enable-languages=c,c++,java
Thread model: posix
gcc version 4.1.1


My C++ knowledge isn't extensive enough to give further details of this other than it's related to string handling, or guess if it's already been reported, but the following preprocessed code reproduces the problem under -O3, but not -O2.  The code performs correctly under GCC 3.4.6 and -O3

Here is the expected output:

op [0]: "A"
op [1]: "B"
op [2]: "C"
op [3]: "D"
op [4]: "E"
op [5]: "F"

Here is a crash caught by GDB:

CfgSchema (this=0xbfd0a400, schema_str=@0xbfd0a40c) at /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:260
260               if (__pred(*__first))
(gdb) bt
#0  CfgSchema (this=0xbfd0a400, schema_str=@0xbfd0a40c) at /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_algo.h:260
#1  0x08048ebe in main () at cfgtblopt.cpp:36
Comment 1 Peter Naulls 2006-07-31 17:56:51 UTC
Created attachment 11981 [details]
Preprocessed C++ demonstrating problem
Comment 2 Paolo Carlini 2006-08-01 12:02:51 UTC
The problem cannot be reproduced in mainline, only in 4_1-branch. Seems an rtl-optimization bug: for the below slightly reduced testcase t97.final_cleanup is identical in mainline and 4_1-branch:

#include <string>
#include <algorithm>

template<typename InputIter, typename SplitPred>
  inline
  void
  SplitTo(InputIter b, InputIter e, SplitPred sp)
  {
    InputIter p = std::find_if(b, e, sp);
    
    while (p != e)
      {
	b = p;
	p = std::find_if(b, e, sp);
      }
  }

template<typename InputIter>
  inline
  void
  SplitTo(InputIter b, InputIter e)
  { SplitTo(b, e, std::bind2nd(std::equal_to<char>(), ';')); }

int
main(void)
{
  const std::string& src = "";
  SplitTo(src.begin(), src.end());
}
Comment 3 Richard Biener 2006-08-01 12:18:06 UTC
-O2 -finline-functions is sufficient to reproduce the problem on the branch, or
if you mark CfgSchema::CfgSchema(const std::string &) 'inline'.
Comment 4 Wolfgang Bangerth 2006-08-24 01:52:50 UTC
Paolo has already confirmed this one.
Comment 5 Richard Biener 2006-10-27 09:41:29 UTC
I cannot reproduce this with 4.1.2 20061024 anymore.
Comment 6 Mark Mitchell 2006-11-01 18:16:53 UTC
Can the original submitter still reproduce this problem?
Comment 7 Peter Naulls 2006-11-02 16:34:42 UTC
I can confirm that this is fixed with the GCC 4.1 now in Debian unstable.
Comment 8 Peter Naulls 2006-12-06 17:37:10 UTC
And it's back, at least in this version:

Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../configure --prefix=/usr/local/gcc-4.1 --enable-languages=c,c++,java
Thread model: posix
gcc version 4.1.2 20061204 (prerelease)
Comment 9 Joseph S. Myers 2008-07-04 15:46:12 UTC
Closing 4.1 branch.