This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [patch] Java definite assignment


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/

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]