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

            Bug ID: 126573
           Summary: ICE with __attribute aligned
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bwheatman at gmail dot com
  Target Milestone: ---

The following minified example crashes.

https://godbolt.org/z/Yhb7qWz5T

```
template<class T>
struct foo { using type = int; };
using af =  __attribute ((aligned(8))) int;
static_assert(alignof(foo<af[2]>::type) == 8);attribute aligned 
```

The full output is 
```
<source>:4:31: error: alignment of array elements is greater than element size
    4 | static_assert(alignof(foo<af[2]>::type) == 8);attribute aligned
      |                               ^
<source>:4:31: error: alignment of array elements is greater than element size
<source>:4:32: error: alignment of array elements is greater than element size
    4 | static_assert(alignof(foo<af[2]>::type) == 8);attribute aligned
      |                                ^

internal compiler error: error reporting routines re-entered.
0x2b79d50
diagnostics::context::report_diagnostic(diagnostics::diagnostic_info*)
        ???:0
0x2b79f68 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
        ???:0
0x2b6da29 error(char const*, ...)
        ???:0
0x1938ff9 build_array_type_1(tree_node*, tree_node*, bool, bool, bool)
        ???:0
0x2be0553 pretty_printer::format(text_info&)
        ???:0
0x2b79863
diagnostics::context::report_diagnostic(diagnostics::diagnostic_info*)
        ???:0
0x2b79f68 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
        ???:0
0x2b6baff warning(diagnostics::option_id, char const*, ...)
        ???:0
0xda0409 canonicalize_type_argument(tree_node*, int)
        ???:0
0xddfa93 coerce_template_parms(tree_node*, tree_node*, tree_node*, int, bool)
        ???:0
0xdcb4e4 lookup_template_class(tree_node*, tree_node*, tree_node*, tree_node*,
int)
        ???:0
0xe364bc finish_template_type(tree_node*, tree_node*, int)
        ???:0
0xd939a3 c_parse_file()
        ???:0
0xf26d59 c_common_parse_file()
        ???:0
/cefs/21/21b5c21c3412bc08f8802901_gcc-trunk-20260801/bin/../libexec/gcc/x86_64-linux-gnu/17.0.0/cc1plus
-quiet -imultiarch x86_64-linux-gnu -iprefix
/cefs/21/21b5c21c3412bc08f8802901_gcc-trunk-20260801/bin/../lib/gcc/x86_64-linux-gnu/17.0.0/
-D_GNU_SOURCE <source> -quiet -dumpdir /app/ -dumpbase output.cpp -dumpbase-ext
.cpp -masm=intel -mtune=generic -march=x86-64 -g -fdiagnostics-color=always
-fno-verbose-asm -o /app/output.s
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1
```

Tested on versions 
g++
(Compiler-Explorer-Build-gcc-4dcc1628511589a85d7e0ddceee6cb022cbe7d32-binutils-2.44)
17.0.0 20260801 (experimental)
and 16.1


I believe the code is invalid in that `__attribute ((aligned(8)))` can't be in
a using statement.  This also leads to oddities where the alignment of the type
can be greater than the size
```
using af =  __attribute ((aligned(8))) int;
static_assert(alignof(af) == 8);
static_assert(sizeof(af) == 4);
```

Which I believe is against the standard since
7.6.2.5
Definition of sizeof
" When applied to a class, the result is the number of bytes in an object of
that class including any padding required for placing objects of that type in
an array."

I think the correct outcome of this is to reject the code as invalid

Reply via email to