Skip to content

Commit a798c8f

Browse files
authored
Merge pull request #8534 from apple/jan_svoboda/pragma-diags-release
[clang][modules] Stop eagerly reading files with diagnostic pragmas
2 parents 21fe9b4 + 0f0ed2f commit a798c8f

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace serialization {
4141
/// Version 4 of AST files also requires that the version control branch and
4242
/// revision match exactly, since there is no backward compatibility of
4343
/// AST files at this time.
44-
const unsigned VERSION_MAJOR = 29;
44+
const unsigned VERSION_MAJOR = 30;
4545

4646
/// AST file minor version number supported by this version of
4747
/// Clang.

clang/lib/Serialization/ASTReader.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6604,17 +6604,15 @@ void ASTReader::ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag) {
66046604
while (NumLocations--) {
66056605
assert(Idx < Record.size() &&
66066606
"Invalid data, missing pragma diagnostic states");
6607-
SourceLocation Loc = ReadSourceLocation(F, Record[Idx++]);
6608-
auto IDAndOffset = SourceMgr.getDecomposedLoc(Loc);
6609-
assert(IDAndOffset.first.isValid() && "invalid FileID for transition");
6610-
assert(IDAndOffset.second == 0 && "not a start location for a FileID");
6607+
FileID FID = ReadFileID(F, Record, Idx);
6608+
assert(FID.isValid() && "invalid FileID for transition");
66116609
unsigned Transitions = Record[Idx++];
66126610

66136611
// Note that we don't need to set up Parent/ParentOffset here, because
66146612
// we won't be changing the diagnostic state within imported FileIDs
66156613
// (other than perhaps appending to the main source file, which has no
66166614
// parent).
6617-
auto &F = Diag.DiagStatesByLoc.Files[IDAndOffset.first];
6615+
auto &F = Diag.DiagStatesByLoc.Files[FID];
66186616
F.StateTransitions.reserve(F.StateTransitions.size() + Transitions);
66196617
for (unsigned I = 0; I != Transitions; ++I) {
66206618
unsigned Offset = Record[Idx++];

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3132,9 +3132,7 @@ void ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag,
31323132
continue;
31333133
++NumLocations;
31343134

3135-
SourceLocation Loc = Diag.SourceMgr->getComposedLoc(FileIDAndFile.first, 0);
3136-
assert(!Loc.isInvalid() && "start loc for valid FileID is invalid");
3137-
AddSourceLocation(Loc, Record);
3135+
AddFileID(FileIDAndFile.first, Record);
31383136

31393137
Record.push_back(FileIDAndFile.second.StateTransitions.size());
31403138
for (auto &StatePoint : FileIDAndFile.second.StateTransitions) {
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)