aboutsummaryrefslogtreecommitdiff
path: root/lib/Frontend
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Frontend')
-rw-r--r--lib/Frontend/PCHReader.cpp29
-rw-r--r--lib/Frontend/PCHWriter.cpp12
2 files changed, 33 insertions, 8 deletions
diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp
index f1d7e7a558..e7404f899b 100644
--- a/lib/Frontend/PCHReader.cpp
+++ b/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
diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp
index e61cca554b..11f620279c 100644
--- a/lib/Frontend/PCHWriter.cpp
+++ b/lib/Frontend/PCHWriter.cpp
@@ -1378,11 +1378,21 @@ void PCHWriter::WriteIdentifierTable(Preprocessor &PP) {
// Create and write out the blob that contains the identifier
// strings.
- IdentifierOffsets.resize(IdentifierIDs.size());
{
OnDiskChainedHashTableGenerator<PCHIdentifierTableTrait> Generator;
+ // Look for any identifiers that were named while processing the
+ // headers, but are otherwise not needed. We add these to the hash
+ // table to enable checking of the predefines buffer in the case
+ // where the user adds new macro definitions when building the PCH
+ // file.
+ for (IdentifierTable::iterator ID = PP.getIdentifierTable().begin(),
+ IDEnd = PP.getIdentifierTable().end();
+ ID != IDEnd; ++ID)
+ getIdentifierRef(ID->second);
+
// Create the on-disk hash table representation.
+ IdentifierOffsets.resize(IdentifierIDs.size());
for (llvm::DenseMap<const IdentifierInfo *, pch::IdentID>::iterator
ID = IdentifierIDs.begin(), IDEnd = IdentifierIDs.end();
ID != IDEnd; ++ID) {