Skip to content

Handle offsets on casted pointers soundly #1025

Open
@jerhard

Description

@jerhard

Goblint is currently not sound in some cases when dealing with offsets taken on casted pointers.

1. Comparison of casted pointers with offsets

On the current master, Goblint claims that the last two asserts will pass, even though they actually fail when compiled with Gcc. For the first two asserts Goblint says that the result is unknown, but this sound imprecision seems more incidental.

char* a_intoffset =(char*) (a + 1);
char* b_intoffset = b_char + sizeof(int);
__goblint_check(a_intoffset == b_intoffset);
__goblint_check((char*) (a + 1) == b_char + sizeof(int));
char* a_4intoffset = (char*) (a + 4);
__goblint_check(a_4intoffset == b_intoffset); // FAIL
__goblint_check((char*) (a + 4) == b_char + sizeof(int)); // FAIL

In the example, the char-pointer b_char points to the int-array a. Then, in a conccrete runIn line 22, the variable a_4intoffset points to &a[4], whereas b_intoffset points to (char* a) + 4 = (int* a) + 1 = &a[1].
When creating the index offset in the abstraction, Goblint currently does not take into account the static type of the pointer the offset is taken from. Thus, for b_intoffset, it keeps &a with offset 4 as its value, the same as for a_4intoffset.

2. Reading and writing with casted pointers with offsets

Reading from and writing to an address with such an offsets also needs to be handled soundly. In particular, code casting b_intoffset back to int* and dereferencing it should be soundly abstracted.
A related issue is #582, where only parts of a variable are overwritten with a char-pointer, and Goblint does not yield a sound value for a subsequent read. In #582, however, no offsets are involved.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions