-Wunused-value gets triggered only when storing/using intermediate outputs

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

-Wunused-value gets triggered only when storing/using intermediate outputs

Hans Wennborg via cfe-dev
Dear Clang Devs,

Consider the following code snippet:

#include <sched.h>
void whatever() {
  cpu_set_t d, s1, s2;
  CPU_AND(&d, &s1, &s2);
}

On compiling normally, I see no warnings being emitted: 
$ clang++ -c test.cpp -o test.o -Wall -Wextra -Wunused-value -Werror
$

However, if I ask Clang to save the temporary files:
$ clang++ -c test.cpp -o test.o -Wall -Wextra -Wunused-value -Werror --save-temps
test.cpp:5:308: error: expression result unused [-Werror,-Wunused-value]
  (__extension__ ({ cpu_set_t *__dest = (&d); __const __cpu_mask *__arr1 = (&s1)->__bits; __const __cpu_mask *__arr2 = (&s2)->__bits; size_t __imax = (sizeof (cpu_set_t)) / sizeof (__cpu_mask); size_t __i; for (__i = 0; __i < __imax; ++__i) ((__cpu_mask *) __dest->__bits)[__i] = __arr1[__i] & __arr2[__i]; __dest; }));
                                                                                                                                                                                                                                                                                                                   ^~~~~~
1 error generated.

Another way to look at this problem is by first storing the intermediate output and then trying to use it:
$ clang++ -E -c test.cpp -o test.ii -Wall -Wextra -Wunused-value -Werror
$ clang++ -c test.ii -o test.o -Wall -Wextra -Wunused-value -Werror
test.cpp:5:308: error: expression result unused [-Werror,-Wunused-value]
  (__extension__ ({ cpu_set_t *__dest = (&d); __const __cpu_mask *__arr1 = (&s1)->__bits; __const __cpu_mask *__arr2 = (&s2)->__bits; size_t __imax = (sizeof (cpu_set_t)) / sizeof (__cpu_mask); size_t __i; for (__i = 0; __i < __imax; ++__i) ((__cpu_mask *) __dest->__bits)[__i] = __arr1[__i] & __arr2[__i]; __dest; }));
                                                                                                                                                                                                                                                                                                                   ^~~~~~
1 error generated.


Questions:
- Is this report of unused value legit? GCC doesn't warn anything on the same snippet.
- Is this behavior expected? Why does the warning throw up only when the end user wants to do anything with the intermediate outputs? I ended up here because this was failing my project when I was trying to use distcc.



Cheers!

Nehal J Wani

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: -Wunused-value gets triggered only when storing/using intermediate outputs

Lubos Lunak-2
On Monday 30 of December 2019, Nehal J Wani via cfe-dev wrote:
> - Is this behavior expected? Why does the warning throw up only when the
> end user wants to do anything with the intermediate outputs? I ended up
> here because this was failing my project when I was trying to use distcc.

 Some of Clang's warnings, such as this one, are disabled if the code comes
from a macro expansion. This is why you see the warning only if you first
expand the code.

 If your concern is just related to distributed compiling, either build
without -Werror, or use icecc/icecream, which generally distributes the
builds without preprocessing first.

--
 Lubos Lunak
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: -Wunused-value gets triggered only when storing/using intermediate outputs

Hans Wennborg via cfe-dev
You can also use -frewrite-includes to avoid a full preprocessing (rather than -E). I'm not sure if this necessarily gets you exact warning reproducibility, but closer.

On Sun, Jan 5, 2020 at 8:26 AM Lubos Lunak via cfe-dev <[hidden email]> wrote:
On Monday 30 of December 2019, Nehal J Wani via cfe-dev wrote:
> - Is this behavior expected? Why does the warning throw up only when the
> end user wants to do anything with the intermediate outputs? I ended up
> here because this was failing my project when I was trying to use distcc.

 Some of Clang's warnings, such as this one, are disabled if the code comes
