> 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.
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
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
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
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:
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
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
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
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(-)
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
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:
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
> 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
> 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
> 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
> 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
31 matches
Mail list logo