Bug 31397 - arrays with structs with arrays gets the wrong alignment
Summary: arrays with structs with arrays gets the wrong alignment
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: compile (show other bugs)
Version: unknown
: P2 normal
Target Milestone: 15.1
Assignee: Tom Tromey
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-02-18 02:57 UTC by Andrew Pinski
Modified: 2024-03-14 15:56 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
src.c (117 bytes, text/plain)
2024-02-18 02:57 UTC, Andrew Pinski
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2024-02-18 02:57:10 UTC
```
gcc src.c -gdwarf-5 -o a.out && gdb a.out

(gdb) b 13
Breakpoint 1 at 0x1170: file src.c, line 13.
(gdb) run
Starting program: a.out 

(gdb) expr z[0]._[0] = 1
gdb command line:1:1: error: size of array element is not a multiple of its alignment
Compilation failed.
(gdb) expr y[0]._[0] = 1
(gdb) expr x[0]._[0] = 1
gdb command line:1:1: error: alignment of array elements is greater than element size
Compilation failed.
```

Running with the trunk gcc and the trunk gdb here and this fails.
Comment 1 Andrew Pinski 2024-02-18 02:57:31 UTC
Created attachment 15375 [details]
src.c
Comment 2 Andrew Pinski 2024-02-18 03:01:00 UTC
This was originally reported on the gcc side (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113977) but the debug info seems correct. Since the default alignment is specified, it seems like gcc_convert_symbol is adding the wrong alignment for the struct which causes gcc to reject the array definition. The alignment of s7, s8, and s9 are all 1 since it has an array of char's.
Comment 3 Tom Tromey 2024-02-20 18:25:23 UTC
I think this requires a combination fix, since
the protocol doesn't allow for alignment.
I'll comment on the gcc bug.
Comment 4 Tom Tromey 2024-02-22 01:46:06 UTC
I have a patch.
Comment 5 Sourceware Commits 2024-02-29 22:38:05 UTC
The master branch has been updated by Tom Tromey <tromey@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f9771d0e80c3a98e865c7ee5139cadf9d73db436

commit f9771d0e80c3a98e865c7ee5139cadf9d73db436
Author: Tom Tromey <tom@tromey.com>
Date:   Tue Feb 20 17:15:03 2024 -0700

    Synchronize GCC compile plugin headers
    
    This patch copies some changes to the compile headers from GCC's
    include/ directory.  It is the gdb equivalent of the GCC commit
    bc0e18a9 -- however, while that commit also necessarily touched
    libcc1, this one of course does not.
    
    Tested by rebuilding and also running the gdb.compile tests.
    
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31397
Comment 6 Sourceware Commits 2024-03-14 15:56:03 UTC
The master branch has been updated by Tom Tromey <tromey@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=91e15dbaf9d05747fab0d33e5af7ae69c983398a

commit 91e15dbaf9d05747fab0d33e5af7ae69c983398a
Author: Tom Tromey <tom@tromey.com>
Date:   Wed Feb 21 08:22:01 2024 -0700

    Pass alignment when using GCC_C_FE_VERSION_2
    
    When the GCC compiler plugin responds with GCC_C_FE_VERSION_2, gdb can
    use the new 'finish_record_with_alignment' method.  This lets gdb pass
    alignment information to the compiler, which in turn fixes the test
    case included in this patch.
    
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31397
Comment 7 Tom Tromey 2024-03-14 15:56:37 UTC
Fixed.