This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: C++: Letting compiler know asm block can call function that can throw?
- From: Hans-Peter Nilsson <hp at bitrange dot com>
- To: Michael Matz <matz at suse dot de>
- Cc: Jakub Jelinek <jakub at redhat dot com>, Jan Hubicka <hubicka at ucw dot cz>, Richard Guenther <richard dot guenther at gmail dot com>, Richard Henderson <rth at redhat dot com>, Stephan Bergmann <sbergman at redhat dot com>, gcc at gcc dot gnu dot org
- Date: Mon, 16 Apr 2012 16:01:19 -0400 (EDT)
- Subject: Re: C++: Letting compiler know asm block can call function that can throw?
- References: <4F7409B9.2010407@redhat.com> <4F748A47.4070306@redhat.com> <20120329171639.GD18490@atrey.karlin.mff.cuni.cz> <4F74AB1F.2020607@redhat.com> <CAFiYyc3Z00jGmQFVjotK4bF7_Br6uUkP=2ka=rs_UAtXGnqHtw@mail.gmail.com> <20120330122106.GE8468@kam.mff.cuni.cz> <CAFiYyc2ryHLbzXP_67ngHnB7NGOGkBkjnFO8b8DBYdMAxcmZUQ@mail.gmail.com> <20120330154537.GB1340@kam.mff.cuni.cz> <Pine.LNX.4.64.1204021603570.25409@wotan.suse.de> <20120402141648.GH6148@sunsite.ms.mff.cuni.cz> <Pine.LNX.4.64.1204021740090.25409@wotan.suse.de>
On Mon, 2 Apr 2012, Michael Matz wrote:
> On Mon, 2 Apr 2012, Jakub Jelinek wrote:
>
> > > inline int syscall1(int number, long arg1) {
> > > register int ax __asm__("eax");
> > > register long di __asm__("rdi");
> > > ax = number;
> > > di = arg1;
> > > __asm__ volatile ("syscall");
> > > }
> > >
> > > _then_ we would probably get miscompilations here and there.
> >
> > That is actually what is used on most targets, including x86_64
>
> Yikes! That's indeed the case. I'll want to retract what I said, concede
> with Honza that we're lucky and add that we're lucky mostly because
> register variables are not regarded as gimple registers, hence all stores
> to such variables are regarded as VDEFs. So there will be VDEF/VUSE
> chains between initializer and syscall, which prevents most code motion
> into that chain. That itself doesn't e.g. prevent the load/store
> disambiguator from disambiguating two such decls, even if they refer to
> the same hardreg. So we really are merely lucky, with enough effort we
> probably could create a "miscompiling" testcase.
Lucky perhaps, but documented lucky: this is documented (grep
sysint extend.texi) to work, to avoid having talented gcc
hackers saying "oh, that worked? You have to _stop doing that_;
you've just been lucky in previous versions" rather that "oops,
looks like I broke that; I'll fix it post-haste".
(There's *one* test-case in gcc.target/cris/asmreg-1.c; this
could certainly do with more coverage.)
brgds, H-P