public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/114344] New: [arm/mips] __alignof__ report a member packed struct as 1, while normal load/store instruction is used
@ 2024-03-15  1:09 syq at gcc dot gnu.org
  2024-03-15  1:33 ` [Bug target/114344] " pinskia at gcc dot gnu.org
  2024-03-15  1:35 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: syq at gcc dot gnu.org @ 2024-03-15  1:09 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114344
           Summary: [arm/mips] __alignof__ report a member packed struct
                    as 1, while normal load/store instruction is used
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: syq at gcc dot gnu.org
  Target Milestone: ---

#include <stdio.h>

volatile
struct s
{
  char c[4];
  int i;
  long long l;
  float f;
  double d;
} __attribute__ ((packed)) s;

int main() {
        s.i = 0x12345678;
        printf ("%zd\n", __alignof__ (s.i));
}


For this code, `1` is printed as the align of s.i. While on MIPS and ARM,
normal instructions are emitted.


$ mipsel-linux-gnu-gcc -Wall -mabi=32 -c -O3 xx.c -mips32r2
$ objdump -d xx.o
  ...
  34:   ac620004        sw      v0,4(v1)
  ...
If `__alignof__ (s.i)` reports correctly, `swl/swr` should be used instead of
`sw`.

And for 
$ mipsel-linux-gnu-gcc -c -O3 xx.c -mips32r6 -mno-unaligned-access
$ arm-linux-gnueabihf-gcc -c -O3 xx.c -mno-unaligned-access

4 store_byte instruction should be used, while in fact, `sw/str` is used here.

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

* [Bug target/114344] [arm/mips] __alignof__ report a member packed struct as 1, while normal load/store instruction is used
  2024-03-15  1:09 [Bug target/114344] New: [arm/mips] __alignof__ report a member packed struct as 1, while normal load/store instruction is used syq at gcc dot gnu.org
@ 2024-03-15  1:33 ` pinskia at gcc dot gnu.org
  2024-03-15  1:35 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-15  1:33 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(insn 5 4 6 (set (reg/f:SI 115)
        (symbol_ref:SI ("*.LANCHOR0") [flags 0x182])) "/app/example.cpp":13:13
-1
     (nil))

(insn 6 5 7 (set (reg:SI 116)
        (const_int 305419896 [0x12345678])) "/app/example.cpp":13:13 -1
     (nil))

(insn 7 6 0 (set (mem/v/c:SI (plus:SI (reg/f:SI 115)
                (const_int 4 [0x4])) [2 sD.6114.iD.6110+0 S4 A32])
        (reg:SI 116)) "/app/example.cpp":13:13 -1
     (nil))

        .align  2
        .set    .LANCHOR0,. + 0
        .type   s, %object
        .size   s, 28
s:

The s variable is still aligned to 4 bytes so s.i is still aligned.

Doing:
`s __attribute__((aligned(1)));`

Makes the variable s unknown alignment and we get the multiple stores then.

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

* [Bug target/114344] [arm/mips] __alignof__ report a member packed struct as 1, while normal load/store instruction is used
  2024-03-15  1:09 [Bug target/114344] New: [arm/mips] __alignof__ report a member packed struct as 1, while normal load/store instruction is used syq at gcc dot gnu.org
  2024-03-15  1:33 ` [Bug target/114344] " pinskia at gcc dot gnu.org
@ 2024-03-15  1:35 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-15  1:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note __alignof__ might say 1, but alignof vs what GCC knows the alignment of
the decl are 2 different things.

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

end of thread, other threads:[~2024-03-15  1:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-15  1:09 [Bug target/114344] New: [arm/mips] __alignof__ report a member packed struct as 1, while normal load/store instruction is used syq at gcc dot gnu.org
2024-03-15  1:33 ` [Bug target/114344] " pinskia at gcc dot gnu.org
2024-03-15  1:35 ` pinskia 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).