Skip to contentSkip to conversation

sgen problems

Cocci Wolfram Sang 2 participants 7 messages Oct 17, 2014 – Oct 18, 2014

lore
Share & tools
lore
#0 lore raw

Hi,

so I was trying to convert my spatch from the platform-owner series to a Kernel-cocci with sgen. However, that didn't work and produced a corrupt cocci file (at least the name of the matching rules has been eaten). I used a self-compiled sgen from the Debian rc22. I attach the cocci and config file for easier reproducing. Does the sgen author read the list? Probably it would be easy to fix the broken file, but it seems more sustainable to me to fix the tool :)

Thanks,

Wolfram

-------------- next part --------------
@match1@
declarer name module_platform_driver;
declarer name module_platform_driver_probe;
identifier __driver;
@@
(

	module_platform_driver(__driver);
|
	module_platform_driver_probe(__driver, ...);

)

@fix1 depends on match1@
identifier match1.__driver;
@@

	static struct platform_driver __driver = {
		.driver = {
-			.owner = THIS_MODULE,
		}
	};

@match2@
identifier __driver;
@@
(
platform_driver_register(&__driver)
|

	platform_driver_probe(&__driver, ...)
|
	platform_create_bundle(&__driver, ...)

)

@fix2 depends on match2@
identifier match2.__driver;
@@

	static struct platform_driver __driver = {
		.driver = {
-			.owner = THIS_MODULE,
		}
	};

-------------- next part --------------
// Generated config
description = Remove .owner field if calls are used which set it automatically confidence = Moderate
authors = Wolfram Sang. GPL v2.
fix2 =
org:"No need to set .owner here"
report:"No need to set .owner here"
fix1 =
org:"No need to set .owner here"
report:"No need to set .owner here"
-------------- next part --------------
/// Remove .owner field if calls are used which set it automatically ///
// Confidence: Moderate
// Copyright: (C) 2014 Wolfram Sang. GPL v2.

virtual patch
virtual context
virtual org
virtual report

@declarer name module_platform_driver;
declarer name module_platform_driver_probe;
identifier __driver;
@@
(

	module_platform_driver(__driver);
|
	module_platform_driver_probe(__driver, ...);

)

@fix1 depends on match1 && patch && !context && !org && !report@ identifier match1.__driver;
@@

	static struct platform_driver __driver = {
		.driver = {
-			.owner = THIS_MODULE,
		}
	};

@identifier __driver;
@@
(
platform_driver_register(&__driver)
|

	platform_driver_probe(&__driver, ...)
|
	platform_create_bundle(&__driver, ...)

)

@fix2 depends on match2 && patch && !context && !org && !report@ identifier match2.__driver;
@@

	static struct platform_driver __driver = {
		.driver = {
-			.owner = THIS_MODULE,
		}
	};

// ----------------------------------------------------------------------------

@fix1_context depends on match1 && !patch && (context || org || report)@ identifier match1.__driver;
position j0;
@@

* 	static struct platform_driver __driver at j0 = {
		.driver = {
			.owner = THIS_MODULE,
		}
	};

@fix2_context depends on match2 && !patch && (context || org || report)@ identifier match2.__driver;
position j0;
@@

* 	static struct platform_driver __driver at j0 = {
		.driver = {
			.owner = THIS_MODULE,
		}
	};

// ----------------------------------------------------------------------------

@script:python fix1_org depends on org@
j0 << fix1_context.j0;
@@

msg = "No need to set .owner here."
coccilib.org.print_todo(j0[0], msg)

@script:python fix2_org depends on org@
j0 << fix2_context.j0;
@@

msg = "No need to set .owner here."
coccilib.org.print_todo(j0[0], msg)

// ----------------------------------------------------------------------------

@script:python fix1_report depends on report@
j0 << fix1_context.j0;
@@

msg = "No need to set .owner here."
coccilib.report.print_report(j0[0], msg)

@script:python fix2_report depends on report@
j0 << fix2_context.j0;
@@

msg = "No need to set .owner here."
coccilib.report.print_report(j0[0], msg)

#1 lore raw
Quoted 9 lines · Wolfram Sang

Hi,

so I was trying to convert my spatch from the platform-owner series to a Kernel-cocci with sgen. However, that didn't work and produced a corrupt cocci file (at least the name of the matching rules has been eaten). I used a self-compiled sgen from the Debian rc22. I attach the cocci and config file for easier reproducing. Does the sgen author read the list? Probably it would be easy to fix the broken file, but it seems more sustainable to me to fix the tool :)

I'm not sure whether the sgen author reads the list, but I will ask her to fix the tool. Thanks very much for the feedback!

julia

#2 lore raw
In reply to Wolfram Sang
Quoted 9 lines · Wolfram Sang

Hi,

