From 0081ce4a7506ac1ab05beeb0ded7288afdb21f2e Mon Sep 17 00:00:00 2001 From: Johan Bjork Date: Fri, 6 Nov 2015 19:12:17 -0500 Subject: [PATCH] Fix size-changing cast on packed struct, bug993. Signed-off-by: Wilson Snyder --- Changes | 2 ++ src/V3Width.cpp | 3 +++ test_regress/t/t_cast.v | 10 ++++++++++ 3 files changed, 15 insertions(+) diff --git a/Changes b/Changes index 3bb91959d..6a2c363cc 100644 --- a/Changes +++ b/Changes @@ -7,6 +7,8 @@ indicates the contributor was also the author of the fix; Thanks! **** Fix real parameters causing bad module names, bug992. [Johan Bjork] +**** Fix size-changing cast on packed struct, bug993. [Johan Bjork] + * Verilator 3.878 2015-11-01 diff --git a/src/V3Width.cpp b/src/V3Width.cpp index cc10df093..4ec37ea1c 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -1017,6 +1017,9 @@ private: if (width < 1) { nodep->v3error("Size-changing cast to zero or negative size"); width=1; } nodep->lhsp()->iterateAndNext(*this,WidthVP(SELF,PRELIM).p()); AstBasicDType* underDtp = nodep->lhsp()->dtypep()->castBasicDType(); + if (!underDtp) { + underDtp = nodep->lhsp()->dtypep()->basicp(); + } if (!underDtp) { nodep->v3error("Unsupported: Size-changing cast on non-basic data type"); underDtp = nodep->findLogicBoolDType()->castBasicDType(); diff --git a/test_regress/t/t_cast.v b/test_regress/t/t_cast.v index 616ac394d..b17a103ec 100644 --- a/test_regress/t/t_cast.v +++ b/test_regress/t/t_cast.v @@ -8,6 +8,15 @@ module t; typedef logic [3:0] mc_t; typedef mc_t tocast_t; + typedef struct packed { + logic [15:0] data; + } packed_t; + + packed_t pdata; + assign pdata.data = 16'h1234; + logic [7:0] logic8bit; + assign logic8bit = $bits(logic8bit)'(pdata >> 8); + mc_t o; logic [15:0] allones = 16'hffff; @@ -31,6 +40,7 @@ module t; (27'(coeff2 * samp2) >>> 11)); // 15' size casting to avoid synthesis/simulator warnings initial begin + if (logic8bit != 8'h12) $stop; if (4'shf > 4'sh0) $stop; if (signed'(4'hf) > 4'sh0) $stop; if (4'hf < 4'h0) $stop;