Skip to content

Commit fc3dff9

Browse files
authored
[clang][modules] Stop eagerly reading files with diagnostic pragmas (#87442)
This makes it so that the importer doesn't need to stat all input files of a module that contain diagnostic pragmas, reducing file system traffic.
1 parent 0ad663e commit fc3dff9

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

clang/lib/Serialization/ASTReader.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6626,8 +6626,6 @@ void ASTReader::ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag) {
66266626
"Invalid data, missing pragma diagnostic states");
66276627
FileID FID = ReadFileID(F, Record, Idx);
66286628
assert(FID.isValid() && "invalid FileID for transition");
6629-
// FIXME: Remove this once we don't need the side-effects.
6630-
(void)SourceMgr.getSLocEntryOrNull(FID);
66316629
unsigned Transitions = Record[Idx++];
66326630

66336631
// Note that we don't need to set up Parent/ParentOffset here, because
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// This test demonstrates how -fmodule-map-file-home-is-cwd with -fmodules-embed-all-files
2+
// extend the importer search paths by relying on the side effects of pragma diagnostic
3+
// mappings deserialization.
4+
5+
// RUN: rm -rf %t
6+
// RUN: split-file %s %t
7+
8+
//--- dir1/a.modulemap
9+
module a { header "a.h" }
10+
//--- dir1/a.h
11+
#include "search.h"
12+
// The first compilation is configured such that -I search does contain the search.h header.
13+
//--- dir1/search/search.h
14+
#pragma clang diagnostic push
15+
#pragma clang diagnostic ignored "-Wparentheses"
16+
#pragma clang diagnostic pop
17+
// RUN: cd %t/dir1 && %clang_cc1 -fmodules -I search \
18+
// RUN: -emit-module -fmodule-name=a a.modulemap -o %t/a.pcm \
19+
// RUN: -fmodules-embed-all-files -fmodule-map-file-home-is-cwd
20+
21+
//--- dir2/b.modulemap
22+
module b { header "b.h" }
23+
//--- dir2/b.h
24+
#include "search.h" // expected-error{{'search.h' file not found}}
25+
// The second compilation is configured such that -I search is an empty directory.
26+
// However, since b.pcm simply embeds the headers as "search/search.h", this compilation
27+
// ends up seeing it too. This relies solely on ASTReader::ReadPragmaDiagnosticMappings()
28+
// eagerly reading the corresponding INPUT_FILE record before header search happens.
29+
// Removing the eager deserialization makes this header invisible and so does removing
30+
// the pragma directives.
31+
// RUN: mkdir %t/dir2/search
32+
// RUN: cd %t/dir2 && %clang_cc1 -fmodules -I search \
33+
// RUN: -emit-module -fmodule-name=b b.modulemap -o %t/b.pcm \
34+
// RUN: -fmodule-file=%t/a.pcm -verify

0 commit comments

Comments
 (0)