Skip to content

Writing to a value via a pointer fails in some circumstances #5263

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

Closed
DanielG opened this issue Mar 9, 2020 · 0 comments · Fixed by #5713
Closed

Writing to a value via a pointer fails in some circumstances #5263

DanielG opened this issue Mar 9, 2020 · 0 comments · Fixed by #5713

Comments

@DanielG
Copy link

DanielG commented Mar 9, 2020

CBMC version: 9ee5b9d (develop), also reproducible on 5.11 and 5.10 (from Debian) to an extent
Operating system: Debian amd64

The program below is a minimal reproducer of a problem I encountered while trying to verify a uC program of mine. I have found three "fixes" to get the program to verify one of which only works on develop, see the comments.

Test program:

typedef void (*callback_t)(void);

struct xfer {
        union { /*< FIX: union -> struct */
                struct {
                        int * buf;
                        callback_t callback; /*< FIX: remove */
                } a;
        };
} g_xfer;

int g_buf;

int main()
{
        g_xfer = (struct xfer) {{{ &g_buf }}};

        /* FIX, uncomment (only on cbmc develop 9ee5b9d6): */
        // g_xfer.a.buf = &g_buf;

        /* check the pointer was initialized properly */
        assert(g_xfer.a.buf == &g_buf);

        g_xfer.a.buf[0] = 42; /* write a value via the pointer */
        assert(g_xfer.a.buf[0] == 42); /* check it was written */
        assert(g_buf == 42); /* the underlying value should also be updated */
}

Exact command line resulting in the issue: cbmc test.c
What behaviour did you expect: All three properties should succeed.
What happened instead: The last two assertions fail. Doing what any one of the "FIX" comments say will get all properties to succeed.

tautschnig added a commit to tautschnig/cbmc that referenced this issue Jan 2, 2021
Distinct fields in a union need not refer to distinct memory locations.
Thus treat all fields of a union the same, with pointers assigned to any
field being dereferenceable via another field.

Fixes: diffblue#5263
tautschnig added a commit to tautschnig/cbmc that referenced this issue Jan 4, 2021
Distinct fields in a union need not refer to distinct memory locations.
Thus treat all fields of a union the same, with pointers assigned to any
field being dereferenceable via another field.

Fixes: diffblue#5263
tautschnig added a commit to tautschnig/cbmc that referenced this issue Jan 5, 2021
Distinct fields in a union need not refer to distinct memory locations.
Thus treat all fields of a union the same, with pointers assigned to any
field being dereferenceable via another field.

Fixes: diffblue#5263
tautschnig added a commit to tautschnig/cbmc that referenced this issue Jan 6, 2021
Distinct fields in a union need not refer to distinct memory locations.
Thus treat all fields of a union the same, with pointers assigned to any
field being dereferenceable via another field.

Fixes: diffblue#5263
tautschnig added a commit to tautschnig/cbmc that referenced this issue Jan 8, 2021
Distinct fields in a union need not refer to distinct memory locations.
Thus treat all fields of a union the same, with pointers assigned to any
field being dereferenceable via another field.

Fixes: diffblue#5263
tautschnig added a commit to tautschnig/cbmc that referenced this issue Jan 8, 2021
Distinct fields in a union need not refer to distinct memory locations.
Thus treat all fields of a union the same, with pointers assigned to any
field being dereferenceable via another field.

Fixes: diffblue#5263
tautschnig added a commit to tautschnig/cbmc that referenced this issue Jan 8, 2021
Distinct fields in a union need not refer to distinct memory locations.
Thus treat all fields of a union the same, with pointers assigned to any
field being dereferenceable via another field.

Fixes: diffblue#5263
jezhiggins pushed a commit to jezhiggins/cbmc that referenced this issue Feb 3, 2021
Distinct fields in a union need not refer to distinct memory locations.
Thus treat all fields of a union the same, with pointers assigned to any
field being dereferenceable via another field.

Fixes: diffblue#5263
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant