public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* PR 17949 (unaligned memory accesses due to ivopts) question
@ 2004-10-16 21:29 Zdenek Dvorak
  2004-10-17  1:30 ` Daniel Jacobowitz
  0 siblings, 1 reply; 3+ messages in thread
From: Zdenek Dvorak @ 2004-10-16 21:29 UTC (permalink / raw)
  To: gcc

Hello,

strength reduction in ivopts may turn references to "packed" fields
in structures to accesses via pointers.  The adress obtained this
way may be unaligned, which causes crash when STRICT_ALIGNMENT = 1.

This problem however does not seem to be limited to ivopts.  For example
the testcase below probably (I do not have access to the hardware
just now, so I have checked only assembler, and I cannot read ia64 asm
very well, so I am not entirely sure) fails in the same way.

It seems to me that fixing this in ivopts is not the right place.
Maybe setting DECL_NONADDRESSABLE_P for unaligned fields of structures
when STRICT_ALIGNMENT = 1 would be more correct?

Zdenek

typedef struct
{
  short i __attribute__ ((packed));
  int f[2] __attribute__ ((packed));
} A;

A a;

void foo(int *);

int main(void)
{
  foo (a.f);
  return 0;
}

void foo(int *x)
{
  *x = 0;
}

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PR 17949 (unaligned memory accesses due to ivopts) question
  2004-10-16 21:29 PR 17949 (unaligned memory accesses due to ivopts) question Zdenek Dvorak
@ 2004-10-17  1:30 ` Daniel Jacobowitz
  2004-10-17  1:43   ` Zdenek Dvorak
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Jacobowitz @ 2004-10-17  1:30 UTC (permalink / raw)
  To: Zdenek Dvorak; +Cc: gcc

On Sat, Oct 16, 2004 at 09:35:34PM +0200, Zdenek Dvorak wrote:
> This problem however does not seem to be limited to ivopts.  For example
> the testcase below probably (I do not have access to the hardware
> just now, so I have checked only assembler, and I cannot read ia64 asm
> very well, so I am not entirely sure) fails in the same way.
> 
> It seems to me that fixing this in ivopts is not the right place.
> Maybe setting DECL_NONADDRESSABLE_P for unaligned fields of structures
> when STRICT_ALIGNMENT = 1 would be more correct?

> typedef struct
> {
>   short i __attribute__ ((packed));
>   int f[2] __attribute__ ((packed));
> } A;
> 
> A a;
> 
> void foo(int *);
> 
> int main(void)
> {
>   foo (a.f);
>   return 0;
> }
> 
> void foo(int *x)
> {
>   *x = 0;
> }

Well, a.f ought to be a pointer to unaligned integer.  Don't you get
some kind of warning for this?

-- 
Daniel Jacobowitz

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PR 17949 (unaligned memory accesses due to ivopts) question
  2004-10-17  1:30 ` Daniel Jacobowitz
@ 2004-10-17  1:43   ` Zdenek Dvorak
  0 siblings, 0 replies; 3+ messages in thread
From: Zdenek Dvorak @ 2004-10-17  1:43 UTC (permalink / raw)
  To: gcc

Hello,

> Well, a.f ought to be a pointer to unaligned integer.  Don't you get
> some kind of warning for this?

no.  There is -Wcast-align (disabled by default), but it does not
trigger in this case.  -Wpacked (also disabled by default) announces
that "packed attribute causes inefficient alignment for 'i'"
(but does not mention f; umm...).  And that's it, these are all warnings
that are triggered by STRICT_ALIGNMENT.

Zdenek

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-10-16 20:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-16 21:29 PR 17949 (unaligned memory accesses due to ivopts) question Zdenek Dvorak
2004-10-17  1:30 ` Daniel Jacobowitz
2004-10-17  1:43   ` Zdenek Dvorak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).