Bug 27942 - [4.2 Regression] packed union doesn't make the unaligned magic on sh64-*
Summary: [4.2 Regression] packed union doesn't make the unaligned magic on sh64-*
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.2.0
: P3 normal
Target Milestone: 4.2.0
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
: 27943 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-06-07 23:09 UTC by Kazumoto Kojima
Modified: 2006-06-12 00:24 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: sh64-*-*
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kazumoto Kojima 2006-06-07 23:09:32 UTC
union unaligned
{
  void *ptr;
} __attribute__((__packed__));

void *foo (void *p)
{
  return (((union unaligned *) p)->ptr);
}

is compiled to an aligned word access on sh64-*.  It was compiled
to an unaligned access before the patch

r114364 | echristo | 2006-06-05 04:50:48 +0900 (Mon, 05 Jun 2006) | 17 lines
Comment 1 Andrew Pinski 2006-06-08 00:01:29 UTC
*** Bug 27943 has been marked as a duplicate of this bug. ***
Comment 2 Eric Christopher 2006-06-08 00:10:53 UTC
Since you're using the MS abi then for sh64 you'll need to dig up where I'm doing something wrong.
Comment 3 Kazumoto Kojima 2006-06-08 01:50:08 UTC
It seems that r114364 adds the extra alignment for non bit-field
fields always for the ms_bitfield_layout_p case.  It looks the packed
attribute should be taken into account, though I'm unsure whether
it's the way of ms_bitfield or not.  How does this look?

--- ORIG/trunk/gcc/stor-layout.c	2006-06-06 10:02:03.000000000 +0900
+++ LOCAL/trunk/gcc/stor-layout.c	2006-06-07 23:16:01.000000000 +0900
@@ -693,7 +693,7 @@ update_alignment_for_field (record_layou
 	 the type, except that for zero-size bitfields this only
 	 applies if there was an immediately prior, nonzero-size
 	 bitfield.  (That's the way it is, experimentally.) */
-      if (!is_bitfield
+      if ((!is_bitfield && !DECL_PACKED (field))
 	  || (!integer_zerop (DECL_SIZE (field))
 	      ? !DECL_PACKED (field)
 	      : (rli->prev_field

Comment 4 Eric Christopher 2006-06-08 18:14:22 UTC
Well, I suppose the question is whether or not I'm doing something wrong here. The alignment should be added unilaterally (as far as I can tell from the documents that I included in the documentation). Part of the question is what happens with the packed attribute? I've not seen any part of an abi document that includes that. I'm perfectly willing to include your patch in - it shouldn't affect anything else.
Comment 5 Kazumoto Kojima 2006-06-08 22:17:58 UTC
I also couldn't find any document refering to it.  My patch is just
a guess from the behavior for nonzero-size bitfield with the packed
attribute appeared in the last 3 lines of my patch.  I'd like to
send my patch to gcc-patch to get comments for our abi question.
Comment 6 Eric Christopher 2006-06-08 22:23:41 UTC
Sure. Sounds good. As I said, the ABI stuff I've seen (and helped write) don't take packed into account anywhere :)
Comment 7 patchapp@dberlin.org 2006-06-11 13:55:20 UTC
Subject: Bug number PR 27942

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-06/msg00569.html
Comment 8 Kazumoto Kojima 2006-06-11 23:10:08 UTC
Subject: Bug 27942

Author: kkojima
Date: Sun Jun 11 23:09:58 2006
New Revision: 114552

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114552
Log:
	PR middle-end/27942
	* stor-layout.c (update_alignment_for_field): Don't add extra
	alignment for packed non-bitfield fields in ms_bitfield_layout_p
	code.

	* gcc.dg/attr-ms_struct-packed1.c: New.


Added:
    trunk/gcc/testsuite/gcc.dg/attr-ms_struct-packed1.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/stor-layout.c
    trunk/gcc/testsuite/ChangeLog

Comment 9 Andrew Pinski 2006-06-12 00:24:58 UTC
Fixed.