Skip to content

Commit a75fd47

Browse files
author
Hailong Sun
authored
[ImportVerilog] Fix the segmentation fault caused by the case statement. (#7295)
Because the return of 'convertRvalueExpression()' can return '{}'. For example, when we handle the 'x'/'z' value, it will emit an error and return '{}', so we must estimate whether the return of 'convertRvalueExpression()' is '{}'. Otherwise, it will cause a segmentation fault.
1 parent e2b4cb9 commit a75fd47

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/Conversion/ImportVerilog/Statements.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ struct StmtVisitor {
117117
// Handle case statements.
118118
LogicalResult visit(const slang::ast::CaseStatement &caseStmt) {
119119
auto caseExpr = context.convertRvalueExpression(caseStmt.expr);
120+
if (!caseExpr)
121+
return failure();
122+
120123
auto items = caseStmt.items;
121124
// Used to generate the condition of the default case statement.
122125
SmallVector<Value> defaultConds;
@@ -127,6 +130,9 @@ struct StmtVisitor {
127130
SmallVector<Value> allConds;
128131
for (const auto *expr : item.expressions) {
129132
auto itemExpr = context.convertRvalueExpression(*expr);
133+
if (!itemExpr)
134+
return failure();
135+
130136
auto newEqOp = builder.create<moore::EqOp>(loc, caseExpr, itemExpr);
131137
allConds.push_back(newEqOp);
132138
}

test/Conversion/ImportVerilog/errors.sv

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,25 @@ module Foo;
107107
// expected-error @below {{unpacked arrays in 'inside' expressions not supported}}
108108
int c = a inside { b };
109109
endmodule
110+
111+
// -----
112+
module Foo;
113+
logic a, b;
114+
initial begin
115+
casez (a)
116+
// expected-error @below {{literals with X or Z bits not supported}}
117+
1'bz : b = 1'b1;
118+
endcase
119+
end
120+
endmodule
121+
122+
// -----
123+
module Foo;
124+
logic a;
125+
initial begin
126+
// expected-error @below {{literals with X or Z bits not supported}}
127+
casez (1'bz)
128+
1'bz : a = 1'b1;
129+
endcase
130+
end
131+
endmodule

0 commit comments

Comments
 (0)