From 5e5803060c3d6db3ff73195db798ffd8e5588e78 Mon Sep 17 00:00:00 2001 From: Jozef Lawrynowicz Date: Tue, 25 Jun 2019 09:41:17 +0000 Subject: [PATCH] Implement alternate "__intN__" form of "__intN" type 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 --- gcc/ChangeLog | 26 +++++++++++++++++++ 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/ChangeLog | 4 +++ .../gcc.target/msp430/mlarge-pedwarns.c | 11 ++++++++ gcc/tree.c | 13 +++++++--- 17 files changed, 109 insertions(+), 18 deletions(-) create mode 100644 gcc/testsuite/gcc.target/msp430/mlarge-pedwarns.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f14b8267eb9..1fa1c2f2180 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,29 @@ +2019-06-25 Jozef Lawrynowicz + + * 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 * tree-ssa-alias.c (indirect_ref_may_alias_decl_p): Check that diff --git a/gcc/brig/brig-lang.c b/gcc/brig/brig-lang.c index 91c7cfa35da..1c3a3b00c41 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[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; diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 6013fcaa280..da4aadbc590 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 bf47f67721e..d42be758485 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -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. */ diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 5d49535b0d9..96cd4843a1c 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -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); diff --git a/gcc/cp/lex.c b/gcc/cp/lex.c index 4a4325f13cf..5bfb1e51408 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 e9bdfab443e..4d46cb3eac7 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -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; diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 4f93c7e0de7..7c096804881 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..a0934bcaf87 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[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; diff --git a/gcc/lto/lto-lang.c b/gcc/lto/lto-lang.c index e155ea33d32..cc44afc048c 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[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; diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c index 5d6f2e0166c..583516c4a93 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[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; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ecfca8df524..47542cc1208 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-06-25 Jozef Lawrynowicz + + * gcc.target/msp430/mlarge-pedwarns.c: New test. + 2019-06-25 Jakub Jelinek 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 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 7ecf407e5fa..c97facd7ce5 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -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) -- 2.30.2