Implement alternate "__intN__" form of "__intN" type
authorJozef Lawrynowicz <jozef.l@mittosystems.com>
Tue, 25 Jun 2019 09:41:17 +0000 (09:41 +0000)
committerJozef Lawrynowicz <jozefl@gcc.gnu.org>
Tue, 25 Jun 2019 09:41:17 +0000 (09:41 +0000)
gcc/ChangeLog:

* 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:

* gcc.target/msp430/mlarge-pedwarns.c: New test.

From-SVN: r272640

17 files changed:
gcc/ChangeLog
gcc/brig/brig-lang.c
gcc/c-family/c-common.c
gcc/c/c-decl.c
gcc/c/c-parser.c
gcc/config/msp430/msp430.h
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/cp/lex.c
gcc/cp/parser.c
gcc/doc/invoke.texi
gcc/gimple-ssa-sprintf.c
gcc/lto/lto-lang.c
gcc/stor-layout.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/msp430/mlarge-pedwarns.c [new file with mode: 0644]
gcc/tree.c

index f14b8267eb9c5511bb519c5ebf4a2e0d3634419a..1fa1c2f2180c371e6cf5e321b6fdd39b3bf177a6 100644 (file)
@@ -1,3 +1,29 @@
+2019-06-25  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.
+
 2019-06-25  Jan Hubicka  <jh@suse.cz>
 
        * tree-ssa-alias.c (indirect_ref_may_alias_decl_p): Check that
index 91c7cfa35daee9516a33447e9aeb904b2a10a5d9..1c3a3b00c4123b7abc241ff01b1112867462e664 100644 (file)
@@ -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[50], altname[50];
            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;
index 6013fcaa280e08f826801bd5ff7cb22624092eec..da4aadbc59060ccfc2836acd90640dfe6e91fef3 100644 (file)
@@ -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 ())
index 87ce853d4b7d6e96e9fcc7d677cce8e7757a3cd6..cb2f49fa5a2c1da3a9c223523aaec805050ade4e 100644 (file)
@@ -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);
index df1a304227696f6186d40c3af6f44589e8b7465d..98508721ed9a6aa008cde664c7236cc9ba675652 100644 (file)
@@ -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;
     }
 }
 \f
index c0aa8eacd96849538f996ada0e2fdb0f66b83b16..1288b1a263dbabb6aca68ecfe7cbe2794f4269ba 100644 (file)
@@ -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
index bf47f67721e30df87dbe22802c22683d08adb70a..d42be7584851183d463faaf8fe60ff42d3236c86 100644 (file)
@@ -5866,6 +5866,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.  */
index 5d49535b0d9ed9330b96cd4b50c5e10e9feb8e3e..96cd4843a1c2b483477f76bfdd449c20b7061744 100644 (file)
@@ -10368,6 +10368,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;
@@ -10441,6 +10442,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
@@ -10843,7 +10845,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);
index 4a4325f13cf37903e590d152b831d46171611104..5bfb1e51408536676cd170e07627ed0a24c43be6 100644 (file)
@@ -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);
     }
 }
 
index e9bdfab443e756a04fef6816cb40bd1d7da61085..4d46cb3eac73d9a2177872f5c56edf43fe2a0997 100644 (file)
@@ -17622,6 +17622,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;
index 4f93c7e0de73d1978a33053dfc42237671da834e..7c096804881ddc979b7b81dc0ef5baf4edc80018 100644 (file)
@@ -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}.
index 80b0bf825efcbdc0255f2abface89062c00a3d2e..a0934bcaf87c05f6c52cd50139e3b5200b3e8d53 100644 (file)
@@ -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[50], altname[50];
            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;
index e155ea33d32770db58e5bf2326aabfe3f0df9494..cc44afc048cf5d5b007cb06d84f9dc2f942021f2 100644 (file)
@@ -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[50], altname[50];
            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;
index 5d6f2e0166cee4da93235c66dd0d3dfdeefff5a6..583516c4a93fbe6f8a5c18c14d93ca6ba5a4dd3d 100644 (file)
@@ -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[50], altname[50];
            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;
              }
index ecfca8df524368346747cb92e92a6fb070415eb3..47542cc1208b0d6288863f3e89683fafe78e7891 100644 (file)
@@ -1,3 +1,7 @@
+2019-06-25  Jozef Lawrynowicz  <jozef.l@mittosystems.com>
+
+       * gcc.target/msp430/mlarge-pedwarns.c: New test.
+
 2019-06-25  Jakub Jelinek  <jakub@redhat.com>
 
        PR sanitizer/90954
diff --git a/gcc/testsuite/gcc.target/msp430/mlarge-pedwarns.c b/gcc/testsuite/gcc.target/msp430/mlarge-pedwarns.c
new file mode 100644 (file)
index 0000000..a16f533
--- /dev/null
@@ -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;
index 7ecf407e5face3472e6e725ee53f0d81809981c7..c97facd7ce50a87b3fb9111f2f9fec85a3356e50 100644 (file)
@@ -10385,10 +10385,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[50], altname[50];
            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;
              }
@@ -10412,9 +10414,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[50], altname[50];
            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)