Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
8 changes: 4 additions & 4 deletions cpp2rust/converter/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -2623,7 +2623,7 @@ Converter::GetFunctionPointerDefaultAsString(clang::QualType qual_type) {
auto proto = qual_type->getPointeeType()->getAs<clang::FunctionProtoType>();
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") }))";
Expand Down
2 changes: 2 additions & 0 deletions cpp2rust/converter/mapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -860,6 +861,7 @@ void LoadTranslationRules(Model model, clang::ASTContext &ctx,
llvm::errs() << "Type: " << src << '\n';
type_tgt.dump();
}
#endif
}

} // namespace cpp2rust::Mapper
Loading