from a macro expansion. This is why you see the warning only if you first
expand the code.

 If your concern is just related to distributed compiling, either build
without -Werror, or use icecc/icecream, which generally distributes the
builds without preprocessing first.

--
 Lubos Lunak
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: -Wunused-value gets triggered only when storing/using intermediate outputs

Hans Wennborg via cfe-dev
In reply to this post by Hans Wennborg via cfe-dev
On Mon, Dec 30, 2019 at 2:03 PM Nehal J Wani <[hidden email]> wrote:

>
> Dear Clang Devs,
>
> Consider the following code snippet:
>
> #include <sched.h>
> void whatever() {
>   cpu_set_t d, s1, s2;
>   CPU_AND(&d, &s1, &s2);
> }
>
> On compiling normally, I see no warnings being emitted:
> $ clang++ -c test.cpp -o test.o -Wall -Wextra -Wunused-value -Werror
> $
>
> However, if I ask Clang to save the temporary files:
> $ clang++ -c test.cpp -o test.o -Wall -Wextra -Wunused-value -Werror --save-temps
> test.cpp:5:308: error: expression result unused [-Werror,-Wunused-value]
>   (__extension__ ({ cpu_set_t *__dest = (&d); __const __cpu_mask *__arr1 = (&s1)->__bits; __const __cpu_mask *__arr2 = (&s2)->__bits; size_t __imax = (sizeof (cpu_set_t)) / sizeof (__cpu_mask); size_t __i; for (__i = 0; __i < __imax; ++__i) ((__cpu_mask *) __dest->__bits)[__i] = __arr1[__i] & __arr2[__i]; __dest; }));
>                                                                                                                                                                                                                                                                                                                    ^~~~~~
> 1 error generated.
>
> Another way to look at this problem is by first storing the intermediate output and then trying to use it:
> $ clang++ -E -c test.cpp -o test.ii -Wall -Wextra -Wunused-value -Werror
> $ clang++ -c test.ii -o test.o -Wall -Wextra -Wunused-value -Werror
> test.cpp:5:308: error: expression result unused [-Werror,-Wunused-value]
>   (__extension__ ({ cpu_set_t *__dest = (&d); __const __cpu_mask *__arr1 = (&s1)->__bits; __const __cpu_mask *__arr2 = (&s2)->__bits; size_t __imax = (sizeof (cpu_set_t)) / sizeof (__cpu_mask); size_t __i; for (__i = 0; __i < __imax; ++__i) ((__cpu_mask *) __dest->__bits)[__i] = __arr1[__i] & __arr2[__i]; __dest; }));
>                                                                                                                                                                                                                                                                                                                    ^~~~~~
> 1 error generated.
>
>
> Questions:
> - Is this report of unused value legit? GCC doesn't warn anything on the same snippet.
> - Is this behavior expected? Why does the warning throw up only when the end user wants to do anything with the intermediate outputs? I ended up here because this was failing my project when I was trying to use distcc.
>
>
>
> Cheers!
>
> Nehal J Wani

I was suggested at #llvm to send a ping! :-)
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: -Wunused-value gets triggered only when storing/using intermediate outputs

Lubos Lunak-2
On Tuesday 14 of January 2020, Nehal J Wani via cfe-dev wrote:
> On Mon, Dec 30, 2019 at 2:03 PM Nehal J Wani <[hidden email]> wrote:
...

> > Questions:
> > - Is this report of unused value legit? GCC doesn't warn anything on the
> > same snippet. - Is this behavior expected? Why does the warning throw up
> > only when the end user wants to do anything with the intermediate
> > outputs? I ended up here because this was failing my project when I was
> > trying to use distcc.
> >
> >
> >
> > Cheers!
> >
> > Nehal J Wani
>
> I was suggested at #llvm to send a ping! :-)


 I already answered your questions on Jan 5th. If you missed the mail, check
the archives.

--
 Lubos Lunak
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev