diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-04-28 20:33:11 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-04-28 20:33:11 +0000 |
commit | e6648fb79e9e112098c57fdd7396a21583e2f32b (patch) | |
tree | 4eb3bfd3005c0b468442839b813ec6c3efa7f627 /clang/lib/Frontend/PCHReader.cpp | |
parent | ab4df58193b60455286db0cd4ad3e67b535cd3d6 (diff) | |
download | bcm5719-llvm-e6648fb79e9e112098c57fdd7396a21583e2f32b.tar.gz bcm5719-llvm-e6648fb79e9e112098c57fdd7396a21583e2f32b.zip |
Implement checking for macro definitions that occur on the command
line when using a PCH that were not provided when building the PCH
file. If those names were used as identifiers somewhere in the PCH
file, reject the PCH file.
llvm-svn: 70321
Diffstat (limited to 'clang/lib/Frontend/PCHReader.cpp')
-rw-r--r-- | clang/lib/Frontend/PCHReader.cpp | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/clang/lib/Frontend/PCHReader.cpp b/clang/lib/Frontend/PCHReader.cpp index f1d7e7a5586..e7404f899bc 100644 --- a/clang/lib/Frontend/PCHReader.cpp +++ b/clang/lib/Frontend/PCHReader.cpp @@ -507,9 +507,17 @@ bool PCHReader::CheckPredefinesBuffer(const char *PCHPredef, std::string MacroName = Extra.substr(StartOfMacroName, EndOfMacroName - StartOfMacroName); - // FIXME: Perform this check! - fprintf(stderr, "FIXME: check whether '%s' was used in the PCH file\n", - MacroName.c_str()); + // Check whether this name was used somewhere in the PCH file. If + // so, defining it as a macro could change behavior, so we reject + // the PCH file. + if (IdentifierInfo *II = get(MacroName.c_str(), + MacroName.c_str() + MacroName.size())) { + Diag(diag::warn_macro_name_used_in_pch) + << II; + Diag(diag::note_ignoring_pch) + << FileName; + return true; + } // Add this definition to the suggested predefines buffer. SuggestedPredefines += Extra; @@ -818,9 +826,11 @@ PCHReader::PCHReadResult PCHReader::ReadSLocEntryRecord(unsigned ID) { Name); FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer, ID, Offset); - if (strcmp(Name, "<built-in>") == 0 - && CheckPredefinesBuffer(BlobStart, BlobLen - 1, BufferID)) - return IgnorePCH; + if (strcmp(Name, "<built-in>") == 0) { + PCHPredefinesBufferID = BufferID; + PCHPredefines = BlobStart; + PCHPredefinesLen = BlobLen - 1; + } break; } @@ -1287,7 +1297,12 @@ PCHReader::PCHReadResult PCHReader::ReadPCH(const std::string &FileName) { // Load the translation unit declaration if (Context) ReadDeclRecord(DeclOffsets[0], 0); - + + // Check the predefines buffer. + if (CheckPredefinesBuffer(PCHPredefines, PCHPredefinesLen, + PCHPredefinesBufferID)) + return IgnorePCH; + // Initialization of builtins and library builtins occurs before the // PCH file is read, so there may be some identifiers that were // loaded into the IdentifierTable before we intercepted the |