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

Consider flag/config file for specifying impl-defined behaviour #695

Open
yav opened this issue Nov 5, 2024 · 5 comments
Open

Consider flag/config file for specifying impl-defined behaviour #695

yav opened this issue Nov 5, 2024 · 5 comments
Labels
cn enhancement New feature or request

Comments

@yav
Copy link
Collaborator

yav commented Nov 5, 2024

Testing the following example fails with a violation of the ensures clause.
It however works if we use explicit unsigned char or signed char.

It looks like the error might be a disagreement between the generator and the execution on the sign-edness of char (perhaps one is assume that is signed and the other that it is unsgined?)

int f(char x, char y)                                                               
/*@                                                                                 
requires x < y;                                                                  
ensures return == 1i32;                                                          
@*/                                                                              
{                                                                                
  return x < y;                                                                  
}     
cn --version
git-368d51a1f [2024-11-05 10:05:01 -0500]
@ZippeyKeys12
Copy link
Collaborator

ZippeyKeys12 commented Nov 5, 2024

From my understanding CN is parametric over things such as the signedness of chars and size of ints (thanks to Cerberus), so for runtime testing you'd need to ensure that its using the same model/config/whatever as the system you're running the tests or instrumentation on.

I don't know how that is done, perhaps @dc-mak or @cp526 can help.

This shows up in testing because the execution of the user's code follows their system's rules, but the executable spec generates code based on the CN types (u8 for char in this case). That's why the failure is in the postcondition, but it passes the precondition.

To see with just the instrumentation:

int f(char x, char y)
/*@
requires x < y;
ensures return == 1i32;
@*/
{
  return x < y;
}

int main() {
  f(100, -25);
}

The precondition is unsigned, due to CN converting char to u8.

/* EXECUTABLE CN PRECONDITION */
cn_bits_u8* x_cn = convert_to_cn_bits_u8(x);
cn_bits_u8* y_cn = convert_to_cn_bits_u8(y);
cn_assert(cn_bits_u8_lt(x_cn, y_cn));

@dc-mak
Copy link
Contributor

dc-mak commented Nov 6, 2024

The signed-ness of char is an implementation-defined detail. In CN, it's hard-coded to pKVM-friendly defaults here:

Ocaml_implementation.set Ocaml_implementation.HafniumImpl.impl;

Though that doesn't say much about how to proceed.

@yav
Copy link
Collaborator Author

yav commented Nov 7, 2024

Perhaps we could add a flag or a configuration file to CN for specifying implementation defined behavior?

@dc-mak dc-mak added enhancement New feature or request and removed CN spec testing labels Nov 7, 2024
@dc-mak dc-mak changed the title Confusion with the signedness of char Consider flag/config file for specifying implementation-defined behaviour Nov 7, 2024
@dc-mak dc-mak changed the title Consider flag/config file for specifying implementation-defined behaviour Consider flag/config file for specifying impl-defined behaviour Nov 7, 2024
@cp526
Copy link
Collaborator

cp526 commented Nov 7, 2024

Cerberus's cerberus/ocaml_frontend/ocaml_implementation.ml defines a number of different implementation profiles; backend/cn/bin/main.ml picks Ocaml_implementation.HafniumImpl.impl; (which is good for pKVM. It would probably be easy to make this switchable.

It's not clear to me how this relates to let impl_name = "gcc_4.9.0_x86_64-apple-darwin10.8.0" in setup.ml. @kmemarian ?

@cp526
Copy link
Collaborator

cp526 commented Nov 7, 2024

If we make this switchable, we should check how normal cerberus does the same switching and mirror that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cn enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants