From 9dfa33050b00cf4d5103181ebddc517a2a99d9e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Fri, 6 Dec 2019 13:29:04 +0100 Subject: [PATCH] Add semantic patch to find void f() { ... return ((void)g())); ... } When a function returns void, it can be used as an argument to return in function returning also void, e.g.: void in(void) { return; } void out(void) { return (in()); } while this is legal, it should be rewritten as: void out(void) { in(); return; } The semantic patch just find the occurrences, and they need to be fixed by hand. --- cocci/return-void-from-void.spatch | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 cocci/return-void-from-void.spatch diff --git a/cocci/return-void-from-void.spatch b/cocci/return-void-from-void.spatch new file mode 100644 index 0000000000..fcc639f6ea --- /dev/null +++ b/cocci/return-void-from-void.spatch @@ -0,0 +1,19 @@ +@ rule1 @ +identifier f1; +@@ + +void f1(...) +{ +... +} + +@ rule2 @ +identifier rule1.f1; +identifier f2; +@@ + +void f2(...) { +... +* return(f1(...)); +... +}