Re: False positive unused variable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Den tis 5 dec. 2023 kl 03:51 skrev Segher Boessenkool <
segher@xxxxxxxxxxxxxxxxxxx>:

> On Tue, Dec 05, 2023 at 03:10:05AM +0100, Henrik Holst via Gcc-help wrote:
> > int64_t seq = seq_next (queue); /* get next free place */
> > struct item *item = queue_get (queue, seq); /* get the item at place
> 'seq'
> > */
> >
> > item->a = 1; /* we just fill in dummy data for the example */
> > item->b = 2;
> >
> > queue_publish (queue, seq); /* publish place 'seq' as containing data */
> >
> > Now the issue here is that since 'item' is never referenced by any
> > function, GCC, falsely sees item as being an unused variable. So far
> AFAIK
> > only a warning is issued and that can be ignored, but at one time in the
> > future I fear that the optimizer will kick in here and simply remove
> where
> > we fill item with data.
>
> GCC will never do things like this.  The queue_get function can have
> side effects (=~ it may make changes to state), so the function needs to
> be called, even if the result isn't used.  The warning is because this
> is likely a mistake (maybe you have an "item2" variable as well and you
> confused them somewhere, silly typoes or thinkoes like that).
>

No there is no item2, the code given is basically the code that was giving
the error and GCC complained about the item on this very row.

Now interestingly the warning went away when another thread also used
queue_get() but then read from the returned item, so it simply looks like
GCC was very clever and saw that there was no one actually reading from the
item ever.
So basically I was too quick in sending the first mail.

So nothing to see here and sorry for the disturbance.

/HH



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux