This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [REPOST] Invalid Code when reading from unaligned zero-sized array
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Eric Botcazou <ebotcazou at adacore dot com>
- Cc: Richard Biener <richard dot guenther at gmail dot com>, gcc-patches at gcc dot gnu dot org, Bernd Edlinger <bernd dot edlinger at hotmail dot de>, Jeff Law <law at redhat dot com>
- Date: Tue, 10 Dec 2013 11:22:28 +0100
- Subject: Re: [REPOST] Invalid Code when reading from unaligned zero-sized array
- Authentication-results: sourceware.org; auth=none
- References: <DUB122-W20B5CD3C7B50824A33E21AE4D50 at phx dot gbl> <9742631 dot bqH1dR3knH at polaris> <eb8f7f93-f9f7-44c2-ab8f-43249dcdcc4c at email dot android dot com> <1492537 dot Ex4gsrNT5I at polaris>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Tue, Dec 10, 2013 at 11:04:53AM +0100, Eric Botcazou wrote:
> > What are the transformations that are enabled by making something not
> > BLKmode?
> >
> > On the gimple level I cannot think of one..
>
> On the RTL level, it's simple: anything BLKmode is forced to memory instead of
> being loaded into registers.
>
> > >This could work as well, although I'd restrict this to arrays,
> > >recursively.
> >
> > Works for me.
>
> Are we sure that we really support out-of-bounds accesses for arbitrary arrays
> though? It seems to me that we easily take advantage of them e.g. in loops to
> invoke undefined behavior. IMO it's not clear whether we want to risk more
> accidental ABI changes if they are not supported throughout the compiler.
I think we don't support out-of-bounds accesses for global vars (ok, there
are vars with real flexible array members as GNU extension initialized by
initializers that initialize the flexible array members, but then the decl
size etc. should be adjusted for that), similarly for automatic vars (and in
both cases that includes the hard register vars). What we support is
out of bounds accesses for heap vars if the var's type has flexible array member
or something we treat similarly and there is the possibility that there
could be payload after the heap var that could be accessed from the flexible
array members or similar arrays. And of course if you have just pointer to
some var and can't see what it points to, we need to treat it as if it could
be heap var.
So, I don't see what is the big deal with BLKmode, because all the cases
which actually could have flexible array member extra payloads (or similar)
must necessarily live in memory, if it is the compiler that decides whether
to put it into memory or keep in registers etc., then it can't be heap
allocated.
Jakub