[PATCH] D80733: [AST][RecoveryExpr] Build RecoveryExpr for "undef_var" cases.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 2 07:09:34 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG21ccc684ff4c: [AST][RecoveryExpr] Build RecoveryExpr for "undef_var" cases. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80733/new/

https://reviews.llvm.org/D80733

Files:
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/AST/ast-dump-recovery.cpp


Index: clang/test/AST/ast-dump-recovery.cpp
===================================================================
--- clang/test/AST/ast-dump-recovery.cpp
+++ clang/test/AST/ast-dump-recovery.cpp
@@ -10,6 +10,25 @@
 // CHECK-NEXT:    `-IntegerLiteral {{.*}} 123
 // DISABLED-NOT: -RecoveryExpr {{.*}} contains-errors
 int invalid_call = some_func(123);
+void test_invalid_call(int s) {
+  // CHECK:      CallExpr {{.*}} '<dependent type>' contains-errors
+  // CHECK-NEXT: |-UnresolvedLookupExpr {{.*}} 'some_func'
+  // CHECK-NEXT: |-RecoveryExpr {{.*}} <<invalid sloc>>
+  // CHECK-NEXT: `-BinaryOperator {{.*}} <<invalid sloc>, col:28>
+  // CHECK-NEXT:   |-RecoveryExpr {{.*}} <<invalid sloc>>
+  // CHECK-NEXT:   `-IntegerLiteral {{.*}} <col:28> 'int' 1
+  some_func(undef1, undef2+1);
+
+  // CHECK:      BinaryOperator {{.*}} '<dependent type>' contains-errors '='
+  // CHECK-NEXT: |-DeclRefExpr {{.*}} 's'
+  // CHECK-NEXT: `-CallExpr {{.*}} '<dependent type>' contains-errors
+  // CHECK-NEXT:   |-UnresolvedLookupExpr {{.*}} 'some_func'
+  // CHECK-NEXT:   `-RecoveryExpr {{.*}} contains-errors
+  s = some_func(undef1);
+  // CHECK: `-VarDecl {{.*}} invalid var 'int'
+  // FIXME: preserve the broken call.
+  int var = some_func(undef1);
+}
 
 int ambig_func(double);
 int ambig_func(float);
Index: clang/lib/Sema/SemaExprCXX.cpp
===================================================================
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -8304,8 +8304,21 @@
   }
 
   FullExpr = CorrectDelayedTyposInExpr(FullExpr.get());
-  if (FullExpr.isInvalid())
-    return ExprError();
+  if (FullExpr.isInvalid()) {
+    // Typo-correction fails, we rebuild the broken AST with the typos degraded
+    // to RecoveryExpr.
+    // FIXME: we lose source locations for RecoveryExpr, as TypoExpr doesn't
+    // track source locations.
+    struct TyposReplace : TreeTransform<TyposReplace> {
+      TyposReplace(Sema &SemaRef) : TreeTransform(SemaRef) {}
+      ExprResult TransformTypoExpr(TypoExpr *E) {
+        return this->SemaRef.CreateRecoveryExpr(E->getBeginLoc(),
+                                                E->getEndLoc(), {});
+      }
+    } TT(*this);
+
+    return TT.TransformExpr(FE);
+  }
 
   CheckCompletedExpr(FullExpr.get(), CC, IsConstexpr);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80733.267878.patch
Type: text/x-patch
Size: 2303 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200602/991af662/attachment.bin>


More information about the cfe-commits mailing list