Giter VIP home page Giter VIP logo

Comments (4)

michael-emmi avatar michael-emmi commented on May 26, 2024

OK, handling ptrtoint as well, while we're at it.

from smack.

zvonimir avatar zvonimir commented on May 26, 2024

The way i2p and p2i are implemented right now, SMACK reports a false bug for this example:
int main(void){
int x = (int)malloc(sizeof(int));
long y = (int)x;
int z = (int)y;

_x = 5;
__SMACK_assert(_z == 5);
}

I wonder if i2p and p2i should be just noops? Any good reason not to have them as noops?

from smack.

michael-emmi avatar michael-emmi commented on May 26, 2024

I'm not really sure about this one. If we treat i2p and p2i as no-ops, then any arithmetic on integers derived from the pointers becomes weird, since arithmetic uses only the "offset" component. I'm not really sure where this problem might manifest in practice, but consider the following program:

int _p = malloc(..);
*p = 0;
int x = (int) p;
int y = x + 1;
int z = y - 1;
int *q = (int *) z;
// here p and q alias, since x == z
*q = 5;
assert (_p == 0);
// this assertion does not hold.

Our translation, treating i2p and p2i as no-ops would work as follows:
p := $ptr(R,0);
x := $ptr(R,0);
y := $ptr(NULL,1);
z := $ptr(NULL,0);
q := $ptr(NULL,0);
// here p and q do not alias...
$Mem[q] := 5;
assert ($Mem[p] == 0);
// this assertion holds

The way our translation works now flags this as an error.
p := $ptr(R,0);
x := $ptr(NULL,0);
y := $ptr(NULL,1);
z := $ptr(NULL,0);
q := $ptr(S,0);
// here p and q MAY alias, given that R and S can be equal
$Mem[q] := 5;
assert ($Mem[p] == 0);
// this assertion may not hold

M

from smack.

zvonimir avatar zvonimir commented on May 26, 2024

I agree with your point. What we are doing now is sound, which is great and is probably good enough for most of real-world examples. Handling i2p/p2i precisely without having a good need for that does not make sense at this point. So let's just issue a warning that it is not handled precisely and that's it.

from smack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.