compnerd created this revision. compnerd added a reviewer: rtrieu. compnerd added a subscriber: cfe-commits.
When parsing a ternary expression, we would parse the middle and the last components of the expression. If there was a typo in both, we would only run the typo correction once. Normally, this would be fine, but, when Sema would be destructed in an Asserts build, we would assert that a delayed typo was not handled. This was caused by the fact that the RHS would evaluate as valid as a TypoExpr would be returned via the ExprResult, and invalid simply ensures that an expression is present. Peek into the result and perform the handling that we would reserve for the invalid type. Resolves PR265598. http://reviews.llvm.org/D17239 Files: lib/Parse/ParseExpr.cpp test/SemaCXX/typo-correction-cxx11.cpp test/SemaCXX/typo-correction-delayed.cpp test/SemaObjC/provisional-ivar-lookup.m Index: test/SemaObjC/provisional-ivar-lookup.m =================================================================== --- test/SemaObjC/provisional-ivar-lookup.m +++ test/SemaObjC/provisional-ivar-lookup.m @@ -3,7 +3,7 @@ // rdar:// 8565343 @interface Foo { @private - int _foo; + int _foo; // expected-note {{'_foo' declared here}} int _foo2; } @property (readwrite, nonatomic) int foo, foo1, foo2, foo3; @@ -16,7 +16,7 @@ @synthesize foo1; - (void)setFoo:(int)value { - _foo = foo; // expected-error {{use of undeclared identifier 'foo'}} + _foo = foo; // expected-error {{use of undeclared identifier 'foo'; did you mean '_foo'}} } - (void)setFoo1:(int)value { Index: test/SemaCXX/typo-correction-delayed.cpp =================================================================== --- test/SemaCXX/typo-correction-delayed.cpp +++ test/SemaCXX/typo-correction-delayed.cpp @@ -208,8 +208,18 @@ // expected-error-re@-1 {{use of undeclared identifier 'N'{{$}}}} } +namespace PR26598 { +int main() { + (((str) ? str : str)) + // expected-error@-1 {{use of undeclared identifier 'str'}} + // expected-error@-2 {{use of undeclared identifier 'str'}} + // expected-error@-3 {{use of undeclared identifier 'str'}} +} +} + // PR 23285. This test must be at the end of the file to avoid additional, // unwanted diagnostics. // expected-error-re@+2 {{use of undeclared identifier 'uintmax_t'{{$}}}} // expected-error@+1 {{expected ';' after top level declarator}} unsigned int a = 0(uintmax_t + Index: test/SemaCXX/typo-correction-cxx11.cpp =================================================================== --- test/SemaCXX/typo-correction-cxx11.cpp +++ test/SemaCXX/typo-correction-cxx11.cpp @@ -19,8 +19,13 @@ namespace PR23140 { auto lneed = gned.*[] {}; // expected-error-re {{use of undeclared identifier 'gned'{{$}}}} -void test(int aaa, int bbb, int thisvar) { // expected-note {{'thisvar' declared here}} - int thatval = aaa * (bbb + thatvar); // expected-error {{use of undeclared identifier 'thatvar'; did you mean 'thisvar'?}} +void test(int aaa, int bbb, int thisvar) { + // expected-note@-1 {{'thisvar' declared here}} + int thatval = aaa * (bbb + thatvar); + // expected-error@-1 {{use of undeclared identifier 'thatvar'; did you mean 'thatval'?}} + // expected-note@-2 {{'thatval' declared here}} + int thatval2 = aaa * (bbb + thisval); + // expected-error@-1 {{use of undeclared identifier 'thisval'; did you mean 'thisvar'?}} } } Index: lib/Parse/ParseExpr.cpp =================================================================== --- lib/Parse/ParseExpr.cpp +++ lib/Parse/ParseExpr.cpp @@ -369,7 +369,7 @@ else RHS = ParseCastExpression(false); - if (RHS.isInvalid()) { + if (RHS.isInvalid() || isa<TypoExpr>(RHS.get())) { // FIXME: Errors generated by the delayed typo correction should be // printed before errors from parsing the RHS, not after. Actions.CorrectDelayedTyposInExpr(LHS);
Index: test/SemaObjC/provisional-ivar-lookup.m =================================================================== --- test/SemaObjC/provisional-ivar-lookup.m +++ test/SemaObjC/provisional-ivar-lookup.m @@ -3,7 +3,7 @@ // rdar:// 8565343 @interface Foo { @private - int _foo; + int _foo; // expected-note {{'_foo' declared here}} int _foo2; } @property (readwrite, nonatomic) int foo, foo1, foo2, foo3; @@ -16,7 +16,7 @@ @synthesize foo1; - (void)setFoo:(int)value { - _foo = foo; // expected-error {{use of undeclared identifier 'foo'}} + _foo = foo; // expected-error {{use of undeclared identifier 'foo'; did you mean '_foo'}} } - (void)setFoo1:(int)value { Index: test/SemaCXX/typo-correction-delayed.cpp =================================================================== --- test/SemaCXX/typo-correction-delayed.cpp +++ test/SemaCXX/typo-correction-delayed.cpp @@ -208,8 +208,18 @@ // expected-error-re@-1 {{use of undeclared identifier 'N'{{$}}}} } +namespace PR26598 { +int main() { + (((str) ? str : str)) + // expected-error@-1 {{use of undeclared identifier 'str'}} + // expected-error@-2 {{use of undeclared identifier 'str'}} + // expected-error@-3 {{use of undeclared identifier 'str'}} +} +} + // PR 23285. This test must be at the end of the file to avoid additional, // unwanted diagnostics. // expected-error-re@+2 {{use of undeclared identifier 'uintmax_t'{{$}}}} // expected-error@+1 {{expected ';' after top level declarator}} unsigned int a = 0(uintmax_t + Index: test/SemaCXX/typo-correction-cxx11.cpp =================================================================== --- test/SemaCXX/typo-correction-cxx11.cpp +++ test/SemaCXX/typo-correction-cxx11.cpp @@ -19,8 +19,13 @@ namespace PR23140 { auto lneed = gned.*[] {}; // expected-error-re {{use of undeclared identifier 'gned'{{$}}}} -void test(int aaa, int bbb, int thisvar) { // expected-note {{'thisvar' declared here}} - int thatval = aaa * (bbb + thatvar); // expected-error {{use of undeclared identifier 'thatvar'; did you mean 'thisvar'?}} +void test(int aaa, int bbb, int thisvar) { + // expected-note@-1 {{'thisvar' declared here}} + int thatval = aaa * (bbb + thatvar); + // expected-error@-1 {{use of undeclared identifier 'thatvar'; did you mean 'thatval'?}} + // expected-note@-2 {{'thatval' declared here}} + int thatval2 = aaa * (bbb + thisval); + // expected-error@-1 {{use of undeclared identifier 'thisval'; did you mean 'thisvar'?}} } } Index: lib/Parse/ParseExpr.cpp =================================================================== --- lib/Parse/ParseExpr.cpp +++ lib/Parse/ParseExpr.cpp @@ -369,7 +369,7 @@ else RHS = ParseCastExpression(false); - if (RHS.isInvalid()) { + if (RHS.isInvalid() || isa<TypoExpr>(RHS.get())) { // FIXME: Errors generated by the delayed typo correction should be // printed before errors from parsing the RHS, not after. Actions.CorrectDelayedTyposInExpr(LHS);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits