From 4a58e859a40d18f37658bbb47b7ceb4f2d47f24f Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 3 May 2014 20:20:15 -0400 Subject: [PATCH] Fix concats with no argments mis-sign extending, bug759. --- Changes | 3 ++- src/V3AstNodes.h | 3 ++- src/verilog.y | 3 ++- test_regress/t/t_math_signed4.v | 21 +++++++++++++++++++++ test_regress/t/t_param_concat_bad.pl | 2 +- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Changes b/Changes index 8d06ffb23..05074b8f9 100644 --- a/Changes +++ b/Changes @@ -11,9 +11,10 @@ indicates the contributor was also the author of the fix; Thanks! ** Support streaming operators, bug649. [Glen Gibb] -** Fix expression problems with -Wno-WIDTH, bug729, bug736, bug737. [Clifford Wolf] +** Fix expression problems with -Wno-WIDTH, bug729, bug736, bug737, bug759. Where WIDTH warnings were ignored this might result in different warning messages and results, though it should better match the spec. + [Clifford Wolf] *** Add --no-trace-params. diff --git a/src/V3AstNodes.h b/src/V3AstNodes.h index 8e11cf5b4..2b1f38654 100644 --- a/src/V3AstNodes.h +++ b/src/V3AstNodes.h @@ -4164,6 +4164,8 @@ struct AstConcat : public AstNodeBiop { virtual int instrCount() const { return widthInstrs()*2; } }; struct AstReplicate : public AstNodeBiop { + // Also used as a "Uniop" flavor of Concat, e.g. "{a}" + // Verilog {rhs{lhs}} - Note rhsp() is the replicate value, not the lhsp() private: void init() { if (lhsp()) { @@ -4173,7 +4175,6 @@ private: } } public: - // Verilog {rhs{lhs}} - Note rhsp() is the replicate value, not the lhsp() AstReplicate(FileLine* fl, AstNode* lhsp, AstNode* rhsp) : AstNodeBiop(fl, lhsp, rhsp) { init(); } AstReplicate(FileLine* fl, AstNode* lhsp, uint32_t repCount) diff --git a/src/verilog.y b/src/verilog.y index ae6f672b7..7f875c9d7 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -3003,7 +3003,8 @@ exprNoStr: // expression with string removed exprOkLvalue: // expression that's also OK to use as a variable_lvalue ~l~exprScope { $$ = $1; } // // IEEE: concatenation/constant_concatenation - | '{' cateList '}' { $$ = $2; } + // // Replicate(1) required as otherwise "{a}" would not be self-determined + | '{' cateList '}' { $$ = new AstReplicate($1,$2,1); } // // IEEE: assignment_pattern_expression // // IEEE: [ assignment_pattern_expression_type ] == [ ps_type_id /ps_paremeter_id/data_type] // // We allow more here than the spec requires diff --git a/test_regress/t/t_math_signed4.v b/test_regress/t/t_math_signed4.v index fc70fc6c9..200cb4718 100644 --- a/test_regress/t/t_math_signed4.v +++ b/test_regress/t/t_math_signed4.v @@ -18,6 +18,7 @@ module t (/*AUTOARG*/); reg signed [4:0] w5_s; reg [3:0] w4_u; reg [4:0] w5_u; + reg signed [8:0] w9_s; real r; initial begin // verilator lint_off WIDTH @@ -93,7 +94,11 @@ module t (/*AUTOARG*/); // bug754 w5_u = 4'sb0010 << -2'sd1; // << 3 +`ifdef VCS + `checkh(w5_u, 5'b00000); // VCS E-2014.03 bug +`else `checkh(w5_u, 5'b10000); // VCS E-2014.03 bug +`endif w5_u = 4'sb1000 << 0; // Sign extends `checkh(w5_u, 5'b11000); @@ -112,6 +117,22 @@ module t (/*AUTOARG*/); default: $stop; endcase + // bug759 + w5_u = { -4'sd7 }; + `checkh(w5_u, 5'b01001); + w5_u = {2{ -2'sd1 }}; + `checkh(w5_u, 5'b01111); + // Don't break concats.... + w5_u = {{0{1'b1}}, -4'sd7 }; + `checkh(w5_u, 5'b01001); + w9_s = { -4'sd7, -4'sd7 }; + `checkh(w9_s, 9'b010011001); + {w5_u, {w4_u}} = 9'b10101_1100; + `checkh(w5_u, 5'b10101); + `checkh(w4_u, 4'b1100); + {w4_u} = 4'b1011; + `checkh(w4_u, 4'b1011); + if (fail) $stop; $write("*-* All Finished *-*\n"); $finish; diff --git a/test_regress/t/t_param_concat_bad.pl b/test_regress/t/t_param_concat_bad.pl index 496a4682f..20ca444fe 100755 --- a/test_regress/t/t_param_concat_bad.pl +++ b/test_regress/t/t_param_concat_bad.pl @@ -15,7 +15,7 @@ compile ( '%Warning-WIDTHCONCAT: t/t_param_concat.v:\d+: Unsized numbers/parameters not allowed in concatenations. %Warning-WIDTHCONCAT: Use "/\* verilator lint_off WIDTHCONCAT \*/" and lint_on around source to disable this message. %Warning-WIDTHCONCAT: t/t_param_concat.v:\d+: Unsized numbers/parameters not allowed in replications. -%Error: Exiting due to.*', +.*%Error: Exiting due to.*', ); ok(1);