================
@@ -195,6 +211,98 @@ class ErrorReporter {
}
for (const auto &Note : Error.Notes)
reportNote(Note);
+
+ if (SarifWriter)
+ exportSarifResult(Error, Loc);
+ }
+
+ CharSourceRange getNoteRange(const tooling::DiagnosticMessage &Note) {
+ if (!Note.Ranges.empty())
+ return getRange(Note.Ranges.front());
+ const SourceLocation Loc = getLocation(Note.FilePath, Note.FileOffset);
+ if (Loc.isInvalid())
+ return {};
+ return getOffsetRange(SourceMgr, Loc);
+ }
+
+ SmallVector<ThreadFlow, 8> createThreadFlows(const ClangTidyError &Error) {
+ SmallVector<ThreadFlow, 8> Flows;
+ if (!StringRef(Error.DiagnosticName).starts_with("clang-analyzer-"))
+ return Flows;
+
+ Flows.reserve(Error.Notes.size());
+ for (const tooling::DiagnosticMessage &Note : Error.Notes) {
+ Flows.push_back(ThreadFlow::create()
+ .setRange(getNoteRange(Note))
----------------
zeyi2 wrote:
`getNoteRange()` can return an invalid range, but we still pass it to the SARIF
writer here.
I tried the following case with an assertions-enabled build:
```cpp
#define JOIN(a, b) a ## b
#define CALL JOIN(pre, dicate)
int predicate();
int f(int *p) {
if (CALL()) p = nullptr;
return *p;
}
```
```
clang-tidy -checks='-*,clang-analyzer-core.NullDereference' \
-sarif-export=result.sarif input.cpp --
```
Without SARIF export, this gives the warning and notes normally. With SARIF
export, it aborts in `SarifDocumentWriter::createPhysicalLocation()`.
---
I also hit this on Poco's `dependencies/pcre2/src/pcre2_compile.c`. So this
problem can affect real-world codebase.
Could we support notes without a physical location here? IMO simply skipping
invalid ranges could avoid this assertion, but we would also lose the note
messages. We probably need a better approach to support macros like this.
https://github.com/llvm/llvm-project/pull/219182
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits