Skip to content

Commit a1c8257

Browse files
dalancetaichi-ishitani
authored andcommitted
Merge pull request #2280 from taichi-ishitani/binary_operation_with_large_width_variable
Fix analyzer panic during converting binary op b/w large width variable and `'0` literal
1 parent b862e3a commit a1c8257

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

crates/analyzer/src/ir/tests.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1839,7 +1839,7 @@ fn concat() {
18391839
o: output logic<16>,
18401840
o2: output logic<16>,
18411841
) {
1842-
assign o = {8'hff + 8'h1};
1842+
assign o = {8'hff + 8'h1};
18431843
assign o2 = {8'hf0, 8'hff + 8'h1};
18441844
}
18451845
"#;
@@ -1927,3 +1927,29 @@ module Top {
19271927
"#;
19281928
check_ir(code, exp);
19291929
}
1930+
1931+
#[test]
1932+
fn binary_operation_with_large_width_variable() {
1933+
let code = r#"
1934+
module Top (
1935+
a: input logic<65>,
1936+
b: output logic ,
1937+
) {
1938+
always_comb {
1939+
b = a == '0;
1940+
}
1941+
}
1942+
"#;
1943+
1944+
let exp = r#"module Top {
1945+
input var0(a): logic<65> = 65'hxxxxxxxxxxxxxxxxx;
1946+
output var1(b): logic = 1'hx;
1947+
1948+
comb {
1949+
var1 = (var0 == '0);
1950+
}
1951+
}
1952+
"#;
1953+
1954+
check_ir(code, exp);
1955+
}

crates/analyzer/src/value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ impl Value {
752752
}
753753

754754
pub fn expand(&self, width: usize, use_sign: bool) -> Cow<'_, Self> {
755-
if self.width() == 0 || self.width() >= width {
755+
if (self.width() == 0 && width <= 64) || self.width() >= width {
756756
Cow::Borrowed(self)
757757
} else if width > 64 {
758758
let ret = match self {

0 commit comments

Comments
 (0)