Properly propagate #pragma diagnostic mappings from PCH but not command-line warning flags.
Addresses rdar://8435969&8852495
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123462 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp
index e7a3b0a..2c52f7f 100644
--- a/lib/Serialization/ASTReader.cpp
+++ b/lib/Serialization/ASTReader.cpp
@@ -2128,15 +2128,15 @@
break;
}
- case DIAG_USER_MAPPINGS:
+ case DIAG_PRAGMA_MAPPINGS:
if (Record.size() % 2 != 0) {
Error("invalid DIAG_USER_MAPPINGS block in AST file");
return Failure;
}
- if (UserDiagMappings.empty())
- UserDiagMappings.swap(Record);
+ if (PragmaDiagMappings.empty())
+ PragmaDiagMappings.swap(Record);
else
- UserDiagMappings.insert(UserDiagMappings.end(),
+ PragmaDiagMappings.insert(PragmaDiagMappings.end(),
Record.begin(), Record.end());
break;
}
@@ -2482,7 +2482,7 @@
if (SpecialTypes[SPECIAL_TYPE_INT128_INSTALLED])
Context->setInt128Installed();
- ReadUserDiagnosticMappings(Context->getDiagnostics());
+ ReadPragmaDiagnosticMappings(Context->getDiagnostics());
}
/// \brief Retrieve the name of the original source file name
@@ -2670,13 +2670,23 @@
return ReadMacroRecord(*F, Offset);
}
-void ASTReader::ReadUserDiagnosticMappings(Diagnostic &Diag) {
+void ASTReader::ReadPragmaDiagnosticMappings(Diagnostic &Diag) {
unsigned Idx = 0;
- while (Idx < UserDiagMappings.size()) {
- unsigned DiagID = UserDiagMappings[Idx++];
- unsigned Map = UserDiagMappings[Idx++];
- Diag.setDiagnosticMappingInternal(DiagID, Map, Diag.GetCurDiagState(),
- /*isUser=*/true);
+ while (Idx < PragmaDiagMappings.size()) {
+ SourceLocation
+ Loc = SourceLocation::getFromRawEncoding(PragmaDiagMappings[Idx++]);
+ while (1) {
+ assert(Idx < PragmaDiagMappings.size() &&
+ "Invalid data, didn't find '-1' marking end of diag/map pairs");
+ if (Idx >= PragmaDiagMappings.size())
+ break; // Something is messed up but at least avoid infinite loop in
+ // release build.
+ unsigned DiagID = PragmaDiagMappings[Idx++];
+ if (DiagID == (unsigned)-1)
+ break; // no more diag/map pairs for this location.
+ diag::Mapping Map = (diag::Mapping)PragmaDiagMappings[Idx++];
+ Diag.setDiagnosticMapping(DiagID, Map, Loc);
+ }
}
}