This is an archive of the discontinued LLVM Phabricator instance.

[AST][RecoveryExpr] Build RecoveryExpr for "undef_var" cases.
ClosedPublic

Authored by hokein on May 28 2020, 9:03 AM.

Details

Summary

For a no-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.

Diff Detail

Event Timeline

hokein created this revision.May 28 2020, 9:03 AM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: sstefan1. · View Herald Transcript
sammccall accepted this revision.May 28 2020, 9:39 AM

Nice!

clang/lib/Sema/SemaExprCXX.cpp
8310

This seems reasonably straightforward to fix - there shouldn't be a lot of TypoExprs so we can just add a member. Worth doing I think.

8314

Can't you just write this as : TreeTransform(SemaRef) {}, and drop the using?

This revision is now accepted and ready to land.May 28 2020, 9:39 AM
hokein updated this revision to Diff 267873.Jun 2 2020, 6:57 AM
hokein marked 3 inline comments as done.

Address comments.

hokein added inline comments.Jun 2 2020, 6:58 AM
clang/lib/Sema/SemaExprCXX.cpp
8310

yeah, agree. Will address it in a followup.

8314

yes.

This revision was automatically updated to reflect the committed changes.