Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ir/attrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class FnAttrs final {
void add(AllocKind k) { allockind |= (uint8_t)k; }
bool has(AllocKind k) const { return allockind & (uint8_t)k; }
bool isAlloc() const { return allockind != 0 || has(AllocSize); }
bool isAllocWithoutSize() const { return allockind != 0 && !has(AllocSize); }

void inferImpliedAttributes();

Expand Down
26 changes: 25 additions & 1 deletion ir/instr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2768,7 +2768,31 @@ StateValue FnCall::toSMT(State &s) const {
if (attrs.has(AllocKind::Alloc) ||
attrs.has(AllocKind::Realloc) ||
attrs.has(FnAttrs::AllocSize)) {
Comment thread
nunoplopes marked this conversation as resolved.
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);
FnAttrs new_attrs = attrs;
new_attrs.mem.setCanOnlyAccess(MemoryAccess::Inaccessible);
auto result = s.addFnCall(std::move(fnName_mangled).str(), std::move(inputs),
std::move(ptr_inputs), sizet_type, StateValue{},
nullptr, std::vector<StateValue>{}, new_attrs, indirect_hash);
size = std::move(result.value);
np_size = std::move(result.non_poison);
} else {

FnAttrs new_attrs = attrs;
new_attrs.mem.setCanOnlyAccess(MemoryAccess::Inaccessible);
s.addFnCall(std::move(fnName_mangled).str(), std::move(inputs),
std::move(ptr_inputs), Type::voidTy, StateValue{},
nullptr, std::vector<StateValue>{}, new_attrs, indirect_hash);
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
Expand Down
14 changes: 14 additions & 0 deletions tests/alive-tv/attrs/noallocsize-fn.srctgt.ll
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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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)
3 changes: 3 additions & 0 deletions tools/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,9 @@ static void calculateAndInitConstants(Transform &t) {
fn->getGlobalVar(string_view(call->getFnName()).substr(1)) &&
inaccessiblememonly_fns.emplace(call->getName()).second)
++num_inaccessiblememonly_fns;
} else {
if (inaccessiblememonly_fns.emplace(call->getName()).second)
++num_inaccessiblememonly_fns;
}
if (call->isIndirect()) {
has_indirect_fncalls = true;
Expand Down
Loading