Skip to content

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

Closed

Description

@danielsn

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

Activity

  1. added
    aws
    on Oct 13, 2021
  2. SaswatPadhi commented on Oct 13, 2021

    @SaswatPadhi
    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
    
  3. SaswatPadhi commented on Oct 13, 2021

    @SaswatPadhi
    Contributor

    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
    
  4. jimgrundy commented on Oct 20, 2021

    @jimgrundy
    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".

  5. thomasspriggs commented on Dec 3, 2021

    @thomasspriggs
    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.

  6. thomasspriggs commented on Dec 3, 2021

    @thomasspriggs
    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.

  7. removed their assignment
    on Dec 7, 2021
  8. jimgrundy commented on Dec 16, 2021

    @jimgrundy
    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?

  9. tautschnig commented on May 31, 2022

    @tautschnig
    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.
  10. added a commit that references this issue on May 31, 2022
    af60734
  11. removed their assignment
    on May 31, 2022
  12. added a commit that references this issue on May 31, 2022
    577b0ec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    awsaws-mediumpending merge

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions