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
@@ -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;
@@ -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 ())
@@ -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);
@@ -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;
}
}
@@ -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
@@ -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. */
@@ -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);
@@ -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);
}
}
@@ -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;
@@ -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}.
@@ -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;
@@ -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;
@@ -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;
}
new file mode 100644
@@ -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;
@@ -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
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.