[PATCH] D105533: [clang] Fix an infinite loop during typo-correction

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 9 02:51:18 PDT 2021


hokein updated this revision to Diff 357460.
hokein added a comment.

add the non-simplified sample.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105533

Files:
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/Sema/typo-correction-ambiguity.c
  clang/test/Sema/typo-correction-no-hang.c


Index: clang/test/Sema/typo-correction-no-hang.c
===================================================================
--- /dev/null
+++ clang/test/Sema/typo-correction-no-hang.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// PR50797
+struct a {
+  int xxx; // expected-note {{'xxx' declared here}}
+};
+
+int g_107;
+int g_108;
+int g_109;
+
+struct a g_999; // expected-note 4{{'g_999' declared here}}
+
+void b() { (g_910.xxx = g_910.xxx); } //expected-error 2{{use of undeclared identifier 'g_910'; did you mean 'g_999'}}
+
+void c() { (g_910.xxx = g_910.xxx1); } //expected-error 2{{use of undeclared identifier 'g_910'; did you mean 'g_999'}} \
+                                         expected-error {{no member named 'xxx1' in 'struct a'; did you mean 'xxx'}}
Index: clang/test/Sema/typo-correction-ambiguity.c
===================================================================
--- clang/test/Sema/typo-correction-ambiguity.c
+++ clang/test/Sema/typo-correction-ambiguity.c
@@ -12,3 +12,16 @@
        v_2_0(v_195,  // expected-error {{use of undeclared identifier 'v_195'}}
              v_231);  // expected-error {{use of undeclared identifier 'v_231'}}
 }
+
+// Test: no typo-correction diagnostics are emitted for ambiguous typos.
+struct a {
+  int xxx;
+};
+
+int g_107;
+int g_108;
+int g_109;
+
+struct a g_999;
+struct a g_998;
+void PR50797() { (g_910.xxx = g_910.xxx); } //expected-error 2{{use of undeclared identifier 'g_910'}}
Index: clang/lib/Sema/SemaExprCXX.cpp
===================================================================
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -8343,6 +8343,7 @@
 
         AmbiguousTypoExprs.remove(TE);
         SemaRef.getTypoExprState(TE).Consumer->restoreSavedPosition();
+        TransformCache[TE] = SavedTransformCache[TE];
       }
       TransformCache = std::move(SavedTransformCache);
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105533.357460.patch
Type: text/x-patch
Size: 1909 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210709/92a26cca/attachment.bin>


More information about the cfe-commits mailing list