[clang] [clang][DependencyScanning] Add Test Coverage of `StabeDirs` during By-Name Lookups (PR #168143)

Qiongsi Wu via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 18 10:24:09 PST 2025


================
@@ -0,0 +1,43 @@
+// UNSUPPORTED: system-windows
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// Verify the stable dir path.
+//--- Sysroot/usr/include/SysA/module.modulemap
+module SysA {
+  header "SysA.h"
+}
+
+//--- Sysroot/usr/include/SysA/SysA.h
+int SysVal = 42;
+
+//--- cdb.json.template
+[{
+  "file": "",
+  "directory": "DIR",
+  "command": "clang -fmodules -fmodules-cache-path=DIR/cache -isysroot DIR/Sysroot -IDIR/Sysroot/usr/include -x c"
+}]
----------------
qiongsiwu wrote:

I experimented with avoiding the compilation database and was surprised to discover that we need the json compilation database for -by-name lookups if we don't change the logic in `clang-scan-deps`. 

Specifically, when we do not have a compilation database, we proceed to create a driver, and build a `Compilation` from the driver (https://github.com/llvm/llvm-project/blob/5af03989cc01e7bf9a45240d86411e9eee5b0e8b/clang/tools/clang-scan-deps/ClangScanDeps.cpp#L826). For the compilation to succeed, the clang command needs an input file. With the suggested command, `clang-scan-deps` exists early at https://github.com/llvm/llvm-project/blob/5af03989cc01e7bf9a45240d86411e9eee5b0e8b/clang/tools/clang-scan-deps/ClangScanDeps.cpp#L893. 

I tried creating an empty input file for this test, but the scanner crashed. I believe the reason is that for by-name lookups we end up creating a fake input file ourselves, so it conflicts with the fake one I am adding here. 

In light of this, I think it is ok to keep the json file for this PR. If we are inclined to make sure the one command case work for by-name scans, I will look into how to modify clang-scan-deps so we can handle this case better. 

https://github.com/llvm/llvm-project/pull/168143


More information about the cfe-commits mailing list