xref: /OK3568_Linux_fs/kernel/scripts/coccinelle/misc/uninitialized_var.cocci (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun// SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun///
3*4882a593Smuzhiyun/// Please, don't reintroduce uninitialized_var().
4*4882a593Smuzhiyun/// From Documentation/process/deprecated.rst:
5*4882a593Smuzhiyun///  For any compiler warnings about uninitialized variables, just add
6*4882a593Smuzhiyun///  an initializer. Using warning-silencing tricks is dangerous as it
7*4882a593Smuzhiyun///  papers over real bugs (or can in the future), and suppresses unrelated
8*4882a593Smuzhiyun///  compiler warnings (e.g. "unused variable"). If the compiler thinks it
9*4882a593Smuzhiyun///  is uninitialized, either simply initialize the variable or make compiler
10*4882a593Smuzhiyun///  changes. Keep in mind that in most cases, if an initialization is
11*4882a593Smuzhiyun///  obviously redundant, the compiler's dead-store elimination pass will make
12*4882a593Smuzhiyun///  sure there are no needless variable writes.
13*4882a593Smuzhiyun///
14*4882a593Smuzhiyun// Confidence: High
15*4882a593Smuzhiyun// Copyright: (C) 2020 Denis Efremov ISPRAS
16*4882a593Smuzhiyun// Options: --no-includes --include-headers
17*4882a593Smuzhiyun//
18*4882a593Smuzhiyun
19*4882a593Smuzhiyunvirtual context
20*4882a593Smuzhiyunvirtual report
21*4882a593Smuzhiyunvirtual org
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun@r@
24*4882a593Smuzhiyunidentifier var;
25*4882a593Smuzhiyuntype T;
26*4882a593Smuzhiyunposition p;
27*4882a593Smuzhiyun@@
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun(
30*4882a593Smuzhiyun* T var =@p var;
31*4882a593Smuzhiyun|
32*4882a593Smuzhiyun* T var =@p *(&(var));
33*4882a593Smuzhiyun|
34*4882a593Smuzhiyun* var =@p var
35*4882a593Smuzhiyun|
36*4882a593Smuzhiyun* var =@p *(&(var))
37*4882a593Smuzhiyun)
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun@script:python depends on report@
40*4882a593Smuzhiyunp << r.p;
41*4882a593Smuzhiyun@@
42*4882a593Smuzhiyun
43*4882a593Smuzhiyuncoccilib.report.print_report(p[0],
44*4882a593Smuzhiyun  "WARNING this kind of initialization is deprecated (https://www.kernel.org/doc/html/latest/process/deprecated.html#uninitialized-var)")
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun@script:python depends on org@
47*4882a593Smuzhiyunp << r.p;
48*4882a593Smuzhiyun@@
49*4882a593Smuzhiyun
50*4882a593Smuzhiyuncoccilib.org.print_todo(p[0],
51*4882a593Smuzhiyun  "WARNING this kind of initialization is deprecated (https://www.kernel.org/doc/html/latest/process/deprecated.html#uninitialized-var)")
52