Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

*p and p[0] are treated differently #10

Open
ksqsf opened this issue Feb 5, 2020 · 5 comments
Open

*p and p[0] are treated differently #10

ksqsf opened this issue Feb 5, 2020 · 5 comments
Labels
bitvec type should be raw memory as bitvec inconsistent prover doesn't match C behaviour

Comments

@ksqsf
Copy link

ksqsf commented Feb 5, 2020

using <stdio.h>::{printf, scanf};

fn foo(int *p) -> int {
  // return p[0]; // not ok
  return *p; // ok
}

export fn main() -> int {
    int mut y = 123;
    foo(&y);
    return 0;
}
@aep
Copy link
Collaborator

aep commented Feb 5, 2020

thanks for the report!

that's an unfortunate side effect of the len vs safe theory.

because safe(p) is implicit, the prover knows *p is fine,
but len(p) is undefined, so p + anything is unprovable

a quick fix would be

 assert( = (safe(x) (> len(x) 0) )

but this slows down the prover dramatically

i'd prefer to not fix this until deref is correctly implemented. it actually needs to check len() as well because you might cast to a different pointer size and then deref.

that again isn't implemented yet because i haven't found a good way yet to get target pointer sizes. the current prover VM just assumes 64bit.

@aep aep added the inconsistent prover doesn't match C behaviour label Feb 5, 2020
@jacereda
Copy link

jacereda commented Feb 6, 2020

that again isn't implemented yet because i haven't found a good way yet to get target pointer sizes. the current prover VM just assumes 64bit.

Does __SIZEOF_POINTER__ preprocessor symbol suffice?

@aep
Copy link
Collaborator

aep commented Feb 6, 2020

yes, but the prepro is unavailable to zz.

One leasson learned from rust is that zz will never make assumptions about your target build system, so it cannot possibly know how to call your c compiler with the correct flags for your target.

the options are pretty much

  1. just assume 64bit because the edges cases where 32bit has bugs that 64bit doesnt aren't worth it
  2. add some sort of --architecture build flags
  3. test 64 and 32bit (nope because thats insanely slow)

@jacereda
Copy link

jacereda commented Feb 6, 2020

Well, you can shell-out to the target compiler (would need to be configured) with -dM -E flags to extract things like type sizes and endianness.

I guess 2 could also be a good option.

@aep aep mentioned this issue Feb 14, 2020
4 tasks
@aep aep added the bitvec type should be raw memory as bitvec label Mar 16, 2020
@aep
Copy link
Collaborator

aep commented Oct 13, 2020

actually, this is fixed, isnt it?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bitvec type should be raw memory as bitvec inconsistent prover doesn't match C behaviour
Projects
None yet
Development

No branches or pull requests

3 participants