Skip to content

Commit bd69493

Browse files
committed
[ImportVerilog] Fix empty replications within concatenations
Verilog allows for empty replications like `{0{...}}` to appear within concatenations. Slang assigns them the `void` type, which we can check for in the concatenation. This fixes an issue where the replication lowering would return a null value to indicate an empty replication, which conflicts with the null value being used as error indicator everywhere else in the lowering. Thanks @hailongSun2000 for pointing out the issue!
1 parent c9e048c commit bd69493

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/Conversion/ImportVerilog/Expressions.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,11 @@ struct RvalueExprVisitor {
409409
Value visit(const slang::ast::ConcatenationExpression &expr) {
410410
SmallVector<Value> operands;
411411
for (auto *operand : expr.operands()) {
412+
// Handle empty replications like `{0{...}}` which may occur within
413+
// concatenations. Slang assigns them a `void` type which we can check for
414+
// here.
415+
if (operand->type->isVoid())
416+
continue;
412417
auto value = context.convertRvalueExpression(*operand);
413418
value = context.convertToSimpleBitVector(value);
414419
if (!value)
@@ -421,9 +426,6 @@ struct RvalueExprVisitor {
421426
// Handle replications.
422427
Value visit(const slang::ast::ReplicationExpression &expr) {
423428
auto type = context.convertType(*expr.type);
424-
if (isa<moore::VoidType>(type))
425-
return {};
426-
427429
auto value = context.convertRvalueExpression(expr.concat());
428430
if (!value)
429431
return {};

test/Conversion/ImportVerilog/basic.sv

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,14 @@ module Expressions;
859859
// CHECK: [[TMP2:%.+]] = moore.concat [[TMP1]] : (!moore.i1) -> i1
860860
// CHECK: moore.replicate [[TMP2]] : i1 -> i32
861861
a = {32{1'b0}};
862+
// CHECK: [[TMP1:%.+]] = moore.read %a : <i32>
863+
// CHECK: [[TMP2:%.+]] = moore.read %c : <i32>
864+
// CHECK: moore.concat [[TMP1]], [[TMP2]] : (!moore.i32, !moore.i32) -> i64
865+
a = {a, {0{b}}, c};
866+
// CHECK: [[TMP1:%.+]] = moore.read %a : <i32>
867+
// CHECK: [[TMP2:%.+]] = moore.read %c : <i32>
868+
// CHECK: moore.concat [[TMP1]], [[TMP2]] : (!moore.i32, !moore.i32) -> i64
869+
a = {a, {0{b}}, {0{a, {0{b}}, c}}, c};
862870
// CHECK: [[TMP1:%.+]] = moore.read %vec_1 : <l32>
863871
// CHECK: moore.extract [[TMP1]] from 1 : l32 -> l3
864872
y = vec_1[3:1];

0 commit comments

Comments
 (0)