From 3c336e179f371fa6922e90dcaaf4fc4d6f136841 Mon Sep 17 00:00:00 2001 From: Todd Strader Date: Tue, 29 Sep 2015 21:02:33 -0400 Subject: [PATCH] Fix structure parameter constant propagation, bug968. Signed-off-by: Wilson Snyder --- Changes | 2 ++ src/V3Simulate.h | 3 ++- test_regress/t/t_static_elab_struct.pl | 18 +++++++++++++++ test_regress/t/t_static_elab_struct.v | 32 ++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100755 test_regress/t/t_static_elab_struct.pl create mode 100644 test_regress/t/t_static_elab_struct.v diff --git a/Changes b/Changes index 6463c4a07..f0a936cb4 100644 --- a/Changes +++ b/Changes @@ -13,6 +13,8 @@ indicates the contributor was also the author of the fix; Thanks! **** Fix internal error on dotted refs into generates, bug958. [Jie Xu] +**** Fix structure parameter constant propagation, bug968. [Todd Strader] + **** Fix mis-optimizing public DPI functions, bug963. [Wei Song] diff --git a/src/V3Simulate.h b/src/V3Simulate.h index 2114c8ff3..b09abc03d 100644 --- a/src/V3Simulate.h +++ b/src/V3Simulate.h @@ -261,7 +261,8 @@ private: // as we don't figure out variable ordering. // Delayed is OK though, as we'll decode the next state separately. if (!nodep->varp()->dtypeSkipRefp()->castBasicDType() - && !nodep->varp()->dtypeSkipRefp()->castPackArrayDType()) + && !nodep->varp()->dtypeSkipRefp()->castPackArrayDType() + && !nodep->varp()->dtypeSkipRefp()->castStructDType()) clearOptimizable(nodep,"Array references/not basic"); if (nodep->lvalue()) { if (m_inDlyAssign) { diff --git a/test_regress/t/t_static_elab_struct.pl b/test_regress/t/t_static_elab_struct.pl new file mode 100755 index 000000000..f91289753 --- /dev/null +++ b/test_regress/t/t_static_elab_struct.pl @@ -0,0 +1,18 @@ +#!/usr/bin/perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2003 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. + +compile ( + ); + +execute ( + check_finished=>1, + ); + +ok(1); +1; diff --git a/test_regress/t/t_static_elab_struct.v b/test_regress/t/t_static_elab_struct.v new file mode 100644 index 000000000..18a50326e --- /dev/null +++ b/test_regress/t/t_static_elab_struct.v @@ -0,0 +1,32 @@ +// DESCRIPTION: Verilator: Simple static elaboration case +// +// This file ONLY is placed into the Public Domain, for any use, +// without warranty, 2015 by Todd Strader. + +module t (/*AUTOARG*/); + + typedef struct packed { + logic [ 31 : 0 ] _five; + } five_t; + + function five_t gimme_five (); + automatic five_t result; + + result._five = 5; + + return result; + endfunction + + localparam five_t FIVE = gimme_five(); + + initial begin + if (FIVE._five != 5) begin + $display("%%Error: Got 0b%b instead of 5", FIVE._five); + $stop; + end + + $write("*-* All Finished *-*\n"); + $finish; + end + +endmodule