YosysHQ / yosys

Yosys Open SYnthesis Suite
https://yosyshq.net/yosys/
ISC License
3.5k stars 895 forks source link

Reduce compiler warnings when building yosys #4713

Open ldoolitt opened 2 weeks ago

ldoolitt commented 2 weeks ago

Feature Description

Building current main-branch yosys (specifically commit 2de9f00) with g++ 12.2.0, I get 45 warnings:

I can eliminate most (18) of the maybe-uninitialized with this two-line patch.

diff --git a/kernel/drivertools.h b/kernel/drivertools.h
index 079701c35..39d4bd7a7 100644
--- a/kernel/drivertools.h
+++ b/kernel/drivertools.h
@@ -364,7 +364,7 @@ public:

        unsigned int hash() const
        {
-               unsigned int inner;
+               unsigned int inner = 0;
                switch (type_)
                {
                        case DriveType::NONE:
@@ -912,7 +912,7 @@ public:

        unsigned int hash() const
        {
-               unsigned int inner;
+               unsigned int inner = 0;
                switch (type_)
                {
                        case DriveType::NONE:

Do y'all want a pull request? Should I add a default: assert() to the two switch() statements?

KrystalDelusion commented 2 weeks ago

The sign compares have been raised and should be in progress for fix. PR for this would be appreciated :) type_ is assigned DriveType::NONE by default, so there shouldn't be a need to assert on default, but it wouldn't hurt to check just in case.