From 6ff6f8fb3c7c8075a10bec1034176b44e0cc07c0 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Wed, 13 May 2026 10:10:59 +0200 Subject: [PATCH 01/10] Bump required standard to C++20 --- .github/workflows/test-compile.yml | 16 ++++++++-------- Makefile | 4 ++-- misc/create_vcxsrc.sh | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test-compile.yml b/.github/workflows/test-compile.yml index 9c75784bf..c322c25b2 100644 --- a/.github/workflows/test-compile.yml +++ b/.github/workflows/test-compile.yml @@ -82,20 +82,20 @@ jobs: $CXX --version # minimum standard - - name: Build C++17 - shell: bash - run: | - make config-$CC_SHORT - make -j$procs CXXSTD=c++17 compile-only - - # maximum standard, only on newest compilers - name: Build C++20 - if: ${{ matrix.compiler == 'clang-19' || matrix.compiler == 'gcc-14' }} shell: bash run: | make config-$CC_SHORT make -j$procs CXXSTD=c++20 compile-only + # maximum standard, only on newest compilers + - name: Build C++26 + if: ${{ matrix.compiler == 'clang-19' || matrix.compiler == 'gcc-14' }} + shell: bash + run: | + make config-$CC_SHORT + make -j$procs CXXSTD=c++26 compile-only + test-compile-result: runs-on: ubuntu-latest needs: diff --git a/Makefile b/Makefile index 3c5c10cda..afbc11005 100644 --- a/Makefile +++ b/Makefile @@ -103,7 +103,7 @@ VPATH := $(YOSYS_SRC) # Unit test UNITESTPATH := $(YOSYS_SRC)/tests/unit -export CXXSTD ?= c++17 +export CXXSTD ?= c++20 CXXFLAGS := $(CXXFLAGS) -Wall -Wextra -Werror=unused -ggdb -I. -I"$(YOSYS_SRC)" -MD -MP -D_YOSYS_ -fPIC -I$(PREFIX)/include LIBS := $(LIBS) -lstdc++ -lm PLUGIN_LINKFLAGS := @@ -1142,7 +1142,7 @@ vcxsrc: $(GENFILES) $(EXTRA_TARGETS) kernel/version_$(GIT_REV).cc rm -rf $(VCX_DIR_NAME){,.zip} cp -f kernel/version_$(GIT_REV).cc kernel/version.cc set -e; for f in `ls $(filter %.cc %.cpp,$(GENFILES)) $(addsuffix .cc,$(basename $(OBJS))) $(addsuffix .cpp,$(basename $(OBJS))) 2> /dev/null`; do \ - echo "Analyse: $$f" >&2; cpp -std=c++17 -MM -I. -D_YOSYS_ $$f; done | sed 's,.*:,,; s,//*,/,g; s,/[^/]*/\.\./,/,g; y, \\,\n\n,;' | grep '^[^/]' | sort -u | grep -v kernel/version_ > srcfiles.txt + echo "Analyse: $$f" >&2; cpp -std=c++20 -MM -I. -D_YOSYS_ $$f; done | sed 's,.*:,,; s,//*,/,g; s,/[^/]*/\.\./,/,g; y, \\,\n\n,;' | grep '^[^/]' | sort -u | grep -v kernel/version_ > srcfiles.txt echo "libs/fst/fst_win_unistd.h" >> srcfiles.txt echo "kernel/version.cc" >> srcfiles.txt bash misc/create_vcxsrc.sh $(VCX_DIR_NAME) $(YOSYS_VER) diff --git a/misc/create_vcxsrc.sh b/misc/create_vcxsrc.sh index 98c1817bd..c880c2a48 100644 --- a/misc/create_vcxsrc.sh +++ b/misc/create_vcxsrc.sh @@ -35,7 +35,7 @@ popd tail -n +$((n+1)) "$vcxsrc"/YosysVS/YosysVS.vcxproj } > "$vcxsrc"/YosysVS/YosysVS.vcxproj.new -sed -i 's,,\n stdcpp17\n /Zc:__cplusplus %(AdditionalOptions),g' "$vcxsrc"/YosysVS/YosysVS.vcxproj.new +sed -i 's,,\n stdcpp20\n /Zc:__cplusplus %(AdditionalOptions),g' "$vcxsrc"/YosysVS/YosysVS.vcxproj.new sed -i 's,,YOSYS_ENABLE_THREADS;,g' "$vcxsrc"/YosysVS/YosysVS.vcxproj.new if [ -f "/usr/include/FlexLexer.h" ] ; then sed -i 's,,;..\\yosys\\libs\\flex,g' "$vcxsrc"/YosysVS/YosysVS.vcxproj.new From 90e019e319a0b0b81c4b95199937900b20045cce Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Wed, 13 May 2026 10:11:36 +0200 Subject: [PATCH 02/10] Fix compiling on GCC11 --- passes/cmds/timeest.cc | 6 +++--- passes/sat/formalff.cc | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/passes/cmds/timeest.cc b/passes/cmds/timeest.cc index 1caa1ddaf..4f6105356 100644 --- a/passes/cmds/timeest.cc +++ b/passes/cmds/timeest.cc @@ -100,7 +100,7 @@ struct EstimateSta { log_id(cell), log_id(cell->type)); continue; } - if (ff.sig_clk != clk) + if (!clk || ff.sig_clk.as_bit() != *clk) continue; launch.append(ff.sig_q); sample.append(ff.sig_d); @@ -144,12 +144,12 @@ struct EstimateSta { log_error("Unsupported async memory port '%s'\n", log_id(rd.cell)); continue; } - if (sigmap(rd.clk) != clk) + if (!clk || sigmap(rd.clk).as_bit() != *clk) continue; add_seq(rd.cell, rd.data, {rd.addr, rd.srst, rd.en}); } for (auto &wr : mem.wr_ports) { - if (sigmap(wr.clk) != clk) + if (!clk || sigmap(wr.clk).as_bit() != *clk) continue; add_seq(wr.cell, {}, {wr.en, wr.addr, wr.data}); } diff --git a/passes/sat/formalff.cc b/passes/sat/formalff.cc index 452e0e59b..5ac93eca7 100644 --- a/passes/sat/formalff.cc +++ b/passes/sat/formalff.cc @@ -767,7 +767,7 @@ struct FormalFfPass : public Pass { ff.sig_d = ff.sig_ad; } - if (!ff.has_clk || sigmap(ff.sig_clk) != gate_clock || ff.pol_clk != pol_clk) { + if (!ff.has_clk || sigmap(ff.sig_clk).as_bit() != gate_clock || ff.pol_clk != pol_clk) { log_debug("FF driver for gate enable %s.%s of gated clk bit %s.%s has incompatible clocking: " "%s %s.%s\n", log_id(module), log_signal(SigSpec(gate_enable)), log_id(module), @@ -798,7 +798,7 @@ struct FormalFfPass : public Pass { auto &mem = memories.at(clocked_cell->name); bool changed = false; for (auto &rd_port : mem.rd_ports) { - if (rd_port.clk_enable && rd_port.clk == clk && rd_port.clk_polarity == pol_clk) { + if (rd_port.clk_enable && rd_port.clk.as_bit() == clk && rd_port.clk_polarity == pol_clk) { log_debug("patching rd port\n"); changed = true; rd_port.clk = gate_clock; @@ -808,7 +808,7 @@ struct FormalFfPass : public Pass { } } for (auto &wr_port : mem.wr_ports) { - if (wr_port.clk_enable && wr_port.clk == clk && wr_port.clk_polarity == pol_clk) { + if (wr_port.clk_enable && wr_port.clk.as_bit() == clk && wr_port.clk_polarity == pol_clk) { log_debug("patching wr port\n"); changed = true; wr_port.clk = gate_clock; From 25459bd8b96d2e6fedf120b6de703578b5126889 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Wed, 13 May 2026 11:09:40 +0200 Subject: [PATCH 03/10] Fix for clang-10 toolchain --- .github/workflows/test-compile.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/test-compile.yml b/.github/workflows/test-compile.yml index c322c25b2..2540a8415 100644 --- a/.github/workflows/test-compile.yml +++ b/.github/workflows/test-compile.yml @@ -74,6 +74,7 @@ jobs: uses: aminya/setup-cpp@v1 with: compiler: ${{ matrix.compiler }} + gcc: ${{ (matrix.os == 'ubuntu-latest' && matrix.compiler == 'clang-10') && '10' || '' }} - name: Tool versions shell: bash @@ -81,6 +82,11 @@ jobs: $CC --version $CXX --version + - name: Fix clang-10 toolchain + if: matrix.os == 'ubuntu-latest' && matrix.compiler == 'clang-10' + run: | + echo "CXXFLAGS=--gcc-toolchain=/usr/lib/gcc/x86_64-linux-gnu/10 -stdlib=libstdc++" >> $GITHUB_ENV + # minimum standard - name: Build C++20 shell: bash From 1ef6311e5b80d6a9b5a32cfcd4e987a1f7f93cd1 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Wed, 13 May 2026 11:24:45 +0200 Subject: [PATCH 04/10] Update documentation and few more defines --- docs/source/getting_started/installation.rst | 2 +- docs/source/yosys_internals/extending_yosys/contributing.rst | 2 +- docs/source/yosys_internals/index.rst | 2 +- kernel/yosys_common.h | 4 ++-- pyosys/generator.py | 2 +- tests/functional/test_functional.py | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/source/getting_started/installation.rst b/docs/source/getting_started/installation.rst index 43b996353..2a90a8071 100644 --- a/docs/source/getting_started/installation.rst +++ b/docs/source/getting_started/installation.rst @@ -87,7 +87,7 @@ not regularly tested: Build prerequisites ^^^^^^^^^^^^^^^^^^^ -A C++ compiler with C++17 support is required as well as some standard tools +A C++ compiler with C++20 support is required as well as some standard tools such as GNU Flex, GNU Bison (>=3.8), Make, and Python (>=3.11). Some additional tools: readline, libffi, Tcl and zlib; are optional but enabled by default (see :makevar:`ENABLE_*` settings in Makefile). Graphviz and Xdot are used by the diff --git a/docs/source/yosys_internals/extending_yosys/contributing.rst b/docs/source/yosys_internals/extending_yosys/contributing.rst index 1ff77a1fd..8d90d2cbe 100644 --- a/docs/source/yosys_internals/extending_yosys/contributing.rst +++ b/docs/source/yosys_internals/extending_yosys/contributing.rst @@ -286,7 +286,7 @@ have incorrect results in unusual situations. Coding style ~~~~~~~~~~~~ -Yosys is written in C++17. +Yosys is written in C++20. In general Yosys uses ``int`` instead of ``size_t``. To avoid compiler warnings for implicit type casts, always use ``GetSize(foobar)`` instead of diff --git a/docs/source/yosys_internals/index.rst b/docs/source/yosys_internals/index.rst index 483cc2bf8..217b88e36 100644 --- a/docs/source/yosys_internals/index.rst +++ b/docs/source/yosys_internals/index.rst @@ -25,7 +25,7 @@ wide range of real-world designs, including the `OpenRISC 1200 CPU`_, the .. _k68 CPU: http://opencores.org/projects/k68 -Yosys is written in C++, targeting C++17 at minimum. This chapter describes some +Yosys is written in C++, targeting C++20 at minimum. This chapter describes some of the fundamental Yosys data structures. For the sake of simplicity the C++ type names used in the Yosys implementation are used in this chapter, even though the chapter only explains the conceptual idea behind it and can be used diff --git a/kernel/yosys_common.h b/kernel/yosys_common.h index 47dae5473..062036dba 100644 --- a/kernel/yosys_common.h +++ b/kernel/yosys_common.h @@ -120,10 +120,10 @@ # define YS_MAYBE_UNUSED #endif -#if __cplusplus >= 201703L +#if __cplusplus >= 202002L # define YS_FALLTHROUGH [[fallthrough]]; #else -# error "C++17 or later compatible compiler is required" +# error "C++20 or later compatible compiler is required" #endif #if defined(__has_cpp_attribute) && __has_cpp_attribute(gnu::cold) diff --git a/pyosys/generator.py b/pyosys/generator.py index f1d429724..4fd7a5698 100644 --- a/pyosys/generator.py +++ b/pyosys/generator.py @@ -376,7 +376,7 @@ class PyosysWrapperGenerator(object): def make_preprocessor_options(self): py_include = get_paths()["include"] preprocessor_bin = shutil.which("clang++") or "g++" - cxx_std = os.getenv("CXX_STD", "c++17") + cxx_std = os.getenv("CXX_STD", "c++20") return ParserOptions( preprocessor=make_gcc_preprocessor( defines=["_YOSYS_", "YOSYS_ENABLE_PYTHON"], diff --git a/tests/functional/test_functional.py b/tests/functional/test_functional.py index aa7500f8b..661af14d1 100644 --- a/tests/functional/test_functional.py +++ b/tests/functional/test_functional.py @@ -21,7 +21,7 @@ def yosys(script): run([base_path / 'yosys', '-Q', '-p', script]) def compile_cpp(in_path, out_path, args): - run(['g++', '-g', '-std=c++17'] + args + [str(in_path), '-o', str(out_path)]) + run(['g++', '-g', '-std=c++20'] + args + [str(in_path), '-o', str(out_path)]) def yosys_synth(verilog_file, rtlil_file): yosys(f"read_verilog {quote(verilog_file)} ; prep ; setundef -undriven -undef ; write_rtlil {quote(rtlil_file)}") From 105011a53b7454f9d819c4bb4978fa03ad565bb2 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Wed, 13 May 2026 12:05:13 +0200 Subject: [PATCH 05/10] Zero array for for MSVC --- kernel/io.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/io.h b/kernel/io.h index 171f47a80..96b5bb55d 100644 --- a/kernel/io.h +++ b/kernel/io.h @@ -441,7 +441,8 @@ public: private: std::string_view fmt; bool has_escapes = false; - FoundFormatSpec specs[sizeof...(Args)] = {}; + // Making array at least size of one to make MSVC happy and strict to standards + FoundFormatSpec specs[sizeof...(Args) ? sizeof...(Args) : 1] = {}; }; template struct WrapType { using type = T; }; From 9182329fa1c0b8e73909744dff0cd7865bead342 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Wed, 13 May 2026 12:05:37 +0200 Subject: [PATCH 06/10] Try making clang-10 to work --- .github/workflows/test-compile.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-compile.yml b/.github/workflows/test-compile.yml index 2540a8415..a896ccf87 100644 --- a/.github/workflows/test-compile.yml +++ b/.github/workflows/test-compile.yml @@ -85,7 +85,7 @@ jobs: - name: Fix clang-10 toolchain if: matrix.os == 'ubuntu-latest' && matrix.compiler == 'clang-10' run: | - echo "CXXFLAGS=--gcc-toolchain=/usr/lib/gcc/x86_64-linux-gnu/10 -stdlib=libstdc++" >> $GITHUB_ENV + echo "CXXFLAGS=--gcc-toolchain=/usr" >> $GITHUB_ENV # minimum standard - name: Build C++20 From 9070c83145068efe16547720c3b6120eb5fdf1f0 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Wed, 13 May 2026 13:28:09 +0200 Subject: [PATCH 07/10] Fix for generated project files to work with latest VS --- misc/create_vcxsrc.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/misc/create_vcxsrc.sh b/misc/create_vcxsrc.sh index c880c2a48..dccc31fac 100644 --- a/misc/create_vcxsrc.sh +++ b/misc/create_vcxsrc.sh @@ -25,6 +25,7 @@ if [ -f "/usr/include/FlexLexer.h" ] ; then cp /usr/include/FlexLexer.h libs/flex/FlexLexer.h ls libs/flex/*.h >> ../../srcfiles.txt fi +sed -i '\#libs/../kernel/yosys.h#d' ../../srcfiles.txt popd { From 6d4e5f5ad045899ba9fde0fa00513d01920f2027 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Wed, 13 May 2026 14:38:58 +0200 Subject: [PATCH 08/10] Bump versions to safe floor --- .github/workflows/test-compile.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test-compile.yml b/.github/workflows/test-compile.yml index a896ccf87..fe6a43634 100644 --- a/.github/workflows/test-compile.yml +++ b/.github/workflows/test-compile.yml @@ -44,8 +44,8 @@ jobs: - ubuntu-latest compiler: # oldest supported - - 'clang-10' - - 'gcc-10' + - 'clang-14' + - 'gcc-11' # newest, make sure to update maximum standard step to match - 'clang-19' - 'gcc-14' @@ -74,7 +74,7 @@ jobs: uses: aminya/setup-cpp@v1 with: compiler: ${{ matrix.compiler }} - gcc: ${{ (matrix.os == 'ubuntu-latest' && matrix.compiler == 'clang-10') && '10' || '' }} + gcc: ${{ (matrix.os == 'ubuntu-latest' && matrix.compiler == 'clang-14') && '12' || '' }} - name: Tool versions shell: bash @@ -82,10 +82,10 @@ jobs: $CC --version $CXX --version - - name: Fix clang-10 toolchain - if: matrix.os == 'ubuntu-latest' && matrix.compiler == 'clang-10' + - name: Fix clang-14 toolchain + if: matrix.os == 'ubuntu-latest' && matrix.compiler == 'clang-14' run: | - echo "CXXFLAGS=--gcc-toolchain=/usr" >> $GITHUB_ENV + echo 'CXXFLAGS=--gcc-toolchain=/usr -isystem /usr/include/c++/12 -isystem /usr/include/x86_64-linux-gnu/c++/12' >> $GITHUB_ENV # minimum standard - name: Build C++20 From 70b17181b42f1c1264dcb4c50916575e61a65f3c Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Thu, 14 May 2026 10:51:40 +0200 Subject: [PATCH 09/10] Bump gcc and clang versions --- .github/workflows/test-compile.yml | 6 +++--- kernel/fmt.cc | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test-compile.yml b/.github/workflows/test-compile.yml index fe6a43634..3e2ac34c9 100644 --- a/.github/workflows/test-compile.yml +++ b/.github/workflows/test-compile.yml @@ -47,8 +47,8 @@ jobs: - 'clang-14' - 'gcc-11' # newest, make sure to update maximum standard step to match - - 'clang-19' - - 'gcc-14' + - 'clang-22' + - 'gcc-15' include: # macOS x86 - os: macos-15-intel @@ -96,7 +96,7 @@ jobs: # maximum standard, only on newest compilers - name: Build C++26 - if: ${{ matrix.compiler == 'clang-19' || matrix.compiler == 'gcc-14' }} + if: ${{ matrix.compiler == 'clang-19' || matrix.compiler == 'clang-22' || matrix.compiler == 'gcc-15' }} shell: bash run: | make config-$CC_SHORT diff --git a/kernel/fmt.cc b/kernel/fmt.cc index 200e7e5ce..15179a75a 100644 --- a/kernel/fmt.cc +++ b/kernel/fmt.cc @@ -804,8 +804,10 @@ std::string Fmt::render() const buf += 'X'; else if (has_z) buf += 'Z'; - else - buf += (part.hex_upper ? "0123456789ABCDEF" : "0123456789abcdef")[subvalue.as_int()]; + else { + const char *digits = part.hex_upper ? "0123456789ABCDEF" : "0123456789abcdef"; + buf += digits[subvalue.as_int()]; + } } } else if (part.base == 10) { if (part.show_base) From c16e0352f766a2d94a9b1c78b86a22965b7782bc Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 15 May 2026 11:13:59 +0200 Subject: [PATCH 10/10] Bump to clang-22 on macOS as well --- .github/workflows/test-compile.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-compile.yml b/.github/workflows/test-compile.yml index 3e2ac34c9..99e4973a7 100644 --- a/.github/workflows/test-compile.yml +++ b/.github/workflows/test-compile.yml @@ -52,10 +52,10 @@ jobs: include: # macOS x86 - os: macos-15-intel - compiler: 'clang-19' + compiler: 'clang-22' # macOS arm - os: macos-latest - compiler: 'clang-19' + compiler: 'clang-22' fail-fast: false steps: - name: Checkout Yosys @@ -96,7 +96,7 @@ jobs: # maximum standard, only on newest compilers - name: Build C++26 - if: ${{ matrix.compiler == 'clang-19' || matrix.compiler == 'clang-22' || matrix.compiler == 'gcc-15' }} + if: ${{ matrix.compiler == 'clang-22' || matrix.compiler == 'gcc-15' }} shell: bash run: | make config-$CC_SHORT