blob: fa6ad6f0a0a9bc06ab262fb1cca0d1a7a8717f11 [file] [log] [blame]
Douglas Gregor2cf26342009-04-09 22:27:44 +00001//===--- PCHReader.cpp - Precompiled Headers Reader -------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the PCHReader class, which reads a precompiled header.
11//
12//===----------------------------------------------------------------------===//
13#include "clang/Frontend/PCHReader.h"
Douglas Gregor0a0428e2009-04-10 20:39:37 +000014#include "clang/Frontend/FrontendDiagnostic.h"
Douglas Gregor2cf26342009-04-09 22:27:44 +000015#include "clang/AST/ASTContext.h"
16#include "clang/AST/Decl.h"
17#include "clang/AST/Type.h"
Chris Lattner42d42b52009-04-10 21:41:48 +000018#include "clang/Lex/MacroInfo.h"
Douglas Gregor14f79002009-04-10 03:52:48 +000019#include "clang/Lex/Preprocessor.h"
20#include "clang/Basic/SourceManager.h"
21#include "clang/Basic/FileManager.h"
Douglas Gregor2bec0412009-04-10 21:16:55 +000022#include "clang/Basic/TargetInfo.h"
Douglas Gregor2cf26342009-04-09 22:27:44 +000023#include "llvm/Bitcode/BitstreamReader.h"
24#include "llvm/Support/Compiler.h"
25#include "llvm/Support/MemoryBuffer.h"
26#include <algorithm>
27#include <cstdio>
28
29using namespace clang;
30
31//===----------------------------------------------------------------------===//
32// Declaration deserialization
33//===----------------------------------------------------------------------===//
34namespace {
35 class VISIBILITY_HIDDEN PCHDeclReader {
36 PCHReader &Reader;
37 const PCHReader::RecordData &Record;
38 unsigned &Idx;
39
40 public:
41 PCHDeclReader(PCHReader &Reader, const PCHReader::RecordData &Record,
42 unsigned &Idx)
43 : Reader(Reader), Record(Record), Idx(Idx) { }
44
45 void VisitDecl(Decl *D);
46 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
47 void VisitNamedDecl(NamedDecl *ND);
48 void VisitTypeDecl(TypeDecl *TD);
49 void VisitTypedefDecl(TypedefDecl *TD);
50 void VisitValueDecl(ValueDecl *VD);
51 void VisitVarDecl(VarDecl *VD);
52
53 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
54 };
55}
56
57void PCHDeclReader::VisitDecl(Decl *D) {
58 D->setDeclContext(cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
59 D->setLexicalDeclContext(
60 cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
61 D->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
62 D->setInvalidDecl(Record[Idx++]);
63 // FIXME: hasAttrs
64 D->setImplicit(Record[Idx++]);
65 D->setAccess((AccessSpecifier)Record[Idx++]);
66}
67
68void PCHDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
69 VisitDecl(TU);
70}
71
72void PCHDeclReader::VisitNamedDecl(NamedDecl *ND) {
73 VisitDecl(ND);
74 ND->setDeclName(Reader.ReadDeclarationName(Record, Idx));
75}
76
77void PCHDeclReader::VisitTypeDecl(TypeDecl *TD) {
78 VisitNamedDecl(TD);
79 // FIXME: circular dependencies here?
80 TD->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
81}
82
83void PCHDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
84 VisitTypeDecl(TD);
85 TD->setUnderlyingType(Reader.GetType(Record[Idx++]));
86}
87
88void PCHDeclReader::VisitValueDecl(ValueDecl *VD) {
89 VisitNamedDecl(VD);
90 VD->setType(Reader.GetType(Record[Idx++]));
91}
92
93void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
94 VisitValueDecl(VD);
95 VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
96 VD->setThreadSpecified(Record[Idx++]);
97 VD->setCXXDirectInitializer(Record[Idx++]);
98 VD->setDeclaredInCondition(Record[Idx++]);
99 VD->setPreviousDeclaration(
100 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
101 VD->setTypeSpecStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
102}
103
104std::pair<uint64_t, uint64_t>
105PCHDeclReader::VisitDeclContext(DeclContext *DC) {
106 uint64_t LexicalOffset = Record[Idx++];
107 uint64_t VisibleOffset = 0;
108 if (DC->getPrimaryContext() == DC)
109 VisibleOffset = Record[Idx++];
110 return std::make_pair(LexicalOffset, VisibleOffset);
111}
112
113// FIXME: use the diagnostics machinery
114static bool Error(const char *Str) {
115 std::fprintf(stderr, "%s\n", Str);
116 return true;
117}
118
Douglas Gregore1d918e2009-04-10 23:10:45 +0000119/// \brief Check the contents of the predefines buffer against the
120/// contents of the predefines buffer used to build the PCH file.
121///
122/// The contents of the two predefines buffers should be the same. If
123/// not, then some command-line option changed the preprocessor state
124/// and we must reject the PCH file.
125///
126/// \param PCHPredef The start of the predefines buffer in the PCH
127/// file.
128///
129/// \param PCHPredefLen The length of the predefines buffer in the PCH
130/// file.
131///
132/// \param PCHBufferID The FileID for the PCH predefines buffer.
133///
134/// \returns true if there was a mismatch (in which case the PCH file
135/// should be ignored), or false otherwise.
136bool PCHReader::CheckPredefinesBuffer(const char *PCHPredef,
137 unsigned PCHPredefLen,
138 FileID PCHBufferID) {
139 const char *Predef = PP.getPredefines().c_str();
140 unsigned PredefLen = PP.getPredefines().size();
141
142 // If the two predefines buffers compare equal, we're done!.
143 if (PredefLen == PCHPredefLen &&
144 strncmp(Predef, PCHPredef, PCHPredefLen) == 0)
145 return false;
146
147 // The predefines buffers are different. Produce a reasonable
148 // diagnostic showing where they are different.
149
150 // The source locations (potentially in the two different predefines
151 // buffers)
152 SourceLocation Loc1, Loc2;
153 SourceManager &SourceMgr = PP.getSourceManager();
154
155 // Create a source buffer for our predefines string, so
156 // that we can build a diagnostic that points into that
157 // source buffer.
158 FileID BufferID;
159 if (Predef && Predef[0]) {
160 llvm::MemoryBuffer *Buffer
161 = llvm::MemoryBuffer::getMemBuffer(Predef, Predef + PredefLen,
162 "<built-in>");
163 BufferID = SourceMgr.createFileIDForMemBuffer(Buffer);
164 }
165
166 unsigned MinLen = std::min(PredefLen, PCHPredefLen);
167 std::pair<const char *, const char *> Locations
168 = std::mismatch(Predef, Predef + MinLen, PCHPredef);
169
170 if (Locations.first != Predef + MinLen) {
171 // We found the location in the two buffers where there is a
172 // difference. Form source locations to point there (in both
173 // buffers).
174 unsigned Offset = Locations.first - Predef;
175 Loc1 = SourceMgr.getLocForStartOfFile(BufferID)
176 .getFileLocWithOffset(Offset);
177 Loc2 = SourceMgr.getLocForStartOfFile(PCHBufferID)
178 .getFileLocWithOffset(Offset);
179 } else if (PredefLen > PCHPredefLen) {
180 Loc1 = SourceMgr.getLocForStartOfFile(BufferID)
181 .getFileLocWithOffset(MinLen);
182 } else {
183 Loc1 = SourceMgr.getLocForStartOfFile(PCHBufferID)
184 .getFileLocWithOffset(MinLen);
185 }
186
187 Diag(Loc1, diag::warn_pch_preprocessor);
188 if (Loc2.isValid())
189 Diag(Loc2, diag::note_predef_in_pch);
190 Diag(diag::note_ignoring_pch) << FileName;
191 return true;
192}
193
Douglas Gregor14f79002009-04-10 03:52:48 +0000194/// \brief Read the source manager block
Douglas Gregore1d918e2009-04-10 23:10:45 +0000195PCHReader::PCHReadResult PCHReader::ReadSourceManagerBlock() {
Douglas Gregor14f79002009-04-10 03:52:48 +0000196 using namespace SrcMgr;
Douglas Gregore1d918e2009-04-10 23:10:45 +0000197 if (Stream.EnterSubBlock(pch::SOURCE_MANAGER_BLOCK_ID)) {
198 Error("Malformed source manager block record");
199 return Failure;
200 }
Douglas Gregor14f79002009-04-10 03:52:48 +0000201
202 SourceManager &SourceMgr = Context.getSourceManager();
203 RecordData Record;
204 while (true) {
205 unsigned Code = Stream.ReadCode();
206 if (Code == llvm::bitc::END_BLOCK) {
Douglas Gregore1d918e2009-04-10 23:10:45 +0000207 if (Stream.ReadBlockEnd()) {
208 Error("Error at end of Source Manager block");
209 return Failure;
210 }
211
212 return Success;
Douglas Gregor14f79002009-04-10 03:52:48 +0000213 }
214
215 if (Code == llvm::bitc::ENTER_SUBBLOCK) {
216 // No known subblocks, always skip them.
217 Stream.ReadSubBlockID();
Douglas Gregore1d918e2009-04-10 23:10:45 +0000218 if (Stream.SkipBlock()) {
219 Error("Malformed block record");
220 return Failure;
221 }
Douglas Gregor14f79002009-04-10 03:52:48 +0000222 continue;
223 }
224
225 if (Code == llvm::bitc::DEFINE_ABBREV) {
226 Stream.ReadAbbrevRecord();
227 continue;
228 }
229
230 // Read a record.
231 const char *BlobStart;
232 unsigned BlobLen;
233 Record.clear();
234 switch (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen)) {
235 default: // Default behavior: ignore.
236 break;
237
238 case pch::SM_SLOC_FILE_ENTRY: {
239 // FIXME: We would really like to delay the creation of this
240 // FileEntry until it is actually required, e.g., when producing
241 // a diagnostic with a source location in this file.
242 const FileEntry *File
243 = PP.getFileManager().getFile(BlobStart, BlobStart + BlobLen);
244 // FIXME: Error recovery if file cannot be found.
245 SourceMgr.createFileID(File,
246 SourceLocation::getFromRawEncoding(Record[1]),
247 (CharacteristicKind)Record[2]);
248 break;
249 }
250
251 case pch::SM_SLOC_BUFFER_ENTRY: {
252 const char *Name = BlobStart;
253 unsigned Code = Stream.ReadCode();
254 Record.clear();
255 unsigned RecCode = Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen);
256 assert(RecCode == pch::SM_SLOC_BUFFER_BLOB && "Ill-formed PCH file");
Douglas Gregore1d918e2009-04-10 23:10:45 +0000257 llvm::MemoryBuffer *Buffer
258 = llvm::MemoryBuffer::getMemBuffer(BlobStart,
259 BlobStart + BlobLen - 1,
260 Name);
261 FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer);
262
263 if (strcmp(Name, "<built-in>") == 0
264 && CheckPredefinesBuffer(BlobStart, BlobLen - 1, BufferID))
265 return IgnorePCH;
Douglas Gregor14f79002009-04-10 03:52:48 +0000266 break;
267 }
268
269 case pch::SM_SLOC_INSTANTIATION_ENTRY: {
270 SourceLocation SpellingLoc
271 = SourceLocation::getFromRawEncoding(Record[1]);
272 SourceMgr.createInstantiationLoc(
273 SpellingLoc,
274 SourceLocation::getFromRawEncoding(Record[2]),
275 SourceLocation::getFromRawEncoding(Record[3]),
276 Lexer::MeasureTokenLength(SpellingLoc,
277 SourceMgr));
278 break;
279 }
280
281 }
282 }
283}
284
Chris Lattner42d42b52009-04-10 21:41:48 +0000285bool PCHReader::ReadPreprocessorBlock() {
286 if (Stream.EnterSubBlock(pch::PREPROCESSOR_BLOCK_ID))
287 return Error("Malformed preprocessor block record");
288
Chris Lattner42d42b52009-04-10 21:41:48 +0000289 RecordData Record;
290 llvm::SmallVector<IdentifierInfo*, 16> MacroArgs;
291 MacroInfo *LastMacro = 0;
292
293 while (true) {
294 unsigned Code = Stream.ReadCode();
295 switch (Code) {
296 case llvm::bitc::END_BLOCK:
297 if (Stream.ReadBlockEnd())
298 return Error("Error at end of preprocessor block");
299 return false;
300
301 case llvm::bitc::ENTER_SUBBLOCK:
302 // No known subblocks, always skip them.
303 Stream.ReadSubBlockID();
304 if (Stream.SkipBlock())
305 return Error("Malformed block record");
306 continue;
307
308 case llvm::bitc::DEFINE_ABBREV:
309 Stream.ReadAbbrevRecord();
310 continue;
311 default: break;
312 }
313
314 // Read a record.
315 Record.clear();
316 pch::PreprocessorRecordTypes RecType =
317 (pch::PreprocessorRecordTypes)Stream.ReadRecord(Code, Record);
318 switch (RecType) {
319 default: // Default behavior: ignore unknown records.
320 break;
Chris Lattnerc1f9d822009-04-13 01:29:17 +0000321 case pch::PP_COUNTER_VALUE:
322 if (!Record.empty())
323 PP.setCounterValue(Record[0]);
324 break;
325
Chris Lattner42d42b52009-04-10 21:41:48 +0000326 case pch::PP_MACRO_OBJECT_LIKE:
327 case pch::PP_MACRO_FUNCTION_LIKE: {
Chris Lattner7356a312009-04-11 21:15:38 +0000328 IdentifierInfo *II = DecodeIdentifierInfo(Record[0]);
329 if (II == 0)
330 return Error("Macro must have a name");
Chris Lattner42d42b52009-04-10 21:41:48 +0000331 SourceLocation Loc = SourceLocation::getFromRawEncoding(Record[1]);
332 bool isUsed = Record[2];
333
334 MacroInfo *MI = PP.AllocateMacroInfo(Loc);
335 MI->setIsUsed(isUsed);
336
337 if (RecType == pch::PP_MACRO_FUNCTION_LIKE) {
338 // Decode function-like macro info.
339 bool isC99VarArgs = Record[3];
340 bool isGNUVarArgs = Record[4];
341 MacroArgs.clear();
342 unsigned NumArgs = Record[5];
343 for (unsigned i = 0; i != NumArgs; ++i)
Chris Lattner7356a312009-04-11 21:15:38 +0000344 MacroArgs.push_back(DecodeIdentifierInfo(Record[6+i]));
Chris Lattner42d42b52009-04-10 21:41:48 +0000345
346 // Install function-like macro info.
347 MI->setIsFunctionLike();
348 if (isC99VarArgs) MI->setIsC99Varargs();
349 if (isGNUVarArgs) MI->setIsGNUVarargs();
350 MI->setArgumentList(&MacroArgs[0], MacroArgs.size(),
351 PP.getPreprocessorAllocator());
352 }
353
354 // Finally, install the macro.
Chris Lattner42d42b52009-04-10 21:41:48 +0000355 PP.setMacroInfo(II, MI);
Chris Lattner42d42b52009-04-10 21:41:48 +0000356
357 // Remember that we saw this macro last so that we add the tokens that
358 // form its body to it.
359 LastMacro = MI;
360 break;
361 }
362
363 case pch::PP_TOKEN: {
364 // If we see a TOKEN before a PP_MACRO_*, then the file is eroneous, just
365 // pretend we didn't see this.
366 if (LastMacro == 0) break;
367
368 Token Tok;
369 Tok.startToken();
370 Tok.setLocation(SourceLocation::getFromRawEncoding(Record[0]));
371 Tok.setLength(Record[1]);
Chris Lattner7356a312009-04-11 21:15:38 +0000372 if (IdentifierInfo *II = DecodeIdentifierInfo(Record[2]))
373 Tok.setIdentifierInfo(II);
Chris Lattner42d42b52009-04-10 21:41:48 +0000374 Tok.setKind((tok::TokenKind)Record[3]);
375 Tok.setFlag((Token::TokenFlags)Record[4]);
376 LastMacro->AddTokenToBody(Tok);
377 break;
378 }
379 }
380 }
381}
382
Douglas Gregor0a0428e2009-04-10 20:39:37 +0000383PCHReader::PCHReadResult PCHReader::ReadPCHBlock() {
384 if (Stream.EnterSubBlock(pch::PCH_BLOCK_ID)) {
385 Error("Malformed block record");
386 return Failure;
387 }
Douglas Gregor2cf26342009-04-09 22:27:44 +0000388
Chris Lattner7356a312009-04-11 21:15:38 +0000389 uint64_t PreprocessorBlockBit = 0;
390
Douglas Gregor2cf26342009-04-09 22:27:44 +0000391 // Read all of the records and blocks for the PCH file.
Douglas Gregor8038d512009-04-10 17:25:41 +0000392 RecordData Record;
Douglas Gregor2cf26342009-04-09 22:27:44 +0000393 while (!Stream.AtEndOfStream()) {
394 unsigned Code = Stream.ReadCode();
395 if (Code == llvm::bitc::END_BLOCK) {
Chris Lattner7356a312009-04-11 21:15:38 +0000396 // If we saw the preprocessor block, read it now.
397 if (PreprocessorBlockBit) {
398 uint64_t SavedPos = Stream.GetCurrentBitNo();
399 Stream.JumpToBit(PreprocessorBlockBit);
400 if (ReadPreprocessorBlock()) {
401 Error("Malformed preprocessor block");
402 return Failure;
403 }
404 Stream.JumpToBit(SavedPos);
405 }
406
Douglas Gregor0a0428e2009-04-10 20:39:37 +0000407 if (Stream.ReadBlockEnd()) {
408 Error("Error at end of module block");
409 return Failure;
410 }
Chris Lattner7356a312009-04-11 21:15:38 +0000411
Douglas Gregor0a0428e2009-04-10 20:39:37 +0000412 return Success;
Douglas Gregor2cf26342009-04-09 22:27:44 +0000413 }
414
415 if (Code == llvm::bitc::ENTER_SUBBLOCK) {
416 switch (Stream.ReadSubBlockID()) {
417 case pch::DECLS_BLOCK_ID: // Skip decls block (lazily loaded)
418 case pch::TYPES_BLOCK_ID: // Skip types block (lazily loaded)
419 default: // Skip unknown content.
Douglas Gregor0a0428e2009-04-10 20:39:37 +0000420 if (Stream.SkipBlock()) {
421 Error("Malformed block record");
422 return Failure;
423 }
Douglas Gregor2cf26342009-04-09 22:27:44 +0000424 break;
425
Chris Lattner7356a312009-04-11 21:15:38 +0000426 case pch::PREPROCESSOR_BLOCK_ID:
427 // Skip the preprocessor block for now, but remember where it is. We
428 // want to read it in after the identifier table.
429 if (PreprocessorBlockBit) {
430 Error("Multiple preprocessor blocks found.");
431 return Failure;
432 }
433 PreprocessorBlockBit = Stream.GetCurrentBitNo();
434 if (Stream.SkipBlock()) {
435 Error("Malformed block record");
436 return Failure;
437 }
438 break;
439
Douglas Gregor14f79002009-04-10 03:52:48 +0000440 case pch::SOURCE_MANAGER_BLOCK_ID:
Douglas Gregore1d918e2009-04-10 23:10:45 +0000441 switch (ReadSourceManagerBlock()) {
442 case Success:
443 break;
444
445 case Failure:
Douglas Gregor0a0428e2009-04-10 20:39:37 +0000446 Error("Malformed source manager block");
447 return Failure;
Douglas Gregore1d918e2009-04-10 23:10:45 +0000448
449 case IgnorePCH:
450 return IgnorePCH;
Douglas Gregor0a0428e2009-04-10 20:39:37 +0000451 }
Douglas Gregor14f79002009-04-10 03:52:48 +0000452 break;
Douglas Gregor2cf26342009-04-09 22:27:44 +0000453 }
Douglas Gregor8038d512009-04-10 17:25:41 +0000454 continue;
455 }
456
457 if (Code == llvm::bitc::DEFINE_ABBREV) {
458 Stream.ReadAbbrevRecord();
459 continue;
460 }
461
462 // Read and process a record.
463 Record.clear();
Douglas Gregor2bec0412009-04-10 21:16:55 +0000464 const char *BlobStart = 0;
465 unsigned BlobLen = 0;
466 switch ((pch::PCHRecordTypes)Stream.ReadRecord(Code, Record,
467 &BlobStart, &BlobLen)) {
Douglas Gregor8038d512009-04-10 17:25:41 +0000468 default: // Default behavior: ignore.
469 break;
470
471 case pch::TYPE_OFFSET:
Douglas Gregor0a0428e2009-04-10 20:39:37 +0000472 if (!TypeOffsets.empty()) {
473 Error("Duplicate TYPE_OFFSET record in PCH file");
474 return Failure;
475 }
Douglas Gregor8038d512009-04-10 17:25:41 +0000476 TypeOffsets.swap(Record);
477 TypeAlreadyLoaded.resize(TypeOffsets.size(), false);
478 break;
479
480 case pch::DECL_OFFSET:
Douglas Gregor0a0428e2009-04-10 20:39:37 +0000481 if (!DeclOffsets.empty()) {
482 Error("Duplicate DECL_OFFSET record in PCH file");
483 return Failure;
484 }
Douglas Gregor8038d512009-04-10 17:25:41 +0000485 DeclOffsets.swap(Record);
486 DeclAlreadyLoaded.resize(DeclOffsets.size(), false);
487 break;
Douglas Gregor0a0428e2009-04-10 20:39:37 +0000488
489 case pch::LANGUAGE_OPTIONS:
490 if (ParseLanguageOptions(Record))
491 return IgnorePCH;
492 break;
Douglas Gregor2bec0412009-04-10 21:16:55 +0000493
Douglas Gregorafaf3082009-04-11 00:14:32 +0000494 case pch::TARGET_TRIPLE: {
Douglas Gregor2bec0412009-04-10 21:16:55 +0000495 std::string TargetTriple(BlobStart, BlobLen);
496 if (TargetTriple != Context.Target.getTargetTriple()) {
497 Diag(diag::warn_pch_target_triple)
498 << TargetTriple << Context.Target.getTargetTriple();
499 Diag(diag::note_ignoring_pch) << FileName;
500 return IgnorePCH;
501 }
502 break;
Douglas Gregor2cf26342009-04-09 22:27:44 +0000503 }
Douglas Gregorafaf3082009-04-11 00:14:32 +0000504
505 case pch::IDENTIFIER_TABLE:
506 IdentifierTable = BlobStart;
507 break;
508
509 case pch::IDENTIFIER_OFFSET:
510 if (!IdentifierData.empty()) {
511 Error("Duplicate IDENTIFIER_OFFSET record in PCH file");
512 return Failure;
513 }
514 IdentifierData.swap(Record);
515#ifndef NDEBUG
516 for (unsigned I = 0, N = IdentifierData.size(); I != N; ++I) {
517 if ((IdentifierData[I] & 0x01) == 0) {
518 Error("Malformed identifier table in the precompiled header");
519 return Failure;
520 }
521 }
522#endif
523 break;
524 }
Douglas Gregor2cf26342009-04-09 22:27:44 +0000525 }
526
Douglas Gregor0a0428e2009-04-10 20:39:37 +0000527 Error("Premature end of bitstream");
528 return Failure;
Douglas Gregor2cf26342009-04-09 22:27:44 +0000529}
530
Douglas Gregore1d918e2009-04-10 23:10:45 +0000531PCHReader::PCHReadResult PCHReader::ReadPCH(const std::string &FileName) {
Douglas Gregor0a0428e2009-04-10 20:39:37 +0000532 // Set the PCH file name.
533 this->FileName = FileName;
534
Douglas Gregor2cf26342009-04-09 22:27:44 +0000535 // Open the PCH file.
536 std::string ErrStr;
537 Buffer.reset(llvm::MemoryBuffer::getFile(FileName.c_str(), &ErrStr));
Douglas Gregore1d918e2009-04-10 23:10:45 +0000538 if (!Buffer) {
539 Error(ErrStr.c_str());
540 return IgnorePCH;
541 }
Douglas Gregor2cf26342009-04-09 22:27:44 +0000542
543 // Initialize the stream
544 Stream.init((const unsigned char *)Buffer->getBufferStart(),
545 (const unsigned char *)Buffer->getBufferEnd());
546
547 // Sniff for the signature.
548 if (Stream.Read(8) != 'C' ||
549 Stream.Read(8) != 'P' ||
550 Stream.Read(8) != 'C' ||
Douglas Gregore1d918e2009-04-10 23:10:45 +0000551 Stream.Read(8) != 'H') {
552 Error("Not a PCH file");
553 return IgnorePCH;
554 }
Douglas Gregor2cf26342009-04-09 22:27:44 +0000555
556 // We expect a number of well-defined blocks, though we don't necessarily
557 // need to understand them all.
558 while (!Stream.AtEndOfStream()) {
559 unsigned Code = Stream.ReadCode();
560
Douglas Gregore1d918e2009-04-10 23:10:45 +0000561 if (Code != llvm::bitc::ENTER_SUBBLOCK) {
562 Error("Invalid record at top-level");
563 return Failure;
564 }
Douglas Gregor2cf26342009-04-09 22:27:44 +0000565
566 unsigned BlockID = Stream.ReadSubBlockID();
567
568 // We only know the PCH subblock ID.
569 switch (BlockID) {
570 case llvm::bitc::BLOCKINFO_BLOCK_ID:
Douglas Gregore1d918e2009-04-10 23:10:45 +0000571 if (Stream.ReadBlockInfoBlock()) {
572 Error("Malformed BlockInfoBlock");
573 return Failure;
574 }
Douglas Gregor2cf26342009-04-09 22:27:44 +0000575 break;
576 case pch::PCH_BLOCK_ID:
Douglas Gregor0a0428e2009-04-10 20:39:37 +0000577 switch (ReadPCHBlock()) {
578 case Success:
579 break;
580
581 case Failure:
Douglas Gregore1d918e2009-04-10 23:10:45 +0000582 return Failure;
Douglas Gregor0a0428e2009-04-10 20:39:37 +0000583
584 case IgnorePCH:
Douglas Gregor2bec0412009-04-10 21:16:55 +0000585 // FIXME: We could consider reading through to the end of this
586 // PCH block, skipping subblocks, to see if there are other
587 // PCH blocks elsewhere.
Douglas Gregore1d918e2009-04-10 23:10:45 +0000588 return IgnorePCH;
Douglas Gregor0a0428e2009-04-10 20:39:37 +0000589 }
Douglas Gregor2cf26342009-04-09 22:27:44 +0000590 break;
591 default:
Douglas Gregore1d918e2009-04-10 23:10:45 +0000592 if (Stream.SkipBlock()) {
593 Error("Malformed block record");
594 return Failure;
595 }
Douglas Gregor2cf26342009-04-09 22:27:44 +0000596 break;
597 }
598 }
599
600 // Load the translation unit declaration
601 ReadDeclRecord(DeclOffsets[0], 0);
602
Douglas Gregore1d918e2009-04-10 23:10:45 +0000603 return Success;
Douglas Gregor2cf26342009-04-09 22:27:44 +0000604}
605
Douglas Gregor0a0428e2009-04-10 20:39:37 +0000606/// \brief Parse the record that corresponds to a LangOptions data
607/// structure.
608///
609/// This routine compares the language options used to generate the
610/// PCH file against the language options set for the current
611/// compilation. For each option, we classify differences between the
612/// two compiler states as either "benign" or "important". Benign
613/// differences don't matter, and we accept them without complaint
614/// (and without modifying the language options). Differences between
615/// the states for important options cause the PCH file to be
616/// unusable, so we emit a warning and return true to indicate that
617/// there was an error.
618///
619/// \returns true if the PCH file is unacceptable, false otherwise.
620bool PCHReader::ParseLanguageOptions(
621 const llvm::SmallVectorImpl<uint64_t> &Record) {
622 const LangOptions &LangOpts = Context.getLangOptions();
623#define PARSE_LANGOPT_BENIGN(Option) ++Idx
624#define PARSE_LANGOPT_IMPORTANT(Option, DiagID) \
625 if (Record[Idx] != LangOpts.Option) { \
626 Diag(DiagID) << (unsigned)Record[Idx] << LangOpts.Option; \
627 Diag(diag::note_ignoring_pch) << FileName; \
628 return true; \
629 } \
630 ++Idx
631
632 unsigned Idx = 0;
633 PARSE_LANGOPT_BENIGN(Trigraphs);
634 PARSE_LANGOPT_BENIGN(BCPLComment);
635 PARSE_LANGOPT_BENIGN(DollarIdents);
636 PARSE_LANGOPT_BENIGN(AsmPreprocessor);
637 PARSE_LANGOPT_IMPORTANT(GNUMode, diag::warn_pch_gnu_extensions);
638 PARSE_LANGOPT_BENIGN(ImplicitInt);
639 PARSE_LANGOPT_BENIGN(Digraphs);
640 PARSE_LANGOPT_BENIGN(HexFloats);
641 PARSE_LANGOPT_IMPORTANT(C99, diag::warn_pch_c99);
642 PARSE_LANGOPT_IMPORTANT(Microsoft, diag::warn_pch_microsoft_extensions);
643 PARSE_LANGOPT_IMPORTANT(CPlusPlus, diag::warn_pch_cplusplus);
644 PARSE_LANGOPT_IMPORTANT(CPlusPlus0x, diag::warn_pch_cplusplus0x);
645 PARSE_LANGOPT_IMPORTANT(NoExtensions, diag::warn_pch_extensions);
646 PARSE_LANGOPT_BENIGN(CXXOperatorName);
647 PARSE_LANGOPT_IMPORTANT(ObjC1, diag::warn_pch_objective_c);
648 PARSE_LANGOPT_IMPORTANT(ObjC2, diag::warn_pch_objective_c2);
649 PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI, diag::warn_pch_nonfragile_abi);
650 PARSE_LANGOPT_BENIGN(PascalStrings);
651 PARSE_LANGOPT_BENIGN(Boolean);
652 PARSE_LANGOPT_BENIGN(WritableStrings);
653 PARSE_LANGOPT_IMPORTANT(LaxVectorConversions,
654 diag::warn_pch_lax_vector_conversions);
655 PARSE_LANGOPT_IMPORTANT(Exceptions, diag::warn_pch_exceptions);
656 PARSE_LANGOPT_IMPORTANT(NeXTRuntime, diag::warn_pch_objc_runtime);
657 PARSE_LANGOPT_IMPORTANT(Freestanding, diag::warn_pch_freestanding);
658 PARSE_LANGOPT_IMPORTANT(NoBuiltin, diag::warn_pch_builtins);
659 PARSE_LANGOPT_IMPORTANT(ThreadsafeStatics,
660 diag::warn_pch_thread_safe_statics);
661 PARSE_LANGOPT_IMPORTANT(Blocks, diag::warn_pch_blocks);
662 PARSE_LANGOPT_BENIGN(EmitAllDecls);
663 PARSE_LANGOPT_IMPORTANT(MathErrno, diag::warn_pch_math_errno);
664 PARSE_LANGOPT_IMPORTANT(OverflowChecking, diag::warn_pch_overflow_checking);
665 PARSE_LANGOPT_IMPORTANT(HeinousExtensions,
666 diag::warn_pch_heinous_extensions);
667 // FIXME: Most of the options below are benign if the macro wasn't
668 // used. Unfortunately, this means that a PCH compiled without
669 // optimization can't be used with optimization turned on, even
670 // though the only thing that changes is whether __OPTIMIZE__ was
671 // defined... but if __OPTIMIZE__ never showed up in the header, it
672 // doesn't matter. We could consider making this some special kind
673 // of check.
674 PARSE_LANGOPT_IMPORTANT(Optimize, diag::warn_pch_optimize);
675 PARSE_LANGOPT_IMPORTANT(OptimizeSize, diag::warn_pch_optimize_size);
676 PARSE_LANGOPT_IMPORTANT(Static, diag::warn_pch_static);
677 PARSE_LANGOPT_IMPORTANT(PICLevel, diag::warn_pch_pic_level);
678 PARSE_LANGOPT_IMPORTANT(GNUInline, diag::warn_pch_gnu_inline);
679 PARSE_LANGOPT_IMPORTANT(NoInline, diag::warn_pch_no_inline);
680 if ((LangOpts.getGCMode() != 0) != (Record[Idx] != 0)) {
681 Diag(diag::warn_pch_gc_mode)
682 << (unsigned)Record[Idx] << LangOpts.getGCMode();
683 Diag(diag::note_ignoring_pch) << FileName;
684 return true;
685 }
686 ++Idx;
687 PARSE_LANGOPT_BENIGN(getVisibilityMode());
688 PARSE_LANGOPT_BENIGN(InstantiationDepth);
689#undef PARSE_LANGOPT_IRRELEVANT
690#undef PARSE_LANGOPT_BENIGN
691
692 return false;
693}
694
Douglas Gregor2cf26342009-04-09 22:27:44 +0000695/// \brief Read and return the type at the given offset.
696///
697/// This routine actually reads the record corresponding to the type
698/// at the given offset in the bitstream. It is a helper routine for
699/// GetType, which deals with reading type IDs.
700QualType PCHReader::ReadTypeRecord(uint64_t Offset) {
701 Stream.JumpToBit(Offset);
702 RecordData Record;
703 unsigned Code = Stream.ReadCode();
704 switch ((pch::TypeCode)Stream.ReadRecord(Code, Record)) {
705 case pch::TYPE_FIXED_WIDTH_INT: {
706 assert(Record.size() == 2 && "Incorrect encoding of fixed-width int type");
707 return Context.getFixedWidthIntType(Record[0], Record[1]);
708 }
709
710 case pch::TYPE_COMPLEX: {
711 assert(Record.size() == 1 && "Incorrect encoding of complex type");
712 QualType ElemType = GetType(Record[0]);
713 return Context.getComplexType(ElemType);
714 }
715
716 case pch::TYPE_POINTER: {
717 assert(Record.size() == 1 && "Incorrect encoding of pointer type");
718 QualType PointeeType = GetType(Record[0]);
719 return Context.getPointerType(PointeeType);
720 }
721
722 case pch::TYPE_BLOCK_POINTER: {
723 assert(Record.size() == 1 && "Incorrect encoding of block pointer type");
724 QualType PointeeType = GetType(Record[0]);
725 return Context.getBlockPointerType(PointeeType);
726 }
727
728 case pch::TYPE_LVALUE_REFERENCE: {
729 assert(Record.size() == 1 && "Incorrect encoding of lvalue reference type");
730 QualType PointeeType = GetType(Record[0]);
731 return Context.getLValueReferenceType(PointeeType);
732 }
733
734 case pch::TYPE_RVALUE_REFERENCE: {
735 assert(Record.size() == 1 && "Incorrect encoding of rvalue reference type");
736 QualType PointeeType = GetType(Record[0]);
737 return Context.getRValueReferenceType(PointeeType);
738 }
739
740 case pch::TYPE_MEMBER_POINTER: {
741 assert(Record.size() == 1 && "Incorrect encoding of member pointer type");
742 QualType PointeeType = GetType(Record[0]);
743 QualType ClassType = GetType(Record[1]);
744 return Context.getMemberPointerType(PointeeType, ClassType.getTypePtr());
745 }
746
747 // FIXME: Several other kinds of types to deserialize here!
748 default:
Douglas Gregor8038d512009-04-10 17:25:41 +0000749 assert(false && "Unable to deserialize this type");
Douglas Gregor2cf26342009-04-09 22:27:44 +0000750 break;
751 }
752
753 // Suppress a GCC warning
754 return QualType();
755}
756
757/// \brief Note that we have loaded the declaration with the given
758/// Index.
759///
760/// This routine notes that this declaration has already been loaded,
761/// so that future GetDecl calls will return this declaration rather
762/// than trying to load a new declaration.
763inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
764 assert(!DeclAlreadyLoaded[Index] && "Decl loaded twice?");
765 DeclAlreadyLoaded[Index] = true;
766 DeclOffsets[Index] = reinterpret_cast<uint64_t>(D);
767}
768
769/// \brief Read the declaration at the given offset from the PCH file.
770Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
771 Decl *D = 0;
772 Stream.JumpToBit(Offset);
773 RecordData Record;
774 unsigned Code = Stream.ReadCode();
775 unsigned Idx = 0;
776 PCHDeclReader Reader(*this, Record, Idx);
777 switch ((pch::DeclCode)Stream.ReadRecord(Code, Record)) {
778 case pch::DECL_TRANSLATION_UNIT:
779 assert(Index == 0 && "Translation unit must be at index 0");
780 Reader.VisitTranslationUnitDecl(Context.getTranslationUnitDecl());
781 D = Context.getTranslationUnitDecl();
782 LoadedDecl(Index, D);
783 break;
784
785 case pch::DECL_TYPEDEF: {
786 TypedefDecl *Typedef = TypedefDecl::Create(Context, 0, SourceLocation(),
787 0, QualType());
788 LoadedDecl(Index, Typedef);
789 Reader.VisitTypedefDecl(Typedef);
790 D = Typedef;
791 break;
792 }
793
794 case pch::DECL_VAR: {
795 VarDecl *Var = VarDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
796 VarDecl::None, SourceLocation());
797 LoadedDecl(Index, Var);
798 Reader.VisitVarDecl(Var);
799 D = Var;
800 break;
801 }
802
803 default:
804 assert(false && "Cannot de-serialize this kind of declaration");
805 break;
806 }
807
808 // If this declaration is also a declaration context, get the
809 // offsets for its tables of lexical and visible declarations.
810 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
811 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
812 if (Offsets.first || Offsets.second) {
813 DC->setHasExternalLexicalStorage(Offsets.first != 0);
814 DC->setHasExternalVisibleStorage(Offsets.second != 0);
815 DeclContextOffsets[DC] = Offsets;
816 }
817 }
818 assert(Idx == Record.size());
819
820 return D;
821}
822
Douglas Gregor8038d512009-04-10 17:25:41 +0000823QualType PCHReader::GetType(pch::TypeID ID) {
Douglas Gregor2cf26342009-04-09 22:27:44 +0000824 unsigned Quals = ID & 0x07;
825 unsigned Index = ID >> 3;
826
827 if (Index < pch::NUM_PREDEF_TYPE_IDS) {
828 QualType T;
829 switch ((pch::PredefinedTypeIDs)Index) {
830 case pch::PREDEF_TYPE_NULL_ID: return QualType();
831 case pch::PREDEF_TYPE_VOID_ID: T = Context.VoidTy; break;
832 case pch::PREDEF_TYPE_BOOL_ID: T = Context.BoolTy; break;
833
834 case pch::PREDEF_TYPE_CHAR_U_ID:
835 case pch::PREDEF_TYPE_CHAR_S_ID:
836 // FIXME: Check that the signedness of CharTy is correct!
837 T = Context.CharTy;
838 break;
839
840 case pch::PREDEF_TYPE_UCHAR_ID: T = Context.UnsignedCharTy; break;
841 case pch::PREDEF_TYPE_USHORT_ID: T = Context.UnsignedShortTy; break;
842 case pch::PREDEF_TYPE_UINT_ID: T = Context.UnsignedIntTy; break;
843 case pch::PREDEF_TYPE_ULONG_ID: T = Context.UnsignedLongTy; break;
844 case pch::PREDEF_TYPE_ULONGLONG_ID: T = Context.UnsignedLongLongTy; break;
845 case pch::PREDEF_TYPE_SCHAR_ID: T = Context.SignedCharTy; break;
846 case pch::PREDEF_TYPE_WCHAR_ID: T = Context.WCharTy; break;
847 case pch::PREDEF_TYPE_SHORT_ID: T = Context.ShortTy; break;
848 case pch::PREDEF_TYPE_INT_ID: T = Context.IntTy; break;
849 case pch::PREDEF_TYPE_LONG_ID: T = Context.LongTy; break;
850 case pch::PREDEF_TYPE_LONGLONG_ID: T = Context.LongLongTy; break;
851 case pch::PREDEF_TYPE_FLOAT_ID: T = Context.FloatTy; break;
852 case pch::PREDEF_TYPE_DOUBLE_ID: T = Context.DoubleTy; break;
853 case pch::PREDEF_TYPE_LONGDOUBLE_ID: T = Context.LongDoubleTy; break;
854 case pch::PREDEF_TYPE_OVERLOAD_ID: T = Context.OverloadTy; break;
855 case pch::PREDEF_TYPE_DEPENDENT_ID: T = Context.DependentTy; break;
856 }
857
858 assert(!T.isNull() && "Unknown predefined type");
859 return T.getQualifiedType(Quals);
860 }
861
862 Index -= pch::NUM_PREDEF_TYPE_IDS;
863 if (!TypeAlreadyLoaded[Index]) {
864 // Load the type from the PCH file.
865 TypeOffsets[Index] = reinterpret_cast<uint64_t>(
866 ReadTypeRecord(TypeOffsets[Index]).getTypePtr());
867 TypeAlreadyLoaded[Index] = true;
868 }
869
870 return QualType(reinterpret_cast<Type *>(TypeOffsets[Index]), Quals);
871}
872
Douglas Gregor8038d512009-04-10 17:25:41 +0000873Decl *PCHReader::GetDecl(pch::DeclID ID) {
Douglas Gregor2cf26342009-04-09 22:27:44 +0000874 if (ID == 0)
875 return 0;
876
877 unsigned Index = ID - 1;
878 if (DeclAlreadyLoaded[Index])
879 return reinterpret_cast<Decl *>(DeclOffsets[Index]);
880
881 // Load the declaration from the PCH file.
882 return ReadDeclRecord(DeclOffsets[Index], Index);
883}
884
885bool PCHReader::ReadDeclsLexicallyInContext(DeclContext *DC,
Douglas Gregor8038d512009-04-10 17:25:41 +0000886 llvm::SmallVectorImpl<pch::DeclID> &Decls) {
Douglas Gregor2cf26342009-04-09 22:27:44 +0000887 assert(DC->hasExternalLexicalStorage() &&
888 "DeclContext has no lexical decls in storage");
889 uint64_t Offset = DeclContextOffsets[DC].first;
890 assert(Offset && "DeclContext has no lexical decls in storage");
891
892 // Load the record containing all of the declarations lexically in
893 // this context.
894 Stream.JumpToBit(Offset);
895 RecordData Record;
896 unsigned Code = Stream.ReadCode();
897 unsigned RecCode = Stream.ReadRecord(Code, Record);
898 assert(RecCode == pch::DECL_CONTEXT_LEXICAL && "Expected lexical block");
899
900 // Load all of the declaration IDs
901 Decls.clear();
902 Decls.insert(Decls.end(), Record.begin(), Record.end());
903 return false;
904}
905
906bool PCHReader::ReadDeclsVisibleInContext(DeclContext *DC,
907 llvm::SmallVectorImpl<VisibleDeclaration> & Decls) {
908 assert(DC->hasExternalVisibleStorage() &&
909 "DeclContext has no visible decls in storage");
910 uint64_t Offset = DeclContextOffsets[DC].second;
911 assert(Offset && "DeclContext has no visible decls in storage");
912
913 // Load the record containing all of the declarations visible in
914 // this context.
915 Stream.JumpToBit(Offset);
916 RecordData Record;
917 unsigned Code = Stream.ReadCode();
918 unsigned RecCode = Stream.ReadRecord(Code, Record);
919 assert(RecCode == pch::DECL_CONTEXT_VISIBLE && "Expected visible block");
920 if (Record.size() == 0)
921 return false;
922
923 Decls.clear();
924
925 unsigned Idx = 0;
926 // llvm::SmallVector<uintptr_t, 16> DeclIDs;
927 while (Idx < Record.size()) {
928 Decls.push_back(VisibleDeclaration());
929 Decls.back().Name = ReadDeclarationName(Record, Idx);
930
931 // FIXME: Don't actually read anything here!
932 unsigned Size = Record[Idx++];
933 llvm::SmallVector<unsigned, 4> & LoadedDecls
934 = Decls.back().Declarations;
935 LoadedDecls.reserve(Size);
936 for (unsigned I = 0; I < Size; ++I)
937 LoadedDecls.push_back(Record[Idx++]);
938 }
939
940 return false;
941}
942
943void PCHReader::PrintStats() {
944 std::fprintf(stderr, "*** PCH Statistics:\n");
945
946 unsigned NumTypesLoaded = std::count(TypeAlreadyLoaded.begin(),
947 TypeAlreadyLoaded.end(),
948 true);
949 unsigned NumDeclsLoaded = std::count(DeclAlreadyLoaded.begin(),
950 DeclAlreadyLoaded.end(),
951 true);
952 std::fprintf(stderr, " %u/%u types read (%f%%)\n",
953 NumTypesLoaded, (unsigned)TypeAlreadyLoaded.size(),
954 ((float)NumTypesLoaded/(float)TypeAlreadyLoaded.size() * 100));
955 std::fprintf(stderr, " %u/%u declarations read (%f%%)\n",
956 NumDeclsLoaded, (unsigned)DeclAlreadyLoaded.size(),
957 ((float)NumDeclsLoaded/(float)DeclAlreadyLoaded.size() * 100));
958 std::fprintf(stderr, "\n");
959}
960
Chris Lattner7356a312009-04-11 21:15:38 +0000961IdentifierInfo *PCHReader::DecodeIdentifierInfo(unsigned ID) {
Douglas Gregorafaf3082009-04-11 00:14:32 +0000962 if (ID == 0)
963 return 0;
Chris Lattner7356a312009-04-11 21:15:38 +0000964
Douglas Gregorafaf3082009-04-11 00:14:32 +0000965 if (!IdentifierTable || IdentifierData.empty()) {
966 Error("No identifier table in PCH file");
967 return 0;
968 }
Chris Lattner7356a312009-04-11 21:15:38 +0000969
Douglas Gregorafaf3082009-04-11 00:14:32 +0000970 if (IdentifierData[ID - 1] & 0x01) {
971 uint64_t Offset = IdentifierData[ID - 1];
972 IdentifierData[ID - 1] = reinterpret_cast<uint64_t>(
Chris Lattner7356a312009-04-11 21:15:38 +0000973 &Context.Idents.get(IdentifierTable + Offset));
Douglas Gregorafaf3082009-04-11 00:14:32 +0000974 }
Chris Lattner7356a312009-04-11 21:15:38 +0000975
976 return reinterpret_cast<IdentifierInfo *>(IdentifierData[ID - 1]);
Douglas Gregor2cf26342009-04-09 22:27:44 +0000977}
978
979DeclarationName
980PCHReader::ReadDeclarationName(const RecordData &Record, unsigned &Idx) {
981 DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++];
982 switch (Kind) {
983 case DeclarationName::Identifier:
984 return DeclarationName(GetIdentifierInfo(Record, Idx));
985
986 case DeclarationName::ObjCZeroArgSelector:
987 case DeclarationName::ObjCOneArgSelector:
988 case DeclarationName::ObjCMultiArgSelector:
989 assert(false && "Unable to de-serialize Objective-C selectors");
990 break;
991
992 case DeclarationName::CXXConstructorName:
993 return Context.DeclarationNames.getCXXConstructorName(
994 GetType(Record[Idx++]));
995
996 case DeclarationName::CXXDestructorName:
997 return Context.DeclarationNames.getCXXDestructorName(
998 GetType(Record[Idx++]));
999
1000 case DeclarationName::CXXConversionFunctionName:
1001 return Context.DeclarationNames.getCXXConversionFunctionName(
1002 GetType(Record[Idx++]));
1003
1004 case DeclarationName::CXXOperatorName:
1005 return Context.DeclarationNames.getCXXOperatorName(
1006 (OverloadedOperatorKind)Record[Idx++]);
1007
1008 case DeclarationName::CXXUsingDirective:
1009 return DeclarationName::getUsingDirectiveName();
1010 }
1011
1012 // Required to silence GCC warning
1013 return DeclarationName();
1014}
Douglas Gregor0a0428e2009-04-10 20:39:37 +00001015
1016DiagnosticBuilder PCHReader::Diag(unsigned DiagID) {
Douglas Gregore1d918e2009-04-10 23:10:45 +00001017 return Diag(SourceLocation(), DiagID);
1018}
1019
1020DiagnosticBuilder PCHReader::Diag(SourceLocation Loc, unsigned DiagID) {
1021 return PP.getDiagnostics().Report(FullSourceLoc(Loc,
Douglas Gregor0a0428e2009-04-10 20:39:37 +00001022 Context.getSourceManager()),
1023 DiagID);
1024}