- doesn't yet handle "taxa" property (§3.27.8)
- handling of "level" property (§3.27.10) doesn't yet support the
full logic for when "level" is absent.
- - doesn't yet handle "relatedLocations" property (§3.27.22)
- doesn't yet handle "fixes" property (§3.27.30)
- doesn't yet support multithreaded flows (§3.36.3)
*/
add_any_annotations (err, annotations);
if (path.m_inner)
err.take_execution_path (std::move (path));
- err.finish ("%s", text.get ());
// §3.27.22 relatedLocations property
+ std::vector<std::pair<libgdiagnostics::diagnostic, label_text>> notes;
const property_spec_ref prop_related_locations
("result", "relatedLocations", "3.27.22");
if (auto related_locations_arr
note.set_location (physical_loc);
note.set_logical_location (logical_loc);
add_any_annotations (note, annotations);
- note.finish ("%s", text.get ());
+ notes.push_back ({std::move (note), std::move (text)});
+ }
+ else
+ {
+ /* Treat related locations without a message as a secondary
+ range. */
+ if (physical_loc.m_inner)
+ err.add_location (physical_loc);
}
}
}
+ err.finish ("%s", text.get ());
+
+ // Flush any notes
+ for (auto &iter : notes)
+ {
+ auto ¬e = iter.first;
+ auto &text = iter.second;
+ note.finish ("%s", text.get ());
+ }
+
return status::ok;
}
--- /dev/null
+{"$schema": "https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json",
+ "version": "2.1.0",
+ "runs": [{"tool": {"driver": {"name": "GNU C23",
+ "fullName": "GNU C23 (GCC) version 15.0.1 20250203 (experimental) (x86_64-pc-linux-gnu)",
+ "version": "15.0.1 20250203 (experimental)",
+ "informationUri": "https://gcc.gnu.org/gcc-15/",
+ "rules": []}},
+ "invocations": [{"executionSuccessful": false,
+ "toolExecutionNotifications": []}],
+ "originalUriBaseIds": {"PWD": {"uri": "file:///nonexistent/"}},
+ "artifacts": [{"location": {"uri": "too-many-arguments.c",
+ "uriBaseId": "PWD"},
+ "sourceLanguage": "c",
+ "contents": {"text": "extern void fn_a ();\n\nvoid test_known_fn (void)\n{\n fn_a (42);\n}\n"},
+ "roles": ["analysisTarget"]}],
+ "results": [{"ruleId": "error",
+ "level": "error",
+ "message": {"text": "too many arguments to function 'fn_a'; expected 0, have 1"},
+ "locations": [{"physicalLocation": {"artifactLocation": {"uri": "too-many-arguments.c",
+ "uriBaseId": "PWD"},
+ "region": {"startLine": 5,
+ "startColumn": 3,
+ "endColumn": 7},
+ "contextRegion": {"startLine": 5,
+ "snippet": {"text": " fn_a (42);\n"}}},
+ "logicalLocations": [{"name": "test_known_fn",
+ "fullyQualifiedName": "test_known_fn",
+ "decoratedName": "test_known_fn",
+ "kind": "function"}],
+ "relationships": [{"target": 0,
+ "kinds": ["relevant"]}]}],
+ "relatedLocations": [{"physicalLocation": {"artifactLocation": {"uri": "too-many-arguments.c",
+ "uriBaseId": "PWD"},
+ "region": {"startLine": 1,
+ "startColumn": 13,
+ "endColumn": 17},
+ "contextRegion": {"startLine": 1,
+ "snippet": {"text": "extern void fn_a ();\n"}}},
+ "message": {"text": "declared here"},
+ "properties": {"nestingLevel": 0}},
+ {"physicalLocation": {"artifactLocation": {"uri": "too-many-arguments.c",
+ "uriBaseId": "PWD"},
+ "region": {"startLine": 5,
+ "startColumn": 9,
+ "endColumn": 11},
+ "contextRegion": {"startLine": 5,
+ "snippet": {"text": " fn_a (42);\n"}}},
+ "id": 0}]}]}]}
+
+/* Verify that we underline the "42" here. */
+/* { dg-begin-multiline-output "" }
+In function 'test_known_fn':
+too-many-arguments.c:5:3: error: too many arguments to function 'fn_a'; expected 0, have 1 [error]
+ 5 | fn_a (42);
+ | ^~~~ ~~
+too-many-arguments.c:1:13: note: declared here
+ 1 | extern void fn_a ();
+ | ^~~~
+ { dg-end-multiline-output "" } */
+// TODO: trailing [error]