Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Got incorrect warning message in latest releases version 4.202 #2938

Closed
yanjiuntw opened this issue May 10, 2021 · 13 comments
Closed

Got incorrect warning message in latest releases version 4.202 #2938

yanjiuntw opened this issue May 10, 2021 · 13 comments
Labels
area: lint Issue involves SystemVerilog lint checking resolution: fixed Closed; fixed

Comments

@yanjiuntw
Copy link

Hello,

I use latest releases version to check lint of my verilog file, but I got a incorrect message.

What 'verilator --version' are you using? Did you try it with the git master version?

$ verilator --version
Verilator 4.202 2021-04-24 rev v4.202

Can you attach an example that shows the issue? (Must be openly licensed, ideally in test_regress format.)

Here is my verilog file content:

// test.v
module test (
  input      [2:0] a,
  input      [7:0] c,

  output reg [7:0] b
);

  integer i;

  always @ (*)
  begin
    case(a)
      {3'b000}:
        b = 8'd1;
      {3'b001}:
        for(i=0;i<4;i=i+1) b[i*2+:2] = {2{c[i]}};
      {3'b010}:
        b = 8'd3;
      {3'b011}:
        b = 8'd4;
      default: b = 0;
    endcase
  end

endmodule

And I use this command run the test, and got a Warning-LATCH message:

$ verilator --lint-only -Wall test.v
%Warning-LATCH: test.v:10:3: Latch inferred for signal 'b' (not all control paths of combinational always assign a value)
                           : ... Suggest use of always_latch for intentional latches
   10 |   always @ (*)
      |   ^~~~~~
                ... For warning description see https://verilator.org/warn/LATCH?v=4.202
                ... Use "/* verilator lint_off LATCH */" and lint_on around source to disable this message.
%Error: Exiting due to 1 warning(s)

Would you be willing to try to fix Verilator yourself with assistance?

I will try if I can understand what wrong.

@yanjiuntw yanjiuntw added the new New issue not seen by maintainers label May 10, 2021
@udif
Copy link
Contributor

udif commented May 10, 2021

Out of curiosity, and taking advantage of a fast 8-core machine and git bisect, I found that the warnings started appearing on:

commit a11700271fc0c681bb1869bf6a299ff594c4028a (refs/bisect/bad)
Author: Julien Margetts <56540603+margej@users.noreply.github.com>
Date:   Tue Jan 5 19:26:01 2021 +0000

    Add LATCH and NOLATCH warnings (#1609) (#2740).

I don't plan doing any further work on this, but it was easy for me to at least help in locating where the issue started.
judging by the commit description, it's not a regression but rather a new feature that never worked for this testcase.

@wsnyder wsnyder added area: lint Issue involves SystemVerilog lint checking and removed new New issue not seen by maintainers labels May 10, 2021
@wsnyder
Copy link
Member

wsnyder commented May 10, 2021

Makes sense. I suspect it gets confused by the bit select range. @margej mind taking and look and making a proposal to fix it?

@margej
Copy link
Contributor

margej commented May 10, 2021

Sure, I'll take a look

@margej
Copy link
Contributor

margej commented May 11, 2021

Latch detection graph does not detect assignment to 'b' in the 3rd if (as commented below). This is probably because the assignments to b here depend upon the current value of b:

        // Body
        if ((4U & (IData)(vlTOPp->a))) {
            vlTOPp->b = 0U;
        } else {
            if ((2U & (IData)(vlTOPp->a))) {
                vlTOPp->b = ((1U & (IData)(vlTOPp->a))
                              ? 4U : 3U);
            } else {
                if ((1U & (IData)(vlTOPp->a))) { // Assignment to b NOT detected here
                    vlTOPp->b = ((0xf0U & (IData)(vlTOPp->b)) 
                                 | ((4U & ((IData)(vlTOPp->c) 
                                           << 1U)) 
                                    | (1U & (IData)(vlTOPp->c))));
                    vlTOPp->b = ((0xfU & (IData)(vlTOPp->b)) 
                                 | ((0x40U & ((IData)(vlTOPp->c) 
                                              << 3U)) 
                                    | (0x10U & 
                                       ((IData)(vlTOPp->c) 
                                        << 2U))));
                } else {
                    vlTOPp->b = 1U;
                }
            }
        }

@margej
Copy link
Contributor

margej commented May 11, 2021

The highlighted 'if' node should be green
image

@margej
Copy link
Contributor

margej commented May 11, 2021

The empty math node visitor 'optimisation' was preventing the graph pass reaching the varRef visitors when part select was used. The following patch seems to resolve the issue:

--- a/src/V3Active.cpp
+++ b/src/V3Active.cpp
@@ -317,8 +317,6 @@ private:
         iterateAndNextNull(nodep->elsesp());
         m_graph.currentp(parentp);
     }
-    // Empty visitors, speed things up
-    virtual void visit(AstNodeMath* nodep) {}
     //--------------------
     virtual void visit(AstNode* nodep) { iterateChildren(nodep); }

@wsnyder
Copy link
Member

wsnyder commented May 11, 2021

Can you please convert that to a pull, along with a test, then we can merge it. Thanks for debugging etc!

@wsnyder
Copy link
Member

wsnyder commented May 11, 2021

Oh, #2948

@margej
Copy link
Contributor

margej commented May 11, 2021

Sure, I'll add the test case provided by @yanjiuntw above (when I remind myself how to add a test)

@margej
Copy link
Contributor

margej commented May 11, 2021

'fix' seems to have lifted the lid on a bunch more false latch detections, but for some reason I can run any tests locally
Even 'make test' fails (as does almost every test in make test_regress with the same sort of error) with:

Archive ar -rcs Vt_a1_first_cc__ALL.a Vt_a1_first_cc__ALL.o
ar: @Vt_a1_first_cc__ALL.a.tmp: No such file or directory
g++    Vt_a1_first_cc__main.o verilated.o verilated_vcd_c.o Vt_a1_first_cc__ALL.a      -o Vt_a1_first_cc
g++: error: Vt_a1_first_cc__ALL.a: No such file or directory
make[1]: *** [Vt_a1_first_cc] Error 1

Clearly something wrong with my setup, but any pointers on what might be wrong would be gratefully received ?
This is with an unmodified checkout of tag v4.202 btw

@margej
Copy link
Contributor

margej commented May 12, 2021

I just realised I've been posting all my comments on the PR, not this issue, so 1, the above was resolved by #2921
2. Please see #2948 (comment) for question on resolving new test failure

@margej
Copy link
Contributor

margej commented May 28, 2021

Re: Issues on PR #2948 I need to distinguish AstIf nodes used for array bounds checking from those present in the RTL. It appears these are generated in V3Unknown.

My hope is I can flag them at creation so they can be later ignored for the purposes of latch detection

@wsnyder
Copy link
Member

wsnyder commented Jun 1, 2021

Thanks for your work on this.

@wsnyder wsnyder closed this as completed Jun 1, 2021
tklam pushed a commit to tklam/verilator that referenced this issue Jun 8, 2021
commit 6fd48da
Author: Wilson Snyder <wsnyder@wsnyder.org>
Date:   Mon Jun 7 07:47:15 2021 -0400

    Untabify cmakefiles. No functional change.

commit b976b8d
Author: Wilson Snyder <wsnyder@wsnyder.org>
Date:   Sun Jun 6 22:09:30 2021 -0400

    Fix slowdown in elaboration (verilator#2911).

commit c238d3d
Author: github action <action@example.com>
Date:   Sun Jun 6 23:57:41 2021 +0000

    Apply clang-format

commit 0edf1f0
Author: Geza Lore <gezalore@gmail.com>
Date:   Mon Jun 7 00:56:30 2021 +0100

    Add ccache-report target to standard Makefile (verilator#3011)

    Using the standard model Makefile, when in addition to an explicit
    target, the target 'ccache-report' is also given, a summary of ccache
    hits/misses during this invocation of 'make' will be prited at the end
    of the build.

commit 31bb73e
Author: Wilson Snyder <wsnyder@wsnyder.org>
Date:   Sun Jun 6 19:32:48 2021 -0400

    Fix MCD close also closing stdout (verilator#2931).

commit 8f2e4f6
Author: Wilson Snyder <wsnyder@wsnyder.org>
Date:   Sun Jun 6 10:32:50 2021 -0400

    Fix clang warning.

commit 2158a45
Author: Wilson Snyder <wsnyder@wsnyder.org>
Date:   Sun Jun 6 10:27:44 2021 -0400

    Tests: Reenable 18.04 MT (verilator#2963).

commit 1e89392
Author: Wilson Snyder <wsnyder@wsnyder.org>
Date:   Sun Jun 6 10:27:01 2021 -0400

    Add --expand-limit argument (verilator#3005).

commit b0c1ac7
Author: Martin Schmidt <martin.schmidt@epita.fr>
Date:   Sun Jun 6 15:27:44 2021 +0200

    Add support of --trace-structs parameter for CMake (verilator#2986)

commit 1f19e8e
Author: Wilson Snyder <wsnyder@wsnyder.org>
Date:   Sun Jun 6 09:17:56 2021 -0400

    Tests: Add test case for verilator#2895.

commit 258d9ad
Author: Geza Lore <gezalore@gmail.com>
Date:   Sat Jun 5 17:40:56 2021 +0100

    Aid IDE code linking in V3AstNodes.h (verilator#3009)

commit fa06357
Author: Miodrag Milanović <mmicko@gmail.com>
Date:   Fri Jun 4 18:04:55 2021 +0200

    Fix Makefiles to support Windows EXEEXT usage (verilator#3008).

commit eea7e1b
Author: Geza Lore <gezalore@gmail.com>
Date:   Fri Jun 4 15:00:13 2021 +0100

    Do not emit leading spaces on blank lines (verilator#3007)

commit fb561d9
Author: Wilson Snyder <wsnyder@wsnyder.org>
Date:   Thu Jun 3 21:19:11 2021 -0400

    Commentary (verilator#2996)

commit 9f5eb8f
Author: Wilson Snyder <wsnyder@wsnyder.org>
Date:   Thu Jun 3 21:15:42 2021 -0400

    Commentary

commit 1f331bd
Author: Julien Margetts <56540603+margej@users.noreply.github.com>
Date:   Tue Jun 1 14:01:18 2021 +0100

    Fix part select issues in LATCH warning. (verilator#2948) (verilator#2938)

commit 2143bcf
Author: Wilson Snyder <wsnyder@wsnyder.org>
Date:   Mon May 31 22:46:41 2021 -0400

    Fix constant function calls with uninit value (verilator#2995).

commit e1f9fff
Author: Geza Lore <gezalore@gmail.com>
Date:   Mon May 31 13:40:22 2021 +0100

    Fix --protect-ids when using SV classes (verilator#2994)

    A few names were incorrectly mangled, which made --protect-ids produce
    invalid output when certain SV class constructs were uses. Now fixed and
    added a few extra tests to catch this.

commit e4dcbb2
Author: Pieter Kapsenberg <pieter.kapsenberg@gmail.com>
Date:   Sun May 30 17:19:35 2021 -0700

    Fix unused variable warnings (verilator#2991)

commit f4c1a7e
Author: Geza Lore <gezalore@gmail.com>
Date:   Sat May 29 23:46:15 2021 +0100

    Emit: Fix indent tracking when // inside string literal (verilator#2990)

    // was so far unconditionally treated as comment.
    c443e22 introduced a string literal in
    the output that contained a http:// url, which broke the indent
    tracking. No functional change intended

commit ef9f477
Author: Geza Lore <gezalore@gmail.com>
Date:   Sat May 22 18:50:55 2021 +0100

    Make _ctror_var_reset and _configure_coverage static. (verilator#2977)

    Another step towards verilator#2958/verilator#2140. Make the mentioned generated functions
    static for modules (but not for classes).

commit 2dd5ef5
Author: Geza Lore <gezalore@gmail.com>
Date:   Sat May 22 12:27:32 2021 +0100

    Internals: Move --coverage and --savable check out of V3EmitC (verilator#2976)

commit a43eba7
Author: github action <action@example.com>
Date:   Sat May 22 10:14:07 2021 +0000

    Apply clang-format

commit 61c9866
Author: Geza Lore <gezalore@gmail.com>
Date:   Sat May 22 11:13:02 2021 +0100

    Internals: Generate ASTGEN_SUPER_* macros instead of expanding. (verilator#2975)

    astgen now generates ASTGEN_SUPER_* macros, instead of expanding the
    ASTGEN_SUPER itself. This means that V3AstNodes.h itself can be included
    in V3Ast.h, which helps IDEs (namely CLion) find definitions in
    V3AstNodes.h a lot better. Albeit this is a little bit more boilerplate,
    writing constructors of Ast nodes should be a lot rarer than trying to
    find their definitions, so hopefully this is an improvement overall.
    astgen will error if the developer calls the wrong superclass
    constructor.

commit 6378255
Author: Wilson Snyder <wsnyder@wsnyder.org>
Date:   Fri May 21 20:47:53 2021 -0400

    Internals: Fix some pylint warnings

commit 8814111
Author: Geza Lore <gezalore@gmail.com>
Date:   Fri May 21 14:34:27 2021 +0100

    Rework Ast hashing to be stable (verilator#2974)

    Rework Ast hashing to be stable

    Eliminated reliance on pointer values in AstNode hashes in order to make
    them stable. This requires moving the sameHash functions into a visitor,
    as nodes pointed to via members (and not child nodes) need to be hashed
    themselves.

    The hashes are now stable (as far as I could test them), and the impact
    on verilation time is small enough not to be reliably measurable.

commit fd35492
Author: Geza Lore <gezalore@gmail.com>
Date:   Fri May 21 01:41:46 2021 +0100

    Split V3Hashed to V3Hasher and V3DupFinder (verilator#2967)

    V3Hasher is responsible for computing AstNode hashes, while V3DupFinder
    can be used to find duplicate trees based on hashes. Interface of
    V3DupFinder simplified somewhat. No functional change intended at this
    point, but hash computation might differ in minor details, this however
    should have no perceivable effect on output/runtime.

    Implements (verilator#2964)

commit a44d2b2
Author: Geza Lore <gezalore@gmail.com>
Date:   Thu May 20 11:30:36 2021 +0100

    Move unreleased changes in right place in Changelog

commit aba3883
Author: Wilson Snyder <wsnyder@wsnyder.org>
Date:   Wed May 19 08:14:14 2021 -0400

    Commentary on MULTIDRIVEN (verilator#2972).

commit 9699192
Author: Geza Lore <gezalore@gmail.com>
Date:   Tue May 18 19:28:48 2021 +0100

    Don't merge bit select assignments in C code (verilator#2971)

commit 0f7ec6c
Author: Wilson Snyder <wsnyder@wsnyder.org>
Date:   Mon May 17 18:24:18 2021 -0400

    Fix missing array include (verilator#2966)

commit 471f14d
Author: Geza Lore <gezalore@gmail.com>
Date:   Mon May 17 13:26:24 2021 +0100

    Clean up V3Combine (verilator#2965)

    - Remove dead code
    - Simplify what is left
    - Minor improvements using C++11
    - Remove special case AstNode constructors used only in one place in
      V3Combine (inlined instead).

commit bdc162d
Author: Wilson Snyder <wsnyder@wsnyder.org>
Date:   Sun May 16 18:38:43 2021 -0400

    Fix 16.04 gcc warning

commit 706842d
Author: Wilson Snyder <wsnyder@wsnyder.org>
Date:   Sun May 16 15:11:25 2021 -0400

    CI: Disable Ubuntu-18.04 clang (verilator#2963)

commit 31779b8
Author: Yutetsu TAKATSUKASA <y.takatsukasa@gmail.com>
Date:   Sun May 16 19:01:03 2021 +0900

    Format time string using integer (verilator#2940)

    Co-authored-by: Wilson Snyder <wsnyder@wsnyder.org>

commit 80d62ad
Author: Geza Lore <gezalore@gmail.com>
Date:   Sat May 15 21:10:16 2021 +0100

    Make all AstNode* base class constructors protected. (verilator#2962)

    No functional changes intended. Boring patch in the hope of being
    helpful to new contributors. Although AstNode* base classes needing to
    be abstract is described in the internals manual, this might provide a
    bit of extra safety.

commit 38cab56
Author: Geza Lore <gezalore@gmail.com>
Date:   Sat May 15 18:04:40 2021 +0100

    Add --reloop-limit argument (verilator#2960)

    Add --reloop-limit argument

commit 828f78e
Author: Geza Lore <gezalore@gmail.com>
Date:   Sat May 15 16:05:24 2021 +0100

    Don't emit empty files with low split limits (verilator#2961)

    Attempt to split output files when we know a function will actually be
    emitted, otherwise we might end up with empty files.

commit 5e95cc9
Author: Geza Lore <gezalore@gmail.com>
Date:   Sat May 15 15:56:28 2021 +0100

    Internals: Make AstAlwaysPost an AstNodeProcedure. (verilator#2959)

    This seems to belong there, eliminates some code duplication in V3Clock,
    and also enables splitting AstAlwaysPost statements into different
    functions in V3Order, but should otherwise have little effect.

commit 88fed4b
Author: Wilson Snyder <wsnyder@wsnyder.org>
Date:   Thu May 13 18:56:07 2021 -0400

    Commentary on traces (verilator#2925)

commit 3718fe1
Author: Wilson Snyder <wsnyder@wsnyder.org>
Date:   Thu May 13 18:34:20 2021 -0400

    Commentary (trigger rebuild)

commit a4ab3e1
Author: Ameya Vikram Singh <ameya.v.singh@gmail.com>
Date:   Thu May 13 23:56:53 2021 +0530

    Update latest C++ Standard Compilation flag (verilator#2951)

    For SystemC Project sets the CXX_STANDARD flag from SystemC CMake build config.

commit 9c85426
Author: Yutetsu TAKATSUKASA <y.takatsukasa@gmail.com>
Date:   Thu May 13 06:45:56 2021 +0900

    Internals: Fix build failure on older gcc such as 4.8.5 on CentOS7. No functional change is intended. (verilator#2954)

commit e3b20a3
Author: Yutetsu TAKATSUKASA <y.takatsukasa@gmail.com>
Date:   Wed May 12 00:45:43 2021 +0900

    Internals: Mark VerilatedContextImp::timeFormatSuffix() const (verilator#2947)

commit f7c23c4
Author: Yutetsu TAKATSUKASA <y.takatsukasa@gmail.com>
Date:   Tue May 11 22:38:13 2021 +0900

    Internals: Set missing timescale though it is not referred yet. (verilator#2946)

commit 00cedf3
Author: Yutetsu TAKATSUKASA <y.takatsukasa@gmail.com>
Date:   Tue May 11 22:27:31 2021 +0900

    Tests: Add a test to check if there is overflow or rounding (verilator#2945)

commit 1422c23
Author: Geza Lore <gezalore@gmail.com>
Date:   Tue May 11 12:44:07 2021 +0100

    Split procedures to better respect --output-split-cfuncs (verilator#2942)

    CFuncs only used to be split at procedure (always/initial/final block),
    which on occasion can still yield huge output files if they have large
    procedures. This patch make CFuncs split at statement boundaries within
    procedures. This has the potential to help a lot, but still does not
    help if there are huge statements within procedures.

commit 1a63782
Author: Geza Lore <gezalore@gmail.com>
Date:   Mon May 10 22:15:12 2021 +0100

    Emit 'else if' without nesting. No functional change intended. (verilator#2944)

    Instead of:

    if (a) {
      x;
    } else {
      if (b) {
        y;
      } else {
        if (c) {
          z;
        } else {
          w;
        }
      }
    }

    Emit:

    if (a) {
      x;
    } else if (b) {
      y;
    } else if (c) {
      z;
    } else {
      w;
    }

commit 267c6f6
Author: Geza Lore <gezalore@gmail.com>
Date:   Mon May 10 18:01:11 2021 +0100

    Improve Reloop to accept constant index offsets. (verilator#2939)

    V3Reloop now can roll up indexed assignments between arrays if there is a
    constant offset between indices on the left and right hand sides, e.g.:

    a[0] = b[2];
    a[1] = b[3];
    ...
    a[x] = b[x + 2];

commit 45fbd98
Author: Yutetsu TAKATSUKASA <y.takatsukasa@gmail.com>
Date:   Sun May 9 07:04:22 2021 +0900

    Use V3OptionParser in verilator_coverage (verilator#2935)

    * Internals: Mark unused to avoid compilation failure. No functional change is intended.

    * Use V3OptionParser in VlcMain.cpp

commit f6c0108
Author: Geza Lore <gezalore@gmail.com>
Date:   Sat May 8 20:04:56 2021 +0100

    Optimize large lookup tables to static data (verilator#2926)

    Implements verilator#2925

commit 37d68d3
Author: Jonathan Drolet <jonathan.drolet@riedel.net>
Date:   Sat May 8 08:42:00 2021 -0400

    Support --trace-fst for SystemC with CMake (verilator#2927)

commit 5e56f4d
Author: Yutetsu TAKATSUKASA <y.takatsukasa@gmail.com>
Date:   Sat May 8 21:20:26 2021 +0900

    Tests: Enable undefined behavior sanitizor when --sanitize is set. (verilator#2923)

commit 2bf248b
Author: Jonathan Drolet <jonathan.drolet@gmail.com>
Date:   Sat May 8 08:18:08 2021 -0400

    Add TRACE_THREADS to CMake (verilator#2934)

commit 39ce2f7
Author: Yutetsu TAKATSUKASA <y.takatsukasa@gmail.com>
Date:   Sat May 8 09:45:58 2021 +0900

    Internals: Remove VerilatedVcd::m_suffixesp. No functional change is intended. (verilator#2933)

    Reasons are:
    - it's error prone to keep updating whennever m_suffixes is resized
    - invalid pointer may be set when there is not signal to trace as in t_trace_dumporder_bad

commit 9797af0
Author: Yutetsu TAKATSUKASA <y.takatsukasa@gmail.com>
Date:   Sat May 8 07:16:40 2021 +0900

    Introduce a macro VL_ATTR_NO_SANITIZE_ALIGN to suppress unaligned access check in ubsan (verilator#2929)

    * Add VL_ATTR_NO_SANITIZE_ALIGN macro to disable alignment check of ubsan

    * Mark a function VL_ATTR_NO_SANITIZE_ALIGN because the function is intentionally using unaligned access for the sake of performance.

    Co-authored-by: Wilson Snyder <wsnyder@wsnyder.org>

commit 1e4839e
Author: Yutetsu TAKATSUKASA <y.takatsukasa@gmail.com>
Date:   Sat May 8 01:00:36 2021 +0900

    Fix casting to integer not to cause integer overflow. (verilator#2930)

commit b2139f6
Author: Todd Strader <todd.strader@gmail.com>
Date:   Fri May 7 07:17:54 2021 -0400

    VPI memory access for packed arrays (verilator#2922)

commit 44fd205
Author: Philipp Wagner <mail@philipp-wagner.com>
Date:   Thu May 6 17:07:15 2021 +0100

    Fix make support for gmake 3.x (verilator#2920) (verilator#2921)

    The "file" make function is only available in gmake 4.x, which isn't
    available on RHEL/CentOS 7. Use alternative syntax to support older
    gmake versions.

    Fixes verilator#2920
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: lint Issue involves SystemVerilog lint checking resolution: fixed Closed; fixed
Projects
None yet
Development

No branches or pull requests

4 participants