vsapsai created this revision. vsapsai added reviewers: rsmith, erik.pilkington, majnemer. Herald added subscribers: dexonsmith, jkorous.
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. This assertion is reproducible with Objective-C method - (void)test { [self undeclaredMethod:undeclaredArg]; NSMutableDictionary *opts = [NSMutableDictionary new]; opts[(__bridge id)undeclaredKey] = @0; } There is no test for the fix because `NumTypos` is still incorrect and we hit the assertion > Assertion failed: (DelayedTypos.empty() && "Uncorrected typos!"), function > ~Sema, file clang/lib/Sema/Sema.cpp, line 382. Another option is to fix tracking delayed typos but it is non-trivial as in many cases we drop erroneous expressions without cleaning up `TypoExpr` they contain. Also the assertion in `~Sema` isn't causing problems with assertions disabled, while a missing `TypoExprState` can cause a segmentation fault. rdar://problem/47403222 https://reviews.llvm.org/D60848 Files: clang/lib/Parse/ParseExpr.cpp clang/test/SemaCXX/typo-correction.cpp Index: clang/test/SemaCXX/typo-correction.cpp =================================================================== --- clang/test/SemaCXX/typo-correction.cpp +++ clang/test/SemaCXX/typo-correction.cpp @@ -678,7 +678,7 @@ struct a0is0 {}; struct b0is0 {}; int g() { - 0 [ // expected-error {{subscripted value is not an array}} + 0 [ sizeof(c0is0)]; // expected-error {{use of undeclared identifier}} }; } Index: clang/lib/Parse/ParseExpr.cpp =================================================================== --- clang/lib/Parse/ParseExpr.cpp +++ clang/lib/Parse/ParseExpr.cpp @@ -1582,7 +1582,9 @@ 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 @@ } } else { LHS = ExprError(); - } - if (LHS.isInvalid()) { - (void)Actions.CorrectDelayedTyposInExpr(OrigLHS); - (void)Actions.CorrectDelayedTyposInExpr(Idx); - (void)Actions.CorrectDelayedTyposInExpr(Length); - LHS = ExprError(); Idx = ExprError(); }
Index: clang/test/SemaCXX/typo-correction.cpp =================================================================== --- clang/test/SemaCXX/typo-correction.cpp +++ clang/test/SemaCXX/typo-correction.cpp @@ -678,7 +678,7 @@ struct a0is0 {}; struct b0is0 {}; int g() { - 0 [ // expected-error {{subscripted value is not an array}} + 0 [ sizeof(c0is0)]; // expected-error {{use of undeclared identifier}} }; } Index: clang/lib/Parse/ParseExpr.cpp =================================================================== --- clang/lib/Parse/ParseExpr.cpp +++ clang/lib/Parse/ParseExpr.cpp @@ -1582,7 +1582,9 @@ 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 @@ } } else { LHS = ExprError(); - } - if (LHS.isInvalid()) { - (void)Actions.CorrectDelayedTyposInExpr(OrigLHS); - (void)Actions.CorrectDelayedTyposInExpr(Idx); - (void)Actions.CorrectDelayedTyposInExpr(Length); - LHS = ExprError(); Idx = ExprError(); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits