[cfe-dev] [RFC] add Function Attribute to disable optimization

Sean Silva silvas at purdue.edu
Mon Jun 17 19:12:01 PDT 2013


On Mon, Jun 17, 2013 at 5:34 PM, Jeffrey Walton <noloader at gmail.com> wrote:

> On Mon, Jun 17, 2013 at 8:23 PM, Jeffrey Walton <noloader at gmail.com>
> wrote:
> > On Mon, Jun 17, 2013 at 7:19 PM, Joshua Cranmer 🐧 <Pidgeot18 at gmail.com>
> wrote:
> >> On 6/17/2013 5:32 PM, Jeffrey Walton wrote:
> >>> On Mon, Jun 17, 2013 at 6:23 PM, Sean Silva <silvas at purdue.edu> wrote:
> >>>>
> >>>> ...
> >>>
> >>> That brings up a good point. As I understand it, volatile is
> >>> essentially implementation defined. What is Clang/LLVM's
> >>> interpretation?
> >>
> >> Volatile has an explicit definition in C99/C11/C++03/C++11, and it's
> roughly
> >> the same in all of them. Volatile objects "may be modified in ways
> unknown
> >> to the
> >> implementation or have other unknown side effects" (to quote C99), and
> the
> >> implementation must therefore preserve the accesses and their order even
> >> when optimizing.
> > OK, thanks. I must have been quoted something else on another list.
> > I'll try and locate the email.
> Here's what I found. It was from Andrew Haley, who I beleve is one of
> the GCC devs.
>
> GCC List >>> A good discussion on the subject can be found at
> GCC List >>> http://gcc.gnu.org/ml/gcc-help/2012-03/msg00239.html.
> GCC List >>>
> GCC List >> The thread includes a discussion of Microsoft's and GCC's
> GCC List >> interpretation of the keyword. The interpretations were so
> different I
> GCC List >> wondered if it was 'implementation defined' in the standard.
> GCC List >
> GCC List > Yes: 6.7.3 Type qualifiers, "What constitutes an access to an
> object
> GCC List > that has volatile-qualified type is implementation-defined."
>
> I'm pretty sure that's where I latched onto 'volatile' being
> implementation defined. I tend to trust the opinions of Ian Lance
> Taylor, Jonathan Wakely, and Andrew Haley when it comes to GCC. Andrew
> cited the standard above.
>

For GCC, I usually just look at what Linux does to coerce the compiler into
submission, since if it breaks, the GCC devs will catch a lot of heat from
the Linux developers. For example, one macro they have is the ACCESS_ONCE
macro <https://lwn.net/Articles/508991/> which is literally just a cast to
a volatile-qualified type.

-- Sean Silva
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130617/d47afaae/attachment.html>


More information about the cfe-dev mailing list