Discussion:
[Cocci] check for non-const arguments used only as const accesses
Julia Lawall
2018-06-11 21:23:30 UTC
Permalink
Many times it would be useful to update functions
where non-const arguments are used only as const
dereferences or as arguments to other function that
use const.
Is it possible for coccinelle to find and show
these types of uses that could be const?
Yes, it's possible. It's a bit complex because the use is often inter
procedural. I made a semantic patch for it, but I didn't invest a lot of
time in it because I wasn't sure if it would be considered to be useful,
or just useless churn.

julia
e.g.
int foo(int val, u8 *a, int index)
{
return val + a[index];
}
where a is indexed but not modified
and could be declared const u8 *a
or
void foo(char *a, char *b)
{
strcpy(a, b);
}
where the 2nd arg to foo could or should
be const char *b
Joe Perches
2018-06-12 00:09:10 UTC
Permalink
Post by Julia Lawall
Many times it would be useful to update functions
where non-const arguments are used only as const
dereferences or as arguments to other function that
use const.
Is it possible for coccinelle to find and show
these types of uses that could be const?
Yes, it's possible. It's a bit complex because the use is often inter
procedural. I made a semantic patch for it, but I didn't invest a lot of
time in it because I wasn't sure if it would be considered to be useful,
or just useless churn.
I believe such a patch would not be useless as
it allows conversion of structures and arrays
that are currently placed into r/w memory (data)
to be moved to const (text).
Julia Lawall
2018-06-12 05:29:59 UTC
Permalink
Post by Joe Perches
Post by Julia Lawall
Many times it would be useful to update functions
where non-const arguments are used only as const
dereferences or as arguments to other function that
use const.
Is it possible for coccinelle to find and show
these types of uses that could be const?
Yes, it's possible. It's a bit complex because the use is often inter
procedural. I made a semantic patch for it, but I didn't invest a lot of
time in it because I wasn't sure if it would be considered to be useful,
or just useless churn.
I believe such a patch would not be useless as
it allows conversion of structures and arrays
that are currently placed into r/w memory (data)
to be moved to const (text).
I guess that for such a patch to be accepted, one would have to show that
it does permit that.

julia

Loading...