diff mbox series

[MSP430] Implement alternate "__intN__" form of "__intN" type

Message ID 20190624112505.748060b3@jozef-kubuntu
State New
Headers show
Series [MSP430] Implement alternate "__intN__" form of "__intN" type | expand

Commit Message

Jozef Lawrynowicz June 24, 2019, 10:25 a.m. UTC
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.

Comments

Jeff Law June 24, 2019, 11:53 p.m. UTC | #1
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 <jozef.l@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  <jozef.l@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  <jozef.l@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
Jozef Lawrynowicz June 25, 2019, 9:57 a.m. UTC | #2
On Mon, 24 Jun 2019 17:53:48 -0600
Jeff Law <law@redhat.com> wrote:

> On 6/24/19 4:25 AM, Jozef Lawrynowicz wrote:
> > 
> > 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.

Thanks, yes that was just an oversight where I thought I could save some space
for "free".
> 
> It looks fine with that fixed.

Fixed and applied.

Thanks,
Jozef
> 
> jeff
diff mbox series

Patch

From 61dfff1b6b3fcaa9f31341ee47623100505bf2e8 Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz <jozef.l@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  <jozef.l@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  <jozef.l@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);
 
-	    if (strcmp (name, SIZE_TYPE) == 0)
+	    if (strcmp (name, SIZE_TYPE) == 0
+		|| strcmp (altname, SIZE_TYPE) == 0)
 	      {
 		intmax_type_node = int_n_trees[i].signed_type;
 		uintmax_type_node = int_n_trees[i].unsigned_type;
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 4057be3aaed..57e84b84f07 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -4024,8 +4024,14 @@  c_common_nodes_and_builtins (void)
       sprintf (name, "__int%d", int_n_data[i].bitsize);
       record_builtin_type ((enum rid)(RID_FIRST_INT_N + i), name,
 			   int_n_trees[i].signed_type);
+      sprintf (name, "__int%d__", int_n_data[i].bitsize);
+      record_builtin_type ((enum rid)(RID_FIRST_INT_N + i), name,
+			   int_n_trees[i].signed_type);
+
       sprintf (name, "__int%d unsigned", int_n_data[i].bitsize);
       record_builtin_type (RID_MAX, name, int_n_trees[i].unsigned_type);
+      sprintf (name, "__int%d__ unsigned", int_n_data[i].bitsize);
+      record_builtin_type (RID_MAX, name, int_n_trees[i].unsigned_type);
     }
 
   if (c_dialect_cxx ())
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index 87ce853d4b7..cb2f49fa5a2 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -10637,7 +10637,11 @@  declspecs_add_type (location_t loc, struct c_declspecs *specs,
 	    case RID_INT_N_2:
 	    case RID_INT_N_3:
 	      specs->int_n_idx = i - RID_INT_N_0;
-	      if (!in_system_header_at (input_location))
+	      if (!in_system_header_at (input_location)
+		  /* If the INT_N type ends in "__", and so is of the format
+		     "__intN__", don't pedwarn.  */
+		  && (strncmp (IDENTIFIER_POINTER (type)
+			       + (IDENTIFIER_LENGTH (type) - 2), "__", 2) != 0))
 		pedwarn (loc, OPT_Wpedantic,
 			 "ISO C does not support %<__int%d%> types",
 			 int_n_data[specs->int_n_idx].bitsize);
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index df1a3042276..98508721ed9 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -157,6 +157,11 @@  c_parse_init (void)
       id = get_identifier (name);
       C_SET_RID_CODE (id, RID_FIRST_INT_N + i);
       C_IS_RESERVED_WORD (id) = 1;
+
+      sprintf (name, "__int%d__", int_n_data[i].bitsize);
+      id = get_identifier (name);
+      C_SET_RID_CODE (id, RID_FIRST_INT_N + i);
+      C_IS_RESERVED_WORD (id) = 1;
     }
 }
 
diff --git a/gcc/config/msp430/msp430.h b/gcc/config/msp430/msp430.h
index c0aa8eacd96..1288b1a263d 100644
--- a/gcc/config/msp430/msp430.h
+++ b/gcc/config/msp430/msp430.h
@@ -185,9 +185,11 @@  extern const char * msp430_select_hwmult_lib (int, const char **);
 /* Layout of Source Language Data Types */
 
 #undef  SIZE_TYPE
