All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cocci] Matching functions with attributes
@ 2015-01-21 14:05 Eliseo Martínez
  2015-01-21 16:15 ` SF Markus Elfring
  2015-01-27 19:01 ` [Cocci] Matching functions with attributes Julia Lawall
  0 siblings, 2 replies; 21+ messages in thread
From: Eliseo Martínez @ 2015-01-21 14:05 UTC (permalink / raw)
  To: cocci

Hi, 

>From what I?ve read, I understand attributes are not supported by coccinelle.
But I?m still wondering it there would be a way to perform a task I?d like to do: Checking whether functions marked as returning non-null are used in any place so that return value is checked for nullness/nonnullness.
So, this breaks into 2 subproblems:

1) Matching desired functions.

I know I can?t directly match functions having certain attributes.
But we don?t use attributes directly. We use some macros for that.
So, all functions I?d like to pick include the macro FUNC_ATTR_NONNULL_RET in their declaration/definition.
Then, would there be any way to match functions having the literal ?FUNC_ATTR_NONNULL_RET? in their declaration/definition?

2) Applying some rules for the same set of functions.

Up until now, I?ve done this by manually obtaining the list of desired functions, and then running this spatch:

```
@@ identifier func =~ "^(transstr|list_alloc|listitem_alloc|dict_alloc|dictitem_alloc|dictitem_copy|vim_strsave_fnameescape|ga_concat_strings|enc_canonize|reverse_text|get_tv_string|get_tv_string_buf|viminfo_readstring|ga_concat_strings_sep|xmalloc|xcalloc|xrealloc|xmallocz|xmemdupz|xstrchrnul|xmemscan|xstpcpy|xstpncpy|xstrdup|xstrndup|xmemdup|msg_show_console_dialog|home_replace_save|get_register|invocation_path_tail|concat_fnames|save_absolute_path|getroom|vim_strsave|vim_strnsave|vim_strsave_escaped|vim_strsave_escaped_ext|vim_strsave_shellescape|vim_strsave_up|vim_strnsave_up|strup_save|concat_str)$"; statement S; @@

(
* if (func(...) == NULL) S;
|
* if (func(...) != NULL) S;
)

@@ identifier func =~ "^(transstr|list_alloc|listitem_alloc|dict_alloc|dictitem_alloc|dictitem_copy|vim_strsave_fnameescape|ga_concat_strings|enc_canonize|reverse_text|get_tv_string|get_tv_string_buf|viminfo_readstring|ga_concat_strings_sep|xmalloc|xcalloc|xrealloc|xmallocz|xmemdupz|xstrchrnul|xmemscan|xstpcpy|xstpncpy|xstrdup|xstrndup|xmemdup|msg_show_console_dialog|home_replace_save|get_register|invocation_path_tail|concat_fnames|save_absolute_path|getroom|vim_strsave|vim_strnsave|vim_strsave_escaped|vim_strsave_escaped_ext|vim_strsave_shellescape|vim_strsave_up|vim_strnsave_up|strup_save|concat_str)$"; identifier var; statement S; expression E; @@

  var = func(...);
  ... when != var = E
(
* if (var == NULL) S;
|
* if (var != NULL) S;
)
```

As you see, I have to replicate the list. Is there any better way to achieve the same effect?

Thanks in advance.
Eliseo.

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2015-01-27 19:01 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-21 14:05 [Cocci] Matching functions with attributes Eliseo Martínez
2015-01-21 16:15 ` SF Markus Elfring
2015-01-21 17:28   ` Eliseo Martínez
2015-01-21 18:03     ` SF Markus Elfring
2015-01-21 21:36       ` Eliseo Martínez
2015-01-21 21:46     ` Julia Lawall
2015-01-21 22:47       ` Eliseo Martínez
2015-01-22  5:58         ` Julia Lawall
2015-01-22  8:45         ` SF Markus Elfring
2015-01-22  8:59         ` SF Markus Elfring
2015-01-22  9:23           ` Eliseo Martínez
2015-01-22  9:36             ` Eliseo Martínez
2015-01-22 10:11               ` SF Markus Elfring
2015-01-22 11:52             ` Julia Lawall
2015-01-22 12:56               ` Eliseo Martínez
2015-01-22 14:44                 ` Julia Lawall
2015-01-22 15:28                 ` SF Markus Elfring
2015-01-22  8:29       ` [Cocci] Run time differences between SmPL disjunctions and regular expressions (in constraints) SF Markus Elfring
2015-01-22  8:37         ` Julia Lawall
2015-01-22  9:50           ` SF Markus Elfring
2015-01-27 19:01 ` [Cocci] Matching functions with attributes Julia Lawall

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.