[llvm] [mlir] [Support] Extract SourceMgrDiagnosticVerifier from MLIR's verifier handler. NFC (PR #227565)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 29 22:53:27 PDT 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- llvm/include/llvm/Support/SourceMgrDiagnosticVerifier.h llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp mlir/lib/IR/Diagnostics.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/include/llvm/Support/SourceMgrDiagnosticVerifier.h b/llvm/include/llvm/Support/SourceMgrDiagnosticVerifier.h
index cbb4643eb..beeea1229 100644
--- a/llvm/include/llvm/Support/SourceMgrDiagnosticVerifier.h
+++ b/llvm/include/llvm/Support/SourceMgrDiagnosticVerifier.h
@@ -37,8 +37,7 @@ public:
struct ExpectedDiag {
ExpectedDiag(SourceMgr::DiagKind kind, unsigned lineNo, SMLoc fileLoc,
StringRef substring)
- : kind(kind), lineNo(lineNo), fileLoc(fileLoc), substring(substring) {
- }
+ : kind(kind), lineNo(lineNo), fileLoc(fileLoc), substring(substring) {}
/// Returns true if this diagnostic matches the given message.
bool match(StringRef str) const;
@@ -88,8 +87,8 @@ public:
/// Computes and caches the list of expected diagnostics for \p buf, if not
/// already cached. Returns the (mutable) cached list.
MutableArrayRef<ExpectedDiag> computeExpectedDiags(raw_ostream &os,
- SourceMgr &mgr,
- const MemoryBuffer *buf);
+ SourceMgr &mgr,
+ const MemoryBuffer *buf);
/// Returns the cached expected diagnostics for the buffer named \p bufName,
/// or std::nullopt if \p computeExpectedDiags hasn't been called for it.
@@ -112,8 +111,8 @@ public:
/// through \p mgr. \p reportUnexpected controls whether near misses /
/// unexpected diagnostics are reported at all.
MatchResult process(raw_ostream &os, SourceMgr &mgr, SourceMgr::DiagKind kind,
- bool hasLoc, const MemoryBuffer *buf, unsigned lineNo,
- StringRef message, bool reportUnexpected = true);
+ bool hasLoc, const MemoryBuffer *buf, unsigned lineNo,
+ StringRef message, bool reportUnexpected = true);
/// Reports (through \p mgr) any expected diagnostic that was never matched
/// by a call to \p process. Returns whether verification succeeded overall,
diff --git a/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp b/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp
index 5941001b6..1e33637f0 100644
--- a/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp
+++ b/llvm/lib/Support/SourceMgrDiagnosticVerifier.cpp
@@ -27,13 +27,11 @@ static StringRef getDiagKindStr(SourceMgr::DiagKind kind) {
llvm_unreachable("Unknown SourceMgr::DiagKind");
}
-bool SourceMgrDiagnosticVerifier::ExpectedDiag::emitError(raw_ostream &os,
- SourceMgr &mgr,
- const Twine &msg
- ) const {
+bool SourceMgrDiagnosticVerifier::ExpectedDiag::emitError(
+ raw_ostream &os, SourceMgr &mgr, const Twine &msg) const {
if (fileLoc.isValid()) {
SMRange range(fileLoc, SMLoc::getFromPointer(fileLoc.getPointer() +
- substring.size()));
+ substring.size()));
mgr.PrintMessage(os, fileLoc, SourceMgr::DK_Error, msg, range);
} else {
mgr.PrintMessage(os, fileLoc, SourceMgr::DK_Error, msg);
@@ -50,7 +48,7 @@ bool SourceMgrDiagnosticVerifier::ExpectedDiag::match(StringRef str) const {
}
bool SourceMgrDiagnosticVerifier::ExpectedDiag::computeRegex(raw_ostream &os,
- SourceMgr &mgr) {
+ SourceMgr &mgr) {
std::string regexStr;
raw_string_ostream regexOS(regexStr);
StringRef strToProcess = substring;
@@ -84,8 +82,8 @@ bool SourceMgrDiagnosticVerifier::ExpectedDiag::computeRegex(raw_ostream &os,
MutableArrayRef<SourceMgrDiagnosticVerifier::ExpectedDiag>
SourceMgrDiagnosticVerifier::computeExpectedDiags(raw_ostream &os,
- SourceMgr &mgr,
- const MemoryBuffer *buf) {
+ SourceMgr &mgr,
+ const MemoryBuffer *buf) {
// If the buffer is invalid, return an empty list.
if (!buf)
return {};
@@ -181,10 +179,11 @@ SourceMgrDiagnosticVerifier::getExpectedDiags(StringRef bufName) {
return std::nullopt;
}
-SourceMgrDiagnosticVerifier::MatchResult SourceMgrDiagnosticVerifier::process(
- raw_ostream &os, SourceMgr &mgr, SourceMgr::DiagKind kind, bool hasLoc,
- const MemoryBuffer *buf, unsigned lineNo, StringRef message,
- bool reportUnexpected) {
+SourceMgrDiagnosticVerifier::MatchResult
+SourceMgrDiagnosticVerifier::process(raw_ostream &os, SourceMgr &mgr,
+ SourceMgr::DiagKind kind, bool hasLoc,
+ const MemoryBuffer *buf, unsigned lineNo,
+ StringRef message, bool reportUnexpected) {
MutableArrayRef<ExpectedDiag> diags;
if (hasLoc) {
// If the buffer couldn't be resolved, `diags` stays empty: a diagnostic
@@ -228,9 +227,9 @@ SourceMgrDiagnosticVerifier::MatchResult SourceMgrDiagnosticVerifier::process(
// Otherwise, emit an error for the near miss.
if (nearMiss) {
mgr.PrintMessage(os, nearMiss->fileLoc, SourceMgr::DK_Error,
- "'" + getDiagKindStr(kind) +
- "' diagnostic emitted when expecting a '" +
- getDiagKindStr(nearMiss->kind) + "'");
+ "'" + getDiagKindStr(kind) +
+ "' diagnostic emitted when expecting a '" +
+ getDiagKindStr(nearMiss->kind) + "'");
return MatchResult::NearMiss;
}
return MatchResult::Unexpected;
@@ -241,8 +240,8 @@ bool SourceMgrDiagnosticVerifier::verify(raw_ostream &os, SourceMgr &mgr) {
auto checkExpectedDiags = [&](ExpectedDiag &diag) {
if (!diag.matched) {
diag.emitError(os, mgr,
- "expected " + getDiagKindStr(diag.kind) + " \"" +
- diag.substring + "\" was not produced");
+ "expected " + getDiagKindStr(diag.kind) + " \"" +
+ diag.substring + "\" was not produced");
ok = false;
}
};
``````````
</details>
https://github.com/llvm/llvm-project/pull/227565
More information about the llvm-commits
mailing list