On 6/24/19 4:25 AM, Jozef Lawrynowicz wrote:
> The MSP430 target in the large memory model uses the (non-ISO) __int20 type 
> for
> SIZE_TYPE and PTRDIFF_TYPE.
> The preprocessor therefore expands a builtin such as __SIZE_TYPE__ to
> "__int20 unsigned" in user code.
> When compiling with the "-pedantic-errors" flag, the use of any of these
> builtin macros results in an error of the form:
> 
>> tester.c:4:9: error: ISO C does not support '__int20' types [-Wpedantic]
> Since -pendantic-errors is often passed as a default flag in the testsuite,
> there are hundreds of false failures when testing with -mlarge, caused by this
> ISO C error.
> 
> The attached patch implements a new builtin type, "__intN__". Apart from the
> name of the type, it is identical and shares RIDs with the corresponding
> "__intN".
> 
> This means the ISO C pedantic warnings can be disabled for __intN__ types,
> but otherwise these types can be used in place of __intN without any other
> changes to behaviour.
> 
> By replacing "__int20" with "__int20__" in the definition of SIZE_TYPE and
> PTRDIFF_TYPE in msp430.h, the following builtin macros can now be used in a
> program compiled with -pedantic-errors, without causing ISO C errors:
>   __SIZE_TYPE__
>   __INTPTR_TYPE__
>   __UINTPTR_TYPE__
>   __PTRDIFF_TYPE__
> 
> Successfully bootstrapped and regtested on x86_64-pc-linux-gnu.
> Successfully regtested for msp430-elf. Additionally, this fixes many tests:
>   332 FAIL->PASS
>   52  UNTESTED->PASS
>   29  FAIL->UNSUPPORTED (test previously failed to compile, now too big to 
> link)
> 
> Ok for trunk?
> 
> There is a patch to Newlib's "_intsup.h" required to support __int20__ that I
> will submit to that mailing list before applying this patch, if this patch is
> accepted.
> 
> 
> 0001-Implement-alternate-__intN__-form-of-__intN-type.patch
> 
> From 61dfff1b6b3fcaa9f31341ee47623100505bf2e8 Mon Sep 17 00:00:00 2001
> From: Jozef Lawrynowicz <joze...@mittosystems.com>
> Date: Wed, 12 Jun 2019 10:40:00 +0100
> Subject: [PATCH] Implement alternate "__intN__" form of "__intN" type
> 
> gcc/ChangeLog:
> 
> 2019-06-18  Jozef Lawrynowicz  <joze...@mittosystems.com>
> 
>       * gcc/c-family/c-common.c (c_common_nodes_and_builtins): Define
>       alternate "__intN__" name for "__intN" types.
>       * gcc/c/c-parser.c (c_parse_init): Create keyword for "__intN__" type.
>       * gcc/cp/lex.c (init_reswords): Likewise.
>       * gcc/config/msp430/msp430.h: Use __int20__ for SIZE_TYPE and
>       PTRDIFF_TYPE.
>       * gcc/cp/cp-tree.h (cp_decl_specifier_seq): New bitfield "int_n_alt".
>       * gcc/c/c-decl.c (declspecs_add_type): Don't pedwarn about "__intN" ISO
>       C incompatibility if alternate "__intN__" form is used.
>       * gcc/cp/decl.c (grokdeclarator): Likewise.
>       * gcc/cp/parser.c (cp_parser_simple_type_specifier): Set
>       decl_specs->int_n_alt if "__intN__" form is used.
>       * gcc/gimple-ssa-sprintf.c (build_intmax_type_nodes): Accept "__intN__"
>       format of "__intN" types for UINTMAX_TYPE.
>       * gcc/brig/brig-lang.c (brig_build_c_type_nodes): Accept "__intN__"
>       format of "__intN" types for SIZE_TYPE.
>       * gcc/lto/lto-lang.c (lto_build_c_type_nodes): Likewise.
>       * gcc/stor-layout.c (initialize_sizetypes): Accept "__intN__"
>       format of "__intN" types for SIZETYPE.
>       * gcc/tree.c (build_common_tree_nodes): Accept "__intN__"
>       format of "__intN" types for SIZE_TYPE and PTRDIFF_TYPE.
>       * gcc/doc/invoke.texi: Document that __intN__ disables pedantic
>       warnings.
> 
> gcc/testsuite/ChangeLog:
> 
> 2019-06-18  Jozef Lawrynowicz  <joze...@mittosystems.com>
> 
>       * gcc.target/msp430/mlarge-pedwarns.c: New test.
> ---
>  gcc/brig/brig-lang.c                              |  6 ++++--
>  gcc/c-family/c-common.c                           |  6 ++++++
>  gcc/c/c-decl.c                                    |  6 +++++-
>  gcc/c/c-parser.c                                  |  5 +++++
>  gcc/config/msp430/msp430.h                        |  6 ++++--
>  gcc/cp/cp-tree.h                                  |  3 +++
>  gcc/cp/decl.c                                     |  6 +++++-
>  gcc/cp/lex.c                                      |  5 +++++
>  gcc/cp/parser.c                                   |  6 ++++++
>  gcc/doc/invoke.texi                               |  6 ++++--
>  gcc/gimple-ssa-sprintf.c                          |  6 ++++--
>  gcc/lto/lto-lang.c                                |  6 ++++--
>  gcc/stor-layout.c                                 |  6 ++++--
>  gcc/testsuite/gcc.target/msp430/mlarge-pedwarns.c | 11 +++++++++++
>  gcc/tree.c                                        | 13 +++++++++----
>  15 files changed, 79 insertions(+), 18 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/msp430/mlarge-pedwarns.c
> 
> diff --git a/gcc/brig/brig-lang.c b/gcc/brig/brig-lang.c
> index 91c7cfa35da..be853ccbc02 100644
> --- a/gcc/brig/brig-lang.c
> +++ b/gcc/brig/brig-lang.c
> @@ -864,10 +864,12 @@ brig_build_c_type_nodes (void)
>        for (i = 0; i < NUM_INT_N_ENTS; i++)
>       if (int_n_enabled_p[i])
>         {
> -         char name[50];
> +         char name[25], altname[25];
>           sprintf (name, "__int%d unsigned", int_n_data[i].bitsize);
> +         sprintf (altname, "__int%d__ unsigned", int_n_data[i].bitsize);
So isn't this going to cause problems with targets where a plain int is
64 bits and the sprintf format checking patches?  In that case it's
going to have to assume the numeric part is 20 characters  + 5 more for
the __int and you've overflowed.

Why not just keep the size at 50 bytes?

Similarly in a few other places where you made similar changes.

It looks fine with that fixed.

jeff

Reply via email to