-
Notifications
You must be signed in to change notification settings - Fork 156
Fix handling of allocation functions without allocsize attribute - #1238
#1252
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 2 commits
c1908c5
2e0640f
77db5dd
b425d12
183a78f
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 |
|---|---|---|
|
|
@@ -2684,7 +2684,23 @@ StateValue FnCall::toSMT(State &s) const { | |
| if (attrs.has(AllocKind::Alloc) || | ||
| attrs.has(AllocKind::Realloc) || | ||
| attrs.has(FnAttrs::AllocSize)) { | ||
| auto [size, np_size] = attrs.computeAllocSize(s, args); | ||
|
|
||
| smt::expr size; | ||
| smt::expr np_size; | ||
|
|
||
| if (!attrs.has(FnAttrs::AllocSize)) { | ||
| static IntType sizet_type(string("size_t"), config::max_sizet_bits); | ||
| auto result = s.addFnCall(std::move(fnName_mangled).str(), std::move(inputs), | ||
| std::move(ptr_inputs), sizet_type, StateValue{}, | ||
| nullptr, std::vector<StateValue>{}, attrs, indirect_hash); | ||
|
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. I think we need to adjust the attrs here so the call is read-only.
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. FnAttrs readonly_attrs = attrs;
readonly_attrs.mem.setCanOnlyRead();
auto result = s.addFnCall(std::move(fnName_mangled).str(), std::move(inputs),
std::move(ptr_inputs), sizet_type, StateValue{},
nullptr, std::vector<StateValue>{}, readonly_attrs, indirect_hash);I attempted the change as above, yet the error
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. The semantics of this behavior are not explicitly specified in the LLVM Language Reference.
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. Uhm, that's a good point about |
||
| size = std::move(result.value); | ||
| np_size = std::move(result.non_poison); | ||
| } else { | ||
| auto result = attrs.computeAllocSize(s, args); | ||
| size = std::move(result.first); | ||
| np_size = std::move(result.second); | ||
| } | ||
|
|
||
| expr nonnull = attrs.isNonNull() ? expr(true) | ||
| : expr::mkBoolVar("malloc_never_fails"); | ||
| // FIXME: alloc-family below | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| ; ERROR: Source and target don't have the same return domain | ||
|
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. This is the wrong output. A call into an allocator can be removed. |
||
|
|
||
| define i64 @src() { | ||
| %stack = call ptr @myalloc() | ||
| %sz = call i64 @llvm.objectsize.i64.p0(ptr %stack, i1 false, i1 false, i1 false) | ||
| ret i64 %sz | ||
| } | ||
|
|
||
| define i64 @tgt() { | ||
| ret i64 -1 | ||
| } | ||
|
|
||
| declare ptr @myalloc() allockind("alloc") | ||
| declare i64 @llvm.objectsize.i64.p0(ptr, i1, i1, i1) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1163,6 +1163,9 @@ static void calculateAndInitConstants(Transform &t) { | |
| inaccessiblememonly_fns.emplace(call->getName()).second) | ||
| ++num_inaccessiblememonly_fns; | ||
| } | ||
| if(attrs.isAllocWithoutSize()) { | ||
|
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. missing space here before ( |
||
| has_write_fncall |= attrs.mem.canWriteSomething(); | ||
|
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. I don't think we want the call to get the object size to write anything.
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 will adjust the arguments to |
||
| } | ||
| if (call->isIndirect()) { | ||
| has_indirect_fncalls = true; | ||
| num_inaccessiblememonly_fns += is_src; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.