Skip to content

Commit

Permalink
fix #1029: byval fn args missing attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
nunoplopes committed Apr 25, 2024
1 parent 94d8e31 commit 61fe61b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
11 changes: 11 additions & 0 deletions ir/pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,17 @@ expr Pointer::isBasedOnArg() const {
(unsigned)has_nowrite);
}

Pointer Pointer::setAttrs(const ParamAttrs &attr) const {
return { m, getBid(), getOffset(), getAttrs() | attr_to_bitvec(attr) };
}

Pointer Pointer::setIsBasedOnArg() const {
unsigned idx = (unsigned)has_nocapture + (unsigned)has_noread +
(unsigned)has_nowrite;
auto attrs = getAttrs();
return { m, getBid(), getOffset(), attrs | expr::mkUInt(1 << idx, attrs) };
}

Pointer Pointer::mkNullPointer(const Memory &m) {
assert(has_null_block);
// A null pointer points to block 0 without any attribute.
Expand Down
3 changes: 3 additions & 0 deletions ir/pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ class Pointer {
smt::expr isNoWrite() const;
smt::expr isBasedOnArg() const;

Pointer setAttrs(const ParamAttrs &attr) const;
Pointer setIsBasedOnArg() const;

smt::expr refined(const Pointer &other) const;
smt::expr fninputRefined(const Pointer &other, std::set<smt::expr> &undef,
const smt::expr &byval_bytes) const;
Expand Down
6 changes: 5 additions & 1 deletion ir/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,11 @@ StateValue Input::mkInput(State &s, const Type &ty, unsigned child) const {
if (hasAttribute(ParamAttrs::ByVal)) {
unsigned bid;
expr size = expr::mkUInt(attrs.blockSize, bits_size_t);
val = get_global(s, smt_name, &size, attrs.align, false, bid);
val = Pointer(s.getMemory(),
get_global(s, smt_name, &size, attrs.align, false, bid))
.setAttrs(attrs)
.setIsBasedOnArg()
.release();
bool is_const = hasAttribute(ParamAttrs::NoWrite) ||
!s.getFn().getFnAttrs().mem.canWrite(MemoryAccess::Args);
s.getMemory().markByVal(bid, is_const);
Expand Down
9 changes: 9 additions & 0 deletions tests/alive-tv/attrs/argmemonly-byval.srctgt.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
define void @src(ptr byval(i32) %0) {
%3 = load i32, ptr %0
ret void
}

define void @tgt(ptr byval(i32) nocapture %0) memory(argmem:readwrite) {
%3 = load i32, ptr %0
ret void
}

0 comments on commit 61fe61b

Please sign in to comment.