Fix case statement comparing string literal (#3544).

This commit is contained in:
Wilson Snyder 2022-08-15 21:56:09 -04:00
parent d32e3f042f
commit f435d96241
4 changed files with 46 additions and 1 deletions

View File

@ -19,6 +19,7 @@ Verilator 4.225 devel
* Fix wrong bit op tree optimization (#3509). [Nathan Graybeal]
* Fix incorrect tristate logic (#3399) [shareefj, Vighnesh Iyer]
* Fix segfault exporting non-existant package (#3535).
* Fix case statement comparing string literal (#3544). [Gustav Svensk]
Verilator 4.224 2022-06-19

View File

@ -3977,8 +3977,10 @@ private:
itemp = VN_AS(itemp->nextp(), CaseItem)) {
for (AstNode* condp = itemp->condsp(); condp; condp = condp->nextp()) {
if (condp->dtypep() != subDTypep) {
if (condp->dtypep()->isDouble()) {
if (condp->dtypep()->isDouble() || subDTypep->isDouble()) {
subDTypep = nodep->findDoubleDType();
} else if (condp->dtypep()->isString() || subDTypep->isString()) {
subDTypep = nodep->findStringDType();
} else {
const int width = std::max(subDTypep->width(), condp->width());
const int mwidth = std::max(subDTypep->widthMin(), condp->widthMin());

View File

@ -0,0 +1,21 @@
#!/usr/bin/env perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2022 by Wilson Snyder. This program is free software; you
# can redistribute it and/or modify it under the terms of either the GNU
# Lesser General Public License Version 3 or the Perl Artistic License
# Version 2.0.
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
scenarios(simulator => 1);
compile(
);
execute(
check_finished => 1,
);
ok(1);
1;

View File

@ -0,0 +1,21 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2022 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0
module t;
function automatic string broken_case(input string some_string);
case(some_string)
"alpha": return "alpha";
default: return "beta";
endcase
endfunction
initial begin
$display(broken_case("gamma"));
$write("*-* All Finished *-*\n");
$finish;
end
endmodule