diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index a13355f6..ccab64dc 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -20,16 +20,38 @@ jobs: - name: Checkout repository uses: actions/checkout@v6 + - 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: languages: ${{ matrix.language }} + trap-caching: false config: | paths-ignore: - 'tests/**' - - name: Autobuild - uses: github/codeql-action/autobuild@v4 + - name: Build C++ code + if: matrix.language == 'cpp' + run: | + mkdir build && cd build + cmake -GNinja .. + ninja + + - name: Build Rust code + if: matrix.language == 'rust' + run: cargo build --verbose + working-directory: libcc2rs - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v4 diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 5e95ac9e..713b4603 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -29,11 +29,12 @@ jobs: uses: dtolnay/rust-toolchain@master with: toolchain: 1.94.0 + components: rustfmt - name: Setup Python uses: actions/setup-python@v6 with: - cache: 'pip' + python-version: '3.x' - name: Install Python dependencies run: pip install tomli diff --git a/CMakeLists.txt b/CMakeLists.txt index b880ff79..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") +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() 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") }))"; 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