Skip to content

Commit c2f1846

Browse files
committed
genksyms: restrict direct-abstract-declarator to take one parameter-type-list
While there is no more grammatical ambiguity in genksyms, the parser logic is still inaccurate. For example, genksyms accepts the following invalid C code: void my_func(int ()(int)); This should result in a syntax error because () cannot be reduced to <direct-abstract-declarator>. ( <abstract-declarator> ) can be reduced, but <abstract-declarator> must not be empty in the following grammar from K&R [1]: <direct-abstract-declarator> ::= ( <abstract-declarator> ) | {<direct-abstract-declarator>}? [ {<constant-expression>}? ] | {<direct-abstract-declarator>}? ( {<parameter-type-list>}? ) Furthermore, genksyms accepts the following weird code: void my_func(int (*callback)(int)(int)(int)); The parser allows <direct-abstract-declarator> to recursively absorb multiple ( {<parameter-type-list>}? ), but this behavior is incorrect. In the example above, (*callback) should be followed by at most one (int). [1]: https://cs.wmich.edu/~gupta/teaching/cs4850/sumII06/The%20syntax%20of%20C%20in%20Backus-Naur%20form.htm Signed-off-by: Masahiro Yamada <[email protected]> Acked-by: Nicolas Schier <[email protected]>
1 parent a952986 commit c2f1846

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

scripts/genksyms/parse.y

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -381,20 +381,24 @@ abstract_declarator:
381381
;
382382

383383
direct_abstract_declarator:
384+
direct_abstract_declarator1
385+
| direct_abstract_declarator1 open_paren parameter_declaration_clause ')'
386+
{ $$ = $4; }
387+
| open_paren parameter_declaration_clause ')'
388+
{ $$ = $3; }
389+
;
390+
391+
direct_abstract_declarator1:
384392
IDENT
385393
{ /* For version 2 checksums, we don't want to remember
386394
private parameter names. */
387395
remove_node($1);
388396
$$ = $1;
389397
}
390-
| direct_abstract_declarator open_paren parameter_declaration_clause ')'
391-
{ $$ = $4; }
392-
| direct_abstract_declarator open_paren error ')'
398+
| direct_abstract_declarator1 open_paren error ')'
393399
{ $$ = $4; }
394-
| direct_abstract_declarator BRACKET_PHRASE
400+
| direct_abstract_declarator1 BRACKET_PHRASE
395401
{ $$ = $2; }
396-
| open_paren parameter_declaration_clause ')'
397-
{ $$ = $3; }
398402
| open_paren abstract_declarator ')'
399403
{ $$ = $3; }
400404
| open_paren error ')'

0 commit comments

Comments
 (0)