This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[gcjx] Definite Assignment Fix
- From: Ranjit Mathew <rmathew at gmail dot com>
- To: java-patches at gcc dot gnu dot org
- Date: Sat, 17 Sep 2005 13:55:51 +0530
- Subject: [gcjx] Definite Assignment Fix
- Openpgp: url=http://ranjitmathew.hostingzero.com/aa_6C114B8F.txt
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
This patch corrects a minor error in variable_state::check_loop()
that was exposed by a couple of Jacks tests. As explained in the
beginning of Chapter 16 of the JLS (page 531 in the JLS3 PDF), we
can conclusively state that an assignment to a variable has occurred
only if it is both definitely assigned and not definitely unassigned.
The method was only checking for the latter.
I found the print() method handy for debugging but it had a couple
of minor problems - it used to print all variables without information
on whether a variable is definitely [un]assigned and it was not a
const method (using const iterators) and was thus ununsable with a
"const variable_state& other". The attached patch also includes a
fix for these.
The net effect of this patch on my Jacks run is:
@@ -48,2 +47,0 @@
-RESULT 16.2.10-definite-unassign-pass-3 FAILED
-RESULT 16.2.11-definite-unassign-pass-3 FAILED
@@ -62 +59,0 @@
-RESULT 16.2.9-definite-unassign-pass-3 FAILED
@@ -252,3 +249,6 @@
-RESULT non-jls-jsr41.4-loop-1 FAILED
-RESULT non-jls-jsr41.4-loop-2 FAILED
-RESULT non-jls-jsr41.4-loop-3 FAILED
+RESULT non-jls-jsr41.4-loop-16 FAILED
+RESULT non-jls-jsr41.4-loop-17 FAILED
+RESULT non-jls-jsr41.4-loop-18 FAILED
+RESULT non-jls-jsr41.4-loop-4 FAILED
+RESULT non-jls-jsr41.4-loop-5 FAILED
+RESULT non-jls-jsr41.4-loop-6 FAILED
The new FAILs are the exposure of a problem with boolean expressions
like "foo && false", which I plan to tackle next.
OK?
Thanks,
Ranjit
- --
Ranjit Mathew Email: rmathew AT gmail DOT com
Bangalore, INDIA. Web: http://ranjitmathew.hostingzero.com/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFDK9MOYb1hx2wRS48RAi2sAKCTqNaU1A+1ZFYSKQLEyue6kUfpegCfQDNl
o6b7KCbeSB2s9dqP/Qt48Ac=
=v+35
-----END PGP SIGNATURE-----
Index: ChangeLog
from Ranjit Mathew <rmathew@gcc.gnu.org>
* defassign.cc (variable_state::check_loop): Complain about possible
multiple assignments only if the variable in question is definitely
assigned and not definitely unassigned.
(variable_state::print): Make const method and use const iterators.
Print out only definitely [un]assigned variables.
Index: defassign.cc
===================================================================
--- defassign.cc 2005-09-17 10:06:59.000000000 +0530
+++ defassign.cc 2005-09-17 13:32:44.000000000 +0530
@@ -170,8 +170,9 @@ public:
// Perform checking after a loop completes. THIS is the state
// before the loop. OTHER is the state after the loop. Look for
- // final variables which are not definitely unassigned in OTHER but
- // are definitely unassigned here and issue errors for them.
+ // final variables which are definitely assigned and not definitely
+ // unassigned in OTHER but are definitely unassigned here and issue
+ // errors for them.
void check_loop (model_element *request, const variable_state &other)
{
for (map_type::const_iterator i = other.unassign.begin ();
@@ -180,9 +181,9 @@ public:
{
if ((*i).first->final_p () && ! (*i).second)
{
- if (unassigned_p ((*i).first))
+ if (other.assigned_p ((*i).first) && unassigned_p ((*i).first))
{
- std::cerr << request->error ("variable %1 may be assigned "
+ std::cerr << request->error ("variable %1 might be assigned "
"multiple times")
// FIXME: need operator% for this.
% (*i).first->get_name ();
@@ -191,18 +192,23 @@ public:
}
}
- /// For debugging convenience.
- void print ()
+ /// For debugging convenience. Prints the definitely [un]assigned
+ /// variables in this state.
+ void print (void) const
{
std::cout << "================" << std::endl;
- for (map_type::iterator i = assign.begin ();
+
+ for (map_type::const_iterator i = assign.begin ();
i != assign.end ();
++i)
- std::cout << "assigned: " << (*i).first->get_name () << std::endl;
- for (map_type::iterator i = unassign.begin ();
+ if ((*i).second)
+ std::cout << "assigned: " << (*i).first->get_name () << std::endl;
+
+ for (map_type::const_iterator i = unassign.begin ();
i != unassign.end ();
++i)
- std::cout << "unassigned: " << (*i).first->get_name () << std::endl;
+ if ((*i).second)
+ std::cout << "unassigned: " << (*i).first->get_name () << std::endl;
}
};