[libvirt] [PATCH] util: clang is failing due to unused variables.

Julio Faracco posted 1 patch 5 years, 8 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20180727205042.30278-1-jcfaracco@gmail.com
Test syntax-check passed
src/util/virmdev.c      | 3 ++-
src/util/virscsivhost.c | 3 ++-
src/util/virusb.c       | 3 ++-
3 files changed, 6 insertions(+), 3 deletions(-)
[libvirt] [PATCH] util: clang is failing due to unused variables.
Posted by Julio Faracco 5 years, 8 months ago
After some recent patches, clang is throwing some errors related to
unused variables. This is not happening when we use GCC with -Werror
enabled. Only clang reports this warning.

make[3]: Entering directory '/home/julio/Desktop/virt/libvirt/src'
  CC       util/libvirt_util_la-virscsivhost.lo
  CC       util/libvirt_util_la-virusb.lo
  CC       util/libvirt_util_la-virmdev.lo
util/virmdev.c:373:36: error: unused variable 'ret' [-Werror,-Wunused-variable]
    VIR_AUTOPTR(virMediatedDevice) ret = virMediatedDeviceListSteal(list, dev);
                                   ^
1 error generated.
Makefile:11579: recipe for target 'util/libvirt_util_la-virmdev.lo' failed
make[3]: *** [util/libvirt_util_la-virmdev.lo] Error 1
make[3]: *** Waiting for unfinished jobs....
util/virscsivhost.c:112:37: error: unused variable 'tmp' [-Werror,-Wunused-variable]
    VIR_AUTOPTR(virSCSIVHostDevice) tmp = virSCSIVHostDeviceListSteal(list, dev);
                                    ^
1 error generated.
Makefile:11411: recipe for target 'util/libvirt_util_la-virscsivhost.lo' failed
make[3]: *** [util/libvirt_util_la-virscsivhost.lo] Error 1
util/virusb.c:511:31: error: unused variable 'ret' [-Werror,-Wunused-variable]
    VIR_AUTOPTR(virUSBDevice) ret = virUSBDeviceListSteal(list, dev);

Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
---
 src/util/virmdev.c      | 3 ++-
 src/util/virscsivhost.c | 3 ++-
 src/util/virusb.c       | 3 ++-
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/util/virmdev.c b/src/util/virmdev.c
index 4050835cc1..63df4e40d8 100644
--- a/src/util/virmdev.c
+++ b/src/util/virmdev.c
@@ -370,7 +370,8 @@ void
 virMediatedDeviceListDel(virMediatedDeviceListPtr list,
                          virMediatedDevicePtr dev)
 {
-    VIR_AUTOPTR(virMediatedDevice) ret = virMediatedDeviceListSteal(list, dev);
+    VIR_AUTOPTR(virMediatedDevice) ret ATTRIBUTE_UNUSED
+            = virMediatedDeviceListSteal(list, dev);
 }
 
 
diff --git a/src/util/virscsivhost.c b/src/util/virscsivhost.c
index 280d0dc2fd..e07cd46ba9 100644
--- a/src/util/virscsivhost.c
+++ b/src/util/virscsivhost.c
@@ -109,7 +109,8 @@ void
 virSCSIVHostDeviceListDel(virSCSIVHostDeviceListPtr list,
                           virSCSIVHostDevicePtr dev)
 {
-    VIR_AUTOPTR(virSCSIVHostDevice) tmp = virSCSIVHostDeviceListSteal(list, dev);
+    VIR_AUTOPTR(virSCSIVHostDevice) tmp ATTRIBUTE_UNUSED
+            = virSCSIVHostDeviceListSteal(list, dev);
 }
 
 
diff --git a/src/util/virusb.c b/src/util/virusb.c
index 609d54836f..73a1041097 100644
--- a/src/util/virusb.c
+++ b/src/util/virusb.c
@@ -508,7 +508,8 @@ void
 virUSBDeviceListDel(virUSBDeviceListPtr list,
                     virUSBDevicePtr dev)
 {
-    VIR_AUTOPTR(virUSBDevice) ret = virUSBDeviceListSteal(list, dev);
+    VIR_AUTOPTR(virUSBDevice) ret ATTRIBUTE_UNUSED
+            = virUSBDeviceListSteal(list, dev);
 }
 
 virUSBDevicePtr
-- 
2.17.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] util: clang is failing due to unused variables.
Posted by John Ferlan 5 years, 8 months ago

