Skip to content

Difficulty using "assert(false)" for unimplemented functions #6393

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
danielsn opened this issue Oct 13, 2021 · 7 comments · Fixed by #6898
Closed

Difficulty using "assert(false)" for unimplemented functions #6393

danielsn opened this issue Oct 13, 2021 · 7 comments · Fixed by #6898
Labels
aws Bugs or features of importance to AWS CBMC users aws-medium pending merge

Comments

@danielsn
Copy link
Contributor

I am trying to use assert(false) instead of return __nondet() for missing functions to increase soundness. You can see the code, and the failure, on this PR for RMC https://github.com/model-checking/rmc/pull/535/files

If I use the arguments '--generate-function-body-options', 'assert-false', '--generate-function-body', '.*', I see the expected failure for missing functions, but also references to missing standard library functions, which was unexpected. Is there a better way to do this?

<builtin-library-memset> function memset
[memset.assertion.1] assertion false: FAILURE
@danielsn danielsn added aws Bugs or features of importance to AWS CBMC users aws-high labels Oct 13, 2021
@SaswatPadhi
Copy link
Contributor

We tried this with malloc and having #include <stdlib.h> doesn't help either.

#include <stdlib.h>

int main() {
    void *x = malloc(1);
    assert(x != 0);
}

commandline:

goto-cc test.c -o test.o
goto-instrument --generate-function-body-options assert-false --generate-function-body '.*' test.o test.2.o
cbmc test.2.o

@SaswatPadhi
Copy link
Contributor

SaswatPadhi commented Oct 13, 2021

If we use --add-library first with goto-instrument, this works as expected.

int main() {
    void *x = malloc(1);  // should not be replaced by `assert(false);`
    assert(x != 0);
    void *y = mallocx(1); // should be replaced by `assert(false);`
    assert(y != 0);
}

commandline:

goto-cc test.c -o test.o
goto-instrument --add-library test.o test.1.o
goto-instrument --generate-function-body-options assert-false --generate-function-body '.*' test.1.o test.2.o
cbmc test.2.o

@jimgrundy
Copy link
Collaborator

Also, rather than just throwing an assert false violation it would save a lot of debug effort if we got an error of the form "undefined function reached".

@thomasspriggs
Copy link
Contributor

Also, rather than just throwing an assert false violation it would save a lot of debug effort if we got an error of the form "undefined function reached".

That sounds like a worthwhile improvement, but it is slightly off track from the original problem described in this issue. I have raised a task in my team's internal tracking system, to keep track of your suggestion.

@thomasspriggs
Copy link
Contributor

It seems like Saswat has managed to find a way to make the functionality you wanted work for the moment. I think that ideally we should generate an appropriate warning/suggestion if an attempt is made to generate function bodies, before the standard libraries have been linked.

@thomasspriggs thomasspriggs removed their assignment Dec 7, 2021
@jimgrundy
Copy link
Collaborator

One could argue that this is a symptom of a more general issue, which is how to we ensure that folks run the steps of a transformation in the right order. We might want to look at annotating code with information about what has/has-not been done to it so we can check if further transformations are safe. There is an RFC started over on #6495 to discuss that.

Can we close this issue and pick up the discussion over there?

@tautschnig
Copy link
Collaborator

Just confirming that using --add-library in the same goto-instrument call together with --generate-function-body works just fine and does exactly the right thing. I will nevertheless issue two follow-up PRs:

  1. Cleanup of goto-instrument to make sure that --add-library works correctly with all code transformations.
  2. Adjusting the comment for the assertion generated.

tautschnig added a commit to tautschnig/cbmc that referenced this issue May 31, 2022
When using --generate-function-body with "assert-false" or
"assert-false-assume-false" make sure we produce a more meaningful
description than "assertion false." Instead, make the comment say
"undefined function should be unreachable."

Fixes: diffblue#6393
@tautschnig tautschnig removed their assignment May 31, 2022
tautschnig added a commit to tautschnig/cbmc that referenced this issue May 31, 2022
When using --generate-function-body with "assert-false" or
"assert-false-assume-false" make sure we produce a more meaningful
description than "assertion false." Instead, make the comment say
"undefined function should be unreachable."

Fixes: diffblue#6393
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws Bugs or features of importance to AWS CBMC users aws-medium pending merge
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants