This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Preventing ISO C errors when using macros for builtin types
- From: Segher Boessenkool <segher at kernel dot crashing dot org>
- To: Jozef Lawrynowicz <jozefl dot gcc at gmail dot com>
- Cc: Richard Biener <richard dot guenther at gmail dot com>, David Malcolm <dmalcolm at redhat dot com>, GCC Development <gcc at gcc dot gnu dot org>
- Date: Mon, 10 Jun 2019 17:09:10 -0500
- Subject: Re: Preventing ISO C errors when using macros for builtin types
- References: <20190605142559.05791323@jozef-kubuntu> <CAFiYyc3cVsk1phrC0gTJa=mJOjzCJ-Be2GTaaYoJemCNBRYb0w@mail.gmail.com> <20190610172031.66eabae6@jozef-kubuntu> <20190610183242.GG31586@gate.crashing.org> <20190610205800.0cf0cdef@jozef-kubuntu>
On Mon, Jun 10, 2019 at 08:58:00PM +0100, Jozef Lawrynowicz wrote:
> On Mon, 10 Jun 2019 13:32:42 -0500
> Segher Boessenkool <segher@kernel.crashing.org> wrote:
> > That is not a fix, that is sweeping the problem under the rug.
> >
> > As a somewhat dirty hack I added
> >
> > #if __MSP430X_LARGE__
> > #undef __SIZE_TYPE__
> > __extension__ typedef unsigned __int20 __SIZE_TYPE__;
> > #endif
> >
> > to the start of the installed stddef.h, and that fixes the problem fine,
> > for correct programs that do not forget to include <stddef.h> (directly
> > or indirectly), anyway.
> But we have some 850 generic tests in gcc/testsuite that use __SIZE_TYPE__
> without including stddef.h. They just rely on the preprocessor to expand this
> using the builtin macro definition.
I did say it is a dirty hack, right?
You could call lang_hooks.types.register_builtin_type defining the type
__SIZE_TYPE__ as the int20 partial int type, and then define SIZE_TYPE as
just __SIZE_TYPE__. That is the same effectively, just not using the
header file.
So something like
tree type_node = builtin_type_for_size (20, 1);
lang_hooks.types.register_builtin_type (type_node, "__SIZE_TYPE__");
or maybe
tree type_node = builtin_type_for_size (POINTER_SIZE, 1);
lang_hooks.types.register_builtin_type (type_node, "__SIZE_TYPE__");
in msp430.c, and
#define SIZE_TYPE "__SIZE_TYPE__"
in msp430.h?
Segher