Skip to content

Commit

Permalink
Do not constant fold mux before it has been typechecked (#3633)
Browse files Browse the repository at this point in the history
Signed-off-by: Mihai Budiu <[email protected]>
  • Loading branch information
Mihai Budiu authored Oct 28, 2022
1 parent 01fedcc commit 4a74084
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions frontends/common/constantFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,9 @@ const IR::Node* DoConstantFolding::postorder(IR::LNot* e) {
}

const IR::Node* DoConstantFolding::postorder(IR::Mux* e) {
if (!typesKnown)
// We want the typechecker to look at the expression first
return e;
auto cond = getConstant(e->e0);
if (cond == nullptr)
return e;
Expand Down
18 changes: 18 additions & 0 deletions testdata/p4_16_errors/issue3622.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
action a(){}
action b(){}
action NoAction(){}
control c() {
table t {
actions = { a ; b; }
}
apply {
switch(t.apply().action_run) {
true ? a : b : {}
}
}
}

control C();
package top(C c);

top(c()) main;
24 changes: 24 additions & 0 deletions testdata/p4_16_errors_outputs/issue3622.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
action a() {
}
action b() {
}
action NoAction() {
}
control c() {
table t {
actions = {
a;
b;
}
}
apply {
switch (t.apply().action_run) {
(true ? a : b): {
}
}
}
}

control C();
package top(C c);
top(c()) main;
3 changes: 3 additions & 0 deletions testdata/p4_16_errors_outputs/issue3622.p4-stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
issue3622.p4(10): [--Werror=type-error] error: ?:: 'switch' label must be an action name or 'default'
true ? a : b : {}
^^^^^^^^^^^^

0 comments on commit 4a74084

Please sign in to comment.