[PATCH] D155802: [clang][dataflow] Print the source line if we saw unexpected diagnostics in tests.
Martin Böhme via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 20 01:54:58 PDT 2023
mboehme created this revision.
Herald added subscribers: martong, xazax.hun.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
This makes it easier to determine which line the unexpected happened on;
previously, we would only get the line number.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D155802
Files:
clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
Index: clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===================================================================
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -12,6 +12,7 @@
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/Basic/SourceLocation.h"
+#include "clang/Frontend/TextDiagnostic.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/STLExtras.h"
@@ -1334,7 +1335,17 @@
auto &SrcMgr = AO.ASTCtx.getSourceManager();
llvm::DenseSet<unsigned> DiagnosticLines;
for (SourceLocation &Loc : Diagnostics) {
- DiagnosticLines.insert(SrcMgr.getPresumedLineNumber(Loc));
+ unsigned Line = SrcMgr.getPresumedLineNumber(Loc);
+ DiagnosticLines.insert(Line);
+ if (!AnnotationLines.contains(Line)) {
+ IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(
+ new DiagnosticOptions());
+ TextDiagnostic TD(llvm::errs(), AO.ASTCtx.getLangOpts(),
+ DiagOpts.get());
+ TD.emitDiagnostic(
+ FullSourceLoc(Loc, SrcMgr), DiagnosticsEngine::Error,
+ "unexpected diagnostic", std::nullopt, std::nullopt);
+ }
}
EXPECT_THAT(DiagnosticLines, ContainerEq(AnnotationLines));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155802.542378.patch
Type: text/x-patch
Size: 1521 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230720/9bca1aec/attachment.bin>
More information about the cfe-commits
mailing list