so I was trying to convert my spatch from the platform-owner series to a Kernel-cocci with sgen. However, that didn't work and produced a corrupt cocci file (at least the name of the matching rules has been eaten). I used a self-compiled sgen from the Debian rc22. I attach the cocci and config file for easier reproducing. Does the sgen author read the list? Probably it would be easy to fix the broken file, but it seems more sustainable to me to fix the tool :)

Two patches are attached. Apply p1 and then p2.

-------------- next part --------------
commit 99fba8e0afe74f8f9cc9ecea14efb096469b0b9a

Author: Chi Pham <[email protected]>
Date:   Sat Oct 18 01:09:36 2014 +0100

sgen: Fixed a file transformation bug.

Bug reported by Wolfram Sang regarding faulty rule headers during file transformation.

(also in this commit: a tiny eta reduction just because)

tools/sgen/source/context_rule.ml +1 -1
index 7efff59..37c309e 100644
@@ -53,7 +53,7 @@ let generate ~new_name ~disj_map ~rule ~context_mode = match rule with
         ("MEGA ERROR: Congratulations! You managed to write a Coccinelle " ^
          "rule that sgen was unable to add a position to! The rule is \"" ^
          nme ^ "\".") in
-      let pos_mv = List.map (fun a -> M.make_metavar ~typ:"position " a) pos in
+      let pos_mv = List.map (M.make_metavar ~typ:"position ") pos in
       let pos_inh = M.inherit_rule cnm pos_mv in
 
       (* check if any extra generated disj rule *)
tools/sgen/source/file_transform.ml +1 -1
index a54eec7..26aef9f 100644
@@ -65,7 +65,7 @@ let match_part rulename =
   regex_match ("^@"^spcmnt_re^(escape rulename)^"\\("^spp_re^".*\\)?$")
 let match_end = regex_match ".*@"
 let match_nameless_rule = regex_match "\\(^\\(@@\\)\\|^@.*@$\\)"
-let match_rule_start = regex_match "^@"
+let match_rule_start = regex_match ("^@"^spcmnt_re^"$")
 let match_rule_end = regex_match (spcmnt_re^"@@")
 let match_non_empty = regex_match (spcmnt_re^"[^ \t]")
 

-------------- next part --------------
commit 5c16e565dc2fc98769e4f7f458812a0ead08334a

Author: Chi Pham <[email protected]>
Date:   Sat Oct 18 01:20:30 2014 +0100

sgen: more defensive programming in file transform.

An extension of the bugfix in 99fba8e0afe74f8f9cc9ecea14efb096469b0b9a that covers more cases of user antics.

tools/sgen/source/file_transform.ml +3 -2
index 26aef9f..83466d6 100644
@@ -65,7 +65,8 @@ let match_part rulename =
   regex_match ("^@"^spcmnt_re^(escape rulename)^"\\("^spp_re^".*\\)?$")
 let match_end = regex_match ".*@"
 let match_nameless_rule = regex_match "\\(^\\(@@\\)\\|^@.*@$\\)"
-let match_rule_start = regex_match ("^@"^spcmnt_re^"$")
+let match_rule_start = regex_match ("^@")
+let match_rule_start_arob = regex_match ("^@"^spcmnt_re^"$")
 let match_rule_end = regex_match (spcmnt_re^"@@")
 let match_non_empty = regex_match (spcmnt_re^"[^ \t]")
 
@@ -110,7 +111,7 @@ let traverse name outch inch =
       (line, inch)
     else if match_part name line then
       find_match nothing match_end inch
-    else if match_rule_start line && not(match_rule_end line) then
+    else if match_rule_start_arob line then
       let (line,inch) = find_match nothing match_non_empty inch in
       if regex_match (sp_re^name) line then
         find_match nothing match_end inch
#3 lore raw
Quoted 12 lines · Julia Lawall
Quoted 9 lines · Wolfram Sang

Hi,

so I was trying to convert my spatch from the platform-owner series to a Kernel-cocci with sgen. However, that didn't work and produced a corrupt cocci file (at least the name of the matching rules has been eaten). I used a self-compiled sgen from the Debian rc22. I attach the cocci and config file for easier reproducing. Does the sgen author read the list? Probably it would be easy to fix the broken file, but it seems more sustainable to me to fix the tool :)

Quoted 1 line

Two patches are attached. Apply p1 and then p2.

Yay, this looks a lot better now. Thanks! I applied the output, looks reasonable to me. Do you think it is okay, too? I am not sure about the confidence level. It is a simple patch, so maybe it could be high as well?

Thanks,

Wolfram

===

/// Remove .owner field if calls are used which set it automatically ///
// Confidence: Moderate
// Copyright: (C) 2014 Wolfram Sang. GPL v2.

virtual patch
virtual context
virtual org
virtual report

