-
Notifications
You must be signed in to change notification settings - Fork 141
Extend state representation to track errno across control-flow
#1284
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2332,6 +2332,18 @@ Memory::alloc(const expr *size, uint64_t align, BlockKind blockKind, | |
| state->addQuantVar(nondet_nonnull); | ||
| allocated = precond && (nonnull || (nooverflow && nondet_nonnull)); | ||
| } | ||
|
|
||
| // Create a new symbolic variable that represents errno if the allocation | ||
| // fails. | ||
| if (blockKind == MALLOC || blockKind == CXX_NEW) { | ||
| expr errno_on_failure = expr::mkFreshVar("#malloc_errno", | ||
| expr::mkUInt(0, 32)); | ||
|
Comment on lines
+2339
to
+2340
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’m experiencing the following false positive for test Possibly we shouldn’t use fresh unique symbolic variables for malloc_errno: I tried switching from using mkFreshVar w/ addNonDetVar to using the dedicated helper getFreshNondetVar instead. This fixes this issue but in doing so we don’t |
||
|
|
||
| expr current_errno = state->getErrno(); | ||
| expr new_errno = expr::mkIf(allocated, current_errno, errno_on_failure); | ||
| state->setErrno(std::move(new_errno)); | ||
| } | ||
|
|
||
| return { std::move(p).release(), std::move(allocated) }; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| define i32 @src(ptr %p) { | ||
| store i32 0, ptr %p | ||
| call ptr @malloc(i64 -9223372036854775808) | ||
| %v = load i32, ptr %p | ||
| ret i32 %v | ||
| } | ||
|
|
||
| define i32 @tgt(ptr %p) { | ||
| store i32 0, ptr %p | ||
| ret i32 0 | ||
| } | ||
|
|
||
| declare noalias ptr @malloc(i64) memory(inaccessiblemem: readwrite, errnomem: write) | ||
|
|
||
| ; ERROR: Mismatch in errno at return |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| define i32 @src(ptr %p, i64 %sz) { | ||
| store i32 0, ptr %p | ||
| call ptr @malloc(i64 %sz) | ||
| %v = load i32, ptr %p | ||
| ret i32 %v | ||
| } | ||
|
|
||
| define i32 @tgt(ptr %p, i64 %sz) { | ||
| store i32 0, ptr %p | ||
| ret i32 0 | ||
| } | ||
|
|
||
| declare noalias ptr @malloc(i64) memory(inaccessiblemem: readwrite, errnomem: write) | ||
|
|
||
| ; ERROR: Mismatch in errno at return | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We generally consider allocation functions to only be called non-deterministically I think -- see llvm/llvm-project#177592. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don’t seem to model realloc as of now, correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we do support realloc!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, there doesn't appear to exist a separate
REALLOCblock kind, instead we seem to reuseMALLOCone when encoding realloc calls (AllocKind::Realloc) into SMT expressions:alive2/ir/instr.cpp
Lines 2774 to 2775 in 2cb1034