Skip to content

Commit

Permalink
fix #961: input ptrs cannot be stack allocated
Browse files Browse the repository at this point in the history
Add a precondition for that. This test is hard to reproduce because it
relies on an optimization not being done just in target, while done in source.
  • Loading branch information
nunoplopes committed Nov 29, 2023
1 parent 307de60 commit 7c2e288
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions ir/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,7 @@ expr Memory::mkInput(const char *name, const ParamAttrs &attrs0) {
auto bid = p.getShortBid();

state->addAxiom(bid.ule(max_bid));
state->addAxiom(!Pointer(*this, max_bid, false).isStackAllocated(false));

AliasSet alias(*this);
alias.setMayAliasUpTo(false, max_bid);
Expand Down
4 changes: 2 additions & 2 deletions ir/pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,11 +502,11 @@ expr Pointer::getAllocType() const {
expr::mkUInt(0, 2));
}

expr Pointer::isStackAllocated() const {
expr Pointer::isStackAllocated(bool simplify) const {
// 1) if a stack object is returned by a callee it's UB
// 2) if a stack object is given as argument by the caller, we can upgrade it
// to a global object, so we can do POR here.
if (!has_alloca || isLocal().isFalse())
if (simplify && (!has_alloca || isLocal().isFalse()))
return false;
return getAllocType() == STACK;
}
Expand Down
2 changes: 1 addition & 1 deletion ir/pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Pointer {
CXX_NEW,
};
smt::expr getAllocType() const;
smt::expr isStackAllocated() const;
smt::expr isStackAllocated(bool simplify = true) const;
smt::expr isHeapAllocated() const;
smt::expr isNocapture(bool simplify = true) const;
smt::expr isNoRead() const;
Expand Down

0 comments on commit 7c2e288

Please sign in to comment.