diff options
| author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-11-05 22:10:18 +0000 |
|---|---|---|
| committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-11-05 22:10:18 +0000 |
| commit | 452707c12542d6ec1a13e7611a86327ef8f8ab45 (patch) | |
| tree | ee4ff6eca1d6b73623765b786505b689b1b33ecc | |
| parent | d87ea457bb0af7366286f78ffa90b9b6c6650417 (diff) | |
| download | bcm5719-llvm-452707c12542d6ec1a13e7611a86327ef8f8ab45.tar.gz bcm5719-llvm-452707c12542d6ec1a13e7611a86327ef8f8ab45.zip | |
Read/write from/to PCH the diagnostic mappings that the user set so that e.g. #pragma clang diagnostic can be used in a PCH.
Fixes rdar://8435969.
llvm-svn: 118303
| -rw-r--r-- | clang/include/clang/Basic/Diagnostic.h | 3 | ||||
| -rw-r--r-- | clang/include/clang/Serialization/ASTBitCodes.h | 5 | ||||
| -rw-r--r-- | clang/include/clang/Serialization/ASTReader.h | 5 | ||||
| -rw-r--r-- | clang/include/clang/Serialization/ASTWriter.h | 1 | ||||
| -rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 23 | ||||
| -rw-r--r-- | clang/lib/Serialization/ASTWriter.cpp | 17 | ||||
| -rw-r--r-- | clang/test/PCH/pragma-diag.c | 19 |
7 files changed, 72 insertions, 1 deletions
diff --git a/clang/include/clang/Basic/Diagnostic.h b/clang/include/clang/Basic/Diagnostic.h index f9c211f3b14..53679b8ce3a 100644 --- a/clang/include/clang/Basic/Diagnostic.h +++ b/clang/include/clang/Basic/Diagnostic.h @@ -640,6 +640,9 @@ private: /// \returns true if the diagnostic was emitted, false if it was /// suppressed. bool ProcessDiag(); + + friend class ASTReader; + friend class ASTWriter; }; //===----------------------------------------------------------------------===// diff --git a/clang/include/clang/Serialization/ASTBitCodes.h b/clang/include/clang/Serialization/ASTBitCodes.h index dbd4fa91e98..38b87ed47ca 100644 --- a/clang/include/clang/Serialization/ASTBitCodes.h +++ b/clang/include/clang/Serialization/ASTBitCodes.h @@ -341,7 +341,10 @@ namespace clang { /// \brief Record code for the table of offsets to CXXBaseSpecifier /// sets. - CXX_BASE_SPECIFIER_OFFSETS = 37 + CXX_BASE_SPECIFIER_OFFSETS = 37, + + /// \brief Record code for diagnostic mappings specified by the user. + DIAG_USER_MAPPINGS = 38 }; /// \brief Record types used within a source manager block. diff --git a/clang/include/clang/Serialization/ASTReader.h b/clang/include/clang/Serialization/ASTReader.h index 420197c2606..b92ca0b6a72 100644 --- a/clang/include/clang/Serialization/ASTReader.h +++ b/clang/include/clang/Serialization/ASTReader.h @@ -570,6 +570,9 @@ private: //@} + /// \brief Diagnostic IDs and their mappings that the user changed. + llvm::SmallVector<uint64_t, 8> UserDiagMappings; + /// \brief The original file name that was used to build the primary AST file, /// which may have been modified for relocatable-pch support. std::string OriginalFileName; @@ -849,6 +852,8 @@ public: /// \brief Read preprocessed entities into the virtual void ReadPreprocessedEntities(); + void ReadUserDiagnosticMappings(Diagnostic &Diag); + /// \brief Returns the number of source locations found in the chain. unsigned getTotalNumSLocs() const { return TotalNumSLocEntries; diff --git a/clang/include/clang/Serialization/ASTWriter.h b/clang/include/clang/Serialization/ASTWriter.h index 5a3fd93d495..6b7884d525d 100644 --- a/clang/include/clang/Serialization/ASTWriter.h +++ b/clang/include/clang/Serialization/ASTWriter.h @@ -304,6 +304,7 @@ private: const Preprocessor &PP, const char* isysroot); void WritePreprocessor(const Preprocessor &PP); + void WriteUserDiagnosticMappings(const Diagnostic &Diag); void WriteType(QualType T); uint64_t WriteDeclContextLexicalBlock(ASTContext &Context, DeclContext *DC); uint64_t WriteDeclContextVisibleBlock(ASTContext &Context, DeclContext *DC); diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index b90203b477b..d70546dbbcf 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -2130,6 +2130,18 @@ ASTReader::ReadASTBlock(PerFileData &F) { F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart; break; } + + case DIAG_USER_MAPPINGS: + if (Record.size() % 2 != 0) { + Error("invalid DIAG_USER_MAPPINGS block in AST file"); + return Failure; + } + if (UserDiagMappings.empty()) + UserDiagMappings.swap(Record); + else + UserDiagMappings.insert(UserDiagMappings.end(), + Record.begin(), Record.end()); + break; } First = false; } @@ -2457,6 +2469,8 @@ void ASTReader::InitializeContext(ASTContext &Ctx) { if (SpecialTypes[SPECIAL_TYPE_INT128_INSTALLED]) Context->setInt128Installed(); + + ReadUserDiagnosticMappings(Context->getDiagnostics()); } /// \brief Retrieve the name of the original source file name @@ -2623,6 +2637,15 @@ void ASTReader::ReadPreprocessedEntities() { ReadDefinedMacros(); } +void ASTReader::ReadUserDiagnosticMappings(Diagnostic &Diag) { + unsigned Idx = 0; + while (Idx < UserDiagMappings.size()) { + unsigned DiagID = UserDiagMappings[Idx++]; + unsigned Map = UserDiagMappings[Idx++]; + Diag.setDiagnosticMappingInternal(DiagID, Map, /*isUser=*/true); + } +} + /// \brief Get the correct cursor and offset for loading a type. ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { PerFileData *F = 0; diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 47ef72f7bd6..a5977f5cfe8 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -1441,6 +1441,19 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP) { } } +void ASTWriter::WriteUserDiagnosticMappings(const Diagnostic &Diag) { + RecordData Record; + for (unsigned i = 0; i != diag::DIAG_UPPER_LIMIT; ++i) { + diag::Mapping Map = Diag.getDiagnosticMappingInfo(i); + if (Map & 0x8) { // user mapping. + Record.push_back(i); + Record.push_back(Map & 0x7); + } + } + + Stream.EmitRecord(DIAG_USER_MAPPINGS, Record); +} + //===----------------------------------------------------------------------===// // Type Serialization //===----------------------------------------------------------------------===// @@ -2402,6 +2415,7 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls, WriteIdentifierTable(PP); WriteTypeDeclOffsets(); + WriteUserDiagnosticMappings(Context.getDiagnostics()); // Write the C++ base-specifier set offsets. if (!CXXBaseSpecifiersOffsets.empty()) { @@ -2635,6 +2649,9 @@ void ASTWriter::WriteASTChain(Sema &SemaRef, MemorizeStatCalls *StatCalls, WriteReferencedSelectorsPool(SemaRef); WriteIdentifierTable(PP); WriteTypeDeclOffsets(); + // FIXME: For chained PCH only write the new mappings (we currently + // write all of them again). + WriteUserDiagnosticMappings(Context.getDiagnostics()); /// Build a record containing first declarations from a chained PCH and the /// most recent declarations in this AST that they point to. diff --git a/clang/test/PCH/pragma-diag.c b/clang/test/PCH/pragma-diag.c new file mode 100644 index 00000000000..c5171036400 --- /dev/null +++ b/clang/test/PCH/pragma-diag.c @@ -0,0 +1,19 @@ +// Test this without pch. +// RUN: %clang_cc1 %s -include %s -verify -fsyntax-only + +// Test with pch. +// RUN: %clang_cc1 %s -emit-pch -o %t +// RUN: %clang_cc1 %s -include-pch %t -verify -fsyntax-only + +#ifndef HEADER +#define HEADER + +#pragma clang diagnostic ignored "-Wtautological-compare" + +#else + +void f() { + int b = b==b; +} + +#endif |

