This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/13179] New: ICE w/template parameter in catch specification



gcc crashes compiling the source below:

$ ./cc1plus  x.cc
 void foo()

x.cc: At global scope:
x.cc:5: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
$

Here's where it's crashing:

Program received signal SIGSEGV, Segmentation fault.
0x08117ebf in import_export_class (ctype=0x400f50d8) at ../../gcc/gcc/cp/decl2.c:1520
1520      if (CLASSTYPE_INTERFACE_KNOWN (ctype))
(gdb) where
#0  0x08117ebf in import_export_class (ctype=0x400f50d8) at ../../gcc/gcc/cp/decl2.c:1520
#1  0x08119484 in import_export_tinfo (decl=0x400f56c0, type=0x400f50d8, is_in_library=false) at ../../gcc/gcc/cp/decl2.c:1753
#2  0x0814a136 in emit_tinfo_decl (decl=0x400f56c0) at ../../gcc/gcc/cp/rtti.c:1453
#3  0x0811b4eb in finish_file () at ../../gcc/gcc/cp/decl2.c:2644
#4  0x0820e2c4 in c_common_parse_file (set_yydebug=0) at ../../gcc/gcc/c-opts.c:1233
#5  0x084e7203 in compile_file () at ../../gcc/gcc/toplev.c:1818
#6  0x084ec300 in do_compile () at ../../gcc/gcc/toplev.c:4602
#7  0x084ec399 in toplev_main (argc=2, argv=0xbfffbc84) at ../../gcc/gcc/toplev.c:4642
#8  0x0821288e in main (argc=2, argv=0xbfffbc84) at ../../gcc/gcc/main.c:35
(gdb) call debug_tree (ctype)
 <template_type_parm 0x400f50d8 T VOID
    align 8 symtab 0 alias set 0
   index 0 level 1 orig_level 1
    chain <type_decl 0x400f5144 T>>


It looks like what's happening is that the type used in the catch
specification is getting put onto the unemitted_tinfo_decls list.
This happens when the template definition is read (prior to instantiation),
and thus the type has not been through tsubst.
Then import_export_class gets a tree that it cannot handle.

I was able to work around this problem by patching emit_tinfo_decl()
to reject types that are typenames or template parameter.
I do not believe that this is the correct fix however; i think
it's just hiding the symptom.

Index: rtti.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/cp/rtti.c,v
retrieving revision 1.175
diff -u -p -r1.175 rtti.c
--- rtti.c	27 Sep 2003 16:44:05 -0000	1.175
+++ rtti.c	24 Nov 2003 18:15:54 -0000
@@ -1441,6 +1441,10 @@ emit_tinfo_decl (tree decl)
   tree var_desc, var_init;
 
   my_friendly_assert (unemitted_tinfo_decl_p (decl), 20030307); 
+
+  if (TREE_CODE(type) == TYPENAME_TYPE ||
+      TREE_CODE(type) == TEMPLATE_TYPE_PARM)
+    return false;
   
   import_export_tinfo (decl, type, in_library);
   if (DECL_REALLY_EXTERN (decl) || !DECL_NEEDED_P (decl))

Environment:
System: Linux karma 2.4.19-emp_2419p5a829i #1 Tue Sep 3 17:42:17 EST 2002 i686 i686 i386 GNU/Linux
Architecture: i686

	<machine, os, target, libraries (multiple lines)>
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc/configure --prefix=/usr/local/gcc --enable-threads=posix --enable-long-long --enable-languages=c,c++,f77

How-To-Repeat:

Compile the following:

-------------------------------------
template <class T>
void foo()
{
  try {}
  catch(T e) {}
}
-------------------------------------
------- Additional Comments From snyder at fnal dot gov  2003-11-24 18:45 -------
Fix:
	<how to correct or work around the problem, if known (multiple lines)>

-- 
           Summary: ICE w/template parameter in catch specification
           Product: gcc
           Version: 3.4
            Status: UNCONFIRMED
          Severity: critical
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: snyder at fnal dot gov
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13179


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]