linux-kernel-mentees.lists.linuxfoundation.org archive mirror
 help / color / mirror / Atom feed
* [Linux-kernel-mentees] [PATCH v4 00/14] cocci: Improve C parsing of attributes
@ 2020-06-05 13:43 Jaskaran Singh
  2020-06-05 13:43 ` [Linux-kernel-mentees] [PATCH v4 01/14] parsing_c: parse_c: Ignore TMacroAttr and TMacroEndAttr in passed tokens Jaskaran Singh
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: Jaskaran Singh @ 2020-06-05 13:43 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

This patch series aims to improve parsing of attributes in C by
Coccinelle's C parser.

These parsing errors were discovered by running a build of Coccinelle's
master branch on gitlab to parse the source code of Linux v5.5-rc4 and Linux
v5.6-rc7. Coccinelle currently manages attributes similar to comments, so
to explicity state what the attributes are to the C parser, a
MACROANNOTATION hint was used in Coccinelle's standard.h file. The hint
enables the parser to correctly identify attributes, and thus potentially
handle them differently in the AST.

Upon collection of these parsing errors, The GNU C Compiler's
grammar was taken as a reference for introducing attributes in correct
places in Coccinelle's C parser.

Upon applying the MACROANNOTATION hint to a majority of the attributes in
Coccinelle's standard.h file and parsing the source code of Linux
v5.6-rc7, the difference between the stats (of --parse-c) before and
after applying this patch series are as follows:

Before:

        NB total files = 28268; perfect = 25697; pbs = 2570; timeout = 0; =========> 90%
        nb good = 19160664,  nb passed = 135235 =========> 0.70% passed
        nb good = 19160664,  nb bad = 129685 =========> 99.33% good or passed

After:

        NB total files = 28268; perfect = 25699; pbs = 2568; timeout = 0; =========> 90%
        nb good = 19160856,  nb passed = 71716 =========> 0.37% passed
        nb good = 19160856,  nb bad = 129493 =========> 99.33% good or passed

What this patch series does not do:
- Add attributes from all the new productions into the C AST. Some of
  these are dropped.
- Reflect changes from the C parser in the SmPL parser.

Separate patches will be sent for the above.


Changes in v4:
-------------
Remove the following patches from the series and add/merge them to [1].
	parsing_c: visitor_c: Add vk_attribute and vk_attribute_s
	parsing_c: lib_parsing_c: Add ii_of_attr
	engine: Add distrf_attr to PARAM functor
	engine: cocci_vs_c: Add allminus argument to attribute_list
	parsing_c: parser: Make abstract_declarator pass attributes
	cocci: Add parameter attributes to C AST
	parsing_c: parser: Place parameter attributes in C AST
	parsing_c: visitor_c: Visit parameter attributes
	parsing_c: unparse_hrule: Add parameter attributes in record
	parsing_c: type_c: Add parameter attributes to record
	engine: cocci_vs_c: "Match" parameter attributes
	engine: c_vs_c: Match parameter attributes

parsing_c: parser: Add rule for optional end attributes
- Add to series.

parsing_c: parser: Add field declaration end attributes production
- Use end_attributes_opt to avoid duplicate code.

parsing_c: parser: Handle struct/union/enum end attributes
- Use end_attributes_opt to avoid duplicate code.

parsing_c: parser: Add MacroDecl end attributes production
- Use end_attributes_opt to avoid duplicate code.

parsing_c: parser: cpp_other end attributes production
- Use end_attributes_opt to avoid duplicate code.


Changes in v3:
-------------
parsing_c: parser: Place parameter attributes in C AST
- Remove the "attr is ignored" comments in the declaratorp rule.
- Place the attributes from the "declarator attributes" production
  in the declaratorp rule in the C AST as well.


Changes in v2:
--------------
parsing_c: parser: Add attribute production in spec_qualif_list
- This patch applied on its own causes a build error. Fix the error by
  removing the let binding for abstract_declaratort in the type_name
  rule

parsing_c: parser: Make abstract_declarator pass attributes
- Reflect changes from the above build error fix.


Jaskaran Singh (14):
      parsing_c: parse_c: Ignore TMacroAttr and TMacroEndAttr in passed tokens
      parsing_c: parsing_hacks: Label end attributes correctly
      parsing_c: parsing_hacks: Commentize attributes before qualif/type
      parsing_c: parser: Add rule for multiple end attributes
      parsing_c: parser: Add expression statement attributes
      parsing_c: parser: Add rule for optional end attributes
      parsing_c: parser: Add attribute production in spec_qualif_list
      parsing_c: parser: Add init_declarator_attrs rule
      parsing_c: parser: Add field declaration end attributes production
      parsing_c: parser: Handle struct/union/enum end attributes
      parsing_c: parser: Add MacroDecl end attributes production
      parsing_c: parser: cpp_other end attributes production
      parsing_c: cpp_token_c: Introduce MACROANNOTATION hint
      cocci: standard.h: Annotate attributes with MACROANNOTATION

 parsing_c/cpp_token_c.ml   |    2 
 parsing_c/parse_c.ml       |    4 +
 parsing_c/parser_c.mly     |   91 ++++++++++++++++++++++++-----------
 parsing_c/parsing_hacks.ml |   37 ++++++++++++++
 standard.h                 |  116 ++++++++++++++++++++++-----------------------
 5 files changed, 164 insertions(+), 86 deletions(-)


_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2020-06-05 13:49 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-05 13:43 [Linux-kernel-mentees] [PATCH v4 00/14] cocci: Improve C parsing of attributes Jaskaran Singh
2020-06-05 13:43 ` [Linux-kernel-mentees] [PATCH v4 01/14] parsing_c: parse_c: Ignore TMacroAttr and TMacroEndAttr in passed tokens Jaskaran Singh
2020-06-05 13:43 ` [Linux-kernel-mentees] [PATCH v4 02/14] parsing_c: parsing_hacks: Label end attributes correctly Jaskaran Singh
2020-06-05 13:43 ` [Linux-kernel-mentees] [PATCH v4 03/14] parsing_c: parsing_hacks: Commentize attributes before qualif/type Jaskaran Singh
2020-06-05 13:43 ` [Linux-kernel-mentees] [PATCH v4 04/14] parsing_c: parser: Add rule for multiple end attributes Jaskaran Singh
2020-06-05 13:43 ` [Linux-kernel-mentees] [PATCH v4 05/14] parsing_c: parser: Add expression statement attributes Jaskaran Singh
2020-06-05 13:43 ` [Linux-kernel-mentees] [PATCH v4 06/14] parsing_c: parser: Add rule for optional end attributes Jaskaran Singh
2020-06-05 13:43 ` [Linux-kernel-mentees] [PATCH v4 07/14] parsing_c: parser: Add attribute production in spec_qualif_list Jaskaran Singh
2020-06-05 13:43 ` [Linux-kernel-mentees] [PATCH v4 08/14] parsing_c: parser: Add init_declarator_attrs rule Jaskaran Singh
2020-06-05 13:43 ` [Linux-kernel-mentees] [PATCH v4 09/14] parsing_c: parser: Add field declaration end attributes production Jaskaran Singh
2020-06-05 13:43 ` [Linux-kernel-mentees] [PATCH v4 10/14] parsing_c: parser: Handle struct/union/enum end attributes Jaskaran Singh
2020-06-05 13:43 ` [Linux-kernel-mentees] [PATCH v4 11/14] parsing_c: parser: Add MacroDecl end attributes production Jaskaran Singh
2020-06-05 13:43 ` [Linux-kernel-mentees] [PATCH v4 12/14] parsing_c: parser: cpp_other " Jaskaran Singh
2020-06-05 13:43 ` [Linux-kernel-mentees] [PATCH v4 13/14] parsing_c: cpp_token_c: Introduce MACROANNOTATION hint Jaskaran Singh
2020-06-05 13:43 ` [Linux-kernel-mentees] [PATCH v4 14/14] cocci: standard.h: Annotate attributes with MACROANNOTATION Jaskaran Singh
2020-06-05 13:48 ` [Linux-kernel-mentees] [PATCH v4 00/14] cocci: Improve C parsing of attributes Jaskaran Singh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).