Skip to content

Commit 0276621

Browse files
committed
[clang][serialization] Reduce ASTWriter::WriteControlBlock() scope
1 parent bcb64e1 commit 0276621

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

clang/include/clang/Serialization/ASTWriter.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,7 @@ class ASTWriter : public ASTDeserializationListener,
548548
void WriteSubStmt(Stmt *S);
549549

550550
void WriteBlockInfoBlock();
551-
void WriteControlBlock(Preprocessor &PP, ASTContext &Context,
552-
StringRef isysroot);
551+
void WriteControlBlock(Preprocessor &PP, StringRef isysroot);
553552

554553
/// Write out the signature and diagnostic options, and return the signature.
555554
void writeUnhashedControlBlock(Preprocessor &PP, ASTContext &Context);

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,10 +1403,12 @@ void ASTWriter::writeUnhashedControlBlock(Preprocessor &PP,
14031403
}
14041404

14051405
/// Write the control block.
1406-
void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context,
1407-
StringRef isysroot) {
1406+
void ASTWriter::WriteControlBlock(Preprocessor &PP, StringRef isysroot) {
14081407
using namespace llvm;
14091408

1409+
SourceManager &SourceMgr = PP.getSourceManager();
1410+
FileManager &FileMgr = PP.getFileManager();
1411+
14101412
Stream.EnterSubblock(CONTROL_BLOCK_ID, 5);
14111413
RecordData Record;
14121414

@@ -1454,14 +1456,12 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context,
14541456
SmallString<128> BaseDir;
14551457
if (PP.getHeaderSearchInfo().getHeaderSearchOpts().ModuleFileHomeIsCwd) {
14561458
// Use the current working directory as the base path for all inputs.
1457-
auto CWD =
1458-
Context.getSourceManager().getFileManager().getOptionalDirectoryRef(
1459-
".");
1459+
auto CWD = FileMgr.getOptionalDirectoryRef(".");
14601460
BaseDir.assign(CWD->getName());
14611461
} else {
14621462
BaseDir.assign(WritingModule->Directory->getName());
14631463
}
1464-
cleanPathForOutput(Context.getSourceManager().getFileManager(), BaseDir);
1464+
cleanPathForOutput(FileMgr, BaseDir);
14651465

14661466
// If the home of the module is the current working directory, then we
14671467
// want to pick up the cwd of the build process loading the module, not
@@ -1554,7 +1554,7 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context,
15541554

15551555
// Language options.
15561556
Record.clear();
1557-
const LangOptions &LangOpts = Context.getLangOpts();
1557+
const LangOptions &LangOpts = PP.getLangOpts();
15581558
#define LANGOPT(Name, Bits, Default, Description) \
15591559
Record.push_back(LangOpts.Name);
15601560
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
@@ -1591,7 +1591,7 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context,
15911591

15921592
// Target options.
15931593
Record.clear();
1594-
const TargetInfo &Target = Context.getTargetInfo();
1594+
const TargetInfo &Target = PP.getTargetInfo();
15951595
const TargetOptions &TargetOpts = Target.getTargetOpts();
15961596
AddString(TargetOpts.Triple, Record);
15971597
AddString(TargetOpts.CPU, Record);
@@ -1609,8 +1609,7 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context,
16091609

16101610
// File system options.
16111611
Record.clear();
1612-
const FileSystemOptions &FSOpts =
1613-
Context.getSourceManager().getFileManager().getFileSystemOpts();
1612+
const FileSystemOptions &FSOpts = FileMgr.getFileSystemOpts();
16141613
AddString(FSOpts.WorkingDir, Record);
16151614
Stream.EmitRecord(FILE_SYSTEM_OPTIONS, Record);
16161615

@@ -1675,8 +1674,8 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context,
16751674
Stream.ExitBlock();
16761675

16771676
// Original file name and file ID
1678-
SourceManager &SM = Context.getSourceManager();
1679-
if (auto MainFile = SM.getFileEntryRefForID(SM.getMainFileID())) {
1677+
if (auto MainFile =
1678+
SourceMgr.getFileEntryRefForID(SourceMgr.getMainFileID())) {
16801679
auto FileAbbrev = std::make_shared<BitCodeAbbrev>();
16811680
FileAbbrev->Add(BitCodeAbbrevOp(ORIGINAL_FILE));
16821681
FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // File ID
@@ -1685,16 +1684,15 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context,
16851684

16861685
Record.clear();
16871686
Record.push_back(ORIGINAL_FILE);
1688-
AddFileID(SM.getMainFileID(), Record);
1687+
AddFileID(SourceMgr.getMainFileID(), Record);
16891688
EmitRecordWithPath(FileAbbrevCode, Record, MainFile->getName());
16901689
}
16911690

16921691
Record.clear();
1693-
AddFileID(SM.getMainFileID(), Record);
1692+
AddFileID(SourceMgr.getMainFileID(), Record);
16941693
Stream.EmitRecord(ORIGINAL_FILE_ID, Record);
16951694

1696-
WriteInputFiles(Context.SourceMgr,
1697-
PP.getHeaderSearchInfo().getHeaderSearchOpts());
1695+
WriteInputFiles(SourceMgr, PP.getHeaderSearchInfo().getHeaderSearchOpts());
16981696
Stream.ExitBlock();
16991697
}
17001698

@@ -5432,7 +5430,7 @@ ASTFileSignature ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot,
54325430
PrepareWritingSpecialDecls(SemaRef);
54335431

54345432
// Write the control block
5435-
WriteControlBlock(PP, Context, isysroot);
5433+
WriteControlBlock(PP, isysroot);
54365434

54375435
// Write the remaining AST contents.
54385436
Stream.FlushToWord();

0 commit comments

Comments
 (0)