macro parsing issue?
Hi,
So I was trying to do something (related to locking, changes in Linux net/mac80211/debugfs_sta.c, in sta_agg_status_write), but it looks like spatch doesn't parse the entire file correctly?
Here's a simplified test that should work on the current upstream version:
@test@
identifier fn =~ "sta_agg_status_write";
type t;
@@
t fn(...)
{
...
}
@@
identifier test.fn;
type test.t;
expression pos, exp;
identifier ret;
@@
t fn(...)
{
...
(
+#if SOMETHING
ret = strsep(pos, exp);
+#endif
)
...
}
It does nothing, but seems like it should? It ends up skipping that entire function, I think, because of parsing issues with the STA_FILE() or STA_OPS_RW() macros?
I've patched it regularly for now, which is fine too. So this is more FYI.
johannes
Quoted 32 lines · Johannes Berg
Hi,
So I was trying to do something (related to locking, changes in Linux
net/mac80211/debugfs_sta.c, insta_agg_status_write), but it looks like spatch doesn't parse the entire file correctly?Here's a simplified test that should work on the current upstream version:
@test@
identifier fn =~ "sta_agg_status_write";
type t;
@@
t fn(...)
{
...
}@@
identifier test.fn;
type test.t;
expression pos, exp;
identifier ret;
@@
t fn(...)
{
...
((quoted diff) +2
-0+#if SOMETHING ret = strsep(pos, exp); +#endif
Quoted 3 lines
)
...
}
The code parses fine. The problem is that ... requires that the pattern before and after the ... is not matched in the ... region. You probably just want all calls to be modified whereever they occur, so you would want <... ...>.
You don't actually need two separate rules for what you are showing, but perhaps that is an artifact of the simplification process.
julia
Quoted 12 lines
It does nothing, but seems like it should? It ends up skipping that entire function, I think, because of parsing issues with the
STA_FILE()orSTA_OPS_RW()macros?I've patched it regularly for now, which is fine too. So this is more FYI.
johannes
Quoted 13 lines · Julia Lawall
Quoted 13 lines
@@
identifier test.fn;
type test.t;
expression pos, exp;
identifier ret;
@@
t fn(...)
{
...
((quoted diff) +2
-0+#if SOMETHING ret = strsep(pos, exp); +#endif
Quoted 8 lines
Quoted 3 lines
)
...
}The code parses fine. The problem is that ... requires that the pattern before and after the ... is not matched in the ... region. You probably just want all calls to be modified whereever they occur, so you would want <... ...>.
Hm, yes, I think I want <... ...>, I can never remember this properly and erroneously tried <+... ...+> and ended up with this ... oops.
Still though, getting verbose output shows it's mismatching some macros?
ERROR-RECOV: found sync end of #define, line 37
parsing pass2: try again
ERROR-RECOV: found sync end of #define, line 37
parse error
= File "net/mac80211/debugfs_sta.c", line 37, column 1, charpos = 1146
around = '',
whole content = }
badcount: 7
bad: #define STA_READ_D(name, field) STA_READ(name, field, "%d\n") bad:
bad: #define STA_OPS(name) \
bad: static const struct file_operations sta_ ##name## _ops = { \
bad: .read = sta_##name##_read, \
bad: .open = simple_open, \
bad: .llseek = generic_file_llseek, \
BAD:!!!!! }
ERROR-RECOV: found sync end of #define, line 45
parsing pass2: try again
ERROR-RECOV: found sync end of #define, line 45
parse error
= File "net/mac80211/debugfs_sta.c", line 45, column 1, charpos = 1380
around = '',
whole content = }
badcount: 8
bad: }
bad:
bad: #define STA_OPS_RW(name) \
bad: static const struct file_operations sta_ ##name## _ops = { \
bad: .read = sta_##name##_read, \
bad: .write = sta_##name##_write, \
bad: .open = simple_open, \
bad: .llseek = generic_file_llseek, \
BAD:!!!!! }
ERROR-RECOV: found sync end of #define, line 49
parsing pass2: try again
ERROR-RECOV: found sync end of #define, line 49
parse error
= File "net/mac80211/debugfs_sta.c", line 49, column 2, charpos = 1466
around = 'STA_OPS',
whole content = STA_OPS(name)
badcount: 4
bad: }
bad:
bad: #define STA_FILE(name, field, format) \
bad: STA_READ_##format(name, field) \
BAD:!!!!! STA_OPS(name)
ERROR-RECOV: found sync '}' at line 84
ERROR-RECOV: found sync bis, eating } and ;
parsing pass2: try again
(ONCE) CPP-DEFINE: inside function, I treat it as comment (ONCE) CPP-UNDEF: inside function, I treat it as comment
ERROR-RECOV: found sync end of #define, line 447
parsing pass2: try again
ERROR-RECOV: found sync end of #define, line 447
parse error
= File "net/mac80211/debugfs_sta.c", line 447, column 1, charpos = 12210
around = '',
whole content = }
badcount: 8
bad: STA_OPS_RW(agg_status);
bad:
bad: /* link sta attributes */
bad: #define LINK_STA_OPS(name) \
bad: static const struct file_operations link_sta_ ##name## _ops = { \
bad: .read = link_sta_##name##_read, \
bad: .open = simple_open, \
bad: .llseek = generic_file_llseek, \
BAD:!!!!! }
(though with 1.1.1)
I had interpreted that as it getting confused about the macro layout in the file ... sounds like that was wrong!
Quoted 2 lines
You don't actually need two separate rules for what you are showing, but perhaps that is an artifact of the simplification process.
Indeed, the =~ line was much more complex, and I needed two modification rules, and didn't want to duplicate the =~ line.
johannes
Quoted 23 lines · Johannes Berg
Quoted 13 lines · Julia Lawall
Quoted 13 lines
@@
identifier test.fn;
type test.t;
expression pos, exp;
identifier ret;
@@
t fn(...)
{
...
((quoted diff) +2
-0+#if SOMETHING ret = strsep(pos, exp); +#endifQuoted 8 lines
Quoted 3 lines
)
...
}The code parses fine. The problem is that ... requires that the pattern before and after the ... is not matched in the ... region. You probably just want all calls to be modified whereever they occur, so you would want <... ...>.
Quoted 4 lines
Hm, yes, I think I want <... ...>, I can never remember this properly and erroneously tried <+... ...+> and ended up with this ... oops.
Still though, getting verbose output shows it's mismatching some macros?
True, but that just affects the macro definitions, but not your change. There isn't a BAD or bad in front of any function code. BAD or bad lines are not getting processed.
julia
Quoted 85 lines
ERROR-RECOV: found sync end of #define, line 37
parsing pass2: try again
ERROR-RECOV: found sync end of #define, line 37
parse error
= File "net/mac80211/debugfs_sta.c", line 37, column 1, charpos = 1146
around = '',
whole content = }
badcount: 7
bad: #defineSTA_READ_D(name, field)STA_READ(name, field, "%d\n")bad:
bad: #defineSTA_OPS(name)\
bad: static const structfile_operationssta_##name##_ops= { \
bad: .read = sta_##name##_read, \
bad: .open =simple_open, \
bad: .llseek =generic_file_llseek, \
BAD:!!!!! }
ERROR-RECOV: found sync end of #define, line 45
parsing pass2: try again
ERROR-RECOV: found sync end of #define, line 45
parse error
= File "net/mac80211/debugfs_sta.c", line 45, column 1, charpos = 1380
around = '',
whole content = }
badcount: 8
bad: }
bad:
bad: #defineSTA_OPS_RW(name)\
bad: static const structfile_operationssta_##name##_ops= { \
bad: .read = sta_##name##_read, \
bad: .write = sta_##name##_write, \
bad: .open =simple_open, \
bad: .llseek =generic_file_llseek, \
BAD:!!!!! }
ERROR-RECOV: found sync end of #define, line 49
parsing pass2: try again
ERROR-RECOV: found sync end of #define, line 49
parse error
= File "net/mac80211/debugfs_sta.c", line 49, column 2, charpos = 1466
around = 'STA_OPS',
whole content =STA_OPS(name)
badcount: 4
bad: }
bad:
bad: #defineSTA_FILE(name, field, format)\
bad: STA_READ_##format(name, field) \
BAD:!!!!!STA_OPS(name)
ERROR-RECOV: found sync '}' at line 84
ERROR-RECOV: found sync bis, eating } and ;
parsing pass2: try again
(ONCE) CPP-DEFINE: inside function, I treat it as comment (ONCE) CPP-UNDEF: inside function, I treat it as comment
ERROR-RECOV: found sync end of #define, line 447
parsing pass2: try again
ERROR-RECOV: found sync end of #define, line 447
parse error
= File "net/mac80211/debugfs_sta.c", line 447, column 1, charpos = 12210
around = '',
whole content = }
badcount: 8
bad:STA_OPS_RW(agg_status);
bad:
bad: /* link sta attributes */
bad: #defineLINK_STA_OPS(name)\
bad: static const structfile_operationslink_sta_##name##_ops= { \
bad: .read = link_sta_##name##_read, \
bad: .open =simple_open, \
bad: .llseek =generic_file_llseek, \
BAD:!!!!! }(though with 1.1.1)
I had interpreted that as it getting confused about the macro layout in the file ... sounds like that was wrong!
Quoted 2 lines
You don't actually need two separate rules for what you are showing, but perhaps that is an artifact of the simplification process.
Indeed, the =~ line was much more complex, and I needed two modification rules, and didn't want to duplicate the =~ line.
johannes
Quoted 5 lines · Julia Lawall
Quoted 1 line
Still though, getting verbose output shows it's mismatching some macros?
True, but that just affects the macro definitions, but not your change. There isn't a BAD or bad in front of any function code. BAD or bad lines are not getting processed.
OK. Didn't know that was line-dependent.
I think what threw me off was the "found sync end of #define".
Either way, thanks a lot!
johannes
Quoted 1 line
I think what threw me off was the "found sync end of #define".
I imagine that better explanations will become more helpful also for such special data output.
Another example:
--parse-c output
2021-06-06
https://gitlab.inria.fr/coccinelle/coccinelle/-/issues/26
The Coccinelle software tends to operate on control flow graphs. How good does preprocessor code fit into applied abstraction levels?
https://en.cppreference.com/w/c/language/translation_phases
Regards,
Markus