llvm-project/clang/lib/Parse
Haojian Wu 733edf9750 [AST] Add RecoveryExpr to retain expressions on semantic errors
Normally clang avoids creating expressions when it encounters semantic
errors, even if the parser knows which expression to produce.

This works well for the compiler. However, this is not ideal for
source-level tools that have to deal with broken code, e.g. clangd is
not able to provide navigation features even for names that compiler
knows how to resolve.

The new RecoveryExpr aims to capture the minimal set of information
useful for the tools that need to deal with incorrect code:

source range of the expression being dropped,
subexpressions of the expression.
We aim to make constructing RecoveryExprs as simple as possible to
ensure writing code to avoid dropping expressions is easy.

Producing RecoveryExprs can result in new code paths being taken in the
frontend. In particular, clang can produce some new diagnostics now and
we aim to suppress bogus ones based on Expr::containsErrors.

We deliberately produce RecoveryExprs only in the parser for now to
minimize the code affected by this patch. Producing RecoveryExprs in
Sema potentially allows to preserve more information (e.g. type of an
expression), but also results in more code being affected. E.g.
SFINAE checks will have to take presence of RecoveryExprs into account.

Initial implementation only works in C++ mode, as it relies on compiler
postponing diagnostics on dependent expressions. C and ObjC often do not
do this, so they require more work to make sure we do not produce too
many bogus diagnostics on the new expressions.

See documentation of RecoveryExpr for more details.

original patch from Ilya
This change is based on https://reviews.llvm.org/D61722

Reviewers: sammccall, rsmith

Reviewed By: sammccall, rsmith

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69330
2020-03-24 09:20:37 +01:00
..
CMakeLists.txt [OpenMP][NFCI] Introduce llvm/IR/OpenMPConstants.h 2019-12-10 00:10:09 -06:00
ParseAST.cpp [Support] Add TimeTraceScope constructor without detail arg 2019-12-11 14:32:21 +00:00
ParseCXXInlineMethods.cpp [Concepts] Placeholder constraints and abbreviated templates 2020-01-23 19:39:43 +02:00
ParseDecl.cpp Clean up and simplify after collision of c48442c and 19fccc5, which 2020-03-20 14:53:09 -07:00
ParseDeclCXX.cpp PR45267: Don't reject pure-specifiers with escaped newlines in their '0' token. 2020-03-20 18:44:55 -07:00
ParseExpr.cpp [AST] Add RecoveryExpr to retain expressions on semantic errors 2020-03-24 09:20:37 +01:00
ParseExprCXX.cpp PR45142: 'template ~X<T>' is ill-formed; reject it rather than crashing. 2020-03-23 15:07:06 -07:00
ParseInit.cpp [clang][CodeComplete] Support for designated initializers 2020-01-28 16:34:15 +01:00
ParseObjc.cpp Prune TargetInfo.h include from ParsedAttr.h, NFC 2020-03-11 20:47:11 -07:00
ParseOpenMP.cpp [OPENMP50]Add 'default' modifier in reduction clauses. 2020-03-23 18:18:08 -04:00
ParsePragma.cpp Fix docs and comments for max_tokens_total pragma 2020-02-07 11:37:14 +01:00
ParseStmt.cpp [FPEnv] Extended FPOptions with new attributes 2020-01-26 21:03:53 +07:00
ParseStmtAsm.cpp [Parser] Avoid spurious 'missing template' error in presence of typos. 2020-03-19 16:15:27 +01:00
ParseTemplate.cpp [Parser] Avoid spurious 'missing template' error in presence of typos. 2020-03-19 16:15:27 +01:00
ParseTentative.cpp Fix TryParsePtrOperatorSeq. 2020-02-24 08:08:47 -05:00
Parser.cpp [Parser] Avoid spurious 'missing template' error in presence of typos. 2020-03-19 16:15:27 +01:00