0001 // SPDX-License-Identifier: GPL-2.0-only
0002 ///
0003 /// Please, don't reintroduce uninitialized_var().
0004 ///
0005 /// From Documentation/process/deprecated.rst,
0006 /// commit 4b19bec97c88 ("docs: deprecated.rst: Add uninitialized_var()"):
0007 /// For any compiler warnings about uninitialized variables, just add
0008 /// an initializer. Using warning-silencing tricks is dangerous as it
0009 /// papers over real bugs (or can in the future), and suppresses unrelated
0010 /// compiler warnings (e.g. "unused variable"). If the compiler thinks it
0011 /// is uninitialized, either simply initialize the variable or make compiler
0012 /// changes. Keep in mind that in most cases, if an initialization is
0013 /// obviously redundant, the compiler's dead-store elimination pass will make
0014 /// sure there are no needless variable writes.
0015 ///
0016 /// Later, commit 3942ea7a10c9 ("deprecated.rst: Remove now removed
0017 /// uninitialized_var") removed this section because all initializations of
0018 /// this kind were cleaned-up from the kernel. This cocci rule checks that
0019 /// the macro is not explicitly or implicitly reintroduced.
0020 ///
0021 // Confidence: High
0022 // Copyright: (C) 2020 Denis Efremov ISPRAS
0023 // Options: --no-includes --include-headers
0024 //
0025
0026 virtual context
0027 virtual report
0028 virtual org
0029
0030 @r@
0031 identifier var;
0032 type T;
0033 position p;
0034 @@
0035
0036 (
0037 * T var =@p var;
0038 |
0039 * T var =@p *(&(var));
0040 |
0041 * var =@p var
0042 |
0043 * var =@p *(&(var))
0044 )
0045
0046 @script:python depends on report@
0047 p << r.p;
0048 @@
0049
0050 coccilib.report.print_report(p[0], "WARNING this kind of initialization is deprecated")
0051
0052 @script:python depends on org@
0053 p << r.p;
0054 @@
0055
0056 coccilib.org.print_todo(p[0], "WARNING this kind of initialization is deprecated")