Date: Sat, 20 Feb 2016 13:01:27 +1100 (EST) From: Bruce Evans <brde@optusnet.com.au> To: Benjamin Kaduk <bjkfbsd@gmail.com> Cc: Gleb Smirnoff <glebius@freebsd.org>, Alan Somers <asomers@freebsd.org>, "svn-src-head@freebsd.org" <svn-src-head@freebsd.org>, "svn-src-all@freebsd.org" <svn-src-all@freebsd.org>, Sergey Kandaurov <pluknet@gmail.com>, "src-committers@freebsd.org" <src-committers@freebsd.org> Subject: Re: svn commit: r295768 - head/usr.sbin/iostat Message-ID: <20160220123404.F1403@besplex.bde.org> In-Reply-To: <CAJ5_RoCbWLUkwdRv4FeFVGpzCENooJbokH0SNXtiCeoRSeW%2BfQ@mail.gmail.com> References: <201602182008.u1IK81vg092127@repo.freebsd.org> <CAE-mSO%2B7p=Equq81PPQjfZv1piPydBr4Mnk363CEs3w9EXRi9w@mail.gmail.com> <CAOtMX2hyZ=GFgp8F6t0dMDYF5FSPdoP9KdMU7V5rmscpaPUnsw@mail.gmail.com> <20160219230612.GR1945@FreeBSD.org> <CAJ5_RoCbWLUkwdRv4FeFVGpzCENooJbokH0SNXtiCeoRSeW%2BfQ@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 19 Feb 2016, Benjamin Kaduk wrote: > On Fri, Feb 19, 2016 at 5:06 PM, Gleb Smirnoff <glebius@freebsd.org> wrote: > >> On Fri, Feb 19, 2016 at 08:49:43AM -0700, Alan Somers wrote: >> A> On Fri, Feb 19, 2016 at 5:24 AM, Sergey Kandaurov <pluknet@gmail.com> >> wrote: >> A> Yeah, it was being implicitly zeroized before. But Clang complained >> A> about the structures being only partially initialized. Since the >> A> whole point of my commit was to increase the WARNS level, I explicitly >> A> zeroed the zero fields to silence Clang. >> >> Isn't zero filling part of the standard? I don't see why lack of >> explicit zeroing is a warning? Looks a false warning to me. > > It is not quite as simple as this would make it sound. The elements or > members of an aggregate (e.g.) structure type are initialized as if it were > an object of static storage duration (i.e., to zero) if the initializer > list does not contain enough initializers for all members of the aggregate > type, per item 21 of section 6.7.8 of n1256.pdf. However, such > initialization does not necessarily need to zero any padding bytes that are > present, which may take unspecified values. Perhaps, but then there is even less reason to expect that initializing all the struct members initialzes the padding between them. > Personally, I think this > particular clang warning can be too aggressive, especially for complex > structs, but on the other hand given the indeterminateness of padding, > bzero/memset are often a better choice anyway. It is just a bug in clang. Using auto structs with initialzers, auto structs initialized by memset/ bzero followed by initializing a few fields, are almost equally good pessimizations. Some compilers generate similar code for them (like the code shown by pluknet -- the initializer is optimized to an inlined memset followed by initializing 1 field. But doing this this on every function call is a good pessimization if the struct never changes or rarely changes or only changes slightly. Some compilers generate the worse code of keeping a static copy and generating an inline memcpy to the auto variable on every function call. 6.7.8p9 says that unnamed members have indeterminate values even after initialization, except where explicitly stated otherwise. I couldn't find anywhere "explicitly stating otherwise" that padding is initialized. It takes an explicit statements in p21 to get the unnamed members in an initializer initialized, but padding isn't even. p21 says that any unnamed struct member is initialized as if it had static storage duration with no initializer, but I couldn't find anything requiring initialization for padding in that case. Apparently, only quality of implementation prevents it being initialized with passwords from the previous program :-(. Bruce
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20160220123404.F1403>