[llvm-bugs] [Bug 51595] New: -Wunused-but-set-variable fails to see variable is used

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Aug 24 01:18:36 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=51595

            Bug ID: 51595
           Summary: -Wunused-but-set-variable fails to see variable is
                    used
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C
          Assignee: unassignedclangbugs at nondot.org
          Reporter: mprivozn at redhat.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

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:

https://gitlab.com/libvirt/libvirt/-/jobs/1528604467

The corresponding code can be seen here:

https://gitlab.com/libvirt/libvirt/-/blob/master/src/util/viridentity.c#L135

Another location that triggers the warning:

https://gitlab.com/libvirt/libvirt/-/blob/master/src/rpc/virnetclient.c#L883

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210824/014760bc/attachment.html>


More information about the llvm-bugs mailing list