<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Poor fixit suggestion for an uninitialized then dereferenced pointer"
   href="https://bugs.llvm.org/show_bug.cgi?id=52559">52559</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Poor fixit suggestion for an uninitialized then dereferenced pointer
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>natechancellor@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Initially reported at
<a href="https://lore.kernel.org/r/YZdhYEVCgqh5MB3J@smile.fi.intel.com/">https://lore.kernel.org/r/YZdhYEVCgqh5MB3J@smile.fi.intel.com/</a>.

Reproducer: <a href="https://godbolt.org/z/EcPP7o1T9">https://godbolt.org/z/EcPP7o1T9</a>

$ cat test.c
#define NULL ((void *)0)

struct foo {
        int x;
};

void bar(void) {
        struct foo *a;
        a->x = 1;
}

$ gcc --version
gcc (GCC) 11.1.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ gcc -Wuninitialized -c -o /dev/null test.c
test.c: In function ‘bar’:
test.c:9:14: warning: ‘a’ is used uninitialized [-Wuninitialized]
    9 |         a->x = 1;
      |         ~~~~~^~~

$ clang --version
clang version 13.0.0
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/sbin

$ clang -fsyntax-only -Wuninitialized test.c
test.c:9:2: warning: variable 'a' is uninitialized when used here
[-Wuninitialized]
        a->x = 1;
        ^
test.c:8:15: note: initialize the variable 'a' to silence this warning
        struct foo *a;
                     ^
                      = NULL
1 warning generated.

This seems like a poor suggestion, as it is going to just result in the user's
program crashing (it probably already will but the hint does nothing to improve
that). Perhaps it should be omitted if the pointer is dereferenced (or just
altogether, since it is likely that a pointer is going to be dereferenced at
some point in its lifetime)? Having the location of the variable is helpful in
the warning but I think emitting the '= NULL' part of it is not helpful.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>