[cfe-commits] [PATCH] Improved error-recovery for malformed declarations

Richard Smith richard at metafoo.co.uk
Wed Apr 11 13:11:45 PDT 2012


Ping. A slightly modified patch is attached: the r_brace check got lost in
some refactorings.

On Tue, Apr 3, 2012 at 1:27 PM, Richard Smith <richard at metafoo.co.uk> wrote:

> Hi,
>
> Currently, after a malformed declaration, clang skips until it reaches an
> unparenthesized '}' or ';'. One fairly common error (especially among vim
> users) is for the first line of a file to have junk in it. This leads to
> abysmal error recovery, where we skip all 'namespace { ... }' and 'extern
> "C" { ... }' blocks and function definitions until we get to a top-level
> semicolon (which often doesn't arrive until we're past all the #included
> header files and somewhere in the main source file). We then produce a
> large pile of incorrect diagnostics, because we have not seen any
> declarations yet.
>
> The attached patch improves this situation by tweaking the recovery
> heuristic as follows: we skip the shortest sequence of
> brace/bracket/paren-balanced tokens which either ends with a semicolon or a
> close brace[1] (and any following semicolon), or is followed by a namespace
> definition at the start of a line.
>
> In my testing, this seems to be a strict improvement. Does this seem like
> a reasonable change? I'm sure there are other places where this style of
> recovery would be a better option than a simple SkipUntil(tok::r_brace),
> but I don't have evidence of a specific common pattern of errors leading to
> poor recovery elsewhere.
>
> Thanks!
> Richard
>
> [1] If the close brace is followed by ',', '{' or 'try', we could be in
> the initializer-list for a constructor, so we keep skipping.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120411/14d05697/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: decl-recovery.diff
Type: application/octet-stream
Size: 5161 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120411/14d05697/attachment.obj>


More information about the cfe-commits mailing list