<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 - -Wunused-but-set-variable fails to see variable is used"
   href="https://bugs.llvm.org/show_bug.cgi?id=51595">51595</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>-Wunused-but-set-variable fails to see variable is used
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Linux
          </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>mprivozn@redhat.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>I've updated my Rawhide and as a result clang-13.0.0~rc1-1.fc35.x86_64 was
installed. But that version broke build of libvirt. In libvirt we use glib and
its g_autoptr() and g_autofree to automatically free memory when variable goes
out of scope. An example of failure can be seen in our CI:

<a href="https://gitlab.com/libvirt/libvirt/-/jobs/1528604467">https://gitlab.com/libvirt/libvirt/-/jobs/1528604467</a>

The corresponding code can be seen here:

<a href="https://gitlab.com/libvirt/libvirt/-/blob/master/src/util/viridentity.c#L135">https://gitlab.com/libvirt/libvirt/-/blob/master/src/util/viridentity.c#L135</a>

Another location that triggers the warning:

<a href="https://gitlab.com/libvirt/libvirt/-/blob/master/src/rpc/virnetclient.c#L883">https://gitlab.com/libvirt/libvirt/-/blob/master/src/rpc/virnetclient.c#L883</a>

The code can be simplified to the following:

// clang $(pkg-config --cflags --libs glib-2.0) -Wunused-but-set-variable
repro.c -o repro
#include <glib.h>

int main(int argc, char *argv[])
{
    g_autoptr(GSource) source = NULL;

    source = g_source_new(NULL, 0);
}

I don't think that the warning should be emitted in this case, because the
variable is actually used - in the cleanup function. Please note that this
scenario is different to plain: g_autoptr(GSource) source = NULL;  (that is
leaving the g_source_new() line out) in which case the warning is warranted.</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>