Skip to content

Commit

Permalink
Error casting bool const to other than bit<1>
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisDodd committed Feb 19, 2024
1 parent a34e426 commit 6f3c393
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ make_relative_link ()
make_relative_link "${mydir}/.gdbinit" "backends/bmv2/p4c-bm2-psa-gdb.gdb"
make_relative_link "${mydir}/.gdbinit" "backends/bmv2/p4c-bm2-ss-gdb.gdb"
make_relative_link "${mydir}/.gdbinit" "backends/dpdk/p4c-dpdk-gdb.gdb"
make_relative_link "${mydir}/.gdbinit" "backends/dpdk/p4test-gdb.gdb"
make_relative_link "${mydir}/.gdbinit" "backends/p4test/p4test-gdb.gdb"
3 changes: 3 additions & 0 deletions frontends/common/constantFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,9 @@ const IR::Node *DoConstantFolding::postorder(IR::Cast *e) {
if (auto arg = expr->to<IR::Constant>()) {
return cast(arg, arg->base, type);
} else if (auto arg = expr->to<IR::BoolLiteral>()) {
if (type->isSigned || type->size != 1)
error(ErrorType::ERR_INVALID, "%1%: Cannot cast %1% directly to %2% (use bit<1>)",
arg, type);
int v = arg->value ? 1 : 0;
return new IR::Constant(e->srcInfo, type, v, 10);
} else if (expr->is<IR::Member>()) {
Expand Down

0 comments on commit 6f3c393

Please sign in to comment.