[PATCH] D60848: [Parser] Avoid correcting delayed typos in array subscript multiple times.
Volodymyr Sapsai via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 17 19:06:56 PDT 2019
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();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60848.195662.patch
Type: text/x-patch
Size: 1380 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190418/524d10e9/attachment.bin>
More information about the cfe-commits
mailing list