r236337 - Eagerly correct typos in ParenExprs that may be type casts for non-C++ code.

Kaelyn Takata rikka at google.com
Fri May 1 12:36:25 PDT 2015


Author: rikka
Date: Fri May  1 14:36:25 2015
New Revision: 236337

URL: http://llvm.org/viewvc/llvm-project?rev=236337&view=rev
Log:
Eagerly correct typos in ParenExprs that may be type casts for non-C++ code.

This is needed to ensure the type casts are parsed properly. Fixes
PR23101.

Modified:
    cfe/trunk/lib/Parse/ParseExpr.cpp
    cfe/trunk/test/Sema/typo-correction.c

Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=236337&r1=236336&r2=236337&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Fri May  1 14:36:25 2015
@@ -2285,6 +2285,11 @@ Parser::ParseParenExpression(ParenParseO
     InMessageExpressionRAIIObject InMessage(*this, false);
 
     Result = ParseExpression(MaybeTypeCast);
+    if (!getLangOpts().CPlusPlus && MaybeTypeCast && Result.isUsable()) {
+      // Correct typos in non-C++ code earlier so that implicit-cast-like
+      // expressions are parsed correctly.
+      Result = Actions.CorrectDelayedTyposInExpr(Result);
+    }
     ExprType = SimpleExpr;
 
     if (isFoldOperator(Tok.getKind()) && NextToken().is(tok::ellipsis))

Modified: cfe/trunk/test/Sema/typo-correction.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/typo-correction.c?rev=236337&r1=236336&r2=236337&view=diff
==============================================================================
--- cfe/trunk/test/Sema/typo-correction.c (original)
+++ cfe/trunk/test/Sema/typo-correction.c Fri May  1 14:36:25 2015
@@ -34,3 +34,9 @@ int c11Generic(int arg) {
   _Generic(hello, int : banana)();  // expected-error-re {{use of undeclared identifier 'hello'{{$}}}}
   _Generic(arg, int : bandana)();  // expected-error {{use of undeclared identifier 'bandana'; did you mean 'banana'?}}
 }
+
+typedef long long __m128i __attribute__((__vector_size__(16)));
+int PR23101(__m128i __x) {
+  return foo((__v2di)__x);  // expected-warning {{implicit declaration of function 'foo'}} \
+                            // expected-error {{use of undeclared identifier '__v2di'}}
+}





More information about the cfe-commits mailing list