This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch] Java definite assignment
- To: Mo DeJong <mdejong at cygnus dot com>
- Subject: Re: [patch] Java definite assignment
- From: Per Bothner <per at bothner dot com>
- Date: 06 Feb 2001 12:11:31 -0800
- Cc: gcc-patches at gcc dot gnu dot org, java at gcc dot gnu dot org
- References: <Pine.SOL.3.91.1010206095207.18644E-100000@cse.cygnus.com>
Mo DeJong <mdejong@cygnus.com> writes:
> tcltest::test non-const-1 { for + if with nonconst variable,
> this should fail since we can't know at compile time
> that b is true } {
> empty_main NC1 {
> int i;
> boolean b = true;
> for (;;) {
> if (b) {
> i = 0;
> break;
> }
> }
> i++;
> }
>
> } FAIL
This should succeed. The value of b is irrelevant. The point
is that *if* control reaches the i++, then we know that i has
definitely been assigned to. *Whether* control reaches the i++
is a completely separate issue, a matter of unreachable
statements, specified in a separate part of the JLS.
> tcltest::test non-const-2 { for + if with nonconst variable,
> this should fail since we can't know at compile time
> that b is true } {
> empty_main NC2 {
> int i;
> boolean b = false;
> for (;;) {
> if (b) {
> i = 0;
> break;
> }
> }
> i++;
> }
>
> } FAIL
Likewise.
> ==== false-1 for loop + if + break FAILED
> ==== Contents of test case:
>
> empty_main F1 {
> int i;
> for (;;) {
> if (false) {
> i = 0;
> break;
> }
> }
> i++;
> }
>
> ---- Result was:
> PASS
> ---- Result should have been:
> FAIL
This should also pass. Superficially, it looks like this should fail
as an "unreachale statement" (*not* lack of definite assignment),
but there is a special rule for if(false)... See page 298 of the JLS
(1st edition).
> ==== non-const-1 for + if with nonconst variable,
> this should fail since we can't know at compile time
> that b is true FAILED
> ==== Contents of test case:
>
> empty_main NC1 {
> int i;
> boolean b = true;
> for (;;) {
> if (b) {
> i = 0;
> break;
> }
> }
> i++;
> }
>
>
> ---- Result was:
> PASS
> ---- Result should have been:
> FAIL
This should be PASS.
> ==== non-const-1 FAILED
>
> ==== non-const-2 for + if with nonconst variable,
> this should fail since we can't know at compile time
> that b is true FAILED
> ==== Contents of test case:
>
> empty_main NC2 {
> int i;
> boolean b = false;
> for (;;) {
> if (b) {
> i = 0;
> break;
> }
> }
> i++;
> }
>
>
> ---- Result was:
> PASS
> ---- Result should have been:
> FAIL
Likewise should be PASS.
> At this point, I would advise against adding
> that patch.
At this point, I advise fixing the testsuite.
--
--Per Bothner
per@bothner.com http://www.bothner.com/~per/