This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: asm volatile statement reordering
- From: Segher Boessenkool <segher at kernel dot crashing dot org>
- To: Jeffrey Walton <noloader at gmail dot com>
- Cc: David Brown <david at westcontrol dot com>, Xi Ruoyao <ryxi at stu dot xidian dot edu dot cn>, "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Tue, 17 Oct 2017 03:22:23 -0500
- Subject: Re: asm volatile statement reordering
- Authentication-results: sourceware.org; auth=none
- References: <c77403fd-08fc-c64b-ceaf-a1cf5679c214@westcontrol.com> <1508214021.2368.1.camel@stu.xidian.edu.cn> <59E5AE88.4060707@westcontrol.com> <CAH8yC8nW4q+kZzi46fPPwzWC9xBzBvDjxHK1g=aX72S9shagwg@mail.gmail.com>
On Tue, Oct 17, 2017 at 03:32:25AM -0400, Jeffrey Walton wrote:
> On Tue, Oct 17, 2017 at 3:17 AM, David Brown <david@westcontrol.com> wrote:
> > ...
> > If gcc cannot guarantee this, then pretty much every OS and every
> > embedded system programmed using gcc works by luck rather than design.
> > Sequences like the one in my link are very common, deep down in many
> > systems.
>
> Right, but its not GCC's fault. Using volatile and hoping that things
> works as expected has always been held together with duct tape and a
> prayer. Also see Ian Lance Taylor's
> https://www.airs.com/blog/archives/154.
I don't think you've understood what Ian says.
> GCC guesses wrong on occasion. It will remove code that has value that
> but does not produce an output because the language does not allow us
> to express it.
Yes, the compiler is bad at guessing what you mean. It does not even
try; it only cares about what you *say*.
If you believe volatile means something else than it does, the results
will not be very satisfying.
> The C language lacks what we need to express what we need to do. Its a
> failure of the C (and C++) committees. Its not a GCC failure.
But "volatile asm" is defined by GCC, not by the C standard.
Segher