broken comments handling
Hi!
I've found potentialy harmful bug while using spatch, see below.
bug.c:
int a; /* This is comment for a */
int b; /* This is comment for b */
bug.cocci:
@@ @@
-int b;
spatch-23 bug.cocci bug.cinit_defs_builtins: /usr/local/share/coccinelle/standard.h
warning: line 2: should b be a metavariable?
HANDLING: bug.c
tmp/cocci-output-2227-08362d-bug.c renamed from bug.c +1 -2
@@ -1,2 +1 @@ -int a;/* This is comment for a */ -int b;/* This is comment for b */ +int a;/* This is comment for b */
The comment for a is removed and replaced with the comment for b, which may lead to serious confusion.
Signature · 2 lines
Cyril Hrubis chrubis at suse.cz
Quoted 23 lines · Cyril Hrubis
Hi!
I've found potentialy harmful bug while using spatch, see below.
bug.c:
int a; /* This is comment for a */
int b; /* This is comment for b */
bug.cocci:
@@ @@
-int b;spatch-23
bug.coccibug.cinit_defs_builtins:/usr/local/share/coccinelle/standard.h
warning: line 2: should b be a metavariable?
HANDLING:bug.c
diff =tmp/cocci-output-2227-08362d-bug.c renamed from bug.c +1
-2@@ -1,2 +1 @@ -int a;/* This is comment for a */ -int b;/* This is comment for b */ +int a;/* This is comment for b */
Quoted 2 lines
The comment for a is removed and replaced with the comment for b, which may lead to serious confusion.
Thanks.
I would have expected that both comments would stay. I will look into it. Thanks for the report.
julia
Hi!
Quoted 7 lines
Quoted 2 lines
The comment for a is removed and replaced with the comment for b, which may lead to serious confusion.
Thanks.
I would have expected that both comments would stay. I will look into it. Thanks for the report.
In this case removing the comment for the removed variable makes more sense to me.
Signature · 2 lines
Cyril Hrubis chrubis at suse.cz
Quoted 11 lines · Cyril Hrubis
Hi!
Quoted 7 lines
Quoted 2 lines
The comment for a is removed and replaced with the comment for b, which may lead to serious confusion.
Thanks.
I would have expected that both comments would stay. I will look into it. Thanks for the report.
In this case removing the comment for the removed variable makes more sense to me.
Sure but Coccinelle is not always that clever...
julia
[Cocci] Source code adjustments together with comments?
In reply to Cyril HrubisQuoted 5 lines
Quoted 2 lines
I would have expected that both comments would stay. I will look into it. Thanks for the report.
In this case removing the comment for the removed variable makes more sense to me.
Would you like to be more explicit in the semantic patch language around source code adjustments which should also affect corresponding comments?
Regards,
Markus
[Cocci] Source code adjustments together with comments?
Quoted 9 lines · SF Markus Elfring
Quoted 5 lines
Quoted 2 lines
I would have expected that both comments would stay. I will look into it. Thanks for the report.
In this case removing the comment for the removed variable makes more sense to me.
Would you like to be more explicit in the semantic patch language around source code adjustments which should also affect corresponding comments?
It seems complicated, and people don't always follow the same comventions.
Probably it is thinking that the code looks like this:
/*some comment on b */
int b;
I could change it so that this strategy is only followed if /*some comment on b */ starts at the beginning of the line.
julia
[Cocci] Source code adjustments together with comments?
Hi!
Quoted 10 lines
Quoted 3 lines
Would you like to be more explicit in the semantic patch language around source code adjustments which should also affect corresponding comments?
It seems complicated, and people don't always follow the same comventions.
Probably it is thinking that the code looks like this:
/*some comment on b */
int b;
That explains it.
Quoted 2 lines
I could change it so that this strategy is only followed if /*some comment on b */ starts at the beginning of the line.
That sounds good. What would be the strategy for the other case then?
Signature · 2 lines
Cyril Hrubis chrubis at suse.cz
[Cocci] Source code adjustments together with comments?
Quoted 4 lines
Quoted 2 lines
I could change it so that this strategy is only followed if /*some comment on b */ starts at the beginning of the line.
That sounds good. What would be the strategy for the other case then?
I expect that you will end up with both comments. Perhaps it could be possible to detect that the remaining line only contains a comment and delete that. I guess that would be better.
julia
[Cocci] Source code adjustments together with comments?
In reply to Cyril HrubisQuoted 12 lines · Cyril Hrubis
Hi!
Quoted 10 lines
Quoted 3 lines
Would you like to be more explicit in the semantic patch language around source code adjustments which should also affect corresponding comments?
It seems complicated, and people don't always follow the same comventions.
Probably it is thinking that the code looks like this:
/*some comment on b */
int b;
Quoted 6 lines
That explains it.
Quoted 2 lines
I could change it so that this strategy is only followed if /*some comment on b */ starts at the beginning of the line.
That sounds good. What would be the strategy for the other case then?
It seems to be a reasonable heuristic that a comment beginning on a line which also contains code is attached to that code, while a comment beginning on a line by itself is attached to the following code (whether that means one or more lines of code is of course impossible to guess).
So, in the former case, if the code is simply removed, the comment should also vanish. But what if the semantic patch contains + code? Something like
- int hash;
+ unsigned int hash;
In that case, it's probably best to leave the comment. But one can probably always find examples where whatever coccinelle does, something else would have been better. For example, if the comment should stay but needs rewording, good luck teaching any computer program to do that.
In short, nothing can save one from doing a manual review of the generated patch, especially when comments are involved.
Rasmus
[Cocci] Source code adjustments together with comments?
Quoted 33 lines · Rasmus Villemoes
Quoted 12 lines · Cyril Hrubis
Hi!
Quoted 10 lines
Quoted 3 lines
Would you like to be more explicit in the semantic patch language around source code adjustments which should also affect corresponding comments?
It seems complicated, and people don't always follow the same comventions.
Probably it is thinking that the code looks like this:
/*some comment on b */
int b;Quoted 6 lines
That explains it.
Quoted 2 lines
I could change it so that this strategy is only followed if /*some comment on b */ starts at the beginning of the line.
That sounds good. What would be the strategy for the other case then?
It seems to be a reasonable heuristic that a comment beginning on a line which also contains code is attached to that code, while a comment beginning on a line by itself is attached to the following code (whether that means one or more lines of code is of course impossible to guess).
So, in the former case, if the code is simply removed, the comment should also vanish. But what if the semantic patch contains + code? Something like
- int hash;
+ unsigned int hash;
Quoted 7 lines
In that case, it's probably best to leave the comment. But one can probably always find examples where whatever coccinelle does, something else would have been better. For example, if the comment should stay but needs rewording, good luck teaching any computer program to do that.
In short, nothing can save one from doing a manual review of the generated patch, especially when comments are involved.
I agree. But I also agree with Cyril that the current situation is not desirable, because the result is quite confusing.
julia
[Cocci] Source code adjustments together with comments?
In reply to SF Markus ElfringHi!
Quoted 6 lines
Quoted 2 lines
In this case removing the comment for the removed variable makes more sense to me.
Would you like to be more explicit in the semantic patch language around source code adjustments which should also affect corresponding comments?
I would rather see it work right (tm). The thing is that I do not use the tool that often. It comes very handy in large scale fixes and cleanups but the more complicated the patch language is the the higher is the bar for actual usage.
I wouldn't mind having more options but I doubt I would need these. And the tool should, in my opinion, do what is the most reasonable action by default.
Signature · 2 lines
Cyril Hrubis chrubis at suse.cz
[Cocci] Source code adjustments together with comments?
Quoted 2 lines
And the tool should, in my opinion, do what is the most reasonable action by default.
I guess that there are some software development challenges for further considerations.
Which rules do you use for the connection of a specific amount of comments to statements in other source code places?
Would you like to express any preferences for consistent software builds?
Regards,
Markus
[Cocci] Source code adjustments together with comments?
Hi!
Quoted 5 lines
Quoted 2 lines
And the tool should, in my opinion, do what is the most reasonable action by default.
I guess that there are some software development challenges for further considerations.
Indeed, unfortunatelly I do not expect this to be solved without some trial and error.
Quoted 2 lines
Which rules do you use for the connection of a specific amount of comments to statements in other source code places?
I may see this overly simplistic but there are two types of comment in common use. Comments on a separate line(s) that most of the time belongs to the closest code block. Then there are comments that continue after the semicolon to the end of the line and these to belong to the same line as the code beforehand. There may be far more strange special cases, but for 99% of situations these two classes should work. But as I said I do not expect this to be solved without some trial and error.
Signature · 2 lines
Cyril Hrubis chrubis at suse.cz