Fix array sizes created by Java FE (PR libgcj/57074)

Submitted by Jakub Jelinek on May 3, 2013, 5:10 p.m.


Message ID
State New
Headers show

Commit Message

Jakub Jelinek May 3, 2013, 5:10 p.m.

As discovered by Alan Modra, the GCJ FE sometimes emits VAR_DECLs
that have smaller DECL_SIZE (and TYPE_SIZE (TREE_TYPE ())) than the
size of their initializers.  I went through all build_constructor
calls in the java FE and it seems only these two spots are problematic,
they keep using arrays with one_elt_array_domain_type domain
(which is one_elt_array_domain_type = build_index_type (integer_one_node);
so practically two element array rather than one element, <min 0>, <max 1>,
is that on purpose?), but the initializers can have more (or even fewer than
the two?, dunno about that) elements.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, but
not tested on powerpc32 where it actually caused runtime issues, can
somebody please try it there?  Ok for trunk/4.8?

2013-05-03  Jakub Jelinek  <>

	PR libgcj/57074
	* class.c (emit_symbol_table): Use array type of the
	right size for the_syms_decl and its DECL_INITIAL, instead
	of symbols_array_type.  Set TREE_TYPE (the_syms_decl) to it.
	(emit_assertion_table): Use array type of the right size
	for table_decl and its DECL_INITIAL.



Alan Modra May 4, 2013, 12:24 a.m.
Here's a smaller case that shows the same problem

/home/amodra/build/gcc-current/./gcc/jc1 /home/amodra/src/gcc-current/libjava/classpath/lib/gnu/java/awt/dnd/peer/gtk/GtkDragSourceContextPeer.class -fhash-synchronization -fuse-divide-subroutine -fuse-boehm-gc -fnon-call-exceptions -fPIC -fkeep-inline-functions -msecure-plt -quiet -dumpbase GtkDragSourceContextPeer.class -m64 -auxbase-strip xxx.o -g -O2 -Wno-deprecated -version -fencoding=UTF-8 -fbootstrap-classes -fsource-filename=/home/amodra/build/gcc-current/powerpc-linux/64/libjava/classpath/lib/classes -fjni -findirect-dispatch -fno-indirect-classes -fPIC -fbootclasspath=./:/home/amodra/src/gcc-current/libjava/classpath/lib/ -o GtkDragSourceContextPeer.s

Patch hide | download patch | download mbox

--- gcc/java/class.c.jj	2013-01-11 09:02:30.000000000 +0100
+++ gcc/java/class.c	2013-05-02 20:38:13.848886817 +0200
@@ -2958,9 +2958,13 @@  emit_symbol_table (tree name, tree the_t
-  table = build_constructor (symbols_array_type, v);
+  tree symbols_arr_type
+    = build_prim_array_type (symbol_type, vec_safe_length (v));
+  table = build_constructor (symbols_arr_type, v);
   /* Make it the initial value for otable_syms and emit the decl. */
+  TREE_TYPE (the_syms_decl) = symbols_arr_type;
   DECL_INITIAL (the_syms_decl) = table;
   DECL_ARTIFICIAL (the_syms_decl) = 1;
   DECL_IGNORED_P (the_syms_decl) = 1;
@@ -3109,12 +3114,15 @@  emit_assertion_table (tree klass)
+  tree type
+    = build_prim_array_type (assertion_entry_type, vec_safe_length (v));
-  ctor = build_constructor (assertion_table_type, v);
+  ctor = build_constructor (type, v);
   table_decl = build_decl (input_location,
 			   VAR_DECL, mangled_classname ("_type_assert_", klass),
-			   assertion_table_type);
+			   type);
   TREE_STATIC (table_decl) = 1;
   TREE_READONLY (table_decl) = 1;