[clang-tools-extra] [clangd] Fix remark diagnostics without a prior main diagnostic (PR #198249)
via cfe-commits
cfe-commits at lists.llvm.org
Mon May 18 01:11:08 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tools-extra
Author: Daniel Christian Mandolang (danielcm585)
<details>
<summary>Changes</summary>
This fixes #<!-- -->197758
---
Full diff: https://github.com/llvm/llvm-project/pull/198249.diff
2 Files Affected:
- (modified) clang-tools-extra/clangd/Diagnostics.cpp (+1-1)
- (modified) clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp (+9)
``````````diff
diff --git a/clang-tools-extra/clangd/Diagnostics.cpp b/clang-tools-extra/clangd/Diagnostics.cpp
index d0baf0224a18e..f6ead2e677db2 100644
--- a/clang-tools-extra/clangd/Diagnostics.cpp
+++ b/clang-tools-extra/clangd/Diagnostics.cpp
@@ -237,7 +237,7 @@ bool tryMoveToMainFile(Diag &D, FullSourceLoc DiagLoc) {
}
bool isNote(DiagnosticsEngine::Level L) {
- return L == DiagnosticsEngine::Note || L == DiagnosticsEngine::Remark;
+ return L == DiagnosticsEngine::Note;
}
llvm::StringRef diagLeveltoString(DiagnosticsEngine::Level Lvl) {
diff --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
index 4258f7faf34fd..62fd3a502ab7b 100644
--- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -1168,6 +1168,15 @@ TEST(DiagnosticsTest, PragmaSystemHeader) {
EXPECT_THAT(TU.build().getDiagnostics(), IsEmpty());
}
+// Regression test for https://github.com/llvm/llvm-project/issues/197681
+// #pragma clang __debug sloc_usage emits a remark followed by notes.
+// StoreDiags must not crash when a remark arrives without a prior main diag.
+TEST(DiagnosticsTest, PragmaDebugSlocUsage) {
+ auto TU = TestTU::withCode("#pragma clang __debug sloc_usage\n");
+ // Just verify we don't crash (the assertion was firing before the fix).
+ TU.build().getDiagnostics();
+}
+
TEST(ClangdTest, MSAsm) {
// Parsing MS assembly tries to use the target MCAsmInfo, which we don't link.
// We used to crash here. Now clang emits a diagnostic, which we filter out.
``````````
</details>
https://github.com/llvm/llvm-project/pull/198249
More information about the cfe-commits
mailing list