Skip to content

Commit 403994b

Browse files
authored
Merge pull request #2253 from tignear/fix/analyze-constant-folding-concat
fixes incorrect `context_width` propagation in concatenation constant folding
2 parents 68eb5a1 + a654024 commit 403994b

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

crates/analyzer/src/ir/expression.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ impl Expression {
140140
Expression::Concatenation(x) => {
141141
let mut ret = Value::new(0, 0, false);
142142
for (exp, rep) in x.iter() {
143-
let exp = exp.eval_value(context, context_width, signed)?;
143+
let exp = exp.eval_value(context, None, signed)?;
144144

145145
let rep = if let Some(rep) = rep {
146146
let token = rep.token_range();
147-
let rep = rep.eval_value(context, context_width, signed)?;
147+
let rep = rep.eval_value(context, None, signed)?;
148148
let rep = rep.to_usize()?;
149149
context.check_size(rep, token)?
150150
} else {
@@ -473,7 +473,7 @@ impl Expression {
473473
let mut kind = TypeKind::Bit;
474474
for (expr, repeat) in x {
475475
let range = expr.token_range();
476-
let expr = expr.eval_comptime(context, context_width, signed);
476+
let expr = expr.eval_comptime(context, None, signed);
477477

478478
// array / type can't be operated
479479
if expr.r#type.is_array() | expr.r#type.is_type() {

crates/analyzer/src/ir/tests.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,3 +1831,29 @@ module ModuleB {
18311831

18321832
check_ir(code, exp);
18331833
}
1834+
1835+
#[test]
1836+
fn concat() {
1837+
let code = r#"
1838+
module Top (
1839+
o: output logic<16>,
1840+
o2: output logic<16>,
1841+
) {
1842+
assign o = {8'hff + 8'h1};
1843+
assign o2 = {8'hf0, 8'hff + 8'h1};
1844+
}
1845+
"#;
1846+
let exp = r#"module Top {
1847+
output var0(o): logic<16> = 16'hxxxx;
1848+
output var1(o2): logic<16> = 16'hxxxx;
1849+
1850+
comb {
1851+
var0 = 8'h00;
1852+
}
1853+
comb {
1854+
var1 = 16'hf000;
1855+
}
1856+
}
1857+
"#;
1858+
check_ir(code, exp);
1859+
}

0 commit comments

Comments
 (0)