[cfe-commits] r68824 - in /cfe/trunk: include/clang/Basic/DiagnosticFrontendKinds.td include/clang/Frontend/PCHBitCodes.h include/clang/Frontend/PCHWriter.h lib/Frontend/PCHReader.cpp lib/Frontend/PCHWriter.cpp
Douglas Gregor
dgregor at apple.com
Fri Apr 10 14:16:56 PDT 2009
Author: dgregor
Date: Fri Apr 10 16:16:55 2009
New Revision: 68824
URL: http://llvm.org/viewvc/llvm-project?rev=68824&view=rev
Log:
Encode the target triple in the PCH file, and check that target triple when using the PCH file
Modified:
cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
cfe/trunk/include/clang/Frontend/PCHBitCodes.h
cfe/trunk/include/clang/Frontend/PCHWriter.h
cfe/trunk/lib/Frontend/PCHReader.cpp
cfe/trunk/lib/Frontend/PCHWriter.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td?rev=68824&r1=68823&r2=68824&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td Fri Apr 10 16:16:55 2009
@@ -24,24 +24,27 @@
"FIX-IT detected errors it could not fix; no output will be generated">;
// PCH reader
+def warn_pch_target_triple : Warning<
+ "PCH file was compiled for the target '%0' but the current translation "
+ "unit is being compiled for target '%1'">;
def note_ignoring_pch : Note<
"ignoring precompiled header '%0'">;
-def warn_pch_c99 : Error<
+def warn_pch_c99 : Warning<
"C99 support was %select{disabled|enabled}0 in PCH file but is "
"currently %select{disabled|enabled}1">;
-def warn_pch_cplusplus : Error<
+def warn_pch_cplusplus : Warning<
"C++ support was %select{disabled|enabled}0 in PCH file but is "
"currently %select{disabled|enabled}1">;
-def warn_pch_cplusplus0x : Error<
+def warn_pch_cplusplus0x : Warning<
"C++0x support was %select{disabled|enabled}0 in PCH file but is "
"currently %select{disabled|enabled}1">;
-def warn_pch_objective_c : Error<
+def warn_pch_objective_c : Warning<
"Objective-C support was %select{disabled|enabled}0 in PCH file but is "
"currently %select{disabled|enabled}1">;
-def warn_pch_objective_c2 : Error<
+def warn_pch_objective_c2 : Warning<
"Objective-C 2.0 support was %select{disabled|enabled}0 in PCH file but "
"is currently %select{disabled|enabled}1">;
-def warn_pch_nonfragile_abi : Error<
+def warn_pch_nonfragile_abi : Warning<
"PCH file was compiled with the %select{32-bit|non-fragile}0 Objective-C "
"ABI but the %select{32-bit|non-fragile}1 Objective-C ABI is selected">;
def warn_pch_extensions : Warning<
Modified: cfe/trunk/include/clang/Frontend/PCHBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHBitCodes.h?rev=68824&r1=68823&r2=68824&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHBitCodes.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHBitCodes.h Fri Apr 10 16:16:55 2009
@@ -100,7 +100,11 @@
/// LangOptions structure. We serialize the entire contents of
/// the structure, and let the reader decide which options are
/// actually important to check.
- LANGUAGE_OPTIONS = 3
+ LANGUAGE_OPTIONS = 3,
+
+ /// \brief Record code for the target triple used to build the
+ /// PCH file.
+ TARGET_TRIPLE = 4
};
/// \brief Record types used within a source manager block.
Modified: cfe/trunk/include/clang/Frontend/PCHWriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHWriter.h?rev=68824&r1=68823&r2=68824&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHWriter.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHWriter.h Fri Apr 10 16:16:55 2009
@@ -29,9 +29,10 @@
namespace clang {
-class SourceManager;
-class Preprocessor;
class ASTContext;
+class Preprocessor;
+class SourceManager;
+class TargetInfo;
/// \brief Writes a precompiled header containing the contents of a
/// translation unit.
@@ -76,6 +77,7 @@
/// \brief The type ID that will be assigned to the next new type.
pch::TypeID NextTypeID;
+ void WriteTargetTriple(const TargetInfo &Target);
void WriteLanguageOptions(const LangOptions &LangOpts);
void WriteSourceManagerBlock(SourceManager &SourceMgr);
void WritePreprocessor(const Preprocessor &PP);
Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=68824&r1=68823&r2=68824&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Fri Apr 10 16:16:55 2009
@@ -18,6 +18,7 @@
#include "clang/Lex/Preprocessor.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/FileManager.h"
+#include "clang/Basic/TargetInfo.h"
#include "llvm/Bitcode/BitstreamReader.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/MemoryBuffer.h"
@@ -238,7 +239,10 @@
// Read and process a record.
Record.clear();
- switch ((pch::PCHRecordTypes)Stream.ReadRecord(Code, Record)) {
+ const char *BlobStart = 0;
+ unsigned BlobLen = 0;
+ switch ((pch::PCHRecordTypes)Stream.ReadRecord(Code, Record,
+ &BlobStart, &BlobLen)) {
default: // Default behavior: ignore.
break;
@@ -264,6 +268,16 @@
if (ParseLanguageOptions(Record))
return IgnorePCH;
break;
+
+ case pch::TARGET_TRIPLE:
+ std::string TargetTriple(BlobStart, BlobLen);
+ if (TargetTriple != Context.Target.getTargetTriple()) {
+ Diag(diag::warn_pch_target_triple)
+ << TargetTriple << Context.Target.getTargetTriple();
+ Diag(diag::note_ignoring_pch) << FileName;
+ return IgnorePCH;
+ }
+ break;
}
}
@@ -319,10 +333,9 @@
return true;
case IgnorePCH:
- if (Stream.SkipBlock()) {
- Error("Malformed block record");
- return true;
- }
+ // FIXME: We could consider reading through to the end of this
+ // PCH block, skipping subblocks, to see if there are other
+ // PCH blocks elsewhere.
return false;
}
break;
Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=68824&r1=68823&r2=68824&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Fri Apr 10 16:16:55 2009
@@ -21,6 +21,7 @@
#include "clang/Lex/Preprocessor.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TargetInfo.h"
#include "llvm/Bitcode/BitstreamWriter.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/MemoryBuffer.h"
@@ -328,6 +329,21 @@
// PCHWriter Implementation
//===----------------------------------------------------------------------===//
+/// \brief Write the target triple (e.g., i686-apple-darwin9).
+void PCHWriter::WriteTargetTriple(const TargetInfo &Target) {
+ using namespace llvm;
+ BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
+ Abbrev->Add(BitCodeAbbrevOp(pch::TARGET_TRIPLE));
+ Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Triple name
+ unsigned TripleAbbrev = S.EmitAbbrev(Abbrev);
+
+ RecordData Record;
+ Record.push_back(pch::TARGET_TRIPLE);
+ const char *Triple = Target.getTargetTriple();
+ S.EmitRecordWithBlob(TripleAbbrev, Record, Triple, strlen(Triple));
+}
+
+/// \brief Write the LangOptions structure.
void PCHWriter::WriteLanguageOptions(const LangOptions &LangOpts) {
RecordData Record;
Record.push_back(LangOpts.Trigraphs);
@@ -815,7 +831,8 @@
DeclsToEmit.push(Context.getTranslationUnitDecl());
// Write the remaining PCH contents.
- S.EnterSubblock(pch::PCH_BLOCK_ID, 2);
+ S.EnterSubblock(pch::PCH_BLOCK_ID, 3);
+ WriteTargetTriple(Context.Target);
WriteLanguageOptions(Context.getLangOptions());
WriteSourceManagerBlock(Context.getSourceManager());
WritePreprocessor(PP);
More information about the cfe-commits
mailing list