[Bug 2122360] [NEW] GCC 13.3.0 ICE: pointer to subobject used as non-type template parameter in minimal template instantiation (anonymous union member)

Anton Zinoviev 2122360 at bugs.launchpad.net
Mon Sep 8 19:07:12 UTC 2025


Public bug reported:

Environment
-----------

* GCC version:
  * gcc version 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04)
* Target:
  * x86_64-linux-gnu
* Configure options (from g++ -v):
  * Configured with: ../src/configure -v --with-pkgversion='Ubuntu 13.3.0-6ubuntu2~24.04' --with-bugurl=file:///usr/share/doc/gcc-13/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-13 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-libstdcxx-backtrace --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-13-fG75Ri/gcc-13-13.3.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-13-fG75Ri/gcc-13-13.3.0/debian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2

System type
-----------

* x86_64-linux-gnu on Ubuntu 24.04.

Minimal reproducer (gcc_ice_min7.cpp)
-------------------------------------

It is reduced to what appears to be the smallest form that still crashes
GCC. Removing any piece tends to avoid the ICE.

template <int* Ptr>
struct StaticIntPtr {};

template <typename P>
struct S {
    union { P payload; };
    S() {}
};

S<int> n{};
S<StaticIntPtr<&n.payload>> m;

int main() { return 0; }

Command line to reproduce
-------------------------

* g++ -std=c++20 -O2 -Wall -Wextra -pedantic -v -o gcc_ice_min7.gcc
gcc_ice_min7.cpp

Compiler output
---------------

* Excerpt from a failing build (segmentation fault/ICE):

$ g++ -std=c++20 -O2 -Wall -Wextra -pedantic -o gcc_ice_min7 gcc_ice_min7.cpp
gcc_ice_min7.cpp: In instantiation of ‘S<P>::S() [with P = StaticIntPtr<(& n.S<int>::<anonymous>.S<int>::<unnamed union>::payload)>]’:
gcc_ice_min7.cpp:7:10:   required from ‘S<P>::S() [with P = StaticIntPtr<(& n.S<int>::<anonymous>.S<int>::<unnamed union>::payload)>]’
gcc_ice_min7.cpp:11:29:   required from here
gcc_ice_min7.cpp:7:5: internal compiler error: Нарушение на разделянето(segfault)
    7 |     S() {}
      |     ^
0x70b3b6a4532f ???
	./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0x70b3b6a2a1c9 __libc_start_call_main
	../sysdeps/nptl/libc_start_call_main.h:58
0x70b3b6a2a28a __libc_start_main_impl
	../csu/libc-start.c:360
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-13/README.Bugs> for instructions.

Observed behavior
-----------------

* GCC 13.3.0 crashes with an ICE (segmentation fault) when compiling the above code.
* Clang (tested with libc++) compiles similar patterns without error.

Expected behavior
-----------------

* The code should either compile or be rejected with a diagnostic, but
it should not cause an internal compiler error.

Notes
-----

* The reproducer uses:
  * A single NTTP overall (pointer to subobject &n.payload embedded in the type parameter P = StaticIntPtr<&n.payload>).
  * A simple anonymous union { P payload; } inside S.
  * Static objects n and m in the same translation unit.
* The ICE seems tied to using the address of an anonymous union/struct subobject as an NTTP.  The program compiles if instead of the anonymous union, a named union is used.

Attachment
----------

Preprocessed source produced by:
* g++ -std=c++20 -E gcc_ice_min7.cpp -o gcc_ice_min7.ii

** Affects: gcc-13 (Ubuntu)
     Importance: Undecided
         Status: New

** Attachment added: "Preprocessed source"
   https://bugs.launchpad.net/bugs/2122360/+attachment/5907855/+files/gcc_ice_min7.ii

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to gcc-13 in Ubuntu.
https://bugs.launchpad.net/bugs/2122360

Title:
  GCC 13.3.0 ICE: pointer to subobject used as non-type template
  parameter in minimal template instantiation (anonymous union member)

Status in gcc-13 package in Ubuntu:
  New

Bug description:
  Environment
  -----------

  * GCC version:
    * gcc version 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04)
  * Target:
    * x86_64-linux-gnu
  * Configure options (from g++ -v):
    * Configured with: ../src/configure -v --with-pkgversion='Ubuntu 13.3.0-6ubuntu2~24.04' --with-bugurl=file:///usr/share/doc/gcc-13/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-13 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-libstdcxx-backtrace --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-13-fG75Ri/gcc-13-13.3.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-13-fG75Ri/gcc-13-13.3.0/debian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2

  System type
  -----------

  * x86_64-linux-gnu on Ubuntu 24.04.

  Minimal reproducer (gcc_ice_min7.cpp)
  -------------------------------------

  It is reduced to what appears to be the smallest form that still
  crashes GCC. Removing any piece tends to avoid the ICE.

  template <int* Ptr>
  struct StaticIntPtr {};

  template <typename P>
  struct S {
      union { P payload; };
      S() {}
  };

  S<int> n{};
  S<StaticIntPtr<&n.payload>> m;

  int main() { return 0; }

  Command line to reproduce
  -------------------------

  * g++ -std=c++20 -O2 -Wall -Wextra -pedantic -v -o gcc_ice_min7.gcc
  gcc_ice_min7.cpp

  Compiler output
  ---------------

  * Excerpt from a failing build (segmentation fault/ICE):

  $ g++ -std=c++20 -O2 -Wall -Wextra -pedantic -o gcc_ice_min7 gcc_ice_min7.cpp
  gcc_ice_min7.cpp: In instantiation of ‘S<P>::S() [with P = StaticIntPtr<(& n.S<int>::<anonymous>.S<int>::<unnamed union>::payload)>]’:
  gcc_ice_min7.cpp:7:10:   required from ‘S<P>::S() [with P = StaticIntPtr<(& n.S<int>::<anonymous>.S<int>::<unnamed union>::payload)>]’
  gcc_ice_min7.cpp:11:29:   required from here
  gcc_ice_min7.cpp:7:5: internal compiler error: Нарушение на разделянето(segfault)
      7 |     S() {}
        |     ^
  0x70b3b6a4532f ???
  	./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
  0x70b3b6a2a1c9 __libc_start_call_main
  	../sysdeps/nptl/libc_start_call_main.h:58
  0x70b3b6a2a28a __libc_start_main_impl
  	../csu/libc-start.c:360
  Please submit a full bug report, with preprocessed source (by using -freport-bug).
  Please include the complete backtrace with any bug report.
  See <file:///usr/share/doc/gcc-13/README.Bugs> for instructions.

  Observed behavior
  -----------------

  * GCC 13.3.0 crashes with an ICE (segmentation fault) when compiling the above code.
  * Clang (tested with libc++) compiles similar patterns without error.

  Expected behavior
  -----------------

  * The code should either compile or be rejected with a diagnostic, but
  it should not cause an internal compiler error.

  Notes
  -----

  * The reproducer uses:
    * A single NTTP overall (pointer to subobject &n.payload embedded in the type parameter P = StaticIntPtr<&n.payload>).
    * A simple anonymous union { P payload; } inside S.
    * Static objects n and m in the same translation unit.
  * The ICE seems tied to using the address of an anonymous union/struct subobject as an NTTP.  The program compiles if instead of the anonymous union, a named union is used.

  Attachment
  ----------

  Preprocessed source produced by:
  * g++ -std=c++20 -E gcc_ice_min7.cpp -o gcc_ice_min7.ii

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/gcc-13/+bug/2122360/+subscriptions




More information about the foundations-bugs mailing list