Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 9 Oct 2012 14:25:38 -0700
From:      Steve Kargl <sgk@troutmask.apl.washington.edu>
To:        Eitan Adler <eadler@freebsd.org>
Cc:        svn-src-head@freebsd.org, theraven@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, Andrey Chernov <ache@freebsd.org>
Subject:   Re: svn commit: r241373 - head/lib/libc/stdlib
Message-ID:  <20121009212538.GA67848@troutmask.apl.washington.edu>
In-Reply-To: <CAF6rxg=azW682hF3mUw4rh8o7dUiycc_A9FLqmumxa0SGj9EYA@mail.gmail.com>
References:  <201210091425.q99EPFS6020787@svn.freebsd.org> <507451DE.9060909@freebsd.org> <CAF6rxgkDbyrCHfY-5eMjJ%2B7nP9ZCnXsjLgEBB1Q_p=QJ3tCkfg@mail.gmail.com> <50746BF8.5010307@freebsd.org> <CAF6rxg=azW682hF3mUw4rh8o7dUiycc_A9FLqmumxa0SGj9EYA@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Oct 09, 2012 at 04:23:59PM -0400, Eitan Adler wrote:
> On 9 October 2012 14:24, Andrey Chernov <ache@freebsd.org> wrote:
> > I don't have ISO9899 nearby, could you directly quote mentioned
> > sections, please?
> 
> Accesses to volatile object (a) produce side effects (b) have
> implementation defined values.
> 
> A more careful re-reading of the relevant section leads me to believe
> I may have been wrong
> with this comment.  It isn't made explicit, but the C standard never
> says that accesses
> to uninitialized volatile is defined. On the other hand, the existence
> of "const volatile" proves me wrong.
> Interestingly, clang and gcc disagree on whether to warn:
> 
> [8084 eitan@radar ~ ]%gcc46 -Wall -Wextra -ansi -pedantic a.c
> [8089 eitan@radar ~ ]%clang -Wall -Wextra -ansi -pedantic a.c
> a.c:3:9: warning: variable 'a' is uninitialized when used here
>  [-Wuninitialized]

Given that I cannot see a.c, I'll assume that 'a' is declared
with a volatile-qualified type.  In that case, it appears that
clang has a bug.  From 6.7.3, page 109 in n1256.pdf, one finds:

   An object that has volatile-qualified type may be modified
   in ways unknown to the implementation or have other unknown
   side effects.  Therefore any expression referring to such
   an object shall be evaluated strictly according to the rules
   of the abstract machine, as described in 5.1.2.3.  Furthermore,
   at every sequence point the value last stored in the object
   shall agree with that prescribed by the abstract machine,
   except as modified by the unknown factors mentioned
   previously. 116)

   116) A volatile declaration may be used to describe an object
      corresponding to a memory-mapped input/output port or an
      object accessed by an asynchronously interrupting function.
      Actions on objects so declared shall not be ``optimized out''
      by an implementation or reordered except as permitted by
      the rules for evaluating expressions.

Clang has no way of determining if 'a' is initialized or not.
If David is correct that 'junk' is optimized out by clang/llvm,
then it seems that clang violates footnote 116.  Yes, I know
it is non-normative text.

> I still don't like volatile though here for the other reasons
> mentioned. In general, the entire piece of code should be replaced
> with something that can't fail, so this is a moot point.

Agreed.

-- 
Steve



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20121009212538.GA67848>