-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[clang][deps] Lazy dependency directives (#86347)
Since b4c83a1, `Preprocessor` and `Lexer` are aware of the concept of scanning dependency directives. This makes it possible to scan for them on-demand rather than eagerly on the first filesystem operation (open, or even just stat). This might improve performance, but is also necessary for the "PCH as module" mode. Some precompiled header sources use the ".pch" file extension, which means they were not getting scanned for dependency directives. This was okay when the PCH was the main input file in a separate scan step, because there we just lex the file in a scanning-specific frontend action. But when such source gets treated as a module implicitly loaded from a TU, it will get compiled as any other module - with Sema - which will result in compilation errors. (See attached test case.) rdar://107663951
- Loading branch information
1 parent
5d18789
commit b768a8c
Showing
4 changed files
with
60 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// RUN: rm -rf %t | ||
// RUN: split-file %s %t | ||
|
||
// This test checks that source files with uncommon extensions still undergo | ||
// dependency directives scan. If header.pch would not and b.h would, the scan | ||
// would fail when parsing `void function(B)` and not knowing the symbol B. | ||
|
||
//--- module.modulemap | ||
module __PCH { header "header.pch" } | ||
module B { header "b.h" } | ||
|
||
//--- header.pch | ||
#include "b.h" | ||
void function(B); | ||
|
||
//--- b.h | ||
typedef int B; | ||
|
||
//--- tu.c | ||
int main() { | ||
function(0); | ||
return 0; | ||
} | ||
|
||
//--- cdb.json.in | ||
[{ | ||
"directory": "DIR", | ||
"file": "DIR/tu.c", | ||
"command": "clang -c DIR/tu.c -fmodules -fmodules-cache-path=DIR/cache -fimplicit-module-maps -include DIR/header.pch" | ||
}] | ||
|
||
// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.in > %t/cdb.json | ||
// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full > %t/deps.json |