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

[Bug java/15525] suggestion to enable cast elimination


------- Additional Comments From tromey at gcc dot gnu dot org  2005-05-01 00:57 -------
There are a couple more cases where explicit casts can be eliminated.

Code like this will introduce an unneeded cast:

   Object o = "something";
   String s = (String) o;

Of course this is the simplest possible case; I don't know whether
this occurs in real code or not.


Another case is rearranging an array:

   Object[] array = something();
   array[0] = array[1];

This will generate a call to check whether the array can hold the
object, due to the special role arrays play in the type system;
for example this is valid but throws an exception at runtime:

   String[] sarray = ...;
   Object[] oarray = sarray;
   oarray[0] = new Integer(5);

... because Integer can't be cast to String.
In the first array example, we know that the check can be
eliminated because the rhs of the assignment comes from the
same array.

Currently we emit calls to _Jv_CheckArrayStore for this situation.
While we could inline it (making the type check explicit and allowing
elimination in the style of the other parts of this PR), size of the generated
code might be a concern.

Sometimes the precise type of an array is known, for instance if it
is the result of a 'new'.  In this case it would be nice to be able
to eliminate even more checks.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15525


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