Skip to content

[clang][Modules] Adding C-API for Negative Stat Caching Diagnostics #10524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 1, 2025
5 changes: 5 additions & 0 deletions clang/include/clang-c/Dependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,11 @@ const char *clang_experimental_DepGraph_getTUContextHash(CXDepGraph);
CINDEX_LINKAGE
CXDiagnosticSet clang_experimental_DepGraph_getDiagnostics(CXDepGraph);

CINDEX_LINKAGE
CXStringSet *
clang_experimental_DependencyScannerService_getInvalidNegStatCachedPaths(
CXDependencyScannerService);

/**
* @}
*/
Expand Down
1 change: 1 addition & 0 deletions clang/test/ClangScanDeps/error-c-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@

// CHECK: error: failed to get dependencies
// CHECK-NEXT: 'missing.h' file not found
// CHECk-NEXT: number of invalid negatively stat cached paths: 0
10 changes: 10 additions & 0 deletions clang/tools/c-index-test/core_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,16 @@ static int scanDeps(ArrayRef<const char *> Args, std::string WorkingDirectory,
clang_disposeString(Spelling);
clang_disposeDiagnostic(Diag);
}

CXStringSet *InvalidNegativeStatCachedPaths =
clang_experimental_DependencyScannerService_getInvalidNegStatCachedPaths(
Service);
if (InvalidNegativeStatCachedPaths) {
llvm::errs() << "note: number of invalid negatively stat cached paths: "
<< InvalidNegativeStatCachedPaths->Count << "\n";
clang_disposeStringSet(InvalidNegativeStatCachedPaths);
}

return 1;
}

Expand Down
19 changes: 19 additions & 0 deletions clang/tools/libclang/CDependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,25 @@ CXDiagnosticSet clang_experimental_DepGraph_getDiagnostics(CXDepGraph Graph) {
return unwrap(Graph)->getDiagnosticSet();
}

CXStringSet *
clang_experimental_DependencyScannerService_getInvalidNegStatCachedPaths(
CXDependencyScannerService S) {
DependencyScanningService *Service = unwrap(S);

// CASFS does not use the SharedCache, so there is nothing to diagnose.
if (Service->useCASFS())
return nullptr;

DependencyScanningFilesystemSharedCache &SharedCache =
Service->getSharedCache();
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS =
llvm::vfs::createPhysicalFileSystem();
auto InvaidNegStatCachedPaths =
SharedCache.getInvalidNegativeStatCachedPaths(*FS.get());
return cxstring::createSet(std::vector<std::string>(
InvaidNegStatCachedPaths.begin(), InvaidNegStatCachedPaths.end()));
}

static std::string
lookupModuleOutput(const ModuleDeps &MD, ModuleOutputKind MOK, void *MLOContext,
std::variant<CXModuleLookupOutputCallback *,
Expand Down
1 change: 1 addition & 0 deletions clang/tools/libclang/libclang.map
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ LLVM_21 {
clang_experimental_DepGraphModule_isCWDIgnored;
clang_experimental_DepGraphModule_isInStableDirs;
clang_getFullyQualifiedName;
clang_experimental_DependencyScannerService_getInvalidNegStatCachedPaths;
};

# Example of how to add a new symbol version entry. If you do add a new symbol
Expand Down