[all-commits] [llvm/llvm-project] 21ccc6: [AST][RecoveryExpr] Build RecoveryExpr for "undef_...

Haojian Wu via All-commits all-commits at lists.llvm.org
Tue Jun 2 07:05:01 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 21ccc684ff4c8563e7b20bed4ae7dc7d18fe03f3
      https://github.com/llvm/llvm-project/commit/21ccc684ff4c8563e7b20bed4ae7dc7d18fe03f3
  Author: Haojian Wu <hokein.wu at gmail.com>
  Date:   2020-06-02 (Tue, 02 Jun 2020)

  Changed paths:
    M clang/lib/Sema/SemaExprCXX.cpp
    M clang/test/AST/ast-dump-recovery.cpp

  Log Message:
  -----------
  [AST][RecoveryExpr] Build RecoveryExpr for "undef_var" cases.

Summary:
For a none-function-like unresolved expression, clang builds a TypoExpr
for it, and tries to correct it afterwards. If the typo-correction
fails, clang just drops the whole expr.

This patch improves the recovery strategy -- if the typo-correction
fails, we preserve the AST by degrading the typo exprs to recovery
exprs.

This would improve toolings for "undef_var" broken cases:
```
void foo();
void test() {
  fo^o(undef_var); // go-to-def, hover still works.
}
```

TESTED=ran tests with this patch + turn-on-recovery-ast patch, it breaks
one declare_variant_messages testcase (the diagnostics are slightly
changed), I think it is acceptable.

```
Error: 'error' diagnostics seen but not expected:
  File llvm-project/clang/test/OpenMP/declare_variant_messages.cpp Line 16: expected 'match' clause on 'omp declare variant' directive
  File llvm-project/clang/test/OpenMP/declare_variant_messages.cpp Line 57: expected 'match' clause on 'omp declare variant' directive
error: 'warning' diagnostics expected but not seen:
  File llvm-project/clang/test/OpenMP/declare_variant_messages.cpp Line 47: the context selector 'kind' in the context set 'device' cannot have a score ('<invalid>'); score ignored
  File llvm-project/clang/test/OpenMP/declare_variant_messages.cpp Line 87: the context selector 'kind' in the context set 'device' cannot have a score ('<invalid>'); score ignored
error: 'warning' diagnostics seen but not expected:
  File llvm-project/clang/test/OpenMP/declare_variant_messages.cpp Line 47: the context selector 'kind' in the context set 'device' cannot have a score ('<recovery-expr>()'); score ignored
  File llvm-project/clang/test/OpenMP/declare_variant_messages.cpp Line 87: the context selector 'kind' in the context set 'device' cannot have a score ('<recovery-expr>()'); score ignored
6 errors generated.
```

Reviewers: sammccall, jdoerfert

Subscribers: sstefan1, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80733




More information about the All-commits mailing list