@match1@
declarer name module_platform_driver;
declarer name module_platform_driver_probe;
identifier __driver;
@@
(

	module_platform_driver(__driver);
|
	module_platform_driver_probe(__driver, ...);

)

@fix1 depends on match1 && patch && !context && !org && !report@ identifier match1.__driver;
@@

	static struct platform_driver __driver = {
		.driver = {
-			.owner = THIS_MODULE,
		}
	};

@match2@
identifier __driver;
@@
(
platform_driver_register(&__driver)
|

	platform_driver_probe(&__driver, ...)
|
	platform_create_bundle(&__driver, ...)

)

@fix2 depends on match2 && patch && !context && !org && !report@ identifier match2.__driver;
@@

	static struct platform_driver __driver = {
		.driver = {
-			.owner = THIS_MODULE,
		}
	};

// ----------------------------------------------------------------------------

@fix1_context depends on match1 && !patch && (context || org || report)@ identifier match1.__driver;
position j0;
@@

* 	static struct platform_driver __driver at j0 = {
		.driver = {
			.owner = THIS_MODULE,
		}
	};

@fix2_context depends on match2 && !patch && (context || org || report)@ identifier match2.__driver;
position j0;
@@

* 	static struct platform_driver __driver at j0 = {
		.driver = {
			.owner = THIS_MODULE,
		}
	};

// ----------------------------------------------------------------------------

@script:python fix1_org depends on org@
j0 << fix1_context.j0;
@@

msg = "No need to set .owner here. The core will do it." coccilib.org.print_todo(j0[0], msg)

@script:python fix2_org depends on org@
j0 << fix2_context.j0;
@@

msg = "No need to set .owner here. The core will do it." coccilib.org.print_todo(j0[0], msg)

// ----------------------------------------------------------------------------

@script:python fix1_report depends on report@
j0 << fix1_context.j0;
@@

msg = "No need to set .owner here. The core will do it." coccilib.report.print_report(j0[0], msg)

@script:python fix2_report depends on report@
j0 << fix2_context.j0;
@@

msg = "No need to set .owner here. The core will do it." coccilib.report.print_report(j0[0], msg)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20141018/ec1384d7/attachment.asc>

#4 lore raw
Quoted 16 lines

@fix1_context depends on match1 && !patch && (context || org || report)@ identifier match1.__driver;
position j0;
@@

* 	static struct platform_driver __driver at j0 = {
		.driver = {
			.owner = THIS_MODULE,
		}
	};

@fix2_context depends on match2 && !patch && (context || org || report)@ identifier match2.__driver;
position j0;
@@

Quoted 5 lines
* 	static struct platform_driver __driver at j0 = {
		.driver = {
			.owner = THIS_MODULE,
		}
	};

In these cases, I think it would look nicer to put the *s and the @j0's on .owner rather than at the start of the structure.

Unless there is some situation in which the transformation is not required, I think High confidence would be appropriate.

julia

#5 lore raw
Quoted 16 lines · Julia Lawall
Quoted 16 lines

@fix1_context depends on match1 && !patch && (context || org || report)@ identifier match1.__driver;
position j0;
@@

* 	static struct platform_driver __driver at j0 = {
		.driver = {
			.owner = THIS_MODULE,
		}
	};

@fix2_context depends on match2 && !patch && (context || org || report)@ identifier match2.__driver;
position j0;
@@

Quoted 8 lines
Quoted 5 lines
* 	static struct platform_driver __driver at j0 = {
		.driver = {
			.owner = THIS_MODULE,
		}
	};

In these cases, I think it would look nicer to put the *s and the @j0's on .owner rather than at the start of the structure.

Is this a manual fix or a fix to sgen?

Quoted 2 lines

Unless there is some situation in which the transformation is not required, I think High confidence would be appropriate.

The calls I check for always set .owner. So it should be 'high', I'd guess. However, if the behavioue of these calls are ever to be changed there is a risk that this spatch gets not updated. More like a general problem, though, which does not really influence the confidence.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20141018/7101dc6f/attachment-0001.asc>

#6 lore raw
Quoted 4 lines
Quoted 2 lines

In these cases, I think it would look nicer to put the *s and the @j0's on .owner rather than at the start of the structure.

Is this a manual fix or a fix to sgen?

I asked Chi whether it could be done automatically, but I would suggest to do it manually for the moment.

Quoted 7 lines
Quoted 2 lines

Unless there is some situation in which the transformation is not required, I think High confidence would be appropriate.

The calls I check for always set .owner. So it should be 'high', I'd guess. However, if the behavioue of these calls are ever to be changed there is a risk that this spatch gets not updated. More like a general problem, though, which does not really influence the confidence.

If there are concerns, you can add the relevant information in the comments at the top.

julia