Bug 20008 - [4.0 Regression] internal compiler error: in expand_case, at stmt.c:2397
Summary: [4.0 Regression] internal compiler error: in expand_case, at stmt.c:2397
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.0.0
Assignee: Alexandre Oliva
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2005-02-16 16:20 UTC by Caolan McNamara
Modified: 2005-02-18 12:26 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-02-17 15:13:15


Attachments
bzip2 compressed preprocesser output (123.84 KB, application/x-bzip)
2005-02-16 16:23 UTC, Caolan McNamara
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Caolan McNamara 2005-02-16 16:20:08 UTC
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --with-gxx-include-dir=/usr/include/c++/3.4.3
--enable-languages=c,c++,java,f95 --enable-java-awt=gtk --host=i386-redhat-linux
Thread model: posix
gcc version 4.0.0 20050216 (Red Hat 4.0.0-0.24)

---

/usr/src/redhat/BUILD/SRC680_m77/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx:756:
internal compiler error: in expand_case, at stmt.c:2397
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
Preprocessed source stored into /tmp/cck1QjtG.out file, please attach this to
your bugreport.

---

g++4 -Wreturn-type -fmessage-length=0 -c -I. -I. -I../inc -I../../../inc
-I../../../unx/inc -I../../../unxlngi6.pro/inc -I.
-I/usr/src/redhat/BUILD/SRC680_m77/solver/680/unxlngi6.pro/inc/stl
-I/usr/src/redhat/BUILD/SRC680_m77/solver/680/unxlngi6.pro/inc/external
-I/usr/src/redhat/BUILD/SRC680_m77/solver/680/unxlngi6.pro/inc
-I/usr/src/redhat/BUILD/SRC680_m77/solenv/unxlngi6/inc
-I/usr/src/redhat/BUILD/SRC680_m77/solenv/inc
-I/usr/src/redhat/BUILD/SRC680_m77/res
-I/usr/src/redhat/BUILD/SRC680_m77/solver/680/unxlngi6.pro/inc/stl
-I/usr/src/redhat/BUILD/SRC680_m77/solenv/inc/Xp31 -I/usr/include
-I/usr/X11R6/include -I/usr/include/mozilla-1.7.5
-I/usr/include/mozilla-1.7.5/nspr -I../../../source/xmlsec -DSYSTEM_MOZILLA
-I/usr/include/mozilla-1.7.5/nss -I/usr/include/mozilla-1.7.5/nspr -I.
-I../../../res -I/usr/include/mozilla-1.7.5/profile
-I/usr/include/mozilla-1.7.5/string -I/usr/include/mozilla-1.7.5/embed_base
-Wuninitialized -g1 -Os -fno-strict-aliasing -DSYSTEM_LIBXML
-I/usr/include/libxml2 -fPIC -g -pipe -mtune=pentiumpro -Wno-ctor-dtor-privacy
-fexceptions -fno-enforce-eh-specs -fno-rtti -Wall -Wconversion -Wpointer-arith
-Wbad-function-cast -Wcast-align -Woverloaded-virtual -Wsynth -Wno-long-long
-pthread -fpic -DLINUX -DUNX -DVCL -DGCC -DC341 -DINTEL
-DGXX_INCLUDE_PATH=/usr/include/c++/3.4.3 -DCVER=C341 -D_USE_NAMESPACE -DGLIBC=2
-DX86 -D_PTHREADS -D_REENTRANT -DNEW_SOLAR -D_USE_NAMESPACE=1
-DSTLPORT_VERSION=400 -DHAVE_GCC_VISIBILITY_FEATURE -D__DMAKE -DUNIX
-DCPPU_ENV=gcc3 -DSUPD=680 -DPRODUCT -DNDEBUG -DPRODUCT_FULL -DOSL_DEBUG_LEVEL=0
-DOPTIMIZE -DEXCEPTIONS_ON -DCUI -DSOLAR_JAVA -DSRC680 -DTRACING
-DXMLSEC_CRYPTO_NSS -DXMLSEC_NO_XSLT -DSHAREDLIB -D_DLL_ -DMULTITHREAD -o
../../../unxlngi6.pro/slo/securityenvironment_nssimpl.o
/usr/src/redhat/BUILD/SRC680_m77/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx
Comment 1 Caolan McNamara 2005-02-16 16:23:50 UTC
Created attachment 8203 [details]
bzip2 compressed preprocesser output
Comment 2 Andrew Pinski 2005-02-16 19:16:57 UTC
Reduced testcase:
typedef enum _SECStatus {
  SECWouldBlock = -2,
  SECFailure = -1,
  SECSuccess = 0
} SECStatus;
typedef enum {
  SEC_ERROR_BAD_SIGNATURE = (-0x2000) + 10
} SECErrorCodes;
void g(void);
void f(SECStatus status)
{
  switch( status )
  {
    case SEC_ERROR_BAD_SIGNATURE :
      g();
      break ;
  }
}
: Search converges between 2004-10-25-161001-trunk (#610) and 2004-10-26-161001-trunk 
(#611).

This is undefined code (as SEC_ERROR_BAD_SIGNATURE is out of the range of SECStatus).  Enums are 
defined differently in C++ than C.
Comment 3 Caolan McNamara 2005-02-17 10:00:21 UTC
FWIW: openoffice.org 1.9.77 side patch to workaround at
http://people.redhat.com/caolanm/gcc4/xmlsecurity.gcc20008.gcc4.patch
Comment 4 Alexandre Oliva 2005-02-17 16:17:54 UTC
Subject: [PR c++/20008, middle-end] handle switch with all cases out-of-range

Sure enough, the testcase relied on undefined behavior, but that's no
reason for us to ICE at compile time.  I suppose it might be nice to
get the tree cfg cleanup code to detect that it can discard cases that
are out of range, but I'm not all that familiar with the cfg cleanup
code, so I figured I'd try this first.

Ok to install if regression testing passes on x86_64-linux-gnu?

Index: gcc/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	PR c++/20008
	* stmt.c (expand_case): Don't assume cleanup_tree_cfg will remove
	cases that are out-of-range for the index type.

Index: gcc/stmt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/stmt.c,v
retrieving revision 1.412
diff -u -p -r1.412 stmt.c
--- gcc/stmt.c 13 Dec 2004 16:03:38 -0000 1.412
+++ gcc/stmt.c 17 Feb 2005 16:12:31 -0000
@@ -1,6 +1,7 @@
 /* Expands front end tree to back end RTL for GCC
    Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
-   1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+   1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
+     Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -2393,8 +2394,14 @@ expand_case (tree exp)
       BITMAP_XFREE (label_bitmap);
 
       /* cleanup_tree_cfg removes all SWITCH_EXPR with a single
-	 destination, such as one with a default case only.  */
-      gcc_assert (count != 0);
+	 destination, such as one with a default case only.  However,
+	 it doesn't remove cases that are out of range for the switch
+	 type, so we may still get a zero here.  */
+      if (count == 0)
+	{
+	  emit_jump (default_label);
+	  return;
+	}
 
       /* Compute span of values.  */
       range = fold (build2 (MINUS_EXPR, index_type, maxval, minval));
Index: gcc/testsuite/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	PR c++/20008
	* g++.dg/opt/switch3.C: New.

Index: gcc/testsuite/g++.dg/opt/switch3.C
===================================================================
RCS file: gcc/testsuite/g++.dg/opt/switch3.C
diff -N gcc/testsuite/g++.dg/opt/switch3.C
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/g++.dg/opt/switch3.C 17 Feb 2005 16:12:45 -0000
@@ -0,0 +1,30 @@
+// { dg-do compile }
+
+// PR c++/20008
+
+// We failed to compile this because CFG cleanup left the switch
+// statement intact, whereas expand_case expected at least one
+// in-range case to remain.
+
+typedef enum _SECStatus {
+  SECWouldBlock = -2,
+  SECFailure = -1,
+  SECSuccess = 0
+} SECStatus;
+
+typedef enum {
+  SEC_ERROR_BAD_SIGNATURE = (-0x2000) + 10
+} SECErrorCodes;
+
+void g(void);
+void f(SECStatus status)
+{
+  switch( status )
+    {
+    case SEC_ERROR_BAD_SIGNATURE :
+      // This case can be optimized away in C++ (but apparently not in
+      // C), because the enum type is defined with a narrow range.
+      g();
+      break ;
+    }
+}

-- 
Alexandre Oliva             http://www.ic.unicamp.br/~oliva/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}
Comment 5 GCC Commits 2005-02-18 12:21:41 UTC
Subject: Bug 20008

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	aoliva@gcc.gnu.org	2005-02-18 12:20:50

Modified files:
	gcc            : ChangeLog stmt.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/opt: switch4.C 

Log message:
	gcc/ChangeLog:
	PR c++/20008
	* stmt.c (expand_case): Don't assume cleanup_tree_cfg will remove
	cases that are out-of-range for the index type.
	gcc/testsuite/ChangeLog:
	PR c++/20008
	* g++.dg/opt/switch4.C: New.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.7522&r2=2.7523
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/stmt.c.diff?cvsroot=gcc&r1=1.415&r2=1.416
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5046&r2=1.5047
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/opt/switch4.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 6 Jakub Jelinek 2005-02-18 12:26:44 UTC
Fixed.