]> granicus.if.org Git - clang/commitdiff
[Parser] Avoid correcting delayed typos in array subscript multiple times.
authorVolodymyr Sapsai <vsapsai@apple.com>
Wed, 1 May 2019 19:24:50 +0000 (19:24 +0000)
committerVolodymyr Sapsai <vsapsai@apple.com>
Wed, 1 May 2019 19:24:50 +0000 (19:24 +0000)
We correct some typos in `ActOnArraySubscriptExpr` and
`ActOnOMPArraySectionExpr`, so when their result is `ExprError`, we can
end up correcting delayed typos in the same expressions again. In
general it is OK but when `NumTypos` is incorrect, we can hit the
assertion

> Assertion failed: (Entry != DelayedTypos.end() && "Failed to get the state for a TypoExpr!"), function getTypoExprState, file clang/lib/Sema/SemaLookup.cpp, line 5219.

Fix by replacing some subscript `ExprResult` with typo-corrected expressions
instead of keeping the original expressions. Thus if original expressions
contained `TypoExpr`, we'll use corrected expressions instead of trying to
correct them again.

rdar://problem/47403222

Reviewers: rsmith, erik.pilkington, majnemer

Reviewed By: erik.pilkington

Subscribers: jkorous, dexonsmith, cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359713 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseExpr.cpp
test/SemaCXX/typo-correction.cpp
test/SemaObjC/typo-correction-subscript.m [new file with mode: 0644]

index 4039df888ad15c6cabbc054c77bb9a85e5aa4eb1..b8f3288284fc01ec87df3adec181a59f24f323dc 100644 (file)
@@ -1582,7 +1582,9 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
 
       SourceLocation RLoc = Tok.getLocation();
 
-      ExprResult OrigLHS = LHS;
+      LHS = Actions.CorrectDelayedTyposInExpr(LHS);
+      Idx = Actions.CorrectDelayedTyposInExpr(Idx);
+      Length = Actions.CorrectDelayedTyposInExpr(Length);
       if (!LHS.isInvalid() && !Idx.isInvalid() && !Length.isInvalid() &&
           Tok.is(tok::r_square)) {
         if (ColonLoc.isValid()) {
@@ -1594,12 +1596,6 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
         }
       } else {
         LHS = ExprError();
-      }
-      if (LHS.isInvalid()) {
-        (void)Actions.CorrectDelayedTyposInExpr(OrigLHS);
-        (void)Actions.CorrectDelayedTyposInExpr(Idx);
-        (void)Actions.CorrectDelayedTyposInExpr(Length);
-        LHS = ExprError();
         Idx = ExprError();
       }
 
index 0b520e0af1d52ff81b71f2fdc36a688555a6fa10..aa5a45eafbf7cc641625cb2c42766552f1b837cb 100644 (file)
@@ -678,7 +678,7 @@ namespace {
 struct a0is0 {};
 struct b0is0 {};
 int g() {
-  0 [                 // expected-error {{subscripted value is not an array}}
+  0 [
       sizeof(c0is0)]; // expected-error {{use of undeclared identifier}}
 };
 }
diff --git a/test/SemaObjC/typo-correction-subscript.m b/test/SemaObjC/typo-correction-subscript.m
new file mode 100644 (file)
index 0000000..19eb860
--- /dev/null
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -triple i386-apple-macosx10.10 -fobjc-arc -fsyntax-only -Wno-objc-root-class %s -verify -disable-free
+
+@class Dictionary;
+
+@interface Test
+@end
+@implementation Test
+// rdar://problem/47403222
+- (void)rdar47403222:(Dictionary *)opts {
+  [self undeclaredMethod:undeclaredArg];
+  // expected-error@-1{{no visible @interface for 'Test' declares the selector 'undeclaredMethod:'}}
+  opts[(__bridge id)undeclaredKey] = 0;
+  // expected-error@-1{{use of undeclared identifier 'undeclaredKey'}}
+}
+@end