From fd38ee304381c00ab9b4e5ff7f1d537c162c32d2 Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Wed, 1 Oct 2025 09:58:52 -0700 Subject: [PATCH] Verilog: retain type of null This changes the representation of Verilog's null. Instead of converting the null type to the type expected in the context, an implicit cast is added. --- src/verilog/expr2verilog.cpp | 4 ++++ src/verilog/verilog_lowering.cpp | 10 ++++++++++ src/verilog/verilog_typecheck_expr.cpp | 7 ++----- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/verilog/expr2verilog.cpp b/src/verilog/expr2verilog.cpp index b44888715..c7160b7ce 100644 --- a/src/verilog/expr2verilog.cpp +++ b/src/verilog/expr2verilog.cpp @@ -1348,6 +1348,10 @@ expr2verilogt::convert_constant(const constant_exprt &src) else return convert_norep(src); } + else if(type.id() == ID_verilog_null) + { + dest = "null"; + } else return convert_norep(src); diff --git a/src/verilog/verilog_lowering.cpp b/src/verilog/verilog_lowering.cpp index 465869999..3da22d8a6 100644 --- a/src/verilog/verilog_lowering.cpp +++ b/src/verilog/verilog_lowering.cpp @@ -251,6 +251,16 @@ exprt verilog_lowering_cast(typecast_exprt expr) auto &src_type = expr.op().type(); auto &dest_type = expr.type(); + if(src_type.id() == ID_verilog_null && dest_type.id() == ID_verilog_chandle) + { + return to_verilog_chandle_type(dest_type).null_expr(); + } + + if(src_type.id() == ID_verilog_null && dest_type.id() == ID_verilog_event) + { + return to_verilog_event_type(dest_type).null_expr(); + } + // float to int if( (src_type.id() == ID_verilog_real || diff --git a/src/verilog/verilog_typecheck_expr.cpp b/src/verilog/verilog_typecheck_expr.cpp index c56a14b5c..1e807e485 100644 --- a/src/verilog/verilog_typecheck_expr.cpp +++ b/src/verilog/verilog_typecheck_expr.cpp @@ -2313,11 +2313,8 @@ void verilog_typecheck_exprt::implicit_typecast( dest_type.id() == ID_verilog_class_type || dest_type.id() == ID_verilog_event) { - if(expr.id() == ID_constant) - { - expr.type() = dest_type; - return; - } + expr = typecast_exprt{expr, dest_type}; + return; } }