tkchia / gcc-ia16

Fork of Lambertsen & Jenner (& al.)'s IA-16 (Intel 16-bit x86) port of GNU compilers ― added far pointers & more • use https://github.com/tkchia/build-ia16 to build • Ubuntu binaries at https://launchpad.net/%7Etkchia/+archive/ubuntu/build-ia16/ • DJGPP/MS-DOS binaries at https://gitlab.com/tkchia/build-ia16/-/releases • mirror of https://gitlab.com/tkchia/gcc-ia16
GNU General Public License v2.0
173 stars 13 forks source link

ICE in g++ for template constructor with -mno-callee-assume-ss-data-segment #137

Open asiekierka opened 1 year ago

asiekierka commented 1 year ago
$ ia16-elf-g++ -O0 -mno-callee-assume-ss-data-segment -MMD -MP -c -o obj/celeste.o src/celeste.c
src/celeste.c: In constructor '_fix32::_fix32(T)':
src/celeste.c:8:43: internal compiler error: Segmentation fault
         template <typename T> _fix32(T v) { *this = v; /* use operator= */ }
                                           ^
Please submit a full bug report,
with preprocessed source if appropriate.

Does not occur without -mno-callee-assume-ss-data-segment. Admittedly, this is a personal build of the toolchain.

Code (sourced from ccleste - this portion is WTFPL-licensed as per issue):

typedef long int32_t;

struct _fix32 {
        int32_t n;

        template <typename T> _fix32(T v) { *this = v; /* use operator= */ }
};
tkchia commented 1 year ago

Hello @asiekierka,

This is hard to fix unfortunately. Named address spaces are simply not supported by G++ at the moment — the C++ middle-end basically assumes that all pointers are compatible with void *. And -mno-callee-assume-ss-data-segment implicitly uses a named address space (__seg_ss).

I guess for the time being I should make gcc-ia16 show a clearer error message for such situations, rather than crashing on a null pointer...

Thank you!

asiekierka commented 1 year ago

Ah, I understand now. I thought the problem is only at the level of code parsing, not throughout the entire middle-end. Thank you!

asiekierka commented 1 year ago

I wonder: wouldn't adding support for the large memory model effectively work around this "cheaper" than making major patches to the C++ middle-end? That is to say, if void * is a far pointer...