Skip to content

Commit 9a9447a

Browse files
Jordan Romeviktormalik
authored andcommitted
Fix binop type check
If either the left or the right is a none type then wait till the final pass before throwing a mismatch error. Issue: bpftrace#3592
1 parent 7cfb563 commit 9a9447a

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/ast/passes/semantic_analyser.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,6 +1987,12 @@ void SemanticAnalyser::binop_ptr(Binop &binop)
19871987
else
19881988
invalid_op();
19891989
}
1990+
// Might need an additional pass to resolve the type
1991+
else if (other.IsNoneTy()) {
1992+
if (is_final_pass()) {
1993+
invalid_op();
1994+
}
1995+
}
19901996
// Binop on a pointer and something else
19911997
else {
19921998
invalid_op();

tests/semantic_analyser.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4265,6 +4265,11 @@ fentry:func_1,tracepoint:sched:sched_one { args }
42654265
)");
42664266
}
42674267

4268+
TEST_F(semantic_analyser_btf, binop_late_ptr_resolution)
4269+
{
4270+
test(R"(fentry:func_1 { if (@a[1] == args.foo1) { } @a[1] = args.foo1; })");
4271+
}
4272+
42684273
TEST(semantic_analyser, buf_strlen_too_large)
42694274
{
42704275
auto bpftrace = get_mock_bpftrace();

0 commit comments

Comments
 (0)