[Bug c/21389] New: optimized code seg faults due to double load on sparcV9

2005-05-04 Thread drew dot johnson at andrew dot com
When -O3 or higher is used, the optimizer utilizes the lddf sparc instruction 
to load doubles into registers.  This can generate a bus-error/seg-fault at 
runtime if the source address of the load is not mod8.  The optimizer does not 
check this, even with -munaligned-doubles set.

-- 
   Summary: optimized code seg faults due to double load on sparcV9
   Product: gcc
   Version: 3.4.3
Status: UNCONFIRMED
  Severity: normal
  Priority: P2
 Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: drew dot johnson at andrew dot com
CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: 3.4.2
  GCC host triplet: sparc-sun-solaris2.8
GCC target triplet: sparc-sun-solaris2.8


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21389


[Bug c/21389] optimized code seg faults due to double load on sparcV9

2005-05-04 Thread drew dot johnson at andrew dot com

--- Additional Comments From drew dot johnson at andrew dot com  2005-05-04 
19:38 ---
Created an attachment (id=8820)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=8820&action=view)
compile with -O3 or higher, and execution generates seg-fault

The included file compiles with just -O3 or higher as arguments.  It should run
and print a bunch of lines to stdout, then exit normally.  When compiled at -O3
or higher, it generates a bus-error on the command line, due to a segmentation
violation signal when run from the debugger.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21389


[Bug target/21389] optimized code seg faults due to double load on sparcV9

2005-05-06 Thread drew dot johnson at andrew dot com


-- 
   What|Removed |Added

   Attachment #8820|compile with -O3 or higher, |compile with -O1 or higher,
description|and execution generates seg-|and execution generates seg-
   |fault   |fault


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21389


[Bug target/21389] optimized code seg faults due to double load on sparcV9

2005-05-06 Thread drew dot johnson at andrew dot com