On 07/27/2018 04:50 PM, Julio Faracco wrote:
> After some recent patches, clang is throwing some errors related to
> unused variables. This is not happening when we use GCC with -Werror
> enabled. Only clang reports this warning.
> 
> make[3]: Entering directory '/home/julio/Desktop/virt/libvirt/src'
>   CC       util/libvirt_util_la-virscsivhost.lo
>   CC       util/libvirt_util_la-virusb.lo
>   CC       util/libvirt_util_la-virmdev.lo
> util/virmdev.c:373:36: error: unused variable 'ret' [-Werror,-Wunused-variable]
>     VIR_AUTOPTR(virMediatedDevice) ret = virMediatedDeviceListSteal(list, dev);
>                                    ^
> 1 error generated.
> Makefile:11579: recipe for target 'util/libvirt_util_la-virmdev.lo' failed
> make[3]: *** [util/libvirt_util_la-virmdev.lo] Error 1
> make[3]: *** Waiting for unfinished jobs....
> util/virscsivhost.c:112:37: error: unused variable 'tmp' [-Werror,-Wunused-variable]
>     VIR_AUTOPTR(virSCSIVHostDevice) tmp = virSCSIVHostDeviceListSteal(list, dev);
>                                     ^
> 1 error generated.
> Makefile:11411: recipe for target 'util/libvirt_util_la-virscsivhost.lo' failed
> make[3]: *** [util/libvirt_util_la-virscsivhost.lo] Error 1
> util/virusb.c:511:31: error: unused variable 'ret' [-Werror,-Wunused-variable]
>     VIR_AUTOPTR(virUSBDevice) ret = virUSBDeviceListSteal(list, dev);
> 
> Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
> ---
>  src/util/virmdev.c      | 3 ++-
>  src/util/virscsivhost.c | 3 ++-
>  src/util/virusb.c       | 3 ++-
>  3 files changed, 6 insertions(+), 3 deletions(-)
> 

<sigh>, see:

https://www.redhat.com/archives/libvir-list/2018-July/msg01917.html

Seems like it's the same thing and we should be consistent in the manner
in which we resolve.

John

> diff --git a/src/util/virmdev.c b/src/util/virmdev.c
> index 4050835cc1..63df4e40d8 100644
> --- a/src/util/virmdev.c
> +++ b/src/util/virmdev.c
> @@ -370,7 +370,8 @@ void
>  virMediatedDeviceListDel(virMediatedDeviceListPtr list,
>                           virMediatedDevicePtr dev)
>  {
> -    VIR_AUTOPTR(virMediatedDevice) ret = virMediatedDeviceListSteal(list, dev);
> +    VIR_AUTOPTR(virMediatedDevice) ret ATTRIBUTE_UNUSED
> +            = virMediatedDeviceListSteal(list, dev);
>  }
>  
>  
> diff --git a/src/util/virscsivhost.c b/src/util/virscsivhost.c
> index 280d0dc2fd..e07cd46ba9 100644
> --- a/src/util/virscsivhost.c
> +++ b/src/util/virscsivhost.c
> @@ -109,7 +109,8 @@ void
>  virSCSIVHostDeviceListDel(virSCSIVHostDeviceListPtr list,
>                            virSCSIVHostDevicePtr dev)
>  {
> -    VIR_AUTOPTR(virSCSIVHostDevice) tmp = virSCSIVHostDeviceListSteal(list, dev);
> +    VIR_AUTOPTR(virSCSIVHostDevice) tmp ATTRIBUTE_UNUSED
> +            = virSCSIVHostDeviceListSteal(list, dev);
>  }
>  
>  
> diff --git a/src/util/virusb.c b/src/util/virusb.c
> index 609d54836f..73a1041097 100644
> --- a/src/util/virusb.c
> +++ b/src/util/virusb.c
> @@ -508,7 +508,8 @@ void
>  virUSBDeviceListDel(virUSBDeviceListPtr list,
>                      virUSBDevicePtr dev)
>  {
> -    VIR_AUTOPTR(virUSBDevice) ret = virUSBDeviceListSteal(list, dev);
> +    VIR_AUTOPTR(virUSBDevice) ret ATTRIBUTE_UNUSED
> +            = virUSBDeviceListSteal(list, dev);
>  }
>  
>  virUSBDevicePtr
> 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] util: clang is failing due to unused variables.
Posted by Eric Blake 5 years, 8 months ago
On 07/27/2018 03:58 PM, John Ferlan wrote:
> 
> 
> On 07/27/2018 04:50 PM, Julio Faracco wrote:
>> After some recent patches, clang is throwing some errors related to
>> unused variables. This is not happening when we use GCC with -Werror
>> enabled. Only clang reports this warning.
>>
>> make[3]: Entering directory '/home/julio/Desktop/virt/libvirt/src'
>>    CC       util/libvirt_util_la-virscsivhost.lo
>>    CC       util/libvirt_util_la-virusb.lo
>>    CC       util/libvirt_util_la-virmdev.lo
>> util/virmdev.c:373:36: error: unused variable 'ret' [-Werror,-Wunused-variable]
>>      VIR_AUTOPTR(virMediatedDevice) ret = virMediatedDeviceListSteal(list, dev);
>>                                     ^

clang is buggy. The variable 'ret' is very much in use, as the 
VIR_AUTOPTR() macro cannot work unless you attach it to a local variable 
to operate on when that variable goes out of scope.

You should file a bug report against clang.

But in the meantime,

> <sigh>, see:
> 
> https://www.redhat.com/archives/libvir-list/2018-July/msg01917.html
> 
> Seems like it's the same thing and we should be consistent in the manner
> in which we resolve.

