This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: RFC - PR java/8608: ICE if WFL not yet set in check_init()
- From: Per Bothner <per at bothner dot com>
- To: Per Bothner <per at bothner dot com>
- Cc: Ranjit Mathew <rmathew at gmail dot com>, GCJ Patches <java-patches at gcc dot gnu dot org>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 12 Feb 2005 10:35:45 -0800
- Subject: Re: RFC - PR java/8608: ICE if WFL not yet set in check_init()
- References: <420A1060.5020901@gmail.com> <420A7AB7.8040504@bothner.com> <420DA1EE.101@bothner.com>
Here's a suggested patch. It's actually quite a simplification,
and brings us forward in phasing out parse_error_context and
"wfl" objects. Furthermore, it narrows down the error location
by setting input_location for each incoming expression. This
only seems to work for --enable-mapped-location, but in that
case I get:
./jc1 /tmp/Foo.java -quiet -o /tmp/Foo.s
/tmp/Foo.java: In class 'Foo':
/tmp/Foo.java: In method 'Foo.bar()':
/tmp/Foo.java:7:10: error: variable ‘a’ may not have been initialized
In the default case I get:
/tmp/Foo.java: In class 'Foo':
/tmp/Foo.java: In method 'Foo.bar()':
/tmp/Foo.java:4: error: variable ‘a’ may not have been initialized
The reason we're getting line 4 instead of line 7 is probably for
the same reason we're got an ICE in the first place: We need to
annotate the 'for' statement with a line number. But that's a
problem for another day.
To get the column numbers requires a small patch to
diagnostic_build_prefix, which may be inappropriate for 4.0.
I'll post that patch shortly - at least I'd like to get it
pre-approved for when mainline opens up for development.
A downside to this patch is that we might lose column number
information in the short term (i.e. until USE_MAPPED_LOCATION
becomes the default) for these errors. Personally, I think it's
worth it for the simplification, and for not having to change
the code after the branch, but I can be convinced otherwise.
There were no testsuite regressions with an earlier version
of this patch, but since I changed things slightlty I'll have
to re-run the testsuite before a check-in.
--
--Per Bothner
per@bothner.com http://per.bothner.com/
2005-02-12 Per Bothner <per@bothner.com>
PR java/8608
* check-init.c (wfl): Remove static.
(final_assign_error, check_init): Replace calls to parse_error_context
by plain error.
(check_init): Save, set, and restore input_location for each exp.
Index: check-init.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/check-init.c,v
retrieving revision 1.63
diff -u -p -r1.63 check-init.c
--- check-init.c 10 Jan 2005 18:01:04 -0000 1.63
+++ check-init.c 12 Feb 2005 17:53:22 -0000
@@ -77,8 +77,6 @@ static int start_current_locals = 0;
static int num_current_words;
-static tree wfl;
-
#define COPYN(DST, SRC, NWORDS) memcpy (DST, SRC, NWORDS * sizeof(word))
#define COPY(DST, SRC) COPYN (DST, SRC, num_current_words)
@@ -247,9 +245,8 @@ get_variable_decl (tree exp)
static void
final_assign_error (tree name)
{
- parse_error_context (wfl,
- "Can't reassign a value to the final variable %qs",
- IDENTIFIER_POINTER (name));
+ error ("Can't reassign a value to the final variable %qs",
+ IDENTIFIER_POINTER (name));
}
static void
@@ -501,7 +498,10 @@ static void
check_init (tree exp, words before)
{
tree tmp;
+ location_t save_location = input_location;
again:
+ if (EXPR_HAS_LOCATION (exp))
+ input_location = EXPR_LOCATION (exp);
switch (TREE_CODE (exp))
{
case VAR_DECL:
@@ -515,10 +515,7 @@ check_init (tree exp, words before)
if (! LOCAL_CLASS_INITIALIZATION_FLAG_P (exp)
&& index >= 0 && ! ASSIGNED_P (before, index))
{
- parse_error_context
- (wfl, "Variable %qs may not have been initialized",
- IDENTIFIER_POINTER (DECL_NAME (exp)));
- /* Suppress further errors. */
+ error ("variable %qD may not have been initialized", exp);
DECL_BIT_INDEX (exp) = -2;
}
}
@@ -531,9 +528,7 @@ check_init (tree exp, words before)
int index = DECL_BIT_INDEX (tmp);
if (index >= 0 && ! ASSIGNED_P (before, index))
{
- parse_error_context
- (wfl, "variable %qs may not have been initialized",
- IDENTIFIER_POINTER (DECL_NAME (tmp)));
+ error ("variable %qD may not have been initialized", tmp);
/* Suppress further errors. */
DECL_BIT_INDEX (tmp) = -2;
}
@@ -669,7 +664,7 @@ check_init (tree exp, words before)
END_ALTERNATIVES (before, alt);
loop_current_locals = save_loop_current_locals;
start_current_locals = save_start_current_locals;
- return;
+ break;
}
case EXIT_EXPR:
{
@@ -684,7 +679,7 @@ check_init (tree exp, words before)
done_alternative (when_true, alt);
COPY (before, when_false);
RELEASE_BUFFERS(when_true);
- return;
+ break;
}
case LABELED_BLOCK_EXPR:
{
@@ -695,7 +690,7 @@ check_init (tree exp, words before)
check_init (LABELED_BLOCK_BODY (exp), before);
done_alternative (before, &alt);
END_ALTERNATIVES (before, alt);
- return;
+ break;
}
case EXIT_BLOCK_EXPR:
{
@@ -705,7 +700,7 @@ check_init (tree exp, words before)
alt = alt->outer;
done_alternative (before, alt);
SET_ALL (before);
- return;
+ break;
}
case SWITCH_EXPR:
{
@@ -722,7 +717,7 @@ check_init (tree exp, words before)
done_alternative (alt.saved, &alt);
FREE_BUFFER(alt.saved, buf);
END_ALTERNATIVES (before, alt);
- return;
+ break;
}
case CASE_EXPR:
case DEFAULT_EXPR:
@@ -764,7 +759,7 @@ check_init (tree exp, words before)
}
END_ALTERNATIVES (before, alt);
}
- return;
+ break;
case TRY_FINALLY_EXPR:
{
@@ -775,7 +770,7 @@ check_init (tree exp, words before)
UNION (before, before, tmp);
RELEASE_BUFFERS(tmp);
}
- return;
+ break;
case RETURN_EXPR:
case THROW_EXPR:
@@ -786,7 +781,7 @@ check_init (tree exp, words before)
case ERROR_MARK:
never_continues:
SET_ALL (before);
- return;
+ break;
case COND_EXPR:
case TRUTH_ANDIF_EXPR:
@@ -848,7 +843,7 @@ check_init (tree exp, words before)
case SAVE_EXPR:
if (IS_INIT_CHECKED (exp))
- return;
+ break;
IS_INIT_CHECKED (exp) = 1;
exp = TREE_OPERAND (exp, 0);
goto again;
@@ -932,11 +927,9 @@ check_init (tree exp, words before)
case EXPR_WITH_FILE_LOCATION:
{
location_t saved_location = input_location;
- tree saved_wfl = wfl;
tree body = EXPR_WFL_NODE (exp);
if (IS_EMPTY_STMT (body))
break;
- wfl = exp;
#ifdef USE_MAPPED_LOCATION
input_location = EXPR_LOCATION (exp);
#else
@@ -945,7 +938,6 @@ check_init (tree exp, words before)
#endif
check_init (body, before);
input_location = saved_location;
- wfl = saved_wfl;
}
break;
@@ -954,6 +946,7 @@ check_init (tree exp, words before)
("internal error in check-init: tree code not implemented: %s",
tree_code_name [(int) TREE_CODE (exp)]);
}
+ input_location = save_location;
}
void