From 23413a4d12ad070c8a356c5a3186f81def705c54 Mon Sep 17 00:00:00 2001 From: gatecat Date: Thu, 25 Feb 2021 11:21:39 +0000 Subject: [PATCH] Fix compiler warnings introduced by -Wextra Signed-off-by: gatecat --- .../internal/gtest-param-util-generated.h | 1 + CMakeLists.txt | 3 +- common/nextpnr.h | 6 ++-- common/relptr.h | 4 +-- common/router2.cc | 2 +- ecp5/archdefs.h | 1 - ecp5/lpf.cc | 2 +- fpga_interchange/dedicated_interconnect.cc | 4 +-- fpga_interchange/fpga_interchange.cpp | 2 +- gowin/arch.cc | 32 +++++++++---------- gowin/arch.h | 16 +++++----- gowin/main.cc | 6 ++-- gui/fpgaviewwidget.h | 2 ++ gui/quadtree.h | 2 -- gui/treemodel.h | 6 ++-- machxo2/arch.cc | 1 + machxo2/archdefs.h | 1 - machxo2/bitstream.cc | 14 -------- tests | 2 +- 19 files changed, 47 insertions(+), 60 deletions(-) diff --git a/3rdparty/googletest/googletest/include/gtest/internal/gtest-param-util-generated.h b/3rdparty/googletest/googletest/include/gtest/internal/gtest-param-util-generated.h index 4d1d81d2..a4cdcc67 100644 --- a/3rdparty/googletest/googletest/include/gtest/internal/gtest-param-util-generated.h +++ b/3rdparty/googletest/googletest/include/gtest/internal/gtest-param-util-generated.h @@ -95,6 +95,7 @@ template class ValueArray2 { public: ValueArray2(T1 v1, T2 v2) : v1_(v1), v2_(v2) {} + ValueArray2(const ValueArray2& other) = default; template operator ParamGenerator() const { diff --git a/CMakeLists.txt b/CMakeLists.txt index f2377975..05b0cce7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,7 +106,8 @@ if (MSVC) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /D_DEBUG /W4 /wd4100 /wd4244 /wd4125 /wd4800 /wd4456 /wd4458 /wd4305 /wd4459 /wd4121 /wd4996") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /W4 /wd4100 /wd4244 /wd4125 /wd4800 /wd4456 /wd4458 /wd4305 /wd4459 /wd4121 /wd4996 /wd4127") else() - set(WARN_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Werror=sign-compare -Werror=return-type") + # N.B. the -Wno-array-bounds is to work around a false positive in GCC 9 + set(WARN_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wno-array-bounds -Werror=sign-compare -Werror=return-type") if (WERROR) set(WARN_FLAGS "${WARN_FLAGS} -Werror") endif() diff --git a/common/nextpnr.h b/common/nextpnr.h index 59198d6d..549e8e35 100644 --- a/common/nextpnr.h +++ b/common/nextpnr.h @@ -99,7 +99,7 @@ inline void assert_fail_impl_str(std::string message, const char *expr_str, cons #define NPNR_ASSERT_FALSE(msg) (assert_fail_impl(msg, "false", __FILE__, __LINE__)) #define NPNR_ASSERT_FALSE_STR(msg) (assert_fail_impl_str(msg, "false", __FILE__, __LINE__)) -#define STRINGIFY(x) #x +#define NPNR_STRINGIFY(x) #x struct BaseCtx; struct Context; @@ -541,7 +541,7 @@ struct Property ret.is_string = false; ret.str.reserve(len); for (int i = offset; i < offset + len; i++) - ret.str.push_back(i < int(str.size()) ? str[i] : padding); + ret.str.push_back(i < int(str.size()) ? str[i] : char(padding)); ret.update_intval(); return ret; } @@ -1255,7 +1255,7 @@ template struct BaseArch : ArchAPI // Default, trivial, implementations of Arch API functions for arches that don't need complex behaviours // Basic config - virtual IdString archId() const override { return this->id(STRINGIFY(ARCHNAME)); } + virtual IdString archId() const override { return this->id(NPNR_STRINGIFY(ARCHNAME)); } virtual IdString archArgsToId(typename R::ArchArgsT args) const override { return IdString(); } virtual int getTilePipDimZ(int x, int y) const override { return 1; } virtual char getNameDelimiter() const override { return ' '; } diff --git a/common/relptr.h b/common/relptr.h index d45912ab..76850bc9 100644 --- a/common/relptr.h +++ b/common/relptr.h @@ -31,8 +31,8 @@ NPNR_PACKED_STRUCT(template struct RelSlice { const T *begin() const { return get(); } const T *end() const { return get() + length; } - const size_t size() const { return length; } - const ptrdiff_t ssize() const { return length; } + size_t size() const { return length; } + ptrdiff_t ssize() const { return length; } const T &operator*() const { return *(get()); } diff --git a/common/router2.cc b/common/router2.cc index a2023f47..f5779356 100644 --- a/common/router2.cc +++ b/common/router2.cc @@ -1211,7 +1211,7 @@ Router2Cfg::Router2Cfg(Context *ctx) hist_cong_weight = ctx->setting("router2/histCongWeight", 1.0f); curr_cong_mult = ctx->setting("router2/currCongWeightMult", 2.0f); estimate_weight = ctx->setting("router2/estimateWeight", 1.75f); - perf_profile = ctx->setting("router2/perfProfile", false); + perf_profile = ctx->setting("router2/perfProfile", false); } NEXTPNR_NAMESPACE_END diff --git a/ecp5/archdefs.h b/ecp5/archdefs.h index 732ea99a..cf6902d3 100644 --- a/ecp5/archdefs.h +++ b/ecp5/archdefs.h @@ -56,7 +56,6 @@ struct Location Location() : x(-1), y(-1){}; Location(int16_t x, int16_t y) : x(x), y(y){}; Location(const LocationPOD &pod) : x(pod.x), y(pod.y){}; - Location(const Location &loc) : x(loc.x), y(loc.y){}; bool operator==(const Location &other) const { return x == other.x && y == other.y; } bool operator!=(const Location &other) const { return x != other.x || y != other.y; } diff --git a/ecp5/lpf.cc b/ecp5/lpf.cc index c12b65c4..22859783 100644 --- a/ecp5/lpf.cc +++ b/ecp5/lpf.cc @@ -77,7 +77,7 @@ bool Arch::apply_lpf(std::string filename, std::istream &in) std::string tmp; while (ss >> tmp) words.push_back(tmp); - if (words.size() >= 0) { + if (words.size() > 0) { std::string verb = words.at(0); if (verb == "BLOCK") { if (words.size() != 2 || (words.at(1) != "ASYNCPATHS" && words.at(1) != "RESETPATHS")) diff --git a/fpga_interchange/dedicated_interconnect.cc b/fpga_interchange/dedicated_interconnect.cc index 820896a3..988b13ab 100644 --- a/fpga_interchange/dedicated_interconnect.cc +++ b/fpga_interchange/dedicated_interconnect.cc @@ -441,7 +441,7 @@ void DedicatedInterconnect::find_dedicated_interconnect() continue; } - for (size_t i = 0; i < bel_data.num_bel_wires; ++i) { + for (int i = 0; i < bel_data.num_bel_wires; ++i) { if (bel_data.types[i] != PORT_IN) { continue; } @@ -470,7 +470,7 @@ void DedicatedInterconnect::find_dedicated_interconnect() continue; } - for (size_t i = 0; i < bel_data.num_bel_wires; ++i) { + for (int i = 0; i < bel_data.num_bel_wires; ++i) { if (bel_data.types[i] != PORT_OUT) { continue; } diff --git a/fpga_interchange/fpga_interchange.cpp b/fpga_interchange/fpga_interchange.cpp index a1642789..9410b117 100644 --- a/fpga_interchange/fpga_interchange.cpp +++ b/fpga_interchange/fpga_interchange.cpp @@ -1018,7 +1018,7 @@ size_t ModuleReader::translate_port_index(LogicalNetlist::Netlist::PortInstance: NPNR_ASSERT(port.isBus()); uint32_t idx = port_inst.getBusIdx().getIdx(); size_t width = get_port_width(port); - NPNR_ASSERT(idx >= 0 && idx < width); + NPNR_ASSERT(idx < width); return width - 1 - idx; } } diff --git a/gowin/arch.cc b/gowin/arch.cc index 7e947341..72051b3f 100644 --- a/gowin/arch.cc +++ b/gowin/arch.cc @@ -613,20 +613,20 @@ Arch::Arch(ArchArgs args) : args(args) // fall through the ++ case ID_LUT7: z++; - dff = false; + dff = false; /* fall-through*/ case ID_LUT6: z++; - dff = false; + dff = false; /* fall-through*/ case ID_LUT5: - z++; + z++; /* fall-through*/ case ID_LUT4: - z++; + z++; /* fall-through*/ case ID_LUT3: - z++; + z++; /* fall-through*/ case ID_LUT2: - z++; + z++; /* fall-through*/ case ID_LUT1: - z++; + z++; /* fall-through*/ case ID_LUT0: // common LUT+DFF code snprintf(buf, 32, "R%dC%d_SLICE%d", row + 1, col + 1, z); @@ -654,23 +654,23 @@ Arch::Arch(ArchArgs args) : args(args) } break; case ID_IOBJ: - z++; + z++; /* fall-through*/ case ID_IOBI: - z++; + z++; /* fall-through*/ case ID_IOBH: - z++; + z++; /* fall-through*/ case ID_IOBG: - z++; + z++; /* fall-through*/ case ID_IOBF: - z++; + z++; /* fall-through*/ case ID_IOBE: - z++; + z++; /* fall-through*/ case ID_IOBD: - z++; + z++; /* fall-through*/ case ID_IOBC: - z++; + z++; /* fall-through*/ case ID_IOBB: - z++; + z++; /* fall-through*/ case ID_IOBA: snprintf(buf, 32, "R%dC%d_IOB%c", row + 1, col + 1, 'A' + z); belname = id(buf); diff --git a/gowin/arch.h b/gowin/arch.h index 052c1545..e0686d1c 100644 --- a/gowin/arch.h +++ b/gowin/arch.h @@ -348,9 +348,9 @@ struct Arch : BaseArch int getGridDimX() const override { return gridDimX; } int getGridDimY() const override { return gridDimY; } - int getTileBelDimZ(int x, int y) const { return tileBelDimZ[x][y]; } - int getTilePipDimZ(int x, int y) const { return tilePipDimZ[x][y]; } - char getNameDelimiter() const + int getTileBelDimZ(int x, int y) const override { return tileBelDimZ[x][y]; } + int getTilePipDimZ(int x, int y) const override { return tilePipDimZ[x][y]; } + char getNameDelimiter() const override { return ' '; /* use a non-existent delimiter as we aren't using IdStringLists yet */ } @@ -431,13 +431,13 @@ struct Arch : BaseArch bool place() override; bool route() override; - bool getCellDelay(const CellInfo *cell, IdString fromPort, IdString toPort, DelayQuad &delay) const; + bool getCellDelay(const CellInfo *cell, IdString fromPort, IdString toPort, DelayQuad &delay) const override; // Get the port class, also setting clockInfoCount to the number of TimingClockingInfos associated with a port - TimingPortClass getPortTimingClass(const CellInfo *cell, IdString port, int &clockInfoCount) const; + TimingPortClass getPortTimingClass(const CellInfo *cell, IdString port, int &clockInfoCount) const override; // Get the TimingClockingInfo of a port - TimingClockingInfo getPortClockingInfo(const CellInfo *cell, IdString port, int index) const; + TimingClockingInfo getPortClockingInfo(const CellInfo *cell, IdString port, int index) const override; - bool isBelLocationValid(BelId bel) const; + bool isBelLocationValid(BelId bel) const override; static const std::string defaultPlacer; static const std::vector availablePlacers; @@ -446,7 +446,7 @@ struct Arch : BaseArch // --------------------------------------------------------------- // Internal usage - void assignArchInfo(); + void assignArchInfo() override; bool cellsCompatible(const CellInfo **cells, int count) const; std::vector cell_types; diff --git a/gowin/main.cc b/gowin/main.cc index 308be4d3..674eac03 100644 --- a/gowin/main.cc +++ b/gowin/main.cc @@ -61,10 +61,10 @@ std::unique_ptr GowinCommandHandler::createContext(std::unordered_map class QuadTreeNode BoundingBox() : x0_(pinf), y0_(pinf), x1_(ninf), y1_(ninf) {} - BoundingBox(const BoundingBox &other) : x0_(other.x0_), y0_(other.y0_), x1_(other.x1_), y1_(other.y1_) {} - // Whether a bounding box contains a given points. // A point is defined to be in a bounding box when it's not lesser than // the lower coordinate or greater than the higher coordinate, eg: diff --git a/gui/treemodel.h b/gui/treemodel.h index 7b599e65..e9c42a0f 100644 --- a/gui/treemodel.h +++ b/gui/treemodel.h @@ -218,7 +218,7 @@ template class ElementList : public Item name.remove(0, prefix.size()); auto item = new IdStringItem(ctx_, idstring, this, child_type_); - managed_[idstring] = std::move(std::unique_ptr(item)); + managed_[idstring] = std::unique_ptr(item); } } @@ -306,7 +306,7 @@ template class ElementXYRoot : public Item // Create X list Item. auto item = new Item(QString("X%1").arg(i), this); - managed_labels_.push_back(std::move(std::unique_ptr(item))); + managed_labels_.push_back(std::unique_ptr(item)); for (auto j : y_present) { // Create Y list ElementList. @@ -314,7 +314,7 @@ template class ElementXYRoot : public Item new ElementList(ctx_, QString("Y%1").arg(j), item, &map_, i, j, getter_, child_type_); // Pre-populate list with one element, other Qt will never ask for more. item2->fetchMore(1); - managed_lists_.push_back(std::move(std::unique_ptr>(item2))); + managed_lists_.push_back(std::unique_ptr>(item2)); } } } diff --git a/machxo2/arch.cc b/machxo2/arch.cc index 74bfc598..6a29dbb1 100644 --- a/machxo2/arch.cc +++ b/machxo2/arch.cc @@ -153,6 +153,7 @@ std::string Arch::get_full_chip_name() const break; case ArchArgs::SPEED_3: name += "3"; + break; case ArchArgs::SPEED_4: name += "4"; break; diff --git a/machxo2/archdefs.h b/machxo2/archdefs.h index f822b907..433b1b6b 100644 --- a/machxo2/archdefs.h +++ b/machxo2/archdefs.h @@ -48,7 +48,6 @@ struct Location Location() : x(-1), y(-1){}; Location(int16_t x, int16_t y) : x(x), y(y){}; Location(const LocationPOD &pod) : x(pod.x), y(pod.y){}; - Location(const Location &loc) : x(loc.x), y(loc.y){}; bool operator==(const Location &other) const { return x == other.x && y == other.y; } bool operator!=(const Location &other) const { return x != other.x || y != other.y; } diff --git a/machxo2/bitstream.cc b/machxo2/bitstream.cc index 37363b09..d695b094 100644 --- a/machxo2/bitstream.cc +++ b/machxo2/bitstream.cc @@ -114,20 +114,6 @@ static std::vector int_to_bitvector(int val, int size) return bv; } -static std::vector str_to_bitvector(std::string str, int size) -{ - std::vector bv; - bv.resize(size, 0); - if (str.substr(0, 2) != "0b") - log_error("error parsing value '%s', expected 0b prefix\n", str.c_str()); - for (int i = 0; i < int(str.size()) - 2; i++) { - char c = str.at((str.size() - i) - 1); - NPNR_ASSERT(c == '0' || c == '1'); - bv.at(i) = (c == '1'); - } - return bv; -} - std::string intstr_or_default(const std::unordered_map &ct, const IdString &key, std::string def = "0") { diff --git a/tests b/tests index 32db04a1..34c51144 160000 --- a/tests +++ b/tests @@ -1 +1 @@ -Subproject commit 32db04a11077e7a32adc6f3d473e5cbefe83ff0a +Subproject commit 34c511444eff51291fa732369e434ff687de310f