From 3ecec0c7cd7ba50ea9e73d3217891d8e92f91f3b Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Sun, 19 Apr 2026 12:38:57 +0100 Subject: [PATCH 01/12] Add LLVM 22 setup step to CodeQL workflow --- .github/workflows/codeql.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index a13355f6..d66f734d 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -20,6 +20,11 @@ jobs: - name: Checkout repository uses: actions/checkout@v6 + - name: Setup LLVM 22 + uses: ZhongRuoyu/setup-llvm@v0 + with: + llvm-version: 22 + - name: Initialize CodeQL uses: github/codeql-action/init@v4 with: From 4017c79987bd38d0063e10d993c05a70ef677719 Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Sun, 19 Apr 2026 12:50:01 +0100 Subject: [PATCH 02/12] Rust support Add support for Rust projects in CodeQL workflow. --- .github/workflows/codeql.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index d66f734d..cbb79ced 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -34,8 +34,20 @@ jobs: - 'tests/**' - name: Autobuild + if: matrix.language != 'rust' uses: github/codeql-action/autobuild@v4 + - name: Set up Rust + if: matrix.language == 'rust' + uses: dtolnay/rust-toolchain@master + with: + toolchain: 1.94.0 + + - name: Build Rust project + if: matrix.language == 'rust' + run: cargo build --verbose + working-directory: libcc2rs + - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v4 with: From 34f892babb9dc374d65df8a14380d40ec870af3f Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Sun, 19 Apr 2026 12:53:02 +0100 Subject: [PATCH 03/12] refactor --- .github/workflows/codeql.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index cbb79ced..c056c6b2 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -20,11 +20,18 @@ jobs: - name: Checkout repository uses: actions/checkout@v6 - - name: Setup LLVM 22 + - name: Setup LLVM + if: matrix.language == 'cpp' uses: ZhongRuoyu/setup-llvm@v0 with: llvm-version: 22 + - name: Setup Rust + if: matrix.language == 'rust' + uses: dtolnay/rust-toolchain@master + with: + toolchain: 1.94.0 + - name: Initialize CodeQL uses: github/codeql-action/init@v4 with: @@ -37,12 +44,6 @@ jobs: if: matrix.language != 'rust' uses: github/codeql-action/autobuild@v4 - - name: Set up Rust - if: matrix.language == 'rust' - uses: dtolnay/rust-toolchain@master - with: - toolchain: 1.94.0 - - name: Build Rust project if: matrix.language == 'rust' run: cargo build --verbose From cbf16f6c9baed28764cecae1bf66a17fac00bbee Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Sun, 19 Apr 2026 13:07:12 +0100 Subject: [PATCH 04/12] Add check for CODEQL_EXTRACTOR_CPP_ROOT environment variable --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b880ff79..c2e1bee7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,7 +34,7 @@ list(APPEND CMAKE_MODULE_PATH "${CLANG_CMAKE_DIR}") include(AddLLVM) include(AddClang) -if (NOT CMAKE_CXX_COMPILER MATCHES "clang") +if (NOT CMAKE_CXX_COMPILER MATCHES "clang" AND NOT DEFINED ENV{CODEQL_EXTRACTOR_CPP_ROOT) set(CMAKE_CXX_COMPILER "${CLANG_CMAKE_DIR}/../../../bin/clang++") endif() From 0d57771fe6530d1a5e5a72a7c3e76c53a7402507 Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Sun, 19 Apr 2026 14:13:28 +0100 Subject: [PATCH 05/12] typo --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c2e1bee7..4c18c1df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,7 +34,7 @@ list(APPEND CMAKE_MODULE_PATH "${CLANG_CMAKE_DIR}") include(AddLLVM) include(AddClang) -if (NOT CMAKE_CXX_COMPILER MATCHES "clang" AND NOT DEFINED ENV{CODEQL_EXTRACTOR_CPP_ROOT) +if (NOT CMAKE_CXX_COMPILER MATCHES "clang" AND NOT DEFINED ENV{CODEQL_EXTRACTOR_CPP_ROOT}) set(CMAKE_CXX_COMPILER "${CLANG_CMAKE_DIR}/../../../bin/clang++") endif() From e997398f69386180384f1a1aa9daa43f2c3d5e73 Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Sun, 19 Apr 2026 14:23:04 +0100 Subject: [PATCH 06/12] edits --- .github/workflows/run-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 5e95ac9e..9a2b3e1f 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -33,6 +33,7 @@ jobs: - name: Setup Python uses: actions/setup-python@v6 with: + python-version: '3.x' cache: 'pip' - name: Install Python dependencies From 14ac85e7bb631630116aa88c734dc05b4db17d41 Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Sun, 19 Apr 2026 14:28:24 +0100 Subject: [PATCH 07/12] edits --- .github/workflows/codeql.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index c056c6b2..79d25db2 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -40,11 +40,14 @@ jobs: paths-ignore: - 'tests/**' - - name: Autobuild - if: matrix.language != 'rust' - uses: github/codeql-action/autobuild@v4 + - name: Build C++ code + if: matrix.language == 'cpp' + run: | + mkdir build && cd build + cmake -DLIT_FLAGS="-v" -GNinja .. + ninja - - name: Build Rust project + - name: Build Rust code if: matrix.language == 'rust' run: cargo build --verbose working-directory: libcc2rs From 3ba4cce8d04ff8eb94c11c3e74747bfc0f9ba5d0 Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Sun, 19 Apr 2026 14:28:37 +0100 Subject: [PATCH 08/12] edits --- .github/workflows/codeql.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 79d25db2..fa0b881c 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -44,7 +44,7 @@ jobs: if: matrix.language == 'cpp' run: | mkdir build && cd build - cmake -DLIT_FLAGS="-v" -GNinja .. + cmake -GNinja .. ninja - name: Build Rust code From 80b014a567534864cc8caf5f49fd128bbe4a6661 Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Sun, 19 Apr 2026 14:34:09 +0100 Subject: [PATCH 09/12] edits --- cpp2rust/converter/converter.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 67afae39..8c27c56a 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -1265,7 +1265,7 @@ void Converter::ConvertPrintf(clang::CallExpr *expr) { Mapper::ToString(expr->getCallee()).starts_with("int fprintf"); StrCat("printf("); - for (auto i = is_fprintf ? 1 : 0; i < expr->getNumArgs(); i++) { + for (unsigned i = is_fprintf; i < expr->getNumArgs(); ++i) { if (i == is_fprintf ? 1 : 0) { Convert(expr->getArg(i)); StrCat("as *const i8"); @@ -2008,7 +2008,7 @@ bool Converter::VisitDeclRefExpr(clang::DeclRefExpr *expr) { // Wrap unsafe function in safe closure because the Fn trait only accepts // safe functions std::string arguments; - for (unsigned i = 0; i < function->getNumParams(); i++) { + for (unsigned i = 0; i < function->getNumParams(); ++i) { arguments += (i ? ", a" : "a") + std::to_string(i); } StrCat("Rc::new", token::kOpenParen); @@ -2255,7 +2255,7 @@ bool Converter::VisitInitListExpr(clang::InitListExpr *expr) { (arr_ty->getSize().getZExtValue() - expr->getNumInits()) && "Number of initializers should be less that total size of array"); for (unsigned i = 0; - i < arr_ty->getSize().getZExtValue() - expr->getNumInits(); i++) { + i < arr_ty->getSize().getZExtValue() - expr->getNumInits(); ++i) { ConvertVarInit(expr->getArrayFiller()->getType(), expr->getArrayFiller()); StrCat(token::kComma); @@ -2623,7 +2623,7 @@ Converter::GetFunctionPointerDefaultAsString(clang::QualType qual_type) { auto proto = qual_type->getPointeeType()->getAs(); assert(proto); ret = "Rc::new(|"; - for (unsigned i = 0; i < proto->getNumParams(); i++) { + for (unsigned i = 0; i < proto->getNumParams(); ++i) { ret += "_,"; } ret += R"(| { panic!("ub: uninit function pointer") }))"; From 19729d2fb176e543dd8e8a5aaa10450359128e59 Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Sun, 19 Apr 2026 14:37:46 +0100 Subject: [PATCH 10/12] edits --- .github/workflows/run-tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 9a2b3e1f..6ad62c99 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -34,7 +34,6 @@ jobs: uses: actions/setup-python@v6 with: python-version: '3.x' - cache: 'pip' - name: Install Python dependencies run: pip install tomli From afc61cbbb903a51f9d4079ae2ea828403dc8386b Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Sun, 19 Apr 2026 14:48:42 +0100 Subject: [PATCH 11/12] edits --- .github/workflows/codeql.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index fa0b881c..ccab64dc 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -36,6 +36,7 @@ jobs: uses: github/codeql-action/init@v4 with: languages: ${{ matrix.language }} + trap-caching: false config: | paths-ignore: - 'tests/**' From 91395f0a7d085432bbd7fc0fd1843b288b0a5bb7 Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Sun, 19 Apr 2026 15:07:06 +0100 Subject: [PATCH 12/12] edits --- .github/workflows/run-tests.yml | 1 + cpp2rust/converter/mapper.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 6ad62c99..713b4603 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -29,6 +29,7 @@ jobs: uses: dtolnay/rust-toolchain@master with: toolchain: 1.94.0 + components: rustfmt - name: Setup Python uses: actions/setup-python@v6 diff --git a/cpp2rust/converter/mapper.cpp b/cpp2rust/converter/mapper.cpp index 478e3c51..a100c969 100644 --- a/cpp2rust/converter/mapper.cpp +++ b/cpp2rust/converter/mapper.cpp @@ -852,6 +852,7 @@ void LoadTranslationRules(Model model, clang::ASTContext &ctx, addRulesFromDirectory(rules_dir, model); addBuiltinTypes(model); +#if 0 for (auto &[src, expr] : exprs_) { llvm::errs() << "Expr: " << src << '\n'; expr.dump(); @@ -860,6 +861,7 @@ void LoadTranslationRules(Model model, clang::ASTContext &ctx, llvm::errs() << "Type: " << src << '\n'; type_tgt.dump(); } +#endif } } // namespace cpp2rust::Mapper