Skip to content

Commit 521821f

Browse files
committed
fixed struct args in wrapped subaction functions.
1 parent ab1f02c commit 521821f

File tree

3 files changed

+51
-13
lines changed

3 files changed

+51
-13
lines changed

lib/dialect/include/rlc/dialect/DynamicArgumentAnalysis.hpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ struct UnboundValue {
7878
llvm::SmallVector<uint64_t> memberAddress;
7979

8080
/*
81-
Returns whether this unbound value corressponds to the term.
81+
Returns whether this unbound value corressponds to the expression.
8282
*/
83-
bool matches(mlir::Value term) {
84-
mlir::Value current = term;
83+
bool matches(mlir::Value expr) {
84+
mlir::Value current = expr;
8585
// walk the member address in reverse, test if it leads to the argument.
8686
for(uint64_t & index : std::ranges::reverse_view(memberAddress)) {
8787
auto definingOp = current.getDefiningOp();
@@ -99,6 +99,32 @@ struct UnboundValue {
9999
return current == argument;
100100
}
101101

102+
/*
103+
Returns true if this unbound value is a recursive member of the given expression.
104+
*/
105+
bool isMemberOf(mlir::Value expr) {
106+
mlir::Value current = expr;
107+
llvm::SmallVector<uint64_t> indices;
108+
109+
while(true) {
110+
if(current == argument) {
111+
for(size_t i = 0; i < indices.size(); i++) {
112+
if(indices[i] != memberAddress[i])
113+
return false;
114+
}
115+
return true;
116+
}
117+
118+
auto definingOp = current.getDefiningOp();
119+
if( not llvm::detail::isPresent(definingOp))
120+
return false;
121+
if(auto memberAccess = mlir::dyn_cast<mlir::rlc::MemberAccess>(definingOp)) {
122+
indices.insert(indices.begin(), memberAccess.getMemberIndex());
123+
current = memberAccess.getValue();
124+
} else return false;
125+
}
126+
}
127+
102128
mlir::Type getType() {
103129
auto type = argument.getType();
104130
for (auto index : memberAddress) {

lib/dialect/src/DynamicArgumentAnalysisPass.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ llvm::SmallVector<llvm::SmallVector<mlir::Value>> DynamicArgumentAnalysis::expan
8686
}
8787

8888
TermType DynamicArgumentAnalysis::decideTermType(mlir::Value term, UnboundValue unbound) {
89-
if(unbound.matches(term))
89+
if(unbound.isMemberOf(term))
9090
return DEPENDS_ON_UNBOUND;
9191

9292
auto boundValue = getBoundValue(term);
@@ -265,14 +265,14 @@ DeducedConstraints DynamicArgumentAnalysis::findImposedConstraints(mlir::rlc::Ca
265265
continue;
266266
}
267267
// and find the index of the argument we're interested in.
268-
if(unbound.matches(current.value())) {
268+
if(unbound.argument == current.value()) {
269269
argIndex = current.index();
270270
break;
271271
}
272272
}
273273
assert(argIndex != -1 && "Expected to find the argument.");
274274
DynamicArgumentAnalysis analysis(underlyingFunction, knownArgsOfUnderlyingFunction, argPicker, builder, loc);
275-
UnboundValue correspongindUnboundValue {underlyingFunction.getPrecondition().getArgument(argIndex), {}};
275+
UnboundValue correspongindUnboundValue {underlyingFunction.getPrecondition().getArgument(argIndex), unbound.memberAddress};
276276
return analysis.deduceIntegerUnboundValueConstraints(correspongindUnboundValue);
277277
}
278278
return {
@@ -399,13 +399,6 @@ DeducedConstraints DynamicArgumentAnalysis::deduceIntegerUnboundValueConstraints
399399
}
400400
}
401401

402-
llvm::dbgs() << "CONSTRAINTS: \n";
403-
for (auto t : constraints) {
404-
llvm::dbgs() << "( ";
405-
t.print(llvm::dbgs());
406-
llvm::dbgs() << " ),";
407-
}
408-
llvm::dbgs() << "\n";
409402

410403
// if there are any constraints on unknown args, emit an if statement for this conjunction.
411404
if(constraints.size() > 0) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,34 @@
11
import fuzzer.cpp_functions
22
import fuzzer.utils
33

4+
fun crash() {false}:
5+
return
6+
47
ent Test:
58
Int a
69
Int b
710

11+
act subact(ctx Test context_struct) -> Subact:
12+
frm subact_frame_var : Int
13+
subact_frame_var = 250
14+
act uses_context_struct(Test t1) {
15+
t1.a == context_struct.b,
16+
t1.b > context_struct.a,
17+
t1.b < subact_frame_var
18+
}
19+
820
act play() -> Play:
21+
frm struct_in_frame : Test
922
act uses_struct(Test t) {
1023
t.a >= 0,
1124
t.a <= 5,
1225
t.b >= -10,
1326
t.a <= 2 or t.b >= 5,
1427
t.b <= 16
1528
}
29+
struct_in_frame = t
30+
31+
subaction*(struct_in_frame) s = subact(struct_in_frame)
32+
crash()
33+
34+

0 commit comments

Comments
 (0)