[clang] 47653db - [clang] Fix an infinite loop during typo-correction

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 9 03:04:36 PDT 2021


Author: Haojian Wu
Date: 2021-07-09T12:03:57+02:00
New Revision: 47653db6d2a3964c14cca5ffa73e79aeee292e8b

URL: https://github.com/llvm/llvm-project/commit/47653db6d2a3964c14cca5ffa73e79aeee292e8b
DIFF: https://github.com/llvm/llvm-project/commit/47653db6d2a3964c14cca5ffa73e79aeee292e8b.diff

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

See https://bugs.llvm.org/show_bug.cgi?id=50797#c6

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

Added: 
    clang/test/Sema/typo-correction-no-hang.c

Modified: 
    clang/lib/Sema/SemaExprCXX.cpp
    clang/test/Sema/typo-correction-ambiguity.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 2e9e9a4a88df..e6bf5c6a7ad8 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -8343,6 +8343,7 @@ class TransformTypos : public TreeTransform<TransformTypos> {
 
         AmbiguousTypoExprs.remove(TE);
         SemaRef.getTypoExprState(TE).Consumer->restoreSavedPosition();
+        TransformCache[TE] = SavedTransformCache[TE];
       }
       TransformCache = std::move(SavedTransformCache);
     }

diff  --git a/clang/test/Sema/typo-correction-ambiguity.c b/clang/test/Sema/typo-correction-ambiguity.c
index bebbf25ce291..c25fe652bd9f 100644
--- a/clang/test/Sema/typo-correction-ambiguity.c
+++ b/clang/test/Sema/typo-correction-ambiguity.c
@@ -12,3 +12,16 @@ int v_3_0() {
        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'}}

diff  --git a/clang/test/Sema/typo-correction-no-hang.c b/clang/test/Sema/typo-correction-no-hang.c
new file mode 100644
index 000000000000..f3d3bf00abe8
--- /dev/null
+++ b/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'}}


        


More information about the cfe-commits mailing list