View | Details | Raw Unified | Return to bug 15525
Collapse All | Expand All

(-)decl.c (-4 / +5 lines)
Lines 920-926 Link Here
920
  TREE_THIS_VOLATILE (throw_node) = 1;
920
  TREE_THIS_VOLATILE (throw_node) = 1;
921
  TREE_SIDE_EFFECTS (throw_node) = 1;
921
  TREE_SIDE_EFFECTS (throw_node) = 1;
922
922
923
  t = build_function_type (int_type_node, endlink);
923
  t = build_function_type (void_type_node, endlink);
924
  soft_monitorenter_node 
924
  soft_monitorenter_node 
925
    = builtin_function ("_Jv_MonitorEnter", t, 0, NOT_BUILT_IN,
925
    = builtin_function ("_Jv_MonitorEnter", t, 0, NOT_BUILT_IN,
926
			NULL, NULL_TREE);
926
			NULL, NULL_TREE);
Lines 974-983 Link Here
974
  TREE_THIS_VOLATILE (soft_nullpointer_node) = 1;
974
  TREE_THIS_VOLATILE (soft_nullpointer_node) = 1;
975
  TREE_SIDE_EFFECTS (soft_nullpointer_node) = 1;
975
  TREE_SIDE_EFFECTS (soft_nullpointer_node) = 1;
976
976
977
  t = tree_cons (NULL_TREE, class_ptr_type,
977
  t = tree_cons (NULL_TREE, void_type_node,
978
		 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
978
		 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
979
  soft_checkcast_node
979
  soft_throwcast_node
980
    = builtin_function ("_Jv_CheckCast",
980
    = builtin_function ("_Jv_ThrowCast",
981
			build_function_type (ptr_type_node, t),
981
			build_function_type (ptr_type_node, t),
982
			0, NOT_BUILT_IN, NULL, NULL_TREE);
982
			0, NOT_BUILT_IN, NULL, NULL_TREE);
983
  t = tree_cons (NULL_TREE, object_ptr_type_node,
983
  t = tree_cons (NULL_TREE, object_ptr_type_node,
Lines 986-991 Link Here
986
    = builtin_function ("_Jv_IsInstanceOf",
986
    = builtin_function ("_Jv_IsInstanceOf",
987
			build_function_type (boolean_type_node, t),
987
			build_function_type (boolean_type_node, t),
988
			0, NOT_BUILT_IN, NULL, NULL_TREE);
988
			0, NOT_BUILT_IN, NULL, NULL_TREE);
989
  DECL_IS_PURE (soft_instanceof_node) = 1;
989
  t = tree_cons (NULL_TREE, object_ptr_type_node,
990
  t = tree_cons (NULL_TREE, object_ptr_type_node,
990
		 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
991
		 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
991
  soft_checkarraystore_node
992
  soft_checkarraystore_node
(-)expr.c (-49 / +47 lines)
Lines 1200-1208 Link Here
1200
{
1200
{
1201
  tree expr;
1201
  tree expr;
1202
  tree itype = TREE_TYPE (TREE_TYPE (soft_instanceof_node));
1202
  tree itype = TREE_TYPE (TREE_TYPE (soft_instanceof_node));
1203
  tree valtype = TREE_TYPE (TREE_TYPE (value));
1203
1204
  tree valclass = TYPE_NAME (valtype);
1204
  value = save_expr (value);
1205
  tree klass;
1206
1205
1207
  /* When compiling from bytecode, we need to ensure that TYPE has
1206
  /* When compiling from bytecode, we need to ensure that TYPE has
1208
     been loaded.  */
1207
     been loaded.  */
Lines 1213-1261 Link Here
1213
      if (! TYPE_SIZE (type) || TREE_CODE (TYPE_SIZE (type)) == ERROR_MARK)
1212
      if (! TYPE_SIZE (type) || TREE_CODE (TYPE_SIZE (type)) == ERROR_MARK)
1214
	return error_mark_node;
1213
	return error_mark_node;
1215
    }
1214
    }
1216
  klass = TYPE_NAME (type);
1217
1215
1218
  if (type == object_type_node || inherits_from_p (valtype, type))
1216
  expr = build3 (CALL_EXPR, itype,
1219
    {
1217
		 build_address_of (soft_instanceof_node),
1220
      /* Anything except `null' is an instance of Object.  Likewise,
1218
		 tree_cons (NULL_TREE, value,
1221
	 if the object is known to be an instance of the class, then
1219
			    build_tree_list (NULL_TREE,
1222
	 we only need to check for `null'.  */
1220
					     build_class_ref (type))),
1223
      expr = build2 (NE_EXPR, itype, value, null_pointer_node);
1221
		 NULL_TREE);
1224
    }
1222
  TREE_SIDE_EFFECTS (expr) = TREE_SIDE_EFFECTS (value);
1225
  else if (! TYPE_ARRAY_P (type)
1223
1226
	   && ! TYPE_ARRAY_P (valtype)
1224
  expr = build2 (TRUTH_AND_EXPR, boolean_type_node,
1227
	   && DECL_P (klass) && DECL_P (valclass)
1225
		 build2 (NE_EXPR, boolean_type_node, value, null_pointer_node),
1228
	   && ! CLASS_INTERFACE (valclass)
1226
		 expr);
1229
	   && ! CLASS_INTERFACE (klass)
1230
	   && ! inherits_from_p (type, valtype)
1231
	   && (CLASS_FINAL (klass)
1232
	       || ! inherits_from_p (valtype, type)))
1233
    {
1234
      /* The classes are from different branches of the derivation
1235
	 tree, so we immediately know the answer.  */
1236
      expr = boolean_false_node;
1237
    }
1238
  else if (DECL_P (klass) && CLASS_FINAL (klass))
1239
    {
1240
      tree save = save_expr (value);
1241
      expr = build3 (COND_EXPR, itype,
1242
		     build2 (NE_EXPR, boolean_type_node,
1243
			     save, null_pointer_node),
1244
		     build2 (EQ_EXPR, itype,
1245
			     build_get_class (save),
1246
			     build_class_ref (type)),
1247
		     boolean_false_node);
1248
    }
1249
  else
1250
    {
1251
      expr = build3 (CALL_EXPR, itype,
1252
		     build_address_of (soft_instanceof_node),
1253
		     tree_cons (NULL_TREE, value,
1254
				build_tree_list (NULL_TREE,
1255
						 build_class_ref (type))),
1256
		     NULL_TREE);
1257
    }
1258
  TREE_SIDE_EFFECTS (expr) = TREE_SIDE_EFFECTS (value);
1227
  TREE_SIDE_EFFECTS (expr) = TREE_SIDE_EFFECTS (value);
1228
1259
  return expr;
1229
  return expr;
1260
}
1230
}
1261
1231
Lines 1267-1281 Link Here
1267
  push_value (value);
1237
  push_value (value);
1268
}
1238
}
1269
1239
1240
tree
1241
build_checkcast (tree value, tree type)
1242
{
1243
  tree expr, inst;
1244
1245
  value = save_expr (value);
1246
  expr = build (CALL_EXPR, void_type_node,
1247
		build_address_of (soft_throwcast_node),
1248
		tree_cons (NULL_TREE, build_class_ref (type),
1249
			   build_tree_list (NULL_TREE, value)),
1250
		NULL_TREE);
1251
  TREE_SIDE_EFFECTS (expr) = 1;
1252
1253
  inst = build (CALL_EXPR, boolean_type_node,
1254
		build_address_of (soft_instanceof_node),
1255
		tree_cons (NULL_TREE, value,
1256
			   build_tree_list (NULL_TREE,
1257
					    build_class_ref (type))),
1258
		NULL_TREE);
1259
  TREE_SIDE_EFFECTS (expr) = TREE_SIDE_EFFECTS (value);
1260
1261
  expr = build (COND_EXPR, type,
1262
		build (EQ_EXPR, boolean_type_node, value, null_pointer_node),
1263
		build1 (NOP_EXPR, type, null_pointer_node),
1264
		build (COND_EXPR, type,
1265
		       inst,
1266
		       build1 (NOP_EXPR, type, value),
1267
		       expr));
1268
1269
  return expr;
1270
}
1271
1270
static void
1272
static void
1271
expand_java_CHECKCAST (tree type)
1273
expand_java_CHECKCAST (tree type)
1272
{
1274
{
1273
  tree value = pop_value (ptr_type_node);
1275
  tree value = pop_value (ptr_type_node);
1274
  value = build3 (CALL_EXPR, promote_type (type),
1276
  value = build_checkcast (value, promote_type (type));
1275
		  build_address_of (soft_checkcast_node),
1276
		  tree_cons (NULL_TREE, build_class_ref (type),
1277
			     build_tree_list (NULL_TREE, value)),
1278
		  NULL_TREE);
1279
  push_value (value);
1277
  push_value (value);
1280
}
1278
}
1281
1279
(-)java-tree.h (-5 / +4 lines)
Lines 379-385 Link Here
379
  JTI_ALLOC_OBJECT_NODE,
379
  JTI_ALLOC_OBJECT_NODE,
380
  JTI_ALLOC_NO_FINALIZER_NODE,
380
  JTI_ALLOC_NO_FINALIZER_NODE,
381
  JTI_SOFT_INSTANCEOF_NODE,
381
  JTI_SOFT_INSTANCEOF_NODE,
382
  JTI_SOFT_CHECKCAST_NODE,
382
  JTI_SOFT_THROWCAST_NODE,
383
  JTI_SOFT_INITCLASS_NODE,
383
  JTI_SOFT_INITCLASS_NODE,
384
  JTI_SOFT_NEWARRAY_NODE,
384
  JTI_SOFT_NEWARRAY_NODE,
385
  JTI_SOFT_ANEWARRAY_NODE,
385
  JTI_SOFT_ANEWARRAY_NODE,
Lines 609-616 Link Here
609
  java_global_trees[JTI_SYMBOLS_ARRAY_TYPE]
609
  java_global_trees[JTI_SYMBOLS_ARRAY_TYPE]
610
#define symbols_array_ptr_type \
610
#define symbols_array_ptr_type \
611
  java_global_trees[JTI_SYMBOLS_ARRAY_PTR_TYPE]
611
  java_global_trees[JTI_SYMBOLS_ARRAY_PTR_TYPE]
612
#define class_refs_decl \
613
  Jjava_global_trees[TI_CLASS_REFS_DECL]
614
612
615
#define end_params_node \
613
#define end_params_node \
616
  java_global_trees[JTI_END_PARAMS_NODE]
614
  java_global_trees[JTI_END_PARAMS_NODE]
Lines 624-631 Link Here
624
  java_global_trees[JTI_ALLOC_NO_FINALIZER_NODE]
622
  java_global_trees[JTI_ALLOC_NO_FINALIZER_NODE]
625
#define soft_instanceof_node \
623
#define soft_instanceof_node \
626
  java_global_trees[JTI_SOFT_INSTANCEOF_NODE]
624
  java_global_trees[JTI_SOFT_INSTANCEOF_NODE]
627
#define soft_checkcast_node \
625
#define soft_throwcast_node \
628
  java_global_trees[JTI_SOFT_CHECKCAST_NODE]
626
  java_global_trees[JTI_SOFT_THROWCAST_NODE]
629
#define soft_initclass_node \
627
#define soft_initclass_node \
630
  java_global_trees[JTI_SOFT_INITCLASS_NODE]
628
  java_global_trees[JTI_SOFT_INITCLASS_NODE]
631
#define soft_newarray_node \
629
#define soft_newarray_node \
Lines 1218-1223 Link Here
1218
extern tree java_check_reference (tree, int);
1216
extern tree java_check_reference (tree, int);
1219
extern tree build_get_class (tree);
1217
extern tree build_get_class (tree);
1220
extern tree build_instanceof (tree, tree);
1218
extern tree build_instanceof (tree, tree);
1219
extern tree build_checkcast (tree, tree);
1221
extern tree create_label_decl (tree);
1220
extern tree create_label_decl (tree);
1222
extern void push_labeled_block (tree);
1221
extern void push_labeled_block (tree);
1223
extern tree prepare_eh_table_type (tree);
1222
extern tree prepare_eh_table_type (tree);
(-)parse.y (-5 / +1 lines)
Lines 14243-14253 Link Here
14243
	}
14243
	}
14244
14244
14245
      /* The cast requires a run-time check */
14245
      /* The cast requires a run-time check */
14246
      return build3 (CALL_EXPR, promote_type (cast_type),
14246
      return build_checkcast (op, promote_type (cast_type));
14247
		     build_address_of (soft_checkcast_node),
14248
		     tree_cons (NULL_TREE, build_class_ref (cast_type),
14249
				build_tree_list (NULL_TREE, op)),
14250
		     NULL_TREE);
14251
    }
14247
    }
14252
14248
14253
  /* Any other casts are proven incorrect at compile time */
14249
  /* Any other casts are proven incorrect at compile time */

Return to bug 15525