[clang] [clang-tools-extra] [Tooling] Resolve relative "directory" against the compilation database (PR #235400)
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 4 21:33:22 PST 2026
================
@@ -409,19 +412,26 @@ bool JSONCompilationDatabase::parse(std::string &ErrorMessage) {
ErrorMessage = "Missing key: \"directory\".";
return false;
}
+ SmallString<8> DirectoryStorage;
+ SmallString<128> DirectoryPath(Directory->getValue(DirectoryStorage));
+ if (!BaseDirectory.empty() && !DirectoryPath.empty() &&
+ !llvm::sys::path::is_absolute(DirectoryPath)) {
+ llvm::sys::path::make_absolute(BaseDirectory, DirectoryPath);
+ llvm::sys::path::remove_dots(DirectoryPath);
+ }
+ StringRef DirectoryName = Directories.insert(DirectoryPath).first->getKey();
SmallString<8> FileStorage;
StringRef FileName = File->getValue(FileStorage);
SmallString<128> NativeFilePath;
if (llvm::sys::path::is_relative(FileName)) {
- SmallString<8> DirectoryStorage;
- SmallString<128> AbsolutePath(Directory->getValue(DirectoryStorage));
+ SmallString<128> AbsolutePath(DirectoryName);
llvm::sys::path::append(AbsolutePath, FileName);
llvm::sys::path::native(AbsolutePath, NativeFilePath);
} else {
llvm::sys::path::native(FileName, NativeFilePath);
}
llvm::sys::path::remove_dots(NativeFilePath, /*remove_dot_dot=*/true);
----------------
MaskRay wrote:
Line 433 can remove .. because it only builds the lookup key, which we never change into. An absolute directory containing .. is already returned as written.
https://github.com/llvm/llvm-project/pull/235400
More information about the cfe-commits
mailing list