Skip to content

verify: Report each conversion error at its source, with its line and caret - #47

Merged
SwayamInSync merged 9 commits into
mainfrom
fix/located-conversion-errors
Oct 21, 2026
Merged

SwayamInSync merged 9 commits into
mainfrom
fix/located-conversion-errors

Conversation

@SwayamInSync

Copy link
Copy Markdown
Owner

An error about a construct the verifier does not represent named only the function:

error: pick: unsupported statement: SwitchStmt

In a file with several functions, or a function with several switches, the user had to find the construct themselves. The converter recorded its 189 error sites as plain strings (std::vector<std::string> Errors), so no location was available to print.

The change gives every conversion error a source range and prints it as a compiler error is:

pick.cpp:4:3: error: pick: unsupported statement: SwitchStmt
    4 |   switch (x) { case 1: return 1; default: return 0; }
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • ASTConverter keeps CurrentRange, the range of the innermost declaration, statement, or expression being converted. convertFunction, convertStmt, and convertExpr set it with llvm::SaveAndRestore, and error(Message) records it. Each site therefore points at what it is about without being edited one by one. Sites outside the conversion of a function name their place: a member function's or template's declaration, and for the checks made after every function is converted (recursion without a measure, mutual recursion, an inductive predicate reached through another spec), the function's declaration.
  • expandInductivePredicates reports through a callback with a location, the predicate's cppverify::inductive marker, instead of appending strings to the converter's list. Transform/ takes no dependency on the converter.
  • The verifier prints a conversion error with Clang's TextDiagnostic, into its own stream rather than through the DiagnosticsEngine. Verification at compile time runs on another thread, and the engine is not thread-safe. It uses presumed locations, as Clang's driver does, so #line is honored. The JSON record carries the start and end of the range.

The message text is unchanged; saying in C++ terms what is unsupported is the second half of E2.

Docs: the tooling page shows the error with its line and caret, as a checked rejects example, and says where whole-function errors point. ARCHITECTURE describes the mechanism, and the release notes get an entry under "Running cpp-verify".

Testing: Verify/located_errors.cpp checks, with --strict-whitespace, the location, line, and caret of five errors: a statement (switch), a member function, a misplaced [[cppverify::trusted]], a non-bool inductive predicate, and a recursion without a measure, which is reported after conversion. It also checks the JSON record of the first. Both RUN lines fail on main. Three mutations fail it: no range for statements, no location for the checks made after conversion, and the old one-line printing.

Over all 396 Verify sources, converted with --lower-only, no converter error prints without a location now. Four other errors still do. Three are valid marker errors from UBChecks (valid marker must be a positive top-level conjunction clause, and two like it), and one is the reads check's error for a callee without a reads clause. Locating them changes UBChecks, which #40 changes too, so they follow once it merges.

Checked: the Verify suite passes in a release build and in a build with assertions (424 with the new test, 1 unsupported), as do the documentation examples and the site build with -W. A verdict differential against main over 431 Verify sources (the ULEB128 exhaustive decoder left out, as it has no error path) changes no verdict and no time; the new test's errors are errors on main too, without their locations.

@SwayamInSync
SwayamInSync merged commit 5165654 into main Oct 21, 2026
14 checks passed
@SwayamInSync
SwayamInSync deleted the fix/located-conversion-errors branch October 21, 2026 03:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant