public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/55428] New: -mms-bitfields hides -mno-align-double option
@ 2012-11-21 14:43 kasberger at heidenhain dot de
  2012-11-21 15:21 ` [Bug c/55428] " mikpe at it dot uu.se
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: kasberger at heidenhain dot de @ 2012-11-21 14:43 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 55428
           Summary: -mms-bitfields hides -mno-align-double option
    Classification: Unclassified
           Product: gcc
           Version: 4.6.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: kasberger@heidenhain.de


i686-pc-linux-gbu-gcc -mno-align-double -mms-bitfields test.cpp

("-mno-align-double" is the equivalent to /zp4)

This command line ignores the "-mno-align-double" option.
With -mno-align-double standalone it will do the correct double alignments but
no the ms bitfield alignment (What is expected)
If I add -mms-bitfields the alignment for bitfields will be correct but the
"-mno-align-double" is now gone

Here the program I have tested. Is it possible to achieve binary compatibility
to ms compiler with option /zp4 enabled


i686-pc-linux-gbu-gcc -mno-align-double -mms-bitfields test.cpp
test.cpp:48:58: warning: large integer implicitly truncated to unsigned type
[-Woverflow]
test.cpp:54:54: warning: large integer implicitly truncated to unsigned type
[-Woverflow]

i686-pc-linux-gbu-gcc -mno-align-double test.cpp
test.cpp:52:53: warning: large integer implicitly truncated to unsigned type
[-Woverflow]
test.cpp:58:53: warning: large integer implicitly truncated to unsigned type
[-Woverflow]

i686-pc-linux-gbu-gcc -mms-bitfields test.cpp
test.cpp:48:58: warning: large integer implicitly truncated to unsigned type
[-Woverflow]
test.cpp:54:54: warning: large integer implicitly truncated to unsigned type
[-Woverflow]



// 8
typedef struct _jhtest1 {
             unsigned long bf_1 : 12; 
             unsigned long : 0; 
             unsigned long bf_2 : 12; 
 } jhtest1;

//??
typedef struct _jhtest2 {
                  char foo : 4; 
                  short : 0; 
                  char bar; 
 } jhtest2;

//??
typedef struct _jhtest3 {
                 char foo : 4; 
                 short : 0; 
                 double bar; 
 } jhtest3;

//4
typedef struct _jhtest4 {
                    char foo : 6; 
                    long : 0; 
    } jhtest4;

// 2
typedef struct _jhtest5 {
                  char foo; 
                  long : 0; 
                  char bar; 
     } jhtest5;

typedef struct _jhtest {
    double xx;
    char y;
    double yy;
    long z;
} jhtest;



unsigned char jh_double = (sizeof (double) == 8 )?1:1111111;

unsigned char jh_test0 = (sizeof (jhtest) == (8*2+8) )?1:1111111;

unsigned char jh_test1 = (sizeof (jhtest1) == 8 )?1:1111111;

unsigned char jh_test2 = (sizeof (jhtest2) == 4 )?1:1111111;  // VC++

unsigned char jh_test3 = (sizeof (jhtest3) == 12 )?1:1111111;

unsigned char jh_test4 = (sizeof (jhtest4) == 4 )?1:1111111;

unsigned char jh_test5 = (sizeof (jhtest5) == 2 )?1:1111111; // VC++

int main()
{
}


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

* [Bug c/55428] -mms-bitfields hides -mno-align-double option
  2012-11-21 14:43 [Bug c/55428] New: -mms-bitfields hides -mno-align-double option kasberger at heidenhain dot de
@ 2012-11-21 15:21 ` mikpe at it dot uu.se
  2012-11-21 15:30 ` ktietz at gcc dot gnu.org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: mikpe at it dot uu.se @ 2012-11-21 15:21 UTC (permalink / raw)
  To: gcc-bugs


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

Mikael Pettersson <mikpe at it dot uu.se> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mikpe at it dot uu.se

--- Comment #1 from Mikael Pettersson <mikpe at it dot uu.se> 2012-11-21 15:20:41 UTC ---
Possibly related to PR52991 (-mms-bitfields breaks attribute((packed))).


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

* [Bug c/55428] -mms-bitfields hides -mno-align-double option
  2012-11-21 14:43 [Bug c/55428] New: -mms-bitfields hides -mno-align-double option kasberger at heidenhain dot de
  2012-11-21 15:21 ` [Bug c/55428] " mikpe at it dot uu.se
@ 2012-11-21 15:30 ` ktietz at gcc dot gnu.org
  2012-11-26  6:38 ` kasberger at heidenhain dot de
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: ktietz at gcc dot gnu.org @ 2012-11-21 15:30 UTC (permalink / raw)
  To: gcc-bugs


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

Kai Tietz <ktietz at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ktietz at gcc dot gnu.org

--- Comment #2 from Kai Tietz <ktietz at gcc dot gnu.org> 2012-11-21 15:30:12 UTC ---
Hmm, it seems that for ms-bitfields the default-field-alignment overrides all
field-local alignments.  I wouldn't assume that __attribute__((packed)) is
directly related to this issue, but of course it is close to it.  For the
packed-case the issue seems to be that it isn't used for the fields, but for
the last element in struct/union.

Btw the testcase works nice, if you use in front a #pragma pack(4).


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

* [Bug c/55428] -mms-bitfields hides -mno-align-double option
  2012-11-21 14:43 [Bug c/55428] New: -mms-bitfields hides -mno-align-double option kasberger at heidenhain dot de
  2012-11-21 15:21 ` [Bug c/55428] " mikpe at it dot uu.se
  2012-11-21 15:30 ` ktietz at gcc dot gnu.org
@ 2012-11-26  6:38 ` kasberger at heidenhain dot de
  2012-11-26  7:22 ` kasberger at heidenhain dot de
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: kasberger at heidenhain dot de @ 2012-11-26  6:38 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #3 from Andreas Kasberger <kasberger at heidenhain dot de> 2012-11-26 06:38:28 UTC ---
It is not working with gcc 4.6.2 or 4.7. I tried an old compiler gcc 3.4.3 and
the behavior was correct(In reply to comment #1)
> Possibly related to PR52991 (-mms-bitfields breaks attribute((packed))).

I tested both versions as well and same behavior
I tried an old compiler gcc 3.4.3 and the behavior was correct.


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

* [Bug c/55428] -mms-bitfields hides -mno-align-double option
  2012-11-21 14:43 [Bug c/55428] New: -mms-bitfields hides -mno-align-double option kasberger at heidenhain dot de
                   ` (2 preceding siblings ...)
  2012-11-26  6:38 ` kasberger at heidenhain dot de
@ 2012-11-26  7:22 ` kasberger at heidenhain dot de
  2012-11-26  9:52 ` [Bug target/55428] " kasberger at heidenhain dot de
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: kasberger at heidenhain dot de @ 2012-11-26  7:22 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #4 from Andreas Kasberger <kasberger at heidenhain dot de> 2012-11-26 07:21:51 UTC ---
(In reply to comment #2)
> Hmm, it seems that for ms-bitfields the default-field-alignment overrides all
> field-local alignments.  I wouldn't assume that __attribute__((packed)) is
> directly related to this issue, but of course it is close to it.  For the
> packed-case the issue seems to be that it isn't used for the fields, but for
> the last element in struct/union.
> 
> Btw the testcase works nice, if you use in front a #pragma pack(4).

I was also noticing the option f-pack-struct=4 will let the example running
fine.

Hmm....the option -mno-align-double is doing the alignment on one word boundary


(In reply to comment #3)
> It is not working with gcc 4.6.2 or 4.7. I tried an old compiler gcc 3.4.3 and
> the behavior was correct(In reply to comment #1)
> > Possibly related to PR52991 (-mms-bitfields breaks attribute((packed))).
> 
> I tested both versions as well and same behavior
> I tried an old compiler gcc 3.4.3 and the behavior was correct.

(In reply to comment #2)
> Hmm, it seems that for ms-bitfields the default-field-alignment overrides all
> field-local alignments.  I wouldn't assume that __attribute__((packed)) is
> directly related to this issue, but of course it is close to it.  For the
> packed-case the issue seems to be that it isn't used for the fields, but for
> the last element in struct/union.
> 
> Btw the testcase works nice, if you use in front a #pragma pack(4).


Yes, you are are right. I noticed that a -fpack-struct=4 doing it correctly. 

Hmm... -mno-align-double documentation says
-malign-double
-mno-align-double
Control whether GCC aligns double, long double, and long long variables on a
two word boundary or a one word boundary. Aligning double variables on a two
word boundary will produce code that runs somewhat faster on a Pentium at the
expense of more memory.

So what I understand is that -mno-align-double will do the boundary on one word
boundary.

-fpack-struct=4 documentation says
-fpack-struct[=n]
Without a value specified, pack all structure members together without holes.
When a value is specified (which must be a small power of two), pack structure
members according to this value, representing the maximum alignment (that is,
objects with default alignment requirements larger than this are output
potentially unaligned at the next fitting location.

In this case this would mean I would do the alignment on a double word
boundary.

The ms compiler option /zp4 will also do the alignment on double word boundary.
documentation:
The command-line option /Zp (Struct Member Alignment) sets the packsize to n,
in which n can be 1, 2, 4, 8, or 16, and in which 8 is the default.

Now I'm totally confused.

I will try to find out more and come back


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

* [Bug target/55428] -mms-bitfields hides -mno-align-double option
  2012-11-21 14:43 [Bug c/55428] New: -mms-bitfields hides -mno-align-double option kasberger at heidenhain dot de
                   ` (3 preceding siblings ...)
  2012-11-26  7:22 ` kasberger at heidenhain dot de
@ 2012-11-26  9:52 ` kasberger at heidenhain dot de
  2012-11-29  9:21 ` kasberger at heidenhain dot de
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: kasberger at heidenhain dot de @ 2012-11-26  9:52 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #5 from Andreas Kasberger <kasberger at heidenhain dot de> 2012-11-26 09:51:50 UTC ---
I found this example on
geeksforgeeks.org/forum/topic/c-structure-size-with-empty-bitfield

#define offset(a,b) (size_t)(&(((a*)(0))->b))
struct emp
{
char s:8;
char c:7;
char d:2;
int:14;
char u;
char g:2;
}e;

int l;
l = offset(struct emp,u);
printf("%d %d",sizeof(struct emp),l);

With this example it is impossible to get vsc++ /zp4 results with gcc options
without changing the souce code itself.
The ms compiler result is "12 8" on gcc I will get mostly 6 4

I'm not able to align the bitfields in the way like ms do it.
Each single bitfield is aligned at word boundary.


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

* [Bug target/55428] -mms-bitfields hides -mno-align-double option
  2012-11-21 14:43 [Bug c/55428] New: -mms-bitfields hides -mno-align-double option kasberger at heidenhain dot de
                   ` (4 preceding siblings ...)
  2012-11-26  9:52 ` [Bug target/55428] " kasberger at heidenhain dot de
@ 2012-11-29  9:21 ` kasberger at heidenhain dot de
  2012-11-29  9:24 ` ktietz at gcc dot gnu.org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: kasberger at heidenhain dot de @ 2012-11-29  9:21 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #6 from Andreas Kasberger <kasberger at heidenhain dot de> 2012-11-29 09:21:06 UTC ---
I hope at least someone can agree that the behavior for "-mms-bitfields
-mno-align-double" options in one command line is wrong and a bug


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

* [Bug target/55428] -mms-bitfields hides -mno-align-double option
  2012-11-21 14:43 [Bug c/55428] New: -mms-bitfields hides -mno-align-double option kasberger at heidenhain dot de
                   ` (5 preceding siblings ...)
  2012-11-29  9:21 ` kasberger at heidenhain dot de
@ 2012-11-29  9:24 ` ktietz at gcc dot gnu.org
  2022-01-10  8:21 ` [Bug target/55428] [9/10/11/12 Regression] " pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: ktietz at gcc dot gnu.org @ 2012-11-29  9:24 UTC (permalink / raw)
  To: gcc-bugs


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

Kai Tietz <ktietz at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-11-29
     Ever Confirmed|0                           |1

--- Comment #7 from Kai Tietz <ktietz at gcc dot gnu.org> 2012-11-29 09:23:55 UTC ---
Well, I can confirm that behavior looks wrong.  It is wrong now for a long-time
...  nevertheless I will take a look to it within next days.  There are other
issues about ms-struct-layout which are at least suspisious, too.


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

* [Bug target/55428] [9/10/11/12 Regression] -mms-bitfields hides -mno-align-double option
  2012-11-21 14:43 [Bug c/55428] New: -mms-bitfields hides -mno-align-double option kasberger at heidenhain dot de
                   ` (6 preceding siblings ...)
  2012-11-29  9:24 ` ktietz at gcc dot gnu.org
@ 2022-01-10  8:21 ` pinskia at gcc dot gnu.org
  2022-01-17 15:21 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-10  8:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55428

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|-mms-bitfields hides        |[9/10/11/12 Regression]
                   |-mno-align-double option    |-mms-bitfields hides
                   |                            |-mno-align-double option
      Known to fail|                            |4.4.7
   Target Milestone|---                         |9.5
           Keywords|                            |ABI, wrong-code

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

* [Bug target/55428] [9/10/11/12 Regression] -mms-bitfields hides -mno-align-double option
  2012-11-21 14:43 [Bug c/55428] New: -mms-bitfields hides -mno-align-double option kasberger at heidenhain dot de
                   ` (7 preceding siblings ...)
  2022-01-10  8:21 ` [Bug target/55428] [9/10/11/12 Regression] " pinskia at gcc dot gnu.org
@ 2022-01-17 15:21 ` rguenth at gcc dot gnu.org
  2022-05-27  9:34 ` [Bug target/55428] [10/11/12/13 " rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-01-17 15:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55428

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2

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

* [Bug target/55428] [10/11/12/13 Regression] -mms-bitfields hides -mno-align-double option
  2012-11-21 14:43 [Bug c/55428] New: -mms-bitfields hides -mno-align-double option kasberger at heidenhain dot de
                   ` (8 preceding siblings ...)
  2022-01-17 15:21 ` rguenth at gcc dot gnu.org
@ 2022-05-27  9:34 ` rguenth at gcc dot gnu.org
  2022-06-28 10:30 ` jakub at gcc dot gnu.org
  2023-07-07 10:29 ` [Bug target/55428] [11/12/13/14 " rguenth at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-05-27  9:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55428

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|9.5                         |10.4

--- Comment #8 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 9 branch is being closed

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

* [Bug target/55428] [10/11/12/13 Regression] -mms-bitfields hides -mno-align-double option
  2012-11-21 14:43 [Bug c/55428] New: -mms-bitfields hides -mno-align-double option kasberger at heidenhain dot de
                   ` (9 preceding siblings ...)
  2022-05-27  9:34 ` [Bug target/55428] [10/11/12/13 " rguenth at gcc dot gnu.org
@ 2022-06-28 10:30 ` jakub at gcc dot gnu.org
  2023-07-07 10:29 ` [Bug target/55428] [11/12/13/14 " rguenth at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-06-28 10:30 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55428

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.4                        |10.5

--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 10.4 is being released, retargeting bugs to GCC 10.5.

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

* [Bug target/55428] [11/12/13/14 Regression] -mms-bitfields hides -mno-align-double option
  2012-11-21 14:43 [Bug c/55428] New: -mms-bitfields hides -mno-align-double option kasberger at heidenhain dot de
                   ` (10 preceding siblings ...)
  2022-06-28 10:30 ` jakub at gcc dot gnu.org
@ 2023-07-07 10:29 ` rguenth at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-07 10:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55428

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.5                        |11.5

--- Comment #10 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 10 branch is being closed.

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

end of thread, other threads:[~2023-07-07 10:29 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-21 14:43 [Bug c/55428] New: -mms-bitfields hides -mno-align-double option kasberger at heidenhain dot de
2012-11-21 15:21 ` [Bug c/55428] " mikpe at it dot uu.se
2012-11-21 15:30 ` ktietz at gcc dot gnu.org
2012-11-26  6:38 ` kasberger at heidenhain dot de
2012-11-26  7:22 ` kasberger at heidenhain dot de
2012-11-26  9:52 ` [Bug target/55428] " kasberger at heidenhain dot de
2012-11-29  9:21 ` kasberger at heidenhain dot de
2012-11-29  9:24 ` ktietz at gcc dot gnu.org
2022-01-10  8:21 ` [Bug target/55428] [9/10/11/12 Regression] " pinskia at gcc dot gnu.org
2022-01-17 15:21 ` rguenth at gcc dot gnu.org
2022-05-27  9:34 ` [Bug target/55428] [10/11/12/13 " rguenth at gcc dot gnu.org
2022-06-28 10:30 ` jakub at gcc dot gnu.org
2023-07-07 10:29 ` [Bug target/55428] [11/12/13/14 " rguenth at gcc dot gnu.org

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).