Skip to content

Commit 959af94

Browse files
authored
Fix CodeQL workflow (#11)
1 parent 907a3e0 commit 959af94

5 files changed

Lines changed: 33 additions & 8 deletions

File tree

.github/workflows/codeql.yml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,38 @@ jobs:
2020
- name: Checkout repository
2121
uses: actions/checkout@v6
2222

23+
- name: Setup LLVM
24+
if: matrix.language == 'cpp'
25+
uses: ZhongRuoyu/setup-llvm@v0
26+
with:
27+
llvm-version: 22
28+
29+
- name: Setup Rust
30+
if: matrix.language == 'rust'
31+
uses: dtolnay/rust-toolchain@master
32+
with:
33+
toolchain: 1.94.0
34+
2335
- name: Initialize CodeQL
2436
uses: github/codeql-action/init@v4
2537
with:
2638
languages: ${{ matrix.language }}
39+
trap-caching: false
2740
config: |
2841
paths-ignore:
2942
- 'tests/**'
3043
31-
- name: Autobuild
32-
uses: github/codeql-action/autobuild@v4
44+
- name: Build C++ code
45+
if: matrix.language == 'cpp'
46+
run: |
47+
mkdir build && cd build
48+
cmake -GNinja ..
49+
ninja
50+
51+
- name: Build Rust code
52+
if: matrix.language == 'rust'
53+
run: cargo build --verbose
54+
working-directory: libcc2rs
3355

3456
- name: Perform CodeQL Analysis
3557
uses: github/codeql-action/analyze@v4

.github/workflows/run-tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ jobs:
2929
uses: dtolnay/rust-toolchain@master
3030
with:
3131
toolchain: 1.94.0
32+
components: rustfmt
3233

3334
- name: Setup Python
3435
uses: actions/setup-python@v6
3536
with:
36-
cache: 'pip'
37+
python-version: '3.x'
3738

3839
- name: Install Python dependencies
3940
run: pip install tomli

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ list(APPEND CMAKE_MODULE_PATH "${CLANG_CMAKE_DIR}")
3434
include(AddLLVM)
3535
include(AddClang)
3636

37-
if (NOT CMAKE_CXX_COMPILER MATCHES "clang")
37+
if (NOT CMAKE_CXX_COMPILER MATCHES "clang" AND NOT DEFINED ENV{CODEQL_EXTRACTOR_CPP_ROOT})
3838
set(CMAKE_CXX_COMPILER "${CLANG_CMAKE_DIR}/../../../bin/clang++")
3939
endif()
4040

cpp2rust/converter/converter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ void Converter::ConvertPrintf(clang::CallExpr *expr) {
12651265
Mapper::ToString(expr->getCallee()).starts_with("int fprintf");
12661266

12671267
StrCat("printf(");
1268-
for (auto i = is_fprintf ? 1 : 0; i < expr->getNumArgs(); i++) {
1268+
for (unsigned i = is_fprintf; i < expr->getNumArgs(); ++i) {
12691269
if (i == is_fprintf ? 1 : 0) {
12701270
Convert(expr->getArg(i));
12711271
StrCat("as *const i8");
@@ -2008,7 +2008,7 @@ bool Converter::VisitDeclRefExpr(clang::DeclRefExpr *expr) {
20082008
// Wrap unsafe function in safe closure because the Fn trait only accepts
20092009
// safe functions
20102010
std::string arguments;
2011-
for (unsigned i = 0; i < function->getNumParams(); i++) {
2011+
for (unsigned i = 0; i < function->getNumParams(); ++i) {
20122012
arguments += (i ? ", a" : "a") + std::to_string(i);
20132013
}
20142014
StrCat("Rc::new", token::kOpenParen);
@@ -2255,7 +2255,7 @@ bool Converter::VisitInitListExpr(clang::InitListExpr *expr) {
22552255
(arr_ty->getSize().getZExtValue() - expr->getNumInits()) &&
22562256
"Number of initializers should be less that total size of array");
22572257
for (unsigned i = 0;
2258-
i < arr_ty->getSize().getZExtValue() - expr->getNumInits(); i++) {
2258+
i < arr_ty->getSize().getZExtValue() - expr->getNumInits(); ++i) {
22592259
ConvertVarInit(expr->getArrayFiller()->getType(),
22602260
expr->getArrayFiller());
22612261
StrCat(token::kComma);
@@ -2623,7 +2623,7 @@ Converter::GetFunctionPointerDefaultAsString(clang::QualType qual_type) {
26232623
auto proto = qual_type->getPointeeType()->getAs<clang::FunctionProtoType>();
26242624
assert(proto);
26252625
ret = "Rc::new(|";
2626-
for (unsigned i = 0; i < proto->getNumParams(); i++) {
2626+
for (unsigned i = 0; i < proto->getNumParams(); ++i) {
26272627
ret += "_,";
26282628
}
26292629
ret += R"(| { panic!("ub: uninit function pointer") }))";

cpp2rust/converter/mapper.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,7 @@ void LoadTranslationRules(Model model, clang::ASTContext &ctx,
852852
addRulesFromDirectory(rules_dir, model);
853853
addBuiltinTypes(model);
854854

855+
#if 0
855856
for (auto &[src, expr] : exprs_) {
856857
llvm::errs() << "Expr: " << src << '\n';
857858
expr.dump();
@@ -860,6 +861,7 @@ void LoadTranslationRules(Model model, clang::ASTContext &ctx,
860861
llvm::errs() << "Type: " << src << '\n';
861862
type_tgt.dump();
862863
}
864+
#endif
863865
}
864866

865867
} // namespace cpp2rust::Mapper

0 commit comments

Comments
 (0)