-#define SIZE_TYPE			(TARGET_LARGE ? "__int20 unsigned" : "unsigned int")
+#define SIZE_TYPE			(TARGET_LARGE \
+					 ? "__int20__ unsigned" \
+					 : "unsigned int")
 #undef  PTRDIFF_TYPE
-#define PTRDIFF_TYPE			(TARGET_LARGE ? "__int20" : "int")
+#define PTRDIFF_TYPE			(TARGET_LARGE ? "__int20__" : "int")
 #undef  WCHAR_TYPE
 #define WCHAR_TYPE			"long int"
 #undef  WCHAR_TYPE_SIZE
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 1f4e1e15554..91ac0a2d06c 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -5863,6 +5863,9 @@  struct cp_decl_specifier_seq {
   BOOL_BITFIELD gnu_thread_keyword_p : 1;
   /* True iff the type is a decltype.  */
   BOOL_BITFIELD decltype_p : 1;
+  /* True iff the alternate "__intN__" form of the __intN type has been
+     used.  */
+  BOOL_BITFIELD int_n_alt: 1;
 };
 
 /* The various kinds of declarators.  */
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 0a3ef452536..334c024a281 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -10349,6 +10349,7 @@  grokdeclarator (const cp_declarator *declarator,
   tree type = NULL_TREE;
   int longlong = 0;
   int explicit_intN = 0;
+  int int_n_alt = 0;
   int virtualp, explicitp, friendp, inlinep, staticp;
   int explicit_int = 0;
   int explicit_char = 0;
@@ -10422,6 +10423,7 @@  grokdeclarator (const cp_declarator *declarator,
   long_p = decl_spec_seq_has_spec_p (declspecs, ds_long);
   longlong = decl_spec_seq_has_spec_p (declspecs, ds_long_long);
   explicit_intN = declspecs->explicit_intN_p;
+  int_n_alt = declspecs->int_n_alt;
   thread_p = decl_spec_seq_has_spec_p (declspecs, ds_thread);
 
   // Was concept_p specified? Note that ds_concept
@@ -10823,7 +10825,9 @@  grokdeclarator (const cp_declarator *declarator,
 		 int_n_data[declspecs->int_n_idx].bitsize);
 	  explicit_intN = false;
 	}
-      else if (pedantic && ! in_system_header_at (input_location))
+      /* Don't pedwarn if the alternate "__intN__" form has been used instead
+	 of "__intN".  */
+      else if (!int_n_alt && pedantic && ! in_system_header_at (input_location))
 	pedwarn (input_location, OPT_Wpedantic,
 		 "ISO C++ does not support %<__int%d%> for %qs",
 		 int_n_data[declspecs->int_n_idx].bitsize, name);
diff --git a/gcc/cp/lex.c b/gcc/cp/lex.c
index 20965e49fe4..526c95e3539 100644
--- a/gcc/cp/lex.c
+++ b/gcc/cp/lex.c
@@ -262,6 +262,11 @@  init_reswords (void)
       id = get_identifier (name);
       C_SET_RID_CODE (id, RID_FIRST_INT_N + i);
       set_identifier_kind (id, cik_keyword);
+
+      sprintf (name, "__int%d__", int_n_data[i].bitsize);
+      id = get_identifier (name);
+      C_SET_RID_CODE (id, RID_FIRST_INT_N + i);
+      set_identifier_kind (id, cik_keyword);
     }
 }
 
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 6b4aab8a12f..60570ca13cb 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -17613,6 +17613,12 @@  cp_parser_simple_type_specifier (cp_parser* parser,
 	{
 	  decl_specs->explicit_intN_p = true;
 	  decl_specs->int_n_idx = idx;
+	  /* Check if the alternate "__intN__" form has been used instead of
+	     "__intN".  */
+	  if (strncmp (IDENTIFIER_POINTER (token->u.value)
+			+ (IDENTIFIER_LENGTH (token->u.value) - 2),
+			"__", 2) == 0)
+	    decl_specs->int_n_alt = true;
 	}
       type = int_n_trees [idx].signed_type;
       break;
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index eaef4cd63d2..e6078917ab4 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -4337,8 +4337,10 @@  without this option, certain GNU extensions and traditional C and C++
 features are supported as well.  With this option, they are rejected.
 
 @option{-Wpedantic} does not cause warning messages for use of the
-alternate keywords whose names begin and end with @samp{__}.  Pedantic
-warnings are also disabled in the expression that follows
+alternate keywords whose names begin and end with @samp{__}.  This alternate
+format can also be used to disable warnings for non-ISO @samp{__intN} types,
+i.e. @samp{__intN__}.
+Pedantic warnings are also disabled in the expression that follows
 @code{__extension__}.  However, only system header files should use
 these escape routes; application programs should avoid them.
 @xref{Alternate Keywords}.
diff --git a/gcc/gimple-ssa-sprintf.c b/gcc/gimple-ssa-sprintf.c
index 80b0bf825ef..81e0f62cf8b 100644
--- a/gcc/gimple-ssa-sprintf.c
+++ b/gcc/gimple-ssa-sprintf.c
@@ -1019,10 +1019,12 @@  build_intmax_type_nodes (tree *pintmax, tree *puintmax)
       for (int 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);
 
-	    if (strcmp (name, UINTMAX_TYPE) == 0)
+	    if (strcmp (name, UINTMAX_TYPE) == 0
+		|| strcmp (altname, UINTMAX_TYPE) == 0)
 	      {
 	        *pintmax = int_n_trees[i].signed_type;
 	        *puintmax = int_n_trees[i].unsigned_type;
diff --git a/gcc/lto/lto-lang.c b/gcc/lto/lto-lang.c
index e155ea33d32..4b486970b2e 100644
--- a/gcc/lto/lto-lang.c
+++ b/gcc/lto/lto-lang.c
@@ -1259,10 +1259,12 @@  lto_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);
 
-	    if (strcmp (name, SIZE_TYPE) == 0)
+	    if (strcmp (name, SIZE_TYPE) == 0
+		|| strcmp (altname, SIZE_TYPE) == 0)
 	      {
 		intmax_type_node = int_n_trees[i].signed_type;
 		uintmax_type_node = int_n_trees[i].unsigned_type;
diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c
index 5d6f2e0166c..5887773c0ec 100644
--- a/gcc/stor-layout.c
+++ b/gcc/stor-layout.c
@@ -2716,10 +2716,12 @@  initialize_sizetypes (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);
 
-	    if (strcmp (name, SIZETYPE) == 0)
+	    if (strcmp (name, SIZETYPE) == 0
+		|| strcmp (altname, SIZETYPE) == 0)
 	      {
 		precision = int_n_data[i].bitsize;
 	      }
diff --git a/gcc/testsuite/gcc.target/msp430/mlarge-pedwarns.c b/gcc/testsuite/gcc.target/msp430/mlarge-pedwarns.c
new file mode 100644
index 00000000000..a16f53342db
--- /dev/null
+++ b/gcc/testsuite/gcc.target/msp430/mlarge-pedwarns.c
@@ -0,0 +1,11 @@ 
+/* { dg-do compile } */
+/* { dg-skip-if "" { "*-*-*" } { "-mcpu=msp430" } { "" } } */
+/* { dg-options "-mlarge -pedantic-errors" } */
+
+/* Ensure the use of builtin macros that contain __int20__ in their
+   expansion don't cause ISO C errors when -pedantic-errors is passed.  */
+
+__SIZE_TYPE__ a;
+__INTPTR_TYPE__ b;
+__UINTPTR_TYPE__ c;
+__PTRDIFF_TYPE__ d;
diff --git a/gcc/tree.c b/gcc/tree.c
index e879f15a841..f89d875ef8e 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -10382,10 +10382,12 @@  build_common_tree_nodes (bool signed_char)
       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);
 
-	    if (strcmp (name, SIZE_TYPE) == 0)
+	    if (strcmp (name, SIZE_TYPE) == 0
+		|| strcmp (altname, SIZE_TYPE) == 0)
 	      {
 		size_type_node = int_n_trees[i].unsigned_type;
 	      }
@@ -10409,9 +10411,12 @@  build_common_tree_nodes (bool signed_char)
       for (int 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", int_n_data[i].bitsize);
-	    if (strcmp (name, PTRDIFF_TYPE) == 0)
+	    sprintf (altname, "__int%d__", int_n_data[i].bitsize);
+
+	    if (strcmp (name, PTRDIFF_TYPE) == 0
+		|| strcmp (altname, PTRDIFF_TYPE) == 0)
 	      ptrdiff_type_node = int_n_trees[i].signed_type;
 	  }
       if (ptrdiff_type_node == NULL_TREE)
-- 
2.17.1