Skip to content

Add possibility for malloc to fail (via setting) - #798

Open
schuessf wants to merge 9 commits into
devfrom
wip/fs/malloc2
Open

Add possibility for malloc to fail (via setting)#798
schuessf wants to merge 9 commits into
devfrom
wip/fs/malloc2

Conversation

@schuessf

Copy link
Copy Markdown
Member

Previously, our C translation assumed that malloc (and the other allocation functions, calloc and realloc) could never fail and return NULL. For SV-COMP, it was decided that this assumption should be dropped (see !1686 for the corresponding benchmark changes and discussion). Therefore, this PR includes the following changes:

  • A setting Assume that allocation on the heap always succeeds was added. When disabled (the new default), allocation may return NULL in our translation, otherwise the behavior remains unchanged.
  • The translation was adapted to reflect this setting: For malloc, the procedure contract was changed (see NonDetStrategy2D and SimpleIncreasingStrategy), while for calloc and realloc the body in the translation was changed (see StdlibLibraryModel and ConstructRealloc).
  • There are two places where we generate malloc calls internally, for "non-standard" purposes, that still rely on the allocation never failing: varargs handling (see FunctionHandler) and non-deterministic string generation (see FunctionModelHelper). Rather than introduce a separate allocation function, I took the simpler route of just adding an explicit assume statement after these two calls.
  • Since the new setting defaults to false, several regression tests needed explicit NULL-handling so they don't fail after this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant