xref: /linux/scripts/coccinelle/misc/uninitialized_var.cocci (revision 762f99f4f3cb41a775b5157dd761217beba65873)
17c9dc603SDenis Efremov// SPDX-License-Identifier: GPL-2.0-only
27c9dc603SDenis Efremov///
37c9dc603SDenis Efremov/// Please, don't reintroduce uninitialized_var().
4*cb62732dSDenis Efremov///
5*cb62732dSDenis Efremov/// From Documentation/process/deprecated.rst,
6*cb62732dSDenis Efremov/// commit 4b19bec97c88 ("docs: deprecated.rst: Add uninitialized_var()"):
77c9dc603SDenis Efremov///  For any compiler warnings about uninitialized variables, just add
87c9dc603SDenis Efremov///  an initializer. Using warning-silencing tricks is dangerous as it
97c9dc603SDenis Efremov///  papers over real bugs (or can in the future), and suppresses unrelated
107c9dc603SDenis Efremov///  compiler warnings (e.g. "unused variable"). If the compiler thinks it
117c9dc603SDenis Efremov///  is uninitialized, either simply initialize the variable or make compiler
127c9dc603SDenis Efremov///  changes. Keep in mind that in most cases, if an initialization is
137c9dc603SDenis Efremov///  obviously redundant, the compiler's dead-store elimination pass will make
147c9dc603SDenis Efremov///  sure there are no needless variable writes.
157c9dc603SDenis Efremov///
16*cb62732dSDenis Efremov/// Later, commit 3942ea7a10c9 ("deprecated.rst: Remove now removed
17*cb62732dSDenis Efremov/// uninitialized_var") removed this section because all initializations of
18*cb62732dSDenis Efremov/// this kind were cleaned-up from the kernel. This cocci rule checks that
19*cb62732dSDenis Efremov/// the macro is not explicitly or implicitly reintroduced.
20*cb62732dSDenis Efremov///
217c9dc603SDenis Efremov// Confidence: High
227c9dc603SDenis Efremov// Copyright: (C) 2020 Denis Efremov ISPRAS
237c9dc603SDenis Efremov// Options: --no-includes --include-headers
247c9dc603SDenis Efremov//
257c9dc603SDenis Efremov
267c9dc603SDenis Efremovvirtual context
277c9dc603SDenis Efremovvirtual report
287c9dc603SDenis Efremovvirtual org
297c9dc603SDenis Efremov
307c9dc603SDenis Efremov@r@
317c9dc603SDenis Efremovidentifier var;
327c9dc603SDenis Efremovtype T;
337c9dc603SDenis Efremovposition p;
347c9dc603SDenis Efremov@@
357c9dc603SDenis Efremov
367c9dc603SDenis Efremov(
377c9dc603SDenis Efremov* T var =@p var;
387c9dc603SDenis Efremov|
397c9dc603SDenis Efremov* T var =@p *(&(var));
407c9dc603SDenis Efremov|
417c9dc603SDenis Efremov* var =@p var
427c9dc603SDenis Efremov|
437c9dc603SDenis Efremov* var =@p *(&(var))
447c9dc603SDenis Efremov)
457c9dc603SDenis Efremov
467c9dc603SDenis Efremov@script:python depends on report@
477c9dc603SDenis Efremovp << r.p;
487c9dc603SDenis Efremov@@
497c9dc603SDenis Efremov
50*cb62732dSDenis Efremovcoccilib.report.print_report(p[0], "WARNING this kind of initialization is deprecated")
517c9dc603SDenis Efremov
527c9dc603SDenis Efremov@script:python depends on org@
537c9dc603SDenis Efremovp << r.p;
547c9dc603SDenis Efremov@@
557c9dc603SDenis Efremov
56*cb62732dSDenis Efremovcoccilib.org.print_todo(p[0], "WARNING this kind of initialization is deprecated")
57