--- Additional Comments From drew dot johnson at andrew dot com  2005-05-06 
18:53 ---
(In reply to comment #0)
> When -O3 or higher is used, the optimizer utilizes the lddf sparc 
instruction 
> to load doubles into registers.  This can generate a bus-error/seg-fault at 
> runtime if the source address of the load is not mod8.  The optimizer does 
not 
> check this, even with -munaligned-doubles set.

This actually fails when -O1 or higher is used.  For some reason, I thought 
that -O2 was the default.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21389


[Bug target/21389] optimized code seg faults due to double load on sparcV9

2005-05-06 Thread drew dot johnson at andrew dot com

--- Additional Comments From drew dot johnson at andrew dot com  2005-05-06 
19:04 ---
Subject: RE:  optimized code seg faults due to double load on sparcV9

I don't think so.  Malloc does not guarantee anything but mod-4
alignment.  You have to use memalign to get something better (at least
on a Sun).  I only did the +4 pointer stuff to ensure that the double
would be misaligned mod8, as this is what was happening in my code.  As
long as I am on a mod4 boundary for my struct, the -munaligned-doubles
flag should force the handling of doubles as though they are unaligned.
The compiler with no optimization does this.  But as soon as you turn on
-O1, it ignores the unaligned-doubles directive.

Drew

-Original Message-
From: pinskia at gcc dot gnu dot org [mailto:[EMAIL PROTECTED] 
Sent: Friday, May 06, 2005 2:55 PM
To: Johnson, Drew
Subject: [Bug target/21389] optimized code seg faults due to double load
on sparcV9


--- Additional Comments From pinskia at gcc dot gnu dot org
2005-05-06 18:54 ---
I think you violating alignment rules in C:

x = tptr[1].f3;
p = (char *)tptr;
p += 4;
tptr = (test1 *)p;

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21389

--- You are receiving this mail because: ---
You reported the bug, or are watching the reporter.




This message is for the designated recipient only and may
contain privileged, proprietary, or otherwise private information.  
If you have received it in error, please notify the sender
immediately and delete the original.  Any unauthorized use of
this email is prohibited.

[mf2]


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21389


[Bug target/21389] optimized code seg faults due to double load on sparcV9

2005-05-06 Thread drew dot johnson at andrew dot com

--- Additional Comments From drew dot johnson at andrew dot com  2005-05-06 
19:47 ---
Subject: RE:  optimized code seg faults due to double load on sparcV9

Then what is the point of the -munaligned-doubles flag?  Is this simply
ignored?  I understand your point about malloc, but what if we have
casts to buffers that are not mod8-aligned?  Isn't that what
-munaligned-doubles is for? 

I am going back over the original code to find out how we are allocating
the data struct that is causing my program to fail.  I will let you know
when I find something more.

Drew

-Original Message-
From: pinskia at gcc dot gnu dot org [mailto:[EMAIL PROTECTED] 
Sent: Friday, May 06, 2005 3:08 PM
To: Johnson, Drew
Subject: [Bug target/21389] optimized code seg faults due to double load
on sparcV9


--- Additional Comments From pinskia at gcc dot gnu dot org
2005-05-06 19:07 ---
(In reply to comment #4)
> Subject: RE:  optimized code seg faults due to double load on sparcV9
> 
> I don't think so.  Malloc does not guarantee anything but mod-4
> alignment.  You have to use memalign to get something better (at least
> on a Sun).  I only did the +4 pointer stuff to ensure that the double
> would be misaligned mod8, as this is what was happening in my code.
As
> long as I am on a mod4 boundary for my struct, the -munaligned-doubles
> flag should force the handling of doubles as though they are
unaligned.
> The compiler with no optimization does this.  But as soon as you turn
on
> -O1, it ignores the unaligned-doubles directive.

Again what you said about malloc is not true and has not been true since
1989.
The C standard says malloc aligns things the largest alignment required
for that machine.  In this case 
doubles are aligned by 8.  So your code is invalid.

-- 
   What|Removed |Added


 Status|UNCONFIRMED |RESOLVED
 Resolution||INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21389

--- You are receiving this mail because: ---
You reported the bug, or are watching the reporter.




This message is for the designated recipient only and may
contain privileged, proprietary, or otherwise private information.  
If you have received it in error, please notify the sender
immediately and delete the original.  Any unauthorized use of
this email is prohibited.

[mf2]


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21389


[Bug target/21389] optimized code seg faults due to double load on sparcV9

2005-05-10 Thread drew dot johnson at andrew dot com

--- Additional Comments From drew dot johnson at andrew dot com  2005-05-10 
12:57 ---
Subject: RE:  optimized code seg faults due to double load on sparcV9

OK, I see your point.  Sorry for inconvenience.  I see that the status
in bugzilla has been updated accordingly.  Is there anything else I
should do to close this?

Drew

-Original Message-
From: ebotcazou at gcc dot gnu dot org [mailto:[EMAIL PROTECTED]

Sent: Sunday, May 08, 2005 6:59 AM
To: Johnson, Drew
Subject: [Bug target/21389] optimized code seg faults due to double load
on sparcV9


--- Additional Comments From ebotcazou at gcc dot gnu dot org
2005-05-08 10:58 ---
> Then what is the point of the -munaligned-doubles flag?  Is this
simply
> ignored?  I understand your point about malloc, but what if we have
> casts to buffers that are not mod8-aligned?  Isn't that what
> -munaligned-doubles is for? 

Excerpt from the manual:

 With `-munaligned-doubles', GCC assumes that doubles have 8 byte
 alignment only if they are contained in another type, or if they
 have an absolute address.  Otherwise, it assumes they have 4 byte
 alignment.  Specifying this option avoids some rare compatibility
 problems with code generated by other compilers.  It is not the
 default because it results in a performance loss, especially for
 floating point code.

So -munaligned-doubles cannot do anything for your invalid code and the
bus
error is to be expected.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21389

--- You are receiving this mail because: ---
You reported the bug, or are watching the reporter.




This message is for the designated recipient only and may
contain privileged, proprietary, or otherwise private information.  
If you have received it in error, please notify the sender
immediately and delete the original.  Any unauthorized use of
this email is prohibited.

[mf2]


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21389