Yes, that approach is much nicer - it is also less typing and less magic.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] util: clang is failing due to unused variables.
Posted by Julio Faracco 5 years, 8 months ago
Ow,
I was pretty sure that clang would complain about not handling the function
return properly. Well, I changed it and clang is not throwing any error. Weird!

Sending a V2.
Michael's patch was applied, so we need a new one to remove the other
occurrences.

Em sex, 27 de jul de 2018 às 17:59, John Ferlan <jferlan@redhat.com> escreveu:
>
>
>
> On 07/27/2018 04:50 PM, Julio Faracco wrote:
> > After some recent patches, clang is throwing some errors related to
> > unused variables. This is not happening when we use GCC with -Werror
> > enabled. Only clang reports this warning.
> >
> > make[3]: Entering directory '/home/julio/Desktop/virt/libvirt/src'
> >   CC       util/libvirt_util_la-virscsivhost.lo
> >   CC       util/libvirt_util_la-virusb.lo
> >   CC       util/libvirt_util_la-virmdev.lo
> > util/virmdev.c:373:36: error: unused variable 'ret' [-Werror,-Wunused-variable]
> >     VIR_AUTOPTR(virMediatedDevice) ret = virMediatedDeviceListSteal(list, dev);
> >                                    ^
> > 1 error generated.
> > Makefile:11579: recipe for target 'util/libvirt_util_la-virmdev.lo' failed
> > make[3]: *** [util/libvirt_util_la-virmdev.lo] Error 1
> > make[3]: *** Waiting for unfinished jobs....
> > util/virscsivhost.c:112:37: error: unused variable 'tmp' [-Werror,-Wunused-variable]
> >     VIR_AUTOPTR(virSCSIVHostDevice) tmp = virSCSIVHostDeviceListSteal(list, dev);
> >                                     ^
> > 1 error generated.
> > Makefile:11411: recipe for target 'util/libvirt_util_la-virscsivhost.lo' failed
> > make[3]: *** [util/libvirt_util_la-virscsivhost.lo] Error 1
> > util/virusb.c:511:31: error: unused variable 'ret' [-Werror,-Wunused-variable]
> >     VIR_AUTOPTR(virUSBDevice) ret = virUSBDeviceListSteal(list, dev);
> >
> > Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
> > ---
> >  src/util/virmdev.c      | 3 ++-
> >  src/util/virscsivhost.c | 3 ++-
> >  src/util/virusb.c       | 3 ++-
> >  3 files changed, 6 insertions(+), 3 deletions(-)
> >
>
> <sigh>, see:
>
> https://www.redhat.com/archives/libvir-list/2018-July/msg01917.html
>
> Seems like it's the same thing and we should be consistent in the manner
> in which we resolve.
>
> John
>
> > diff --git a/src/util/virmdev.c b/src/util/virmdev.c
> > index 4050835cc1..63df4e40d8 100644
> > --- a/src/util/virmdev.c
> > +++ b/src/util/virmdev.c
> > @@ -370,7 +370,8 @@ void
> >  virMediatedDeviceListDel(virMediatedDeviceListPtr list,
> >                           virMediatedDevicePtr dev)
> >  {
> > -    VIR_AUTOPTR(virMediatedDevice) ret = virMediatedDeviceListSteal(list, dev);
> > +    VIR_AUTOPTR(virMediatedDevice) ret ATTRIBUTE_UNUSED
> > +            = virMediatedDeviceListSteal(list, dev);
> >  }
> >
> >
> > diff --git a/src/util/virscsivhost.c b/src/util/virscsivhost.c
> > index 280d0dc2fd..e07cd46ba9 100644
> > --- a/src/util/virscsivhost.c
> > +++ b/src/util/virscsivhost.c
> > @@ -109,7 +109,8 @@ void
> >  virSCSIVHostDeviceListDel(virSCSIVHostDeviceListPtr list,
> >                            virSCSIVHostDevicePtr dev)
> >  {
> > -    VIR_AUTOPTR(virSCSIVHostDevice) tmp = virSCSIVHostDeviceListSteal(list, dev);
> > +    VIR_AUTOPTR(virSCSIVHostDevice) tmp ATTRIBUTE_UNUSED
> > +            = virSCSIVHostDeviceListSteal(list, dev);
> >  }
> >
> >
> > diff --git a/src/util/virusb.c b/src/util/virusb.c
> > index 609d54836f..73a1041097 100644
> > --- a/src/util/virusb.c
> > +++ b/src/util/virusb.c
> > @@ -508,7 +508,8 @@ void
> >  virUSBDeviceListDel(virUSBDeviceListPtr list,
> >                      virUSBDevicePtr dev)
> >  {
> > -    VIR_AUTOPTR(virUSBDevice) ret = virUSBDeviceListSteal(list, dev);
> > +    VIR_AUTOPTR(virUSBDevice) ret ATTRIBUTE_UNUSED
> > +            = virUSBDeviceListSteal(list, dev);
> >  }
> >
> >  virUSBDevicePtr
> >

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list