KeYProject / key

KeY Theorem Prover for Deductive Java Verification
https://key-project.org
Other
41 stars 24 forks source link

Return statements in nested loops cannot be verified #676

Open wadoon opened 1 year ago

wadoon commented 1 year ago

This issue was created at git.key-project.org where the discussions are preserved.


Description

A program with a return statement which appears within at least 2 nested loops cannot be verified in general.

The problem is that there is a program variable "rtrn" holding whether a return has been encountered. It is introduced when handling the first loop. Since it is a program variable assigned to in the loop body, it becomes anonymised when handling the inner loop. Due to this effect, the program loses information. This cannot be fixed in a JML invariant since the new program variables are introduced only after parsing the specification.

Steps to reproduce

Try to verify the attached file.

Files

AA.java:

class AA {

    boolean earlyExit;

    //@ ensures \result == 1;
    int m() {

    /*@ loop_invariant true; 
      @ decreases 100-i; 
      @ assignable \strictly_nothing;
      (at)*/
    for(int i = 0; i < 100; i++) {

        /* @ loop_invariant true;
          @ decreases 100-j; 
          @ assignable \strictly_nothing; 
          (at)*/
        for(int j= 0; j < 100; j++) {
        if(earlyExit) {
            return 1;
        }
        }
    }

    return 1;
    }
}

History

Attributes


View in Mantis


Information:

FliegendeWurst commented 1 year ago

It does work with the new Loop Scope rule (see #1495)