[all-commits] [llvm/llvm-project] 733edf: [AST] Add RecoveryExpr to retain expressions on se...

Haojian Wu via All-commits all-commits at lists.llvm.org
Tue Mar 24 01:24:36 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 733edf9750a4893d5f50329ad68b3901935303a9
      https://github.com/llvm/llvm-project/commit/733edf9750a4893d5f50329ad68b3901935303a9
  Author: Haojian Wu <hokein.wu at gmail.com>
  Date:   2020-03-24 (Tue, 24 Mar 2020)

  Changed paths:
    M clang/include/clang/AST/ComputeDependence.h
    M clang/include/clang/AST/Expr.h
    M clang/include/clang/AST/RecursiveASTVisitor.h
    M clang/include/clang/Basic/LangOptions.def
    M clang/include/clang/Basic/StmtNodes.td
    M clang/include/clang/Driver/CC1Options.td
    M clang/include/clang/Sema/Sema.h
    M clang/include/clang/Serialization/ASTBitCodes.h
    M clang/lib/AST/ComputeDependence.cpp
    M clang/lib/AST/Expr.cpp
    M clang/lib/AST/ExprClassification.cpp
    M clang/lib/AST/ExprConstant.cpp
    M clang/lib/AST/ItaniumMangle.cpp
    M clang/lib/AST/StmtPrinter.cpp
    M clang/lib/AST/StmtProfile.cpp
    M clang/lib/Frontend/CompilerInvocation.cpp
    M clang/lib/Parse/ParseExpr.cpp
    M clang/lib/Sema/SemaDecl.cpp
    M clang/lib/Sema/SemaExceptionSpec.cpp
    M clang/lib/Sema/SemaExpr.cpp
    M clang/lib/Sema/TreeTransform.h
    M clang/lib/Serialization/ASTReaderStmt.cpp
    M clang/lib/Serialization/ASTWriterDecl.cpp
    M clang/lib/Serialization/ASTWriterStmt.cpp
    M clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
    A clang/test/AST/ast-dump-expr-errors.cpp
    A clang/test/AST/ast-dump-recovery.cpp
    A clang/test/Index/getcursor-recovery.cpp
    A clang/test/SemaTemplate/recovery-tree-transform.cpp
    M clang/tools/libclang/CXCursor.cpp

  Log Message:
  -----------
  [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




More information about the All-commits mailing list