Re: [Cocci] console: Complete exception handling in newport_probe()

2020-04-24 Thread Markus Elfring
> Sorry, I do not know how to use the SmPL script. I would like to try again to make you more familiar with applications of the Coccinelle software.

[Cocci] [RFC PATCH 11/25] parsing_c: parser: cpp_other end attributes production

2020-04-24 Thread Jaskaran Singh
Add a production for a macro call in the cpp_other rule of Coccinelle's C parser. This parses the following C code from Linux v5.6-rc7 successfully: arch/x86/kernel/irq_64.c: DEFINE_PER_CPU_PAGE_ALIGNED(struct irq_stack, irq_stack_backing_store) __visible; Signed-off-by: Jaskaran

[Cocci] [RFC PATCH 06/25] parsing_c: parser: Add attribute production in spec_qualif_list

2020-04-24 Thread Jaskaran Singh
As per GCC's C grammar, the specifier-qualifier-list has the following production: specifier-qualifier-list: gnu-attributes specifier-qualifier-list[opt] Add this production to the spec_qualif_list rule of Coccinelle's C parser. This parses attributes in struct fields and casts

[Cocci] [RFC PATCH 07/25] parsing_c: parser: Add init_declarator_attrs rule

2020-04-24 Thread Jaskaran Singh
As per GCC's C grammar, the init-declarator rule has the following production: init-declarator: declarator simple-asm-expr[opt] gnu-attributes[opt] declarator simple-asm-expr[opt] gnu-attributes[opt] = initializer Due to conflicts in Coccinelle's C grammar, adding

[Cocci] [RFC PATCH 09/25] parsing_c: parser: Handle struct/union/enum end attributes

2020-04-24 Thread Jaskaran Singh
As per GCC's C grammar, the struct-or-union-specifier and enum-specifier have the following productions: struct-or-union-specifier: struct-or-union attribute-specifier-sequence[opt] gnu-attributes[opt] identifier[opt] { struct-contents } gnu-attributes[opt] enum-specifier:

[Cocci] [RFC PATCH 04/25] parsing_c: parser: Add rule for multiple end attributes

2020-04-24 Thread Jaskaran Singh
There is no rule for productions of multiple end attributes. Add a case similar to that of attribute_list for end attributes. Signed-off-by: Jaskaran Singh --- parsing_c/parser_c.mly | 5 - 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/parsing_c/parser_c.mly

[Cocci] [RFC PATCH 03/25] parsing_c: parsing_hacks: Commentize attributes before qualif/type

2020-04-24 Thread Jaskaran Singh
For the following example from fs/btrfs/ctree.h in Linux v5.6-rc7: __cold __noreturn static inline void assertfail(const char *expr, const char *file, int line) { pr_err("assertion failed: %s, in %s:%d\n", expr, file, line); BUG(); } __cold and __noreturn are not labeled

[Cocci] [RFC PATCH 10/25] parsing_c: parser: Add MacroDecl end attributes production

2020-04-24 Thread Jaskaran Singh
Add a production for macro declaration end attributes. This parses the following C code from Linux v5.6-rc7: arch/x86/kernel/nmi_selftest.c: static DECLARE_BITMAP(nmi_ipi_mask, NR_CPUS) __initdata; Signed-off-by: Jaskaran Singh --- parsing_c/parser_c.mly | 11 +++ 1 file

[Cocci] [RFC PATCH 01/25] parsing_c: parse_c: Ignore TMacroAttr and TMacroEndAttr in passed tokens

2020-04-24 Thread Jaskaran Singh
Most cases in parsing_hacks do not consider attributes before or after the token in question. So, do not pass TMacroAttr or TMacroEndAttr tokens to parsing_hacks in the before list. Signed-off-by: Jaskaran Singh --- parsing_c/parse_c.ml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)

[Cocci] [RFC PATCH 08/25] parsing_c: parser: Add field declaration end attributes production

2020-04-24 Thread Jaskaran Singh
As per GCC's C grammar, the struct-declarator rule has the following productions: struct-declarator: declarator gnu-attributes[opt] declarator[opt] : constant-expression gnu-attributes[opt] While these productions are handled in the struct_declarator rule of

[Cocci] [RFC PATCH 05/25] parsing_c: parser: Add expression statement attributes

