aboutsummaryrefslogtreecommitdiff
path: root/gcc/c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2019-11-14 20:18:33 +0000
committerJoseph Myers <jsm28@gcc.gnu.org>2019-11-14 20:18:33 +0000
commit7c5890cc0a0ecea0e88cc39e9fba6385fb579e61 (patch)
treef751de7e59697865e2ffa028877728284227c355 /gcc/c
parent3771033244b3ee1b53a8a00d734580b16384fdd3 (diff)
downloadgcc-7c5890cc0a0ecea0e88cc39e9fba6385fb579e61.zip
gcc-7c5890cc0a0ecea0e88cc39e9fba6385fb579e61.tar.gz
gcc-7c5890cc0a0ecea0e88cc39e9fba6385fb579e61.tar.bz2
Support UTF-8 character constants for C2x.
C2x adds u8'' character constants to C. This patch adds the corresponding GCC support. Most of the support was already present for C++ and just needed enabling for C2x. However, in C2x these constants have type unsigned char, which required corresponding adjustments in the compiler and the preprocessor to give them that type for C. For C, it seems clear to me that having type unsigned char means the constants are unsigned in the preprocessor (and thus treated as having type uintmax_t in #if conditionals), so this patch implements that. I included a conditional in the libcpp change to avoid affecting signedness for C++, but I'm not sure if in fact these constants should also be unsigned in the preprocessor for C++ in which case that !CPP_OPTION (pfile, cplusplus) conditional would not be needed. Bootstrapped with no regressions on x86_64-pc-linux-gnu. gcc/c: * c-parser.c (c_parser_postfix_expression) (c_parser_check_literal_zero): Handle CPP_UTF8CHAR. * gimple-parser.c (c_parser_gimple_postfix_expression): Likewise. gcc/c-family: * c-lex.c (lex_charconst): Make CPP_UTF8CHAR constants unsigned char for C. gcc/testsuite: * gcc.dg/c11-utf8char-1.c, gcc.dg/c2x-utf8char-1.c, gcc.dg/c2x-utf8char-2.c, gcc.dg/c2x-utf8char-3.c, gcc.dg/gnu2x-utf8char-1.c: New tests. libcpp: * charset.c (narrow_str_to_charconst): Make CPP_UTF8CHAR constants unsigned for C. * init.c (lang_defaults): Set utf8_char_literals for GNUC2X and STDC2X. From-SVN: r278265
Diffstat (limited to 'gcc/c')
-rw-r--r--gcc/c/ChangeLog6
-rw-r--r--gcc/c/c-parser.c2
-rw-r--r--gcc/c/gimple-parser.c1
3 files changed, 9 insertions, 0 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 04dce4b..b881cab 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,9 @@
+2019-11-14 Joseph Myers <joseph@codesourcery.com>
+
+ * c-parser.c (c_parser_postfix_expression)
+ (c_parser_check_literal_zero): Handle CPP_UTF8CHAR.
+ * gimple-parser.c (c_parser_gimple_postfix_expression): Likewise.
+
2019-11-14 Richard Sandiford <richard.sandiford@arm.com>
* c-typeck.c (build_conditional_expr): Use truth_type_for instead
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 5e30a7f..8ce4e70 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -8783,6 +8783,7 @@ c_parser_postfix_expression (c_parser *parser)
case CPP_CHAR:
case CPP_CHAR16:
case CPP_CHAR32:
+ case CPP_UTF8CHAR:
case CPP_WCHAR:
expr.value = c_parser_peek_token (parser)->value;
/* For the purpose of warning when a pointer is compared with
@@ -10459,6 +10460,7 @@ c_parser_check_literal_zero (c_parser *parser, unsigned *literal_zero_mask,
case CPP_WCHAR:
case CPP_CHAR16:
case CPP_CHAR32:
+ case CPP_UTF8CHAR:
/* If a parameter is literal zero alone, remember it
for -Wmemset-transposed-args warning. */
if (integer_zerop (tok->value)
diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c
index 6fdb83c..c16d0df 100644
--- a/gcc/c/gimple-parser.c
+++ b/gcc/c/gimple-parser.c
@@ -1395,6 +1395,7 @@ c_parser_gimple_postfix_expression (gimple_parser &parser)
case CPP_CHAR:
case CPP_CHAR16:
case CPP_CHAR32:
+ case CPP_UTF8CHAR:
case CPP_WCHAR:
expr.value = c_parser_peek_token (parser)->value;
set_c_expr_source_range (&expr, tok_range);