From 6f3c393f8141636da905e37402b0b6c916c1865c Mon Sep 17 00:00:00 2001 From: Chris Dodd Date: Tue, 13 Feb 2024 03:56:27 +0000 Subject: [PATCH] Error casting bool const to other than bit<1> --- bootstrap.sh | 2 +- frontends/common/constantFolding.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/bootstrap.sh b/bootstrap.sh index 2496eef0f72..9bad99d3a63 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -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" diff --git a/frontends/common/constantFolding.cpp b/frontends/common/constantFolding.cpp index 2b4f9ba17b7..b6c826c355b 100644 --- a/frontends/common/constantFolding.cpp +++ b/frontends/common/constantFolding.cpp @@ -798,6 +798,9 @@ const IR::Node *DoConstantFolding::postorder(IR::Cast *e) { if (auto arg = expr->to()) { return cast(arg, arg->base, type); } else if (auto arg = expr->to()) { + 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()) {