Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TruncDiv applied to permission values crashes VerCors #1271

Open
superaxander opened this issue Oct 21, 2024 · 0 comments
Open

TruncDiv applied to permission values crashes VerCors #1271

superaxander opened this issue Oct 21, 2024 · 0 comments
Labels
A-Bug F-C Frontend: C F-Java Frontend: Java

Comments

@superaxander
Copy link
Member

The Java, C, and C++ frontends encode the division operator / as truncating division. If you use this operator to divide a permission value this crashes vercors.

C test file:

int f;

//@ requires Perm(f, write/2);
void foo() {
}

Java test file:

class Min {
    static int f;

    //@ requires Perm(f, write/2);
    void foo() {
    }
}
The error

viper.api.backend.SilverBackend$ConsistencyErrors: The silver AST delivered to viper is not valid:                                                                                                                                                              
 - Consistency error: Function truncdiv with formal arguments List(a: Int, b: Int) cannot be applied to provided arguments List(write, 2). (/home/alexander/vercors/min.java-4-26--4-33;unique_id=105)                                                          
 - Consistency error: Function truncdiv with formal arguments List(a: Int, b: Int) cannot be applied to provided arguments List(write, 2). (/home/alexander/vercors/min.java-4-26--4-33;unique_id=137)                                                          
        at viper.api.backend.SilverBackend.$anonfun$transform$1(SilverBackend.scala:107)                                                                                                                                                                        
        at hre.progress.task.NameSequenceTask.scope(NameSequenceTask.scala:16)                                                                                                                                                                                  
        at hre.progress.Progress$.stages(Progress.scala:47)                                                                                                                                                                                                     
        at viper.api.backend.SilverBackend.transform(SilverBackend.scala:90)                                                                                                                                                                                    
        at viper.api.backend.SilverBackend.transform$(SilverBackend.scala:81)                                                                                                                                                                                   
        at viper.api.backend.silicon.Silicon.transform(Silicon.scala:34)                                                                                                                                                                                        
        at vct.main.stages.SilverBackend.transform(Backend.scala:196)                                                                                                                                                                                           
        at vct.main.stages.Backend.$anonfun$run$3(Backend.scala:152)

I believe this is specifically because the type of write is TBoundedInt which can be coerced into TInt causing this to be treated as an integer division. Then once we get to Viper there's a mismatch because there write is of type Perm and the function truncdiv expects only Ints. Possible solutions:

  • Make the type of write TFraction
  • Generate an error when using the / operator on permission values instead of the \ operator

Also I think we should mention on the wiki somewhere that integer division and modulo is implemented differently in PVL versus our other frontends

@superaxander superaxander added A-Bug F-C Frontend: C F-Java Frontend: Java labels Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Bug F-C Frontend: C F-Java Frontend: Java
Projects
None yet
Development

No branches or pull requests

1 participant