[cfe-commits] r144153 - in /cfe/trunk: include/clang/Basic/Diagnostic.h lib/Basic/Diagnostic.cpp lib/Serialization/ASTReader.cpp test/Index/Inputs/pragma_disable_warning.h test/Index/pragma-diag-reparse.c
Argyrios Kyrtzidis
akyrtzi at gmail.com
Tue Nov 8 17:24:17 PST 2011
Author: akirtzidis
Date: Tue Nov 8 19:24:17 2011
New Revision: 144153
URL: http://llvm.org/viewvc/llvm-project?rev=144153&view=rev
Log:
[PCH] Fix reading from PCH of diagnostic pragmas.
In certain cases ASTReader would call the normal DiagnosticsEngine API to initialize
the state of diagnostic pragmas but DiagnosticsEngine would try to compare source locations
leading to crash because the main FileID was not yet initialized.
Yet another case of the ASTReader trying to use the normal APIs and inadvertently breaking
invariants. Fix this by having the ASTReader set up the internal state directly.
Added:
cfe/trunk/test/Index/Inputs/pragma_disable_warning.h
Modified:
cfe/trunk/include/clang/Basic/Diagnostic.h
cfe/trunk/lib/Basic/Diagnostic.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/test/Index/pragma-diag-reparse.c
Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=144153&r1=144152&r2=144153&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Tue Nov 8 19:24:17 2011
@@ -624,6 +624,21 @@
/// to insert, remove, or modify at a particular position.
FixItHint FixItHints[MaxFixItHints];
+ DiagnosticMappingInfo makeMappingInfo(diag::Mapping Map, SourceLocation L) {
+ bool isPragma = L.isValid();
+ DiagnosticMappingInfo MappingInfo = DiagnosticMappingInfo::Make(
+ Map, /*IsUser=*/true, isPragma);
+
+ // If this is a pragma mapping, then set the diagnostic mapping flags so
+ // that we override command line options.
+ if (isPragma) {
+ MappingInfo.setNoWarningAsError(true);
+ MappingInfo.setNoErrorAsFatal(true);
+ }
+
+ return MappingInfo;
+ }
+
/// ProcessDiag - This is the method used to report a diagnostic that is
/// finally fully formed.
///
Modified: cfe/trunk/lib/Basic/Diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Diagnostic.cpp?rev=144153&r1=144152&r2=144153&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/lib/Basic/Diagnostic.cpp Tue Nov 8 19:24:17 2011
@@ -169,18 +169,9 @@
"Cannot map errors into warnings!");
assert(!DiagStatePoints.empty());
- bool isPragma = L.isValid();
FullSourceLoc Loc(L, *SourceMgr);
FullSourceLoc LastStateChangePos = DiagStatePoints.back().Loc;
- DiagnosticMappingInfo MappingInfo = DiagnosticMappingInfo::Make(
- Map, /*IsUser=*/true, isPragma);
-
- // If this is a pragma mapping, then set the diagnostic mapping flags so that
- // we override command line options.
- if (isPragma) {
- MappingInfo.setNoWarningAsError(true);
- MappingInfo.setNoErrorAsFatal(true);
- }
+ DiagnosticMappingInfo MappingInfo = makeMappingInfo(Map, L);
// Common case; setting all the diagnostics of a group in one place.
if (Loc.isInvalid() || Loc == LastStateChangePos) {
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=144153&r1=144152&r2=144153&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Tue Nov 8 19:24:17 2011
@@ -3109,6 +3109,10 @@
unsigned Idx = 0;
while (Idx < F.PragmaDiagMappings.size()) {
SourceLocation Loc = ReadSourceLocation(F, F.PragmaDiagMappings[Idx++]);
+ Diag.DiagStates.push_back(*Diag.GetCurDiagState());
+ Diag.DiagStatePoints.push_back(
+ DiagnosticsEngine::DiagStatePoint(&Diag.DiagStates.back(),
+ FullSourceLoc(Loc, SourceMgr)));
while (1) {
assert(Idx < F.PragmaDiagMappings.size() &&
"Invalid data, didn't find '-1' marking end of diag/map pairs");
@@ -3121,8 +3125,8 @@
break; // no more diag/map pairs for this location.
}
diag::Mapping Map = (diag::Mapping)F.PragmaDiagMappings[Idx++];
- // The user bit gets set by WritePragmaDiagnosticMappings.
- Diag.setDiagnosticMapping(DiagID, Map, Loc);
+ DiagnosticMappingInfo MappingInfo = Diag.makeMappingInfo(Map, Loc);
+ Diag.GetCurDiagState()->setMappingInfo(DiagID, MappingInfo);
}
}
}
Added: cfe/trunk/test/Index/Inputs/pragma_disable_warning.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Inputs/pragma_disable_warning.h?rev=144153&view=auto
==============================================================================
--- cfe/trunk/test/Index/Inputs/pragma_disable_warning.h (added)
+++ cfe/trunk/test/Index/Inputs/pragma_disable_warning.h Tue Nov 8 19:24:17 2011
@@ -0,0 +1 @@
+#pragma clang diagnostic ignored "-Wunused-parameter"
Modified: cfe/trunk/test/Index/pragma-diag-reparse.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/pragma-diag-reparse.c?rev=144153&r1=144152&r2=144153&view=diff
==============================================================================
--- cfe/trunk/test/Index/pragma-diag-reparse.c (original)
+++ cfe/trunk/test/Index/pragma-diag-reparse.c Tue Nov 8 19:24:17 2011
@@ -1,4 +1,5 @@
#pragma clang diagnostic ignored "-Wtautological-compare"
+#include "pragma_disable_warning.h"
int main (int argc, const char * argv[])
{
@@ -13,6 +14,7 @@
void foo() { int b=0; while (b==b); }
// RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_FAILONERROR=1 c-index-test -test-load-source-reparse 5 local \
+// RUN: -I%S/Inputs \
// RUN: %s -Wall -Werror | FileCheck %s
-// CHECK: pragma-diag-reparse.c:7:7: VarDecl=x:7:7 (Definition) Extent=[7:3 - 7:10]
+// CHECK: pragma-diag-reparse.c:8:7: VarDecl=x:8:7 (Definition) Extent=[8:3 - 8:10]
More information about the cfe-commits
mailing list