[igt-dev] [PATCH 01/76] lib: Introduce typed cleanups

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Thu Oct 6 05:28:31 UTC 2022


On Wed, Oct 05, 2022 at 10:02:57AM +0200, Mauro Carvalho Chehab wrote:
> On Wed, 5 Oct 2022 09:45:32 +0200
> Zbigniew Kempczyński <zbigniew.kempczynski at intel.com> wrote:
> 
> > > +void igt_cleanup_fd(volatile int *fd);
> > > +#define igt_fd_t(x__) \
> > > +	volatile int x__ cleanup_with(igt_cleanup_fd) = IGT_OUTER_SCOPE_INIT(-1)  
> > 
> > Why do we need volatile here? Variable after initalization (open) likely won't
> > be touched (until exiting its scope) so what's the risk?
> 
> With current gcc versions, volatile is not needed, but this fails with
> clang. The real problem is that C spec doesn't define what happens
> with an automatic stack variable after doing a longjmp.

If I'm not wrong longjmp stays in same scope where fd is according to
above (GOOD) examples. So I still don't feel what volatile changes in
this case apart of directly touching the memory. I would expect that
fd will be in same stack frame regardless using volatile keyword. 

+Petri
May you elaborate more what's wrong with clang here after removing 
volatile?

--
Zbigniew

> 
> From Petri's feedback, the only solution that works is to declare
> such variables as volatile.
> 
> Regards,
> Mauro


More information about the igt-dev mailing list