1 // SPDX-License-Identifier: GPL-2.0-only 2 /// 3 /// Remove unneeded variable used to store return value. 4 /// 5 // Confidence: Moderate 6 // Copyright: (C) 2012 Peter Senna Tschudin, INRIA/LIP6. 7 // URL: https://coccinelle.gitlabpages.inria.fr/website 8 // Comments: Comments on code can be deleted if near code that is removed. 9 // "when strict" can be removed to get more hits, but adds false 10 // positives 11 // Options: --no-includes --include-headers 12 13 virtual patch 14 virtual report 15 virtual context 16 virtual org 17 18 @depends on patch@ 19 type T; 20 constant C; 21 identifier ret; 22 @@ 23 - T ret = C; 24 ... when != ret 25 when strict 26 return 27 - ret 28 + C 29 ; 30 31 @depends on context@ 32 type T; 33 constant C; 34 identifier ret; 35 @@ 36 * T ret = C; 37 ... when != ret 38 when strict 39 * return ret; 40 41 @r1 depends on report || org@ 42 type T; 43 constant C; 44 identifier ret; 45 position p1, p2; 46 @@ 47 T ret@p1 = C; 48 ... when != ret 49 when strict 50 return ret@p2; 51 52 @script:python depends on report@ 53 p1 << r1.p1; 54 p2 << r1.p2; 55 C << r1.C; 56 ret << r1.ret; 57 @@ 58 coccilib.report.print_report(p1[0], "Unneeded variable: \"" + ret + "\". Return \"" + C + "\" on line " + p2[0].line) 59 60 @script:python depends on org@ 61 p1 << r1.p1; 62 p2 << r1.p2; 63 C << r1.C; 64 ret << r1.ret; 65 @@ 66 cocci.print_main("unneeded \"" + ret + "\" variable", p1) 67 cocci.print_sec("return " + C + " here", p2)
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.