Skip to content

Commit 687449b

Browse files
committed
[Frontend] Check diagnostics in generated sources
The previous commit added support for checking diagnostics in other buffers, enabling diagnostic verification for e.g. macro expansions. Because the diagnostics are in a different buffer, there is no error for not marking them as "expected". This commit expands the scope to include generated sources originating in code in any checked buffer, to help make sure that errors aren't accidentally missed.
1 parent e3d4870 commit 687449b

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

lib/Frontend/DiagnosticVerifier.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ static void validatePrefixList(ArrayRef<std::string> prefixes) {
594594
}
595595
}
596596

597-
bool parseTargetBufferName(StringRef &MatchStart, StringRef &Out, size_t &TextStartIdx) {
597+
static bool parseTargetBufferName(StringRef &MatchStart, StringRef &Out, size_t &TextStartIdx) {
598598
StringRef Offs = MatchStart.slice(0, TextStartIdx);
599599

600600
size_t LineIndex = Offs.find(':');
@@ -1217,8 +1217,19 @@ DiagnosticVerifier::Result DiagnosticVerifier::verifyFile(unsigned BufferID) {
12171217
auto CapturedDiagIter = CapturedDiagnostics.begin();
12181218
while (CapturedDiagIter != CapturedDiagnostics.end()) {
12191219
if (CapturedDiagIter->SourceBufferID != BufferID) {
1220-
++CapturedDiagIter;
1221-
continue;
1220+
if (!CapturedDiagIter->SourceBufferID) {
1221+
++CapturedDiagIter;
1222+
continue;
1223+
}
1224+
1225+
// Diagnostics attached to generated sources originating in this
1226+
// buffer also count as part of this buffer for this purpose.
1227+
const GeneratedSourceInfo *GSI =
1228+
SM.getGeneratedSourceInfo(CapturedDiagIter->SourceBufferID.value());
1229+
if (!GSI || !llvm::find(GSI->ancestors, BufferID)) {
1230+
++CapturedDiagIter;
1231+
continue;
1232+
}
12221233
}
12231234

12241235
HadUnexpectedDiag = true;

0 commit comments

Comments
 (0)