Bug 2141218

Summary: qemu-kvm build fails with clang 15.0.1 due to false unused variable error
Product: Red Hat Enterprise Linux 9 Reporter: Miroslav Rezanina <mrezanin>
Component: qemu-kvmAssignee: Miroslav Rezanina <mrezanin>
qemu-kvm sub component: General QA Contact: jingzhao <jinzhao>
Status: CLOSED ERRATA Docs Contact:
Severity: urgent    
Priority: unspecified CC: coli, jchecahi, juzhang, mprchlik, sipoyare, virt-maint
Version: 9.2Keywords: Triaged
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: qemu-kvm-7.1.0-5.el9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-05-09 07:20:51 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Brew build log for failed build none

Description Miroslav Rezanina 2022-11-09 07:24:13 UTC
Created attachment 1923290 [details]
Brew build log for failed build

When running qemu-kvm build for RHEL 9.2 using clang 15.0.1, build fails with following error:

../hw/usb/host-libusb.c:1840:9: error: variable 'unconnected' set but not used [-Werror,-Wunused-but-set-variable]
    int unconnected = 0;
        ^
1 error generated.


Checking the source shows that variable is used and this error is false pass. 
Building exactly same code with clang 14.0.6 finished successfully.

Comment 1 Miroslav Rezanina 2022-11-09 08:33:47 UTC
Hit different error on another build:

../qemu-img.c:4925:13: error: variable 'block_count' set but not used [-Werror,-Wunused-but-set-variable]
    int64_t block_count = 0, out_pos, in_pos;
            ^
1 error generated.

Comment 2 Miroslav Rezanina 2022-11-09 08:35:32 UTC
Closer inspection shows that in both cases, variable is used only with ++ operator. Is there any change in logic for unused variables in 15.0.1 that cause this kind of usage is now reported as unused variable?

Comment 3 Tom Stellard 2022-11-09 16:34:06 UTC
(In reply to Miroslav Rezanina from comment #2)
> Closer inspection shows that in both cases, variable is used only with ++
> operator. Is there any change in logic for unused variables in 15.0.1 that
> cause this kind of usage is now reported as unused variable?

Yes, there was an improvement to that diagnostic that caused it to start detecting when the only use was with ++ operator: https://releases.llvm.org/15.0.0/tools/clang/docs/ReleaseNotes.html#improvements-to-clang-s-diagnostics

Do you have a link to the full source file?

Comment 4 Miroslav Rezanina 2022-11-09 16:52:15 UTC
(In reply to Tom Stellard from comment #3)
> (In reply to Miroslav Rezanina from comment #2)
> > Closer inspection shows that in both cases, variable is used only with ++
> > operator. Is there any change in logic for unused variables in 15.0.1 that
> > cause this kind of usage is now reported as unused variable?
> 
> Yes, there was an improvement to that diagnostic that caused it to start
> detecting when the only use was with ++ operator:
> https://releases.llvm.org/15.0.0/tools/clang/docs/ReleaseNotes.
> html#improvements-to-clang-s-diagnostics
> 
> Do you have a link to the full source file?

I miss on original warning that code reading the variable is disabled.

I detected four new places causing this warning and already sent fixes upstream:

https://lists.nongnu.org/archive/html/qemu-devel/2022-11/msg01639.html

You can see the files here:

https://git.qemu.org/?p=qemu.git;a=blob;f=qemu-img.c;h=a3b64c88af0f4fce8da9521206ef6a2302bb80e8;hb=HEAD
https://git.qemu.org/?p=qemu.git;a=blob;f=hw/usb/host-libusb.c;h=28f8af8941ff6db20283fcd85d23da120abc6cee;hb=HEAD
https://git.qemu.org/?p=qemu.git;a=blob;f=hw/net/tulip.c;h=b9e42c322ab1fb92416adfc5fda94a93c77543cf;hb=HEAD
https://git.qemu.org/?p=qemu.git;a=blob;f=hw/net/rtl8139.c;h=6b65823b4bf8cab4e5d208f5abcbbbd4343041d3;hb=HEAD

Comment 5 Miroslav Rezanina 2022-11-10 03:41:52 UTC
As the issue is not on the side of compiler, reassign to qemu-kvm that has to fix this.

Comment 7 Yanan Fu 2022-11-15 12:42:13 UTC
QE bot(pre verify): Set 'Verified:Tested,SanityOnly' as gating/tier1 test pass.

Comment 15 errata-xmlrpc 2023-05-09 07:20:51 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Moderate: qemu-kvm security, bug fix, and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2023:2162