diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-05-03 21:50:39 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-05-03 21:50:39 +0000 |
commit | d54dff026b02303a35147224de72bb44cbb53c79 (patch) | |
tree | ad4e52eb5d1269f16c3445e34d59475abff01880 /lib/Serialization | |
parent | 8b08adb279e7db69c65461f7c0029344dc3e4e5f (diff) |
[PCH] When validating that the files coming from PCH did not change, also
validate that we didn't override the contents of any of such files.
If this is detected, emit a diagnostic error and recover gracefully
by using the contents of the original file that the PCH was built from.
Part of rdar://11305263
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156107 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Serialization')
-rw-r--r-- | lib/Serialization/ASTReader.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index f2240561fa..f1ea091627 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -2473,6 +2473,26 @@ ASTReader::ASTReadResult ASTReader::validateFileEntries(ModuleFile &M) { Error("source location entry is incorrect"); return Failure; } + + off_t StoredSize = (off_t)Record[4]; + time_t StoredTime = (time_t)Record[5]; + + // Check if there was a request to override the contents of the file + // that was part of the precompiled header. Overridding such a file + // can lead to problems when lexing using the source locations from the + // PCH. + SourceManager &SM = getSourceManager(); + if (SM.isFileOverridden(File)) { + Error(diag::err_fe_pch_file_overridden, Filename); + // After emitting the diagnostic, recover by disabling the override so + // that the original file will be used. + SM.disableFileContentsOverride(File); + // The FileEntry is a virtual file entry with the size of the contents + // that would override the original contents. Set it to the original's + // size/time. + FileMgr.modifyFileEntry(const_cast<FileEntry*>(File), + StoredSize, StoredTime); + } // The stat info from the FileEntry came from the cached stat // info of the PCH, so we cannot trust it. @@ -2482,12 +2502,12 @@ ASTReader::ASTReadResult ASTReader::validateFileEntries(ModuleFile &M) { StatBuf.st_mtime = File->getModificationTime(); } - if (((off_t)Record[4] != StatBuf.st_size + if ((StoredSize != StatBuf.st_size #if !defined(LLVM_ON_WIN32) // In our regression testing, the Windows file system seems to // have inconsistent modification times that sometimes // erroneously trigger this error-handling path. - || (time_t)Record[5] != StatBuf.st_mtime + || StoredTime != StatBuf.st_mtime #endif )) { Error(diag::err_fe_pch_file_modified, Filename); |