On 11/04/2013 06:21 PM, Jason Merrill wrote:
Surely it should be valid to allocate a Java boolean type. Andrew, how should that work?
Thanks. The problem we are facing (assuming we want to resolve this old isue) is that something seems seriously broken for the builtin Java types as declared in record_builtin_java_type, not just __java_boolean: all of them are just INTEGER_TYPEs or FLOAT_TYPEs. I'm wondering if we should special case the mangling for those in build_java_class_ref, something morally like the below. Then the testcase doesn't ICE anymore and if we add some missing declarations (definitely a _Jv_AllocObject) it even "compiles". But my knowledge of Java is extremely weak, I have no idea how this is going to work.

Paolo.

/////////////////////
Index: init.c
===================================================================
--- init.c      (revision 204355)
+++ init.c      (working copy)
@@ -3068,22 +3068,29 @@ build_java_class_ref (tree type)
       jclass_node = TREE_TYPE (jclass_node);
     }
 
-  /* Mangle the class$ field.  */
-  {
-    tree field;
-    for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
-      if (DECL_NAME (field) == CL_suffix)
+  if (MAYBE_CLASS_TYPE_P (type))
+    {
+      /* Mangle the class$ field.  */
+      tree field;
+      for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
+       if (DECL_NAME (field) == CL_suffix)
+         {
+           mangle_decl (field);
+           name = DECL_ASSEMBLER_NAME (field);
+           break;
+         }
+      if (!field)
        {
-         mangle_decl (field);
-         name = DECL_ASSEMBLER_NAME (field);
-         break;
+         error ("can%'t find %<class$%> in %qT", type);
+         return error_mark_node;
        }
-    if (!field)
-      {
-       error ("can%'t find %<class$%> in %qT", type);
-       return error_mark_node;
-      }
-  }
+    }
+  else
+    {
+      /* Standard Java types per record_builtin_java_type.  */
+      mangle_decl (TYPE_NAME (type));
+      name = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
+    }
 
   class_decl = IDENTIFIER_GLOBAL_VALUE (name);
   if (class_decl == NULL_TREE)
extern "Java"
{
  namespace java
  {
    namespace lang
    {
      class Class;
      class Object;
    }
  }
}

typedef struct java::lang::Object* jobject;
typedef class java::lang::Class* jclass;

extern "C" jobject _Jv_AllocObject (jclass) __attribute__((__malloc__));

void foo () {
  new __java_boolean;
}

Reply via email to