------- Comment #5 from wilson at specifix dot com  2007-10-17 20:53 -------
Subject: Re:  valgrind error with -O2 for linux
 kernel code

bergner at gcc dot gnu dot org wrote:
> ------- Comment #2 from bergner at gcc dot gnu dot org  2007-10-17 04:46 
> -------
> Although valgrind is correct that we are doing an uninitialized read, the code
> is actually working as designed and is correct.

A comment in the code mentioning that the uninit reads are intentional 
would be useful.  Otherwise, you will keep getting this same question, 
and have to keep answering it.

Also, it might be a good idea to make sure that the sparse field is 
marked as volatile, to ensure that reads are never optimized away.  As 
the gcc optimizer gets better, e.g. LTO and aggressive inlining, it 
might be possible to end up with a case where gcc can prove that it has 
an uninit read of this field and optimize it away.  This will result in 
a use of an uninit register.  On IA-64, an uninit register may have the 
NaT (Not a Thing) bit set which is used for speculation.  Hence use of 
an uninit register may cause an unexpected speculation failure, which 
will cause a program to crash.  We can avoid this chain of events by 
making this a volatile field, which will make it impossible for gcc to 
optimize away reads from this field, even if uninitialized.  It also 
serves as a clue to other people reading the code that this field is 
special.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33796

Reply via email to