From 40433f0d9b563f23e13d2b7edbb00eb5c4c2078d Mon Sep 17 00:00:00 2001 From: tignear Date: Wed, 21 Oct 2026 12:08:13 +0900 Subject: [PATCH] fix(sv): defer indexed part-select base binding until types are available Runtime casts in an indexed part-select base were bound during preliminary validation as constant expressions, rejecting valid Taxi DMA selects with a constant-cast-operand error. Validate the positive constant width there and let normal expression lowering bind the variable base with complete type information, as required by IEEE 1800-2023 11.5.1. Add a shared regression for numeric and typedef casts in runtime read and write bases, including truncating indices. Validation: - Shared SV suite: 3287 passed, 90 existing ignores across the backend variants; indexed-select group: 298 passed. - New shared case passes Verilator and Icarus execution. - SV analyzer: 770 passed, 3 existing ignores; project CLI: 17 passed. - Original Taxi AXI CDMA [8-0] and AXI DMA [0-8] builds pass the former cast error and stop at separate combinational expression lowering failures for read_addr_next and addr_next. Neither is counted as an upstream runtime pass. - Formatting and affected-crate all-target Clippy pass. Change-Id: I57adbbd3abcd3c0e4761b3deb63d5232558a7f27 --- .../celox-sv-analyzer/src/ast/validation.rs | 9 +++---- .../src/sv/cases/indexed_select.vtest | 27 +++++++++++++++++++ .../frontends/systemverilog/indexed_select.rs | 4 +++ 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/crates/celox-sv-analyzer/src/ast/validation.rs b/crates/celox-sv-analyzer/src/ast/validation.rs index c68a5d34ca4..efbe9323bcc 100644 --- a/crates/celox-sv-analyzer/src/ast/validation.rs +++ b/crates/celox-sv-analyzer/src/ast/validation.rs @@ -466,12 +466,11 @@ fn validate_scope( return Err(unsupported("mintypmax expression")); } ExprKind::Select { dimension, .. } => { - if let DimensionKind::Indexed { base, width, .. } = dimension.kind { + if let DimensionKind::Indexed { width, .. } = dimension.kind { if parameter_ranges.iter().any(|range| contains(*range, dimension.tokens)) { continue; } - let mut dimensions = indexed_dimensions.clone(); - dimensions.constant_indexed_base = true; - let value = expression_binding::value(base, native, syntax_tree, &dimensions)?; - selects::indexed_expression_value(&syntax_tree.state, value, &dimensions).ok_or_else(|| unsupported("index expression"))?; + // IEEE 1800-2023 11.5.1 permits a variable base. Its + // expression is bound after variable types are available; + // only the width requires constant validation here. check_indexed_width(width, syntax_tree, indexed_dimensions)?; } } diff --git a/crates/celox-test-suite/src/sv/cases/indexed_select.vtest b/crates/celox-test-suite/src/sv/cases/indexed_select.vtest index 34f641f537e..da1e5612b22 100644 --- a/crates/celox-test-suite/src/sv/cases/indexed_select.vtest +++ b/crates/celox-test-suite/src/sv/cases/indexed_select.vtest @@ -1736,3 +1736,30 @@ (top Top) (assert_eq enumeration 10) (assert_eq width 10)) + +(case runtime_indexed_bases_preserve_numeric_and_type_casts + (source "runtime_indexed_cast.sv" #" + module Top(input logic [63:0] data, input logic [1:0] offset, + input logic [3:0] index, + output logic [31:0] y, output logic [3:0] narrowed, + output logic [3:0] typed, output logic [63:0] written); + typedef logic [2:0] index_t; + assign y = data[3'(4-offset)*8 +: 32]; + assign narrowed = data[2'(index) +: 4]; + assign typed = data[index_t'(index) +: 4]; + always_comb begin + written = data; + written[3'(4-offset)*8 +: 8] = 8'hff; + end + endmodule + "#) + (top Top) + (modify (set data 0x0123456789abcdef)) + (for offset_value (range 0 4) + (modify (set offset offset_value)) + (assert_eq y (& (>> 0x0123456789abcdef (* (- 4 offset_value) 8)) 0xffffffff)) + (assert_eq written (| 0x0123456789abcdef (<< 0xff (* (- 4 offset_value) 8))))) + (for index_value (range 0 16) + (modify (set index index_value)) + (assert_eq narrowed (& (>> 0x0123456789abcdef (& index_value 3)) 15)) + (assert_eq typed (& (>> 0x0123456789abcdef (& index_value 7)) 15)))) diff --git a/crates/celox/tests/frontends/systemverilog/indexed_select.rs b/crates/celox/tests/frontends/systemverilog/indexed_select.rs index 9acf8d49142..94701d08590 100644 --- a/crates/celox/tests/frontends/systemverilog/indexed_select.rs +++ b/crates/celox/tests/frontends/systemverilog/indexed_select.rs @@ -128,6 +128,10 @@ sv_backends! { assert_eq!(sim.get(sim.signal("narrow")), 0x1bu8.into()); } + fn runtime_indexed_bases_preserve_numeric_and_type_casts(sim) { + @case "indexed_select::runtime_indexed_bases_preserve_numeric_and_type_casts"; + } + fn indexed_select_preserves_selected_and_cast_bases(sim) { @case "indexed_select::indexed_select_preserves_selected_and_cast_bases"; }