aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2007-11-23 21:49:02 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2007-11-23 21:49:02 +0100
commit360f866c16da467d7851b72b3d9c6c3fd1653721 (patch)
tree025c9ee6f18eef0c2f493c4725f5fb7431ae2dd6 /gcc
parent6ca39fcbf6eb51d39d84916a4c742e20bb2c91e0 (diff)
downloadgcc-360f866c16da467d7851b72b3d9c6c3fd1653721.zip
gcc-360f866c16da467d7851b72b3d9c6c3fd1653721.tar.gz
gcc-360f866c16da467d7851b72b3d9c6c3fd1653721.tar.bz2
re PR c++/30293 (ICE with extern "Java" in store_init_value)
PR c++/30293 PR c++/30294 * decl.c (cp_finish_decl): Disallow variable or field definitions if extern "Java" aggregates. (grokparms): Disallow parameters with extern "Java" aggregates. (check_function_type): Disallow function return values with extern "Java" aggregates. * init.c (build_new_1): Disallow placement new with extern "Java" aggregates. * g++.dg/ext/java-2.C: New test. From-SVN: r130382
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog13
-rw-r--r--gcc/cp/decl.c35
-rw-r--r--gcc/cp/init.c5
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/g++.dg/ext/java-2.C79
5 files changed, 136 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 0aff9b1..9038270 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,16 @@
+2007-11-23 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/30293
+ PR c++/30294
+ * decl.c (cp_finish_decl): Disallow variable or field
+ definitions if extern "Java" aggregates.
+ (grokparms): Disallow parameters with extern "Java"
+ aggregates.
+ (check_function_type): Disallow function return values
+ with extern "Java" aggregates.
+ * init.c (build_new_1): Disallow placement new with
+ extern "Java" aggregates.
+
2007-11-23 Mark Mitchell <mark@codesourcery.com>
Manuel Lopez-Ibanez <manu@gcc.gnu.org>
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 758d95b..f020c27 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -5468,6 +5468,20 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
is *not* defined. */
&& (!DECL_EXTERNAL (decl) || init))
{
+ if (TYPE_FOR_JAVA (type) && IS_AGGR_TYPE (type))
+ {
+ tree jclass
+ = IDENTIFIER_GLOBAL_VALUE (get_identifier ("jclass"));
+ /* Allow libjava/prims.cc define primitive classes. */
+ if (init != NULL_TREE
+ || jclass == NULL_TREE
+ || TREE_CODE (jclass) != TYPE_DECL
+ || !POINTER_TYPE_P (TREE_TYPE (jclass))
+ || !same_type_ignoring_top_level_qualifiers_p
+ (type, TREE_TYPE (TREE_TYPE (jclass))))
+ error ("Java object %qD not allocated with %<new%>", decl);
+ init = NULL_TREE;
+ }
if (init)
{
DECL_NONTRIVIALLY_INITIALIZED_P (decl) = 1;
@@ -5538,6 +5552,9 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
else if (TREE_CODE (type) == ARRAY_TYPE)
layout_type (type);
}
+ else if (TREE_CODE (decl) == FIELD_DECL
+ && TYPE_FOR_JAVA (type) && IS_AGGR_TYPE (type))
+ error ("non-static data member %qD has Java class type", decl);
/* Add this declaration to the statement-tree. This needs to happen
after the call to check_initializer so that the DECL_EXPR for a
@@ -9328,6 +9345,16 @@ grokparms (cp_parameter_declarator *first_parm, tree *parms)
TREE_TYPE (decl) = error_mark_node;
}
+ if (type != error_mark_node
+ && TYPE_FOR_JAVA (type)
+ && IS_AGGR_TYPE (type))
+ {
+ error ("parameter %qD has Java class type", decl);
+ type = error_mark_node;
+ TREE_TYPE (decl) = error_mark_node;
+ init = NULL_TREE;
+ }
+
if (type != error_mark_node)
{
/* Top-level qualifiers on the parameters are
@@ -10914,11 +10941,15 @@ check_function_type (tree decl, tree current_function_parms)
if (dependent_type_p (return_type))
return;
- if (!COMPLETE_OR_VOID_TYPE_P (return_type))
+ if (!COMPLETE_OR_VOID_TYPE_P (return_type)
+ || (TYPE_FOR_JAVA (return_type) && IS_AGGR_TYPE (return_type)))
{
tree args = TYPE_ARG_TYPES (fntype);
- error ("return type %q#T is incomplete", return_type);
+ if (!COMPLETE_OR_VOID_TYPE_P (return_type))
+ error ("return type %q#T is incomplete", return_type);
+ else
+ error ("return type has Java class type %q#T", return_type);
/* Make it return void instead. */
if (TREE_CODE (fntype) == METHOD_TYPE)
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index c5c17b1..202f3b6 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -1786,6 +1786,11 @@ build_new_1 (tree placement, tree type, tree nelts, tree init,
(alloc_fn,
build_tree_list (NULL_TREE, class_addr)));
}
+ else if (TYPE_FOR_JAVA (elt_type))
+ {
+ error ("Java class %q#T object allocated using placement new", elt_type);
+ return error_mark_node;
+ }
else
{
tree fnname;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 5e5578d..6bd778a 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2007-11-23 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/30293
+ PR c++/30294
+ * g++.dg/ext/java-2.C: New test.
+
2007-11-23 Mark Mitchell <mark@codesourcery.com>
Manuel Lopez-Ibanez <manu@gcc.gnu.org>
diff --git a/gcc/testsuite/g++.dg/ext/java-2.C b/gcc/testsuite/g++.dg/ext/java-2.C
new file mode 100644
index 0000000..4015f00
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/java-2.C
@@ -0,0 +1,79 @@
+// PR c++/30293
+// PR c++/30294
+// { dg-do compile }
+// { dg-options "" }
+
+extern "Java" {
+typedef __java_byte jbyte;
+namespace java {
+namespace lang {
+ class Object {};
+ class Class {};
+}
+}
+typedef struct java::lang::Object* jobject;
+typedef java::lang::Class *jclass;
+}
+extern "C" jobject _Jv_AllocObject (jclass);
+
+extern "Java" {
+ struct A { static java::lang::Class class$; };
+}
+
+struct B {
+ A a; // { dg-error "has Java class type" }
+};
+
+void* operator new (__SIZE_TYPE__, void*) throw();
+char buf[1024];
+
+A a; // { dg-error "not allocated with" }
+A b = A (); // { dg-error "not allocated with" }
+A *c = new ((void *) buf) A (); // { dg-error "using placement new" }
+A *d = new A ();
+jbyte e = 6;
+
+const A fn1 () // { dg-error "return type has Java class type" }
+{
+ A a; // { dg-error "not allocated with" }
+ return a;
+}
+
+A fn2 () // { dg-error "return type has Java class type" }
+{
+ A a; // { dg-error "not allocated with" }
+ return a;
+}
+
+A *fn3 ()
+{
+ return new A ();
+}
+
+A &fn4 ()
+{
+ return *c;
+}
+
+jbyte fn5 ()
+{
+ return 7;
+}
+
+void fn6 (A x) // { dg-error "has Java class type" }
+{
+}
+
+void fn7 (const A x) // { dg-error "has Java class type" }
+{
+}
+
+void fn8 (A *x)
+{
+ (void) x;
+}
+
+void fn9 (jbyte x)
+{
+ (void) x;
+}