Skip to content

ast-exporter: pass compilation database directory to Clang - #1963

Open
ShiroKSH wants to merge 1 commit into
immunant:masterfrom
ShiroKSH:fix/compile-database-build-path
Open

ast-exporter: pass compilation database directory to Clang#1963
ShiroKSH wants to merge 1 commit into
immunant:masterfrom
ShiroKSH:fix/compile-database-build-path

Conversation

@ShiroKSH

@ShiroKSH ShiroKSH commented Jul 31, 2026

Copy link
Copy Markdown

Fixes #1809.

CommonOptionsParser expects -p to name the build directory, but the AST exporter passed compile_commands.json itself. Pass its parent directory instead, using . for a bare relative path, and cover both forms.

This is a general correctness fix; #1809 exposed the existing mismatch on Clang 22.

@thedataking thedataking left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CommonOptionsParser treats -p as a build directory and searches that directory for the compilation database. The AST exporter passed the JSON file itself, so newer Clang versions attempted to treat the file as a directory and continued without the database flags.

https://github.com/llvm/llvm-project/commits/main/clang/lib/Tooling/CommonOptionsParser.cpp has not changed its functionality since 2022. I also don't see any recent changes to https://github.com/llvm/llvm-project/commits/main/clang/lib/Tooling/CompilationDatabase.cpp that would make this a clang 22 specific issue.

I do agree that we ought to pass the parent directory of the compilation database, so that part looks good to me. However, I think we ought to clarify whether this is a general correctness fix or what versions of clang need this.

nitpick: C2Rust validation means passing CI so we do not need a validation section. Generally, PRs bodies are shorter and not split into sections. I'd encourage you to take a look at other PRs and make yours follow project conventions.

@ShiroKSH
ShiroKSH force-pushed the fix/compile-database-build-path branch from a33d5e1 to 2b80bee Compare August 1, 2026 07:23
@ShiroKSH

ShiroKSH commented Aug 1, 2026

Copy link
Copy Markdown
Author

Thanks — I shortened the PR body to match the project convention and clarified that this is a general correctness fix; #1809 only exposed the existing mismatch on Clang 22. I also rebased the branch onto the current master.

output
}

#[cfg(test)]

@thedataking thedataking Aug 4, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should be adding these tests. We mainly rely on the integration tests to detect cases where compile_commands.json is not being picked up correctly. It should break most (all) the builds.

IIRC, the macOS builds use clang-22 and linux builds use 15 an 18 so we cover a broad range of releases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

json-compilation-database: Error while opening JSON database: Not a directory

2 participants