Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[clang][modules] Account for non-affecting inputs in
ASTWriter
In D106876, we stopped serializing module map files that didn't affect compilation of the current module. However, since each `SourceLocation` is simply an offset into `SourceManager`'s global buffer of concatenated input files in, these need to be adjusted during serialization. Otherwise, they can incorrectly point after the buffer or into subsequent input file. This patch starts adjusting `SourceLocation`s, `FileID`s and other `SourceManager` offsets in `ASTWriter`. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D136624
- Loading branch information
1 parent
a13122c
commit 6924a49
Showing
3 changed files
with
160 additions
and
89 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,32 @@ | ||
// RUN: rm -rf %t && mkdir %t | ||
// RUN: split-file %s %t | ||
|
||
//--- a.modulemap | ||
//--- a/module.modulemap | ||
module a {} | ||
|
||
//--- b.modulemap | ||
//--- b/module.modulemap | ||
module b {} | ||
|
||
//--- test-simple.m | ||
// expected-no-diagnostics | ||
@import a; | ||
|
||
// Build without b.modulemap: | ||
// | ||
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -fdisable-module-hash \ | ||
// RUN: -fmodule-map-file=%t/a.modulemap %t/test-simple.m -verify | ||
// RUN: mv %t/cache %t/cache-without-b | ||
|
||
// Build with b.modulemap: | ||
// | ||
// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -fdisable-module-hash \ | ||
// RUN: -fmodule-map-file=%t/a.modulemap -fmodule-map-file=%t/b.modulemap %t/test-simple.m -verify | ||
// RUN: mv %t/cache %t/cache-with-b | ||
|
||
// Neither PCM file considers 'b.modulemap' an input: | ||
// | ||
// RUN: %clang_cc1 -module-file-info %t/cache-without-b/a.pcm | FileCheck %s --check-prefix=CHECK-B | ||
// RUN: %clang_cc1 -module-file-info %t/cache-with-b/a.pcm | FileCheck %s --check-prefix=CHECK-B | ||
// CHECK-B-NOT: Input file: {{.*}}b.modulemap | ||
|
||
//--- c.modulemap | ||
module c [no_undeclared_includes] { header "c.h" } | ||
//--- c/module.modulemap | ||
module c {} | ||
|
||
//--- c.h | ||
#if __has_include("d.h") // This should use 'd.modulemap' in order to determine that 'd.h' | ||
// doesn't exist for 'c' because of its '[no_undeclared_includes]'. | ||
#endif | ||
|
||
//--- d.modulemap | ||
module d { header "d.h" } | ||
|
||
//--- d.h | ||
// empty | ||
//--- module.modulemap | ||
module m { header "m.h" } | ||
//--- m.h | ||
@import c; | ||
|
||
//--- test-no-undeclared-includes.m | ||
//--- test-simple.m | ||
// expected-no-diagnostics | ||
@import c; | ||
@import m; | ||
|
||
// Build modules with the non-affecting "a/module.modulemap". | ||
// RUN: %clang_cc1 -I %t/a -I %t/b -I %t/c -I %t -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -fdisable-module-hash %t/test-simple.m -verify | ||
// RUN: mv %t/cache %t/cache-with | ||
|
||
// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t/cache -fdisable-module-hash \ | ||
// RUN: -fmodule-map-file=%t/c.modulemap -fmodule-map-file=%t/d.modulemap \ | ||
// RUN: %t/test-no-undeclared-includes.m -verify | ||
// Build modules without the non-affecting "a/module.modulemap". | ||
// RUN: rm -rf %t/a/module.modulemap | ||
// RUN: %clang_cc1 -I %t/a -I %t/b -I %t/c -I %t -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -fdisable-module-hash %t/test-simple.m -verify | ||
// RUN: mv %t/cache %t/cache-without | ||
|
||
// The PCM file considers 'd.modulemap' an input because it affects the compilation, | ||
// although it doesn't describe the built module or its imports. | ||
// | ||
// RUN: %clang_cc1 -module-file-info %t/cache/c.pcm | FileCheck %s --check-prefix=CHECK-D | ||
// CHECK-D: Input file: {{.*}}d.modulemap | ||
// Check that the PCM files are bit-for-bit identical. | ||
// RUN: diff %t/cache-with/m.pcm %t/cache-without/m.pcm |