Re: [C++ Patch, Java related/RFC] PR 11006

2013-11-06 Thread Andrew Haley
On 11/04/2013 05:21 PM, Jason Merrill wrote:
 Surely it should be valid to allocate a Java boolean type.  Andrew,
 how should that work?

It's not allowed.  All objects that are allocated by new must be of
class type (i.e.  instances of a subclass of java.lang.Object), but
boolean is a primitive type.

Andrew.


Re: [C++ Patch, Java related/RFC] PR 11006

2013-11-06 Thread Jason Merrill

On 11/06/2013 05:42 AM, Andrew Haley wrote:

On 11/04/2013 05:21 PM, Jason Merrill wrote:

Surely it should be valid to allocate a Java boolean type.  Andrew,
how should that work?


It's not allowed.  All objects that are allocated by new must be of
class type (i.e.  instances of a subclass of java.lang.Object), but
boolean is a primitive type.


In that case, Paolo's first patch is OK.

Jason



[C++ Patch, Java related/RFC] PR 11006

2013-11-04 Thread Paolo Carlini

Hi,

we have got this very old bug, where we ICE in build_java_class_ref 
because TYPE is an INTEGER_TYPE and we try to use TYPE_FIELDS on it. 
Shall we apply something like the below and resolve it for good? 
Alternately, we could maybe provide the same message we currently 
provide in release-builds, when we get to:


if (!field)
  {
error (can%'t find %class$% in %qT, type);
return error_mark_node;
  }

Thanks!
Paolo.

//

Index: cp/init.c
===
--- cp/init.c   (revision 204353)
+++ cp/init.c   (working copy)
@@ -2461,9 +2461,16 @@ build_new_1 (vectree, va_gc **placement, tree ty
   if (vec_safe_is_empty (*placement)  TYPE_FOR_JAVA (elt_type))
 {
   tree class_addr;
-  tree class_decl = build_java_class_ref (elt_type);
+  tree class_decl;
   static const char alloc_name[] = _Jv_AllocObject;
 
+  if (!MAYBE_CLASS_TYPE_P (elt_type))
+   {
+ error (%qT isn%'t a valid Java class type, elt_type);
+ return error_mark_node;
+   }
+
+  class_decl = build_java_class_ref (elt_type);
   if (class_decl == error_mark_node)
return error_mark_node;
 
Index: testsuite/g++.dg/other/java3.C
===
--- testsuite/g++.dg/other/java3.C  (revision 0)
+++ testsuite/g++.dg/other/java3.C  (working copy)
@@ -0,0 +1,7 @@
+// PR c++/11006
+
+typedef int* jclass;
+
+void foo () {
+  new __java_boolean;  // { dg-error valid }
+}


Re: [C++ Patch, Java related/RFC] PR 11006

2013-11-04 Thread Jason Merrill
Surely it should be valid to allocate a Java boolean type.  Andrew, how 
should that work?


Jason


Re: [C++ Patch, Java related/RFC] PR 11006

2013-11-04 Thread Paolo Carlini

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;
}