aboutsummaryrefslogtreecommitdiff
path: root/gcc/java
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2001-12-20 17:45:41 +0000
committerTom Tromey <tromey@gcc.gnu.org>2001-12-20 17:45:41 +0000
commit56b8325e5b1c5237547295a1d1b58bba91adac5a (patch)
treef0980b19ce3c384cbedaa0f02606745a4c8b12b2 /gcc/java
parent82af613ff3d8b809dc30ab61b1e6183039e36567 (diff)
downloadgcc-56b8325e5b1c5237547295a1d1b58bba91adac5a.zip
gcc-56b8325e5b1c5237547295a1d1b58bba91adac5a.tar.gz
gcc-56b8325e5b1c5237547295a1d1b58bba91adac5a.tar.bz2
re PR java/3417 (Downcast on integral types.)
Fix for PR java/3417: * parse.y (patch_assignment): Added special processing for `return'. (patch_return): Don't convert booleans to integers, and don't special-case `null'. From-SVN: r48208
Diffstat (limited to 'gcc/java')
-rw-r--r--gcc/java/ChangeLog8
-rw-r--r--gcc/java/parse.y31
2 files changed, 25 insertions, 14 deletions
diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog
index 9c8bfb9..9c738dc 100644
--- a/gcc/java/ChangeLog
+++ b/gcc/java/ChangeLog
@@ -1,3 +1,11 @@
+2001-12-20 Tom Tromey <tromey@redhat.com>
+
+ Fix for PR java/3417:
+ * parse.y (patch_assignment): Added special processing for
+ `return'.
+ (patch_return): Don't convert booleans to integers, and don't
+ special-case `null'.
+
2001-12-20 Joseph S. Myers <jsm28@cam.ac.uk>
* config-lang.in (diff_excludes): Remove.
diff --git a/gcc/java/parse.y b/gcc/java/parse.y
index 87e65e9..47fcd73 100644
--- a/gcc/java/parse.y
+++ b/gcc/java/parse.y
@@ -12526,6 +12526,7 @@ patch_assignment (node, wfl_op1)
tree lhs_type = NULL_TREE, rhs_type, new_rhs = NULL_TREE;
int error_found = 0;
int lvalue_from_array = 0;
+ int is_return = 0;
EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
@@ -12546,7 +12547,15 @@ patch_assignment (node, wfl_op1)
lhs_type = TREE_TYPE (lvalue);
/* Or a function return slot */
else if (TREE_CODE (lvalue) == RESULT_DECL)
- lhs_type = TREE_TYPE (lvalue);
+ {
+ /* If the return type is an integral type, then we create the
+ RESULT_DECL with a promoted type, but we need to do these
+ checks against the unpromoted type to ensure type safety. So
+ here we look at the real type, not the type of the decl we
+ are modifying. */
+ lhs_type = TREE_TYPE (TREE_TYPE (current_function_decl));
+ is_return = 1;
+ }
/* Otherwise, we might want to try to write into an optimized static
final, this is an of a different nature, reported further on. */
else if (TREE_CODE (wfl_op1) == EXPR_WITH_FILE_LOCATION
@@ -12561,6 +12570,7 @@ patch_assignment (node, wfl_op1)
}
rhs_type = TREE_TYPE (rhs);
+
/* 5.1 Try the assignment conversion for builtin type. */
new_rhs = try_builtin_assignconv (wfl_op1, lhs_type, rhs);
@@ -12598,7 +12608,7 @@ patch_assignment (node, wfl_op1)
wfl = wfl_operator;
if (COMPOUND_ASSIGN_P (TREE_OPERAND (node, 1)))
strcpy (operation, "assignment");
- else if (TREE_CODE (TREE_OPERAND (node, 0)) == RESULT_DECL)
+ else if (is_return)
strcpy (operation, "`return'");
else
strcpy (operation, "`='");
@@ -12618,6 +12628,11 @@ patch_assignment (node, wfl_op1)
if (error_found)
return error_mark_node;
+ /* If we're processing a `return' statement, promote the actual type
+ to the promoted type. */
+ if (is_return)
+ new_rhs = convert (TREE_TYPE (lvalue), new_rhs);
+
/* 10.10: Array Store Exception runtime check */
if (!flag_emit_class_files
&& !flag_emit_xref
@@ -14646,18 +14661,6 @@ patch_return (node)
tree exp = java_complete_tree (return_exp);
tree modify, patched;
- /* If the function returned value and EXP are booleans, EXP has
- to be converted into the type of DECL_RESULT, which is integer
- (see complete_start_java_method) */
- if (TREE_TYPE (exp) == boolean_type_node &&
- TREE_TYPE (TREE_TYPE (meth)) == boolean_type_node)
- exp = convert_to_integer (TREE_TYPE (DECL_RESULT (meth)), exp);
-
- /* `null' can be assigned to a function returning a reference */
- if (JREFERENCE_TYPE_P (TREE_TYPE (TREE_TYPE (meth))) &&
- exp == null_pointer_node)
- exp = build_null_of_type (TREE_TYPE (TREE_TYPE (meth)));
-
if ((patched = patch_string (exp)))
exp = patched;