Skip to content

Commit 70319be

Browse files
committed
allow removing attributes from fn calls
1 parent c2f0f64 commit 70319be

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

ir/state.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -940,10 +940,15 @@ void State::addUnreachable() {
940940
unreachable_paths.add(domain());
941941
}
942942

943-
expr State::FnCallInput::implies(const FnCallInput &rhs) const {
944-
if (noret != rhs.noret || willret != rhs.willret ||
945-
(rhs.memaccess.canReadSomething().isTrue() &&
946-
(fncall_ranges != rhs.fncall_ranges || is_neq(m <=> rhs.m))))
943+
expr State::FnCallInput::refines(const FnCallInput &rhs) const {
944+
if (rhs.memaccess.canReadSomething().isTrue() &&
945+
(fncall_ranges != rhs.fncall_ranges || is_neq(m <=> rhs.m)))
946+
return false;
947+
948+
// we can remove attributes, but not add new ones
949+
if (noret && !rhs.noret)
950+
return false;
951+
if (willret && !rhs.willret)
947952
return false;
948953

949954
AndExpr eq;
@@ -966,9 +971,13 @@ expr State::FnCallInput::refinedBy(
966971
const Memory &m2, const SMTMemoryAccess &memaccess2, bool noret2,
967972
bool willret2) const {
968973

969-
if (noret != noret2 ||
970-
willret != willret2 ||
971-
!fncall_ranges.overlaps(callee, memaccess2, fncall_ranges2))
974+
if (!fncall_ranges.overlaps(callee, memaccess2, fncall_ranges2))
975+
return false;
976+
977+
// we can remove attributes, but not add new ones
978+
if (noret2 && !noret)
979+
return false;
980+
if (willret2 && !willret)
972981
return false;
973982

974983
AndExpr refines;
@@ -1051,7 +1060,7 @@ State::FnCallOutput State::FnCallOutput::mkIf(const expr &cond,
10511060
return ret;
10521061
}
10531062

1054-
expr State::FnCallOutput::implies(const FnCallOutput &rhs,
1063+
expr State::FnCallOutput::refines(const FnCallOutput &rhs,
10551064
const Type &retval_ty) const {
10561065
expr ret = ub == rhs.ub;
10571066
ret &= noreturns == rhs.noreturns;
@@ -1260,9 +1269,9 @@ State::addFnCall(const string &name, vector<StateValue> &&inputs,
12601269
for (auto II = calls_fn.begin(), E = calls_fn.end(); II != E; ++II) {
12611270
if (II == I)
12621271
continue;
1263-
auto in_eq = I->first.implies(II->first);
1272+
auto in_eq = I->first.refines(II->first);
12641273
if (!in_eq.isFalse())
1265-
fn_call_pre &= in_eq.implies(I->second.implies(II->second, out_type));
1274+
fn_call_pre &= in_eq.implies(I->second.refines(II->second, out_type));
12661275
}
12671276
}
12681277

ir/state.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class State {
214214
SMTMemoryAccess memaccess;
215215
bool noret, willret;
216216

217-
smt::expr implies(const FnCallInput &rhs) const;
217+
smt::expr refines(const FnCallInput &rhs) const;
218218
smt::expr refinedBy(State &s, const std::string &callee,
219219
unsigned inaccessible_bid,
220220
const std::vector<StateValue> &args_nonptr,
@@ -237,7 +237,7 @@ class State {
237237

238238
static FnCallOutput mkIf(const smt::expr &cond, const FnCallOutput &then,
239239
const FnCallOutput &els);
240-
smt::expr implies(const FnCallOutput &rhs, const Type &retval_ty) const;
240+
smt::expr refines(const FnCallOutput &rhs, const Type &retval_ty) const;
241241
auto operator<=>(const FnCallOutput &rhs) const = default;
242242
};
243243
std::map<std::string, std::map<FnCallInput, FnCallOutput>> fn_call_data;

tests/alive-tv/attrs/noreturn-fail-2.srctgt.ll renamed to tests/alive-tv/attrs/noreturn-dropattr.srctgt.ll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,3 @@ define i8 @tgt() {
99
call void @f()
1010
ret i8 0
1111
}
12-
13-
; ERROR: Source is more defined than target

0 commit comments

Comments
 (0)