[PATCH] D17239: Sema: typo correct both sides of binary expression

Saleem Abdulrasool via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 12 23:22:03 PST 2016


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 at -1 {{use of undeclared identifier 'N'{{$}}}}
 }
 
+namespace PR26598 {
+int main() {
+  (((str) ? str : str))
+  // expected-error at -1 {{use of undeclared identifier 'str'}}
+  // expected-error at -2 {{use of undeclared identifier 'str'}}
+  // expected-error at -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 at +2 {{use of undeclared identifier 'uintmax_t'{{$}}}}
 // expected-error at +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 at -1 {{'thisvar' declared here}}
+  int thatval = aaa * (bbb + thatvar);
+  // expected-error at -1 {{use of undeclared identifier 'thatvar'; did you mean 'thatval'?}}
+  // expected-note at -2 {{'thatval' declared here}}
+  int thatval2 = aaa * (bbb + thisval);
+  // expected-error at -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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17239.47902.patch
Type: text/x-patch
Size: 2994 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160213/480a7d7b/attachment-0001.bin>


More information about the cfe-commits mailing list