public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/94662] New: __attribute__ aligned is ignored
@ 2020-04-19 19:39 petro.karashchenko at gmail dot com
  2021-09-02  3:30 ` [Bug middle-end/94662] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: petro.karashchenko at gmail dot com @ 2020-04-19 19:39 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94662
           Summary: __attribute__ aligned is ignored
           Product: gcc
           Version: 9.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: petro.karashchenko at gmail dot com
  Target Milestone: ---

__attribute__ 'aligned' is ignored.

Test case 1:
----------
int __attribute__((aligned(1))) var;

int foo(void)
{
  return var;
}
----------
arm-none-eabi-gcc -save-temps -Wall -Wextra -c -mcpu=arm7tdmi -mthumb test.c
-O0
----------
Generated assembly:
        .cpu arm7tdmi
        .eabi_attribute 20, 1
        .eabi_attribute 21, 1
        .eabi_attribute 23, 3
        .eabi_attribute 24, 1
        .eabi_attribute 25, 1
        .eabi_attribute 26, 1
        .eabi_attribute 30, 6
        .eabi_attribute 34, 0
        .eabi_attribute 18, 4
        .file   "test.c"
        .text
        .comm   var,4,1
        .align  1
        .global foo
        .arch armv4t
        .syntax unified
        .code   16
        .thumb_func
        .fpu softvfp
        .type   foo, %function
foo:
        @ Function supports interworking.
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 1, uses_anonymous_args = 0
        push    {r7, lr}
        add     r7, sp, #0
        ldr     r3, .L3
        ldr     r3, [r3]
        movs    r0, r3
        mov     sp, r7
        @ sp needed
        pop     {r7}
        pop     {r1}
        bx      r1
.L4:
        .align  2
.L3:
        .word   var
        .size   foo, .-foo
        .ident  "GCC: (GNU Tools for Arm Embedded Processors 9-2019-q4-major)
9.2.1 20191025 (release) [ARM/arm-9-branch revision 277599]"
----------

Test case 2:
----------
int __attribute__((aligned(1))) * var = (int *)0x03;

int foo(void)
{
  return *var;
}
----------
arm-none-eabi-gcc -save-temps -Wall -Wextra -c -mcpu=arm7tdmi -mthumb test.c
-O0
----------
Generated assembly:
        .cpu arm7tdmi
        .eabi_attribute 20, 1
        .eabi_attribute 21, 1
        .eabi_attribute 23, 3
        .eabi_attribute 24, 1
        .eabi_attribute 25, 1
        .eabi_attribute 26, 1
        .eabi_attribute 30, 6
        .eabi_attribute 34, 0
        .eabi_attribute 18, 4
        .file   "test.c"
        .text
        .global var
        .data
        .type   var, %object
        .size   var, 4
var:
        .4byte  3
        .text
        .align  1
        .global foo
        .arch armv4t
        .syntax unified
        .code   16
        .thumb_func
        .fpu softvfp
        .type   foo, %function
foo:
        @ Function supports interworking.
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 1, uses_anonymous_args = 0
        push    {r7, lr}
        add     r7, sp, #0
        ldr     r3, .L3
        ldr     r3, [r3]
        ldr     r3, [r3]
        movs    r0, r3
        mov     sp, r7
        @ sp needed
        pop     {r7}
        pop     {r1}
        bx      r1
.L4:
        .align  2
.L3:
        .word   var
        .size   foo, .-foo
        .ident  "GCC: (GNU Tools for Arm Embedded Processors 9-2019-q4-major)
9.2.1 20191025 (release) [ARM/arm-9-branch revision 277599]"
----------

Test case 3:
----------
int foo(void)
{
  return *(int __attribute__((aligned(1))) *) 0x03;
}
----------
arm-none-eabi-gcc -save-temps -Wall -Wextra -c -mcpu=arm7tdmi -mthumb test.c
-O0
----------
Generated assembly:
        .cpu arm7tdmi
        .eabi_attribute 20, 1
        .eabi_attribute 21, 1
        .eabi_attribute 23, 3
        .eabi_attribute 24, 1
        .eabi_attribute 25, 1
        .eabi_attribute 26, 1
        .eabi_attribute 30, 6
        .eabi_attribute 34, 0
        .eabi_attribute 18, 4
        .file   "test.c"
        .text
        .align  1
        .global foo
        .arch armv4t
        .syntax unified
        .code   16
        .thumb_func
        .fpu softvfp
        .type   foo, %function
foo:
        @ Function supports interworking.
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 1, uses_anonymous_args = 0
        push    {r7, lr}
        add     r7, sp, #0
        movs    r3, #3
        ldr     r3, [r3]
        movs    r0, r3
        mov     sp, r7
        @ sp needed
        pop     {r7}
        pop     {r1}
        bx      r1
        .size   foo, .-foo
        .ident  "GCC: (GNU Tools for Arm Embedded Processors 9-2019-q4-major)
9.2.1 20191025 (release) [ARM/arm-9-branch revision 277599]"
----------

In all 3 test cases I'm expecting that unaligned access code should be
generated, but in all 3 test cases generated access is aligned.

However in next test case the align attribute actually takes effect:
----------
int foo(void)
{
  return **(int * __attribute__((aligned(1))) *) 0x03;
}

int foo1(void)
{
  return ***(int * __attribute__((aligned(1))) * __attribute__((aligned(1))) *)
0x03;
}
----------
arm-none-eabi-gcc -save-temps -Wall -Wextra -c -mcpu=arm7tdmi -mthumb test.c
-O0
----------
Generated assembly:
        .cpu arm7tdmi
        .eabi_attribute 20, 1
        .eabi_attribute 21, 1
        .eabi_attribute 23, 3
        .eabi_attribute 24, 1
        .eabi_attribute 25, 1
        .eabi_attribute 26, 1
        .eabi_attribute 30, 6
        .eabi_attribute 34, 0
        .eabi_attribute 18, 4
        .file   "test.c"
        .text
        .align  1
        .global foo
        .arch armv4t
        .syntax unified
        .code   16
        .thumb_func
        .fpu softvfp
        .type   foo, %function
foo:
        @ Function supports interworking.
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 1, uses_anonymous_args = 0
        push    {r7, lr}
        add     r7, sp, #0
        movs    r3, #3
        ldrb    r2, [r3]
        ldrb    r1, [r3, #1]
        lsls    r1, r1, #8
        orrs    r2, r1
        ldrb    r1, [r3, #2]
        lsls    r1, r1, #16
        orrs    r2, r1
        ldrb    r3, [r3, #3]
        lsls    r3, r3, #24
        orrs    r3, r2
        ldr     r3, [r3]
        movs    r0, r3
        mov     sp, r7
        @ sp needed
        pop     {r7}
        pop     {r1}
        bx      r1
        .size   foo, .-foo
        .align  1
        .global foo1
        .syntax unified
        .code   16
        .thumb_func
        .fpu softvfp
        .type   foo1, %function
foo1:
        @ Function supports interworking.
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 1, uses_anonymous_args = 0
        push    {r7, lr}
        add     r7, sp, #0
        movs    r3, #3
        ldrb    r2, [r3]
        ldrb    r1, [r3, #1]
        lsls    r1, r1, #8
        orrs    r2, r1
        ldrb    r1, [r3, #2]
        lsls    r1, r1, #16
        orrs    r2, r1
        ldrb    r3, [r3, #3]
        lsls    r3, r3, #24
        orrs    r3, r2
        ldrb    r2, [r3]
        ldrb    r1, [r3, #1]
        lsls    r1, r1, #8
        orrs    r2, r1
        ldrb    r1, [r3, #2]
        lsls    r1, r1, #16
        orrs    r2, r1
        ldrb    r3, [r3, #3]
        lsls    r3, r3, #24
        orrs    r3, r2
        ldr     r3, [r3]
        movs    r0, r3
        mov     sp, r7
        @ sp needed
        pop     {r7}
        pop     {r1}
        bx      r1
        .size   foo1, .-foo1
        .ident  "GCC: (GNU Tools for Arm Embedded Processors 9-2019-q4-major)
9.2.1 20191025 (release) [ARM/arm-9-branch revision 277599]"
----------

My expectation is next:
1. int __attribute__((aligned(1))) * var; -- aligned pointer to unaligned 'int'
value, hence the '*var' (memory addressed by pointer access) code should
generate a set of 'ldrb'->`lsls`->'orrs', but 'var' (pointer value access) code
should generate 'ldr'.
2. int * __attribute__((aligned(1))) var; -- unaligned pointer to aligned 'int'
value, hence the 'var' (pointer value access) code should generate a set of
'ldrb'->`lsls`->'orrs', but '*var' (memory addressed by pointer access) code
should generate 'ldr'.
3. int __attribute__((aligned(1))) * __attribute__((aligned(1))) var; --
unaligned pointer to unaligned 'int' value, hence both 'var' (pointer value
access) and '*var' (memory addressed by pointer access) code should generate  a
set of 'ldrb'->`lsls`->'orrs'.

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

* [Bug middle-end/94662] __attribute__ aligned is ignored
  2020-04-19 19:39 [Bug middle-end/94662] New: __attribute__ aligned is ignored petro.karashchenko at gmail dot com
@ 2021-09-02  3:30 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-02  3:30 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 88085.

*** This bug has been marked as a duplicate of bug 88085 ***

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

end of thread, other threads:[~2021-09-02  3:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-19 19:39 [Bug middle-end/94662] New: __attribute__ aligned is ignored petro.karashchenko at gmail dot com
2021-09-02  3:30 ` [Bug middle-end/94662] " 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).