From 1fd8e772b0920684495d6367b58ac34e8f1c2ad0 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Tue, 10 Oct 2023 20:40:21 -0400 Subject: [PATCH] Fix loss of warning source content with `line enter (due to earlier commit 472ad90d837448ebc8e1647d54bbc4fa5bed681a). --- src/V3FileLine.h | 1 + src/V3ParseImp.cpp | 5 ++++- test_regress/t/t_lint_warn_incfile2_bad.out | 2 ++ test_regress/t/t_lint_warn_line_bad.out | 7 +++++++ test_regress/t/t_lint_warn_line_bad.pl | 22 +++++++++++++++++++++ test_regress/t/t_lint_warn_line_bad.v | 14 +++++++++++++ test_regress/t/t_vlt_warn_file_bad.out | 2 ++ 7 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 test_regress/t/t_lint_warn_line_bad.out create mode 100755 test_regress/t/t_lint_warn_line_bad.pl create mode 100644 test_regress/t/t_lint_warn_line_bad.v diff --git a/src/V3FileLine.h b/src/V3FileLine.h index 03cf71695..cdc6ab748 100644 --- a/src/V3FileLine.h +++ b/src/V3FileLine.h @@ -210,6 +210,7 @@ public: lineno(num); m_contentLineno = static_cast(num); } + void contentLinenoFrom(const FileLine* fromp) { m_contentLineno = fromp->m_contentLineno; } void lineno(int num) { m_firstLineno = num; m_lastLineno = num; diff --git a/src/V3ParseImp.cpp b/src/V3ParseImp.cpp index e2bfdedcf..1a058be02 100644 --- a/src/V3ParseImp.cpp +++ b/src/V3ParseImp.cpp @@ -85,8 +85,11 @@ void V3ParseImp::lexPpline(const char* textp) { lexFileline(newFl); lexFileline()->parent(prevFl); } else if (enterExit == 2) { // Exit + const FileLine* const prevFl = lexFileline(); if (FileLine* upFl = lexFileline()->parent()) { - lexFileline(upFl); // Restore warning state to upper file + // Must copy upFl as may be existing nodes that use the FileLine value + lexFileline(new FileLine{upFl}); // Restore warning state to upper file + lexFileline()->contentLinenoFrom(prevFl); } } if (enterExit != -1) { // Line/fn change diff --git a/test_regress/t/t_lint_warn_incfile2_bad.out b/test_regress/t/t_lint_warn_incfile2_bad.out index 5060cbd21..bea3e325b 100644 --- a/test_regress/t/t_lint_warn_incfile2_bad.out +++ b/test_regress/t/t_lint_warn_incfile2_bad.out @@ -1,5 +1,7 @@ %Warning-WIDTHTRUNC: t/t_lint_warn_incfile2_bad.v:13:17: Operator ASSIGN expects 32 bits on the Assign RHS, but Assign RHS's CONST '64'h1' generates 64 bits. : ... note: In instance 't' + 13 | int warn_t = 64'h1; + | ^~~~~ ... For warning description see https://verilator.org/warn/WIDTHTRUNC?v=latest ... Use "/* verilator lint_off WIDTHTRUNC */" and lint_on around source to disable this message. %Error: Exiting due to diff --git a/test_regress/t/t_lint_warn_line_bad.out b/test_regress/t/t_lint_warn_line_bad.out new file mode 100644 index 000000000..eec0f2982 --- /dev/null +++ b/test_regress/t/t_lint_warn_line_bad.out @@ -0,0 +1,7 @@ +%Warning-WIDTHTRUNC: the_line_file:13:17: Operator ASSIGN expects 32 bits on the Assign RHS, but Assign RHS's CONST '64'h1' generates 64 bits. + : ... note: In instance 't' + 13 | int warn_t = 64'h1; + | ^~~~~ + ... For warning description see https://verilator.org/warn/WIDTHTRUNC?v=latest + ... Use "/* verilator lint_off WIDTHTRUNC */" and lint_on around source to disable this message. +%Error: Exiting due to diff --git a/test_regress/t/t_lint_warn_line_bad.pl b/test_regress/t/t_lint_warn_line_bad.pl new file mode 100755 index 000000000..b3cdb56a9 --- /dev/null +++ b/test_regress/t/t_lint_warn_line_bad.pl @@ -0,0 +1,22 @@ +#!/usr/bin/env perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2008 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(vlt => 1); + +lint( + # See also t/t_lint_warn_incfile1_bad + # See also t/t_vlt_warn_file_bad + verilator_flags2 => ["--no-std"], + fails => 1, + expect_filename => $Self->{golden_filename}, + ); + +ok(1); +1; diff --git a/test_regress/t/t_lint_warn_line_bad.v b/test_regress/t/t_lint_warn_line_bad.v new file mode 100644 index 000000000..0c219e8a7 --- /dev/null +++ b/test_regress/t/t_lint_warn_line_bad.v @@ -0,0 +1,14 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2023 by Wilson Snyder. +// SPDX-License-Identifier: CC0-1.0 + +// Check that `line `__LINE__ still shows proper warning context + +`line `__LINE__ "the_line_file" 1 +`line `__LINE__ "the_line_file" 2 + +module t; + int warn_t = 64'h1; // Not suppressed - should warn +endmodule diff --git a/test_regress/t/t_vlt_warn_file_bad.out b/test_regress/t/t_vlt_warn_file_bad.out index 6ff3c6fe0..77804160c 100644 --- a/test_regress/t/t_vlt_warn_file_bad.out +++ b/test_regress/t/t_vlt_warn_file_bad.out @@ -1,5 +1,7 @@ %Warning-WIDTHTRUNC: t/t_vlt_warn_file_bad.v:11:17: Operator ASSIGN expects 32 bits on the Assign RHS, but Assign RHS's CONST '64'h1' generates 64 bits. : ... note: In instance 't' + 11 | int warn_t = 64'h1; + | ^~~~~ ... For warning description see https://verilator.org/warn/WIDTHTRUNC?v=latest ... Use "/* verilator lint_off WIDTHTRUNC */" and lint_on around source to disable this message. %Error: Exiting due to