r198540 - Fix bungled parse recovery in K&R function declarations
Alp Toker
alp at nuanti.com
Sat Jan 4 19:27:57 PST 2014
Author: alp
Date: Sat Jan 4 21:27:57 2014
New Revision: 198540
URL: http://llvm.org/viewvc/llvm-project?rev=198540&view=rev
Log:
Fix bungled parse recovery in K&R function declarations
void knrNoSemi(i) int i { }
Adherents of The C Programming Language unfortunate enough to miss a semicolon
as above would be met with a cascade of errors spanning the remainder of the
TU.
This patch introduces a beautiful parse error recovery, complete with helpful
FixIt to restore sanity.
Before (output redacted for brevity):
error: 'error' diagnostics seen but not expected:
File declarators.c Line 119: declaration does not declare a parameter
File declarators.c Line 123: declaration does not declare a parameter
File declarators.c Line 127: parameter named 'func_E12' is missing
File declarators.c Line 127: expected ';' at end of declaration
File declarators.c Line 133: parameter named 'func_E13' is missing
File declarators.c Line 133: expected ';' at end of declaration
File declarators.c Line 139: parameter named 'func_E14' is missing
File declarators.c Line 139: expected ';' at end of declaration
File declarators.c Line 145: parameter named 'func_E15' is missing
File declarators.c Line 145: expected ';' at end of declaration
File declarators.c Line 150: expected function body after function declarator
File declarators.c Line 119: declaration of 'enum E11' will not be visible outside of this function
File declarators.c Line 123: declaration of 'enum E12' will not be visible outside of this function
File declarators.c Line 133: ISO C forbids forward references to 'enum' types
File declarators.c Line 133: declaration of 'enum E13' will not be visible outside of this function
File declarators.c Line 139: ISO C forbids forward references to 'enum' types
File declarators.c Line 139: declaration of 'enum E14' will not be visible outside of this function
File declarators.c Line 145: ISO C forbids forward references to 'enum' types
File declarators.c Line 145: declaration of 'enum E15' will not be visible outside of this function
...
After:
declarators.c:103:24: error: expected ';' at end of declaration
void knrNoSemi(i) int i { }
^
;
Patch found in a sealed envelope dated 1978 with the message "Do not open until
January 2014"
Modified:
cfe/trunk/lib/Parse/Parser.cpp
cfe/trunk/test/Parser/declarators.c
Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=198540&r1=198539&r2=198540&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Sat Jan 4 21:27:57 2014
@@ -1285,12 +1285,9 @@ void Parser::ParseKNRParamDeclarations(D
ParseDeclarator(ParmDeclarator);
}
- if (ExpectAndConsumeSemi(diag::err_expected_semi_declaration)) {
- // Skip to end of block or statement
- SkipUntil(tok::semi);
- if (Tok.is(tok::semi))
- ConsumeToken();
- }
+ // Consume ';' or recover by skipping to the mandatory function body.
+ if (ExpectAndConsumeSemi(diag::err_expected_semi_declaration))
+ SkipUntil(tok::l_brace, StopBeforeMatch);
}
// The actions module must verify that all arguments were declared.
Modified: cfe/trunk/test/Parser/declarators.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/declarators.c?rev=198540&r1=198539&r2=198540&view=diff
==============================================================================
--- cfe/trunk/test/Parser/declarators.c (original)
+++ cfe/trunk/test/Parser/declarators.c Sat Jan 4 21:27:57 2014
@@ -100,6 +100,7 @@ long struct X { int x; } test15(); // ex
void test16(i) int i j; { } // expected-error {{expected ';' at end of declaration}}
void test17(i, j) int i, j k; { } // expected-error {{expected ';' at end of declaration}}
+void knrNoSemi(i) int i { } // expected-error {{expected ';' at end of declaration}}
// PR12595
More information about the cfe-commits
mailing list