Bug 22508 - [4.0/4.1 Regression] ICE after invalid operator new
Summary: [4.0/4.1 Regression] ICE after invalid operator new
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.1
: P2 minor
Target Milestone: 4.0.2
Assignee: Volker Reichelt
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: error-recovery, ice-on-invalid-code, monitored, patch
Depends on:
Blocks:
 
Reported: 2005-07-16 03:46 UTC by Flash Sheridan
Modified: 2005-08-08 17:07 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-07-16 04:02:02


Attachments
Preprocessed source file (116.26 KB, text/plain)
2005-07-16 03:47 UTC, Flash Sheridan
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Flash Sheridan 2005-07-16 03:46:07 UTC
The command below results in "internal compiler error: Segmentation fault" with the checking-
enabled version of GCC 4.0.1 on Suse Linux 9.2.  It also crashes with Apple GCC 4.0.0 on Mac OSX 
10.4.2.  
    GCC 3.3.4 on Suse rejects the code without crashing, as does CodeSourcery arm-none-linux-
gnueabi-g++ 3.4.3, our local version of arm-softfloat-linux-gnu 3.4.1, and (on OSX) Apple's GCC 3.3 
and my own build of 3.4.0.

/opt/gcc401chk/bin/g++     -c       ../cpp/bugfiles/error/EckelRob_104822.ii 

../jammed/Barney/eckel.cpp: In function ‘std::string EckelCode::FramisTest()’:
../jammed/Barney/eckel.cpp:2039: internal compiler error: Segmentation fault

    With the Apple version of GCC 4.0.0, it gives a crash dialog (with a Report… button which doesn't 
work) with the following text:

The application cc1plus quit unexpectedly…
EXC_BAD_ACCESS (0x1)
KERN_PROTECTION_FAILURE (0X2) at 0xc

Thread 0 Crashed:
0 0x1000 + 457016
…

    I'll attach the preprocessed source.  It was copied by Rob Stevenson, a former PalmSource employee, 
from volume one of Bruce Eckel's _Thinking in C++_.  Here's the relevant function:

string FramisTest() {
   	stringstream ss2;
  Framis* f[Framis::psize];
  try {
    for(int i = 0; i < Framis::psize; i++)
      f[i] = new Framis;
    new Framis; // Out of memory
  } catch(bad_alloc) {
    ss2 << "Out of memory!" << endl;
  }
  delete f[10];
  f[10] = 0;
  // Use released memory:
  Framis* x = new Framis;
  delete x;
  for(int j = 0; j < Framis::psize; j++)	{
  	ss2 << f[j]->ReturnStrStream() ;
    delete f[j]; // Delete f[10] OK
   }
  return ss2.str() ;
} ///:~

______________________________________
Configurations:

Suse:
62> /opt/gcc401chk/bin/g++ -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../configure --enable-checking --prefix=/opt/gcc401chk --enable-languages=c,c+
+
Thread model: posix
gcc version 4.0.1

63> uname -a
Linux thrallis 2.6.8-24.16-default #1 Thu Jun 2 12:09:57 UTC 2005 i686 i686 i386 GNU/Linux


Macintosh:
> gcc -v
Reading specs from /usr/lib/gcc/powerpc-apple-darwin8/4.0.0/specs
Configured with: /private/var/tmp/gcc/gcc-4061.obj~8/src/configure --disable-checking --prefix=/
usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^
[cg][^+.-]*$/s/$/-4.0/ --with-gxx-include-dir=/include/gcc/darwin/4.0/c++ --build=powerpc-
apple-darwin8 --host=powerpc-apple-darwin8 --target=powerpc-apple-darwin8
Thread model: posix
gcc version 4.0.0 20041026 (Apple Computer, Inc. build 4061)

112> uname -a
Darwin klono.local 8.2.0 Darwin Kernel Version 8.2.0: Fri Jun 24 17:46:54 PDT 2005; 
root:xnu-792.2.4.obj~3/RELEASE_PPC Power Macintosh powerpc

PalmSource bug #104822
---
Flash Sheridan
http://pobox.com/~flash
Quality Lead for Compilers and Debuggers
PalmSource, Inc. Tools Quality Management
Comment 1 Flash Sheridan 2005-07-16 03:47:08 UTC
Created attachment 9287 [details]
Preprocessed source file
Comment 2 Andrew Pinski 2005-07-16 04:02:01 UTC
Confirmed, reduced testcase:
typedef __SIZE_TYPE__ size_t;
struct Framis
{
  void* operator new(size_t) throw(bad_alloc);
};
Framis* x = new Framis;
Comment 3 Volker Reichelt 2005-08-05 14:28:55 UTC
Testing a patch.
Comment 4 CVS Commits 2005-08-08 17:03:37 UTC
Subject: Bug 22508

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	reichelt@gcc.gnu.org	2005-08-08 17:03:33

Modified files:
	gcc/cp         : ChangeLog init.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/init: new13.C 

Log message:
	PR c++/22508
	* init.c (build_new_1): Check for empty candidate list.
	
	* g++.dg/init/new13.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4844&r2=1.4845
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/init.c.diff?cvsroot=gcc&r1=1.425&r2=1.426
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5893&r2=1.5894
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/init/new13.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 6 Volker Reichelt 2005-08-08 17:07:29 UTC
Fixed on mainline and 4.0 branch.
Comment 7 CVS Commits 2005-10-20 10:10:16 UTC
Subject: Bug 22508

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	reichelt@gcc.gnu.org	2005-10-20 10:10:10

Modified files:
	gcc/cp         : ChangeLog init.c 

Log message:
	PR c++/22508
	* init.c (build_new_1): Remove misleading comment.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3892.2.247&r2=1.3892.2.248
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/init.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.356.2.18&r2=1.356.2.19