This is the mail archive of the gcc-patches@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]

[patch] Fix PR c++/java 11006: ICE on missing class$


In build_java_class_ref in cp/init.c we have

  if (jclass_node == NULL_TREE)
    fatal_error ("call to Java constructor, while %<jclass%> undefined");

and

  if (!field)
    internal_error ("can't find class$");

Is there are reason why we don't emit a regular error and return
error_mark_node in these cases? Both conditions can be triggered
with user errors (see testcases below) and should be treated as
regular errors IMHO.

See also PR 11006, PR 11468.

===============================
extern "Java"
{
  struct A {};
}

typedef void* jclass;

A* p = new A;
===============================

bug.cc:8: internal compiler error: can't find class$
Please submit a full bug report, [etc.]

===============================
extern "Java"
{
  struct A {};
}

A* p = new A;
===============================

bug.cc:6: fatal error: call to Java constructor, while 'jclass' undefined
compilation terminated.

Bootstrapped and regtested on x86_64-unknown-linux-gnu.
Ok for mainline?

Regards,
Volker

:ADDPATCH C++:


2006-06-22  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/11006
	* init.c (build_new_1): Handle error_mark_nodes returned by
	build_java_class_ref.
	(build_java_class_ref): Do not abort compilation, but return
	error_mark_node.  Improve error message.  Fix indentation.

===================================================================
--- gcc/gcc/cp/init.c	(revision 114838)
+++ gcc/gcc/cp/init.c	(working copy)
@@ -1696,6 +1696,9 @@ build_new_1 (tree placement, tree type,
       tree class_decl = build_java_class_ref (elt_type);
       static const char alloc_name[] = "_Jv_AllocObject";
 
+      if (class_decl == error_mark_node)
+	return error_mark_node;
+
       use_java_new = 1;
       if (!get_global_value_if_present (get_identifier (alloc_name),
 					&alloc_fn))
@@ -2148,8 +2151,10 @@ build_java_class_ref (tree type)
     {
       jclass_node = IDENTIFIER_GLOBAL_VALUE (get_identifier ("jclass"));
       if (jclass_node == NULL_TREE)
-	fatal_error ("call to Java constructor, while %<jclass%> undefined");
-
+	{
+	  error ("call to Java constructor, while %<jclass%> undefined");
+	  return error_mark_node;
+	}
       jclass_node = TREE_TYPE (jclass_node);
     }
 
@@ -2164,8 +2169,11 @@ build_java_class_ref (tree type)
 	  break;
 	}
     if (!field)
-      internal_error ("can't find class$");
-    }
+      {
+	error ("can't find %<class$%> in %qT", type);
+	return error_mark_node;
+      }
+  }
 
   class_decl = IDENTIFIER_GLOBAL_VALUE (name);
   if (class_decl == NULL_TREE)
===================================================================

2006-06-22  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/11006
	* g++.dg/other/java2.C: New test.

===================================================================
--- gcc/gcc/testsuite/g++.dg/other/java2.C	2005-08-29 00:25:44 +0200
+++ gcc/gcc/testsuite/g++.dg/other/java2.C	2006-06-21 14:30:04 +0200
@@ -0,0 +1,11 @@
+// PR c++/???
+// { dg-do compile }
+
+extern "Java"
+{
+  struct A {};
+}
+
+typedef void* jclass;
+
+A* p = new A;  // { dg-error "class\\$" }
===================================================================



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