2020-04-24 Thread Jaskaran Singh
As per GCC's C grammar, the expression statement rule has the following production: expression-statement: gnu-attributes ; Add this production to the expr_statement rule of Coccinelle's C parser. If attributes are recognized, this parses the following code successfully:

[Cocci] [RFC PATCH 00/25] cocci: Improve C parsing of attributes

2020-04-24 Thread Jaskaran Singh
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

[Cocci] [RFC PATCH 12/25] parsing_c: cpp_token_c: Introduce MACROANNOTATION hint

2020-04-24 Thread Jaskaran Singh
A better way of denoting attributes is to pass attribute information from SmPL to the C parser. However, a temporary solution is to introduce a MACROANNOTATION hint to cpp_token_c.ml so that the parser can identify attributes easily. This hint can be used as follows in standard.h, the user

[Cocci] [RFC PATCH 21/25] parsing_c: visitor_c: Visit parameter attributes

2020-04-24 Thread Jaskaran Singh
As attributes are added to the parameter type, have the C AST visitor visit these attributes as well. Signed-off-by: Jaskaran Singh --- parsing_c/visitor_c.ml | 7 ++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/parsing_c/visitor_c.ml b/parsing_c/visitor_c.ml index

[Cocci] [RFC PATCH 17/25] engine: cocci_vs_c: Add allminus argument to attribute_list

2020-04-24 Thread Jaskaran Singh
The allminus argument is used to denote when attributes should be removed. This is with respect to the given SmPL program. Add the allminus argument to attribute_list, and pass it correctly in places where attribute_list is used. This also makes sure that the test case unstruct does not break

[Cocci] [RFC PATCH 18/25] parsing_c: parser: Make abstract_declarator pass attributes

2020-04-24 Thread Jaskaran Singh
The attributes in abstract_declarator can be used for adding parameter attributes, cast attributes and others to the C AST. Make abstract_declarator pass these attributes in a tuple. Signed-off-by: Jaskaran Singh --- parsing_c/parser_c.mly | 13 +++-- 1 file changed, 7 insertions(+), 6

[Cocci] [RFC PATCH 15/25] parsing_c: lib_parsing_c: Add ii_of_attr

2020-04-24 Thread Jaskaran Singh
ii_of_attr can be used to get the corresponding info of a single C attribute. Add this function to lib_parsing_c. Signed-off-by: Jaskaran Singh --- parsing_c/lib_parsing_c.ml | 1 + parsing_c/lib_parsing_c.mli | 1 + 2 files changed, 2 insertions(+) diff --git a/parsing_c/lib_parsing_c.ml

[Cocci] [RFC PATCH 19/25] cocci: Add parameter attributes to C AST

2020-04-24 Thread Jaskaran Singh
With extended support of attributes, parameter attributes are needed in the C AST so that the nocast test case does not break. Add the p_attr field to parameter in the C AST. Signed-off-by: Jaskaran Singh --- ocaml/coccilib.mli | 1 + parsing_c/ast_c.ml | 1 + parsing_c/ast_c.mli | 1 + 3

[Cocci] [RFC PATCH 16/25] engine: Add distrf_attr to PARAM functor

2020-04-24 Thread Jaskaran Singh
distrf_attr can be used to match a single attribute at a time. Add this matcher function to the PARAM functor. Signed-off-by: Jaskaran Singh --- engine/cocci_vs_c.ml | 3 +++ engine/cocci_vs_c.mli | 3 +++ engine/pattern_c.ml| 1 + engine/transformation_c.ml | 5 + 4

[Cocci] [RFC PATCH 23/25] parsing_c: type_c: Add parameter attributes to record

2020-04-24 Thread Jaskaran Singh
Paramter attributes are added to the C AST. Reflect this change in a case in type_c.ml. Signed-off-by: Jaskaran Singh --- parsing_c/type_c.ml | 1 + 1 file changed, 1 insertion(+) diff --git a/parsing_c/type_c.ml b/parsing_c/type_c.ml index 4a85b683..617b6fc6 100644 --- a/parsing_c/type_c.ml

[Cocci] [RFC PATCH 20/25] parsing_c: parser: Place parameter attributes in C AST

2020-04-24 Thread Jaskaran Singh
Parameter attributes are needed so as to not break the nocast test case when attributes are fully supported. Add parameter attributes to the C AST. Signed-off-by: Jaskaran Singh --- parsing_c/parser_c.mly | 14 ++ 1 file changed, 10 insertions(+), 4 deletions(-) diff --git

[Cocci] [RFC PATCH 14/25] parsing_c: visitor_c: Add vk_attribute and vk_attribute_s

2020-04-24 Thread Jaskaran Singh
vk_attribute and vk_attribute_s were not declared in visitor_c.mli. Declare these functions in visitor_c.mli to use these outside of visitor_c.ml. Signed-off-by: Jaskaran Singh --- parsing_c/visitor_c.mli | 3 +++ 1 file changed, 3 insertions(+) diff --git a/parsing_c/visitor_c.mli

[Cocci] [RFC PATCH 25/25] engine: c_vs_c: Match parameter attributes

2020-04-24 Thread Jaskaran Singh
Parameter attributes are added to the C AST. Add an expression to check if attributes are equal on both sides to the parameter case in c_vs_c. Signed-off-by: Jaskaran Singh --- engine/c_vs_c.ml | 12 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/engine/c_vs_c.ml

[Cocci] [RFC PATCH 24/25] engine: cocci_vs_c: "Match" parameter attributes

2020-04-24 Thread Jaskaran Singh
Parameter attributes are added to the C AST, but not to the SmPL AST. Once parameter attributes are added to SmPL as well, they can actually be matched, but for now a call to attribute_list is required to correctly remove attributes. Attributes from a parameter are removed when the whole parameter

[Cocci] [RFC PATCH 02/25] parsing_c: parsing_hacks: Label end attributes correctly

2020-04-24 Thread Jaskaran Singh
Due to certain conflicts in the grammar, a separate token (TMacroEndAttr) is required for attributes before a semicolon or an assignment operator. Prior to this, multiple end attributes were not labeled correctly, i.e., only the single attribute before the semicolon or assignment operator would

[Cocci] [RFC PATCH 13/25] cocci: standard.h: Annotate attributes with MACROANNOTATION

2020-04-24 Thread Jaskaran Singh
Apply the MACROANNOTATION hint to select attributes in standard.h. These hints can be replaced, removed or added by the user as their use case demands. Signed-off-by: Jaskaran Singh --- standard.h | 116 ++--- 1 file changed, 58 insertions(+), 58

[Cocci] [RFC PATCH 22/25] parsing_c: unparse_hrule: Add parameter attributes in record

2020-04-24 Thread Jaskaran Singh
Parameter attributes are added to the C AST. Initialize the parameter attributes field as empty in a case in unparse_hrule.ml. Signed-off-by: Jaskaran Singh --- parsing_c/unparse_hrule.ml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/parsing_c/unparse_hrule.ml

Re: [Cocci] [RFC PATCH 17/25] engine: cocci_vs_c: Add allminus argument to attribute_list

2020-04-24 Thread Markus Elfring
> This also makes sure that the test case unstruct does not break when > attributes are identified correctly by the C parser. Would the wording “are correctly identified” be more appropriate? Regards, Markus ___ Cocci mailing list Cocci@systeme.lip6.fr

Re: [Cocci] [RFC PATCH 12/25] parsing_c: cpp_token_c: Introduce MACROANNOTATION hint

2020-04-24 Thread Markus Elfring
> A better way of denoting attributes is to pass attribute information > from SmPL to the C parser. Such information sounds promising. > However, a temporary solution is to introduce a MACROANNOTATION hint > to cpp_token_c.ml so that the parser can identify attributes easily. Have you got any

Re: [Cocci] [RFC PATCH 00/25] cocci: Improve C parsing of attributes

2020-04-24 Thread Markus Elfring
> This patch series aims to improve parsing of attributes in C by > Coccinelle's C parser. How do you think about to use the wording “in C source code by”? > These parsing errors were discovered by running a build of Coccinelle's Would you like to omit the word “These”? > Coccinelle

Re: [Cocci] [RFC PATCH 23/25] parsing_c: type_c: Add parameter attributes to record

2020-04-24 Thread Markus Elfring
> Paramter attributes are added to the C AST. Please avoid a typo in the first word for this change description. Regards, Markus ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci