From ad1539d5555a161cf6851de8995641d6dfe792d9 Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Mon, 28 Oct 2019 22:46:28 +0000 Subject: PR c/66970 - Add __has_builtin() macro gcc/ChangeLog: PR c/66970 * doc/cpp.texi (__has_builtin): Document. * doc/extend.texi (__builtin_frob_return_addr): Correct spelling. gcc/c/ChangeLog: PR c/66970 * c-decl.c (names_builtin_p): Define a new function. gcc/c-family/ChangeLog: PR c/66970 * c-common.c (c_common_nodes_and_builtins): Call c_define_builtins even when only preprocessing. * c-common.h (names_builtin_p): Declare new function. * c-lex.c (init_c_lex): Set has_builtin. (c_common_has_builtin): Define a new function. * c-ppoutput.c (init_pp_output): Set has_builtin. gcc/cp/ChangeLog: PR c/66970 * cp-objcp-common.c (names_builtin_p): Define new function. gcc/testsuite/ChangeLog: PR c/66970 * c-c++-common/cpp/has-builtin-2.c: New test. * c-c++-common/cpp/has-builtin-3.c: New test. * c-c++-common/cpp/has-builtin.c: New test. From-SVN: r277544 --- libcpp/include/cpplib.h | 6 +++++- libcpp/init.c | 4 +++- libcpp/macro.c | 4 ++++ libcpp/traditional.c | 6 +++--- 4 files changed, 15 insertions(+), 5 deletions(-) (limited to 'libcpp') diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index 224369b..c655d3f 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -676,6 +676,9 @@ struct cpp_callbacks /* Callback to identify whether an attribute exists. */ int (*has_attribute) (cpp_reader *); + /* Callback to determine whether a built-in function is recognized. */ + int (*has_builtin) (cpp_reader *); + /* Callback that can change a user lazy into normal macro. */ void (*user_lazy_macro) (cpp_reader *, cpp_macro *, unsigned); @@ -855,7 +858,8 @@ enum cpp_builtin_type BT_PRAGMA, /* `_Pragma' operator */ BT_TIMESTAMP, /* `__TIMESTAMP__' */ BT_COUNTER, /* `__COUNTER__' */ - BT_HAS_ATTRIBUTE /* `__has_attribute__(x)' */ + BT_HAS_ATTRIBUTE, /* `__has_attribute__(x)' */ + BT_HAS_BUILTIN /* `__has_builtin(x)' */ }; #define CPP_HASHNODE(HNODE) ((cpp_hashnode *) (HNODE)) diff --git a/libcpp/init.c b/libcpp/init.c index 4bcec7b..b094317 100644 --- a/libcpp/init.c +++ b/libcpp/init.c @@ -403,6 +403,7 @@ static const struct builtin_macro builtin_array[] = B("__COUNTER__", BT_COUNTER, true), B("__has_attribute", BT_HAS_ATTRIBUTE, true), B("__has_cpp_attribute", BT_HAS_ATTRIBUTE, true), + B("__has_builtin", BT_HAS_BUILTIN, true), /* Keep builtins not used for -traditional-cpp at the end, and update init_builtins() if any more are added. */ B("_Pragma", BT_PRAGMA, true), @@ -483,7 +484,8 @@ cpp_init_special_builtins (cpp_reader *pfile) for (b = builtin_array; b < builtin_array + n; b++) { - if (b->value == BT_HAS_ATTRIBUTE + if ((b->value == BT_HAS_ATTRIBUTE + || b->value == BT_HAS_BUILTIN) && (CPP_OPTION (pfile, lang) == CLK_ASM || pfile->cb.has_attribute == NULL)) continue; diff --git a/libcpp/macro.c b/libcpp/macro.c index 30d3686..eb8321f 100644 --- a/libcpp/macro.c +++ b/libcpp/macro.c @@ -568,6 +568,10 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node, case BT_HAS_ATTRIBUTE: number = pfile->cb.has_attribute (pfile); break; + + case BT_HAS_BUILTIN: + number = pfile->cb.has_builtin (pfile); + break; } if (result == NULL) diff --git a/libcpp/traditional.c b/libcpp/traditional.c index f1e7279..54738e8 100644 --- a/libcpp/traditional.c +++ b/libcpp/traditional.c @@ -326,9 +326,9 @@ static inline bool fun_like_macro (cpp_hashnode *node) { if (cpp_builtin_macro_p (node)) - return node->value.builtin == BT_HAS_ATTRIBUTE; - else - return node->value.macro->fun_like; + return (node->value.builtin == BT_HAS_ATTRIBUTE + || node->value.builtin == BT_HAS_BUILTIN); + return node->value.macro->fun_like; } /* Set up state for finding the opening '(' of a function-like -- cgit v1.1 From aa23e73b1a090659344ff88361135bd947064e30 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 31 Oct 2019 18:38:44 +0100 Subject: re PR preprocessor/92296 (internal compiler error: Segmentation fault #pragma push_macro("__LINE__")) PR preprocessor/92296 * internal.h (struct def_pragma_macro): Add is_builtin bitfield. (_cpp_restore_special_builtin): Declare. * init.c (_cpp_restore_special_builtin): New function. * directives.c (do_pragma_push_macro): For NT_BUILTIN_MACRO set is_builtin and don't try to grab definition. (cpp_pop_definition): Use _cpp_restore_special_builtin to restore builtin macros. * c-c++-common/cpp/pr92296-1.c: New test. * c-c++-common/cpp/pr92296-2.c: New test. From-SVN: r277685 --- libcpp/ChangeLog | 11 +++++++++++ libcpp/directives.c | 7 +++++++ libcpp/init.c | 19 +++++++++++++++++++ libcpp/internal.h | 4 ++++ 4 files changed, 41 insertions(+) (limited to 'libcpp') diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 670e97b..a13f750 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,14 @@ +2019-10-31 Jakub Jelinek + + PR preprocessor/92296 + * internal.h (struct def_pragma_macro): Add is_builtin bitfield. + (_cpp_restore_special_builtin): Declare. + * init.c (_cpp_restore_special_builtin): New function. + * directives.c (do_pragma_push_macro): For NT_BUILTIN_MACRO + set is_builtin and don't try to grab definition. + (cpp_pop_definition): Use _cpp_restore_special_builtin to restore + builtin macros. + 2019-10-15 Nathan Sidwell * include/line-map.h (struct maps_info_ordinary): Make cache diff --git a/libcpp/directives.c b/libcpp/directives.c index 61f1fef..6e011a1 100644 --- a/libcpp/directives.c +++ b/libcpp/directives.c @@ -1582,6 +1582,8 @@ do_pragma_push_macro (cpp_reader *pfile) node = _cpp_lex_identifier (pfile, c->name); if (node->type == NT_VOID) c->is_undef = 1; + else if (node->type == NT_BUILTIN_MACRO) + c->is_builtin = 1; else { defn = cpp_macro_definition (pfile, node); @@ -2470,6 +2472,11 @@ cpp_pop_definition (cpp_reader *pfile, struct def_pragma_macro *c) if (c->is_undef) return; + if (c->is_builtin) + { + _cpp_restore_special_builtin (pfile, c); + return; + } { size_t namelen; diff --git a/libcpp/init.c b/libcpp/init.c index b094317..32b0e70 100644 --- a/libcpp/init.c +++ b/libcpp/init.c @@ -497,6 +497,25 @@ cpp_init_special_builtins (cpp_reader *pfile) } } +/* Restore macro C to builtin macro definition. */ + +void +_cpp_restore_special_builtin (cpp_reader *pfile, struct def_pragma_macro *c) +{ + size_t len = strlen (c->name); + + for (const struct builtin_macro *b = builtin_array; + b < builtin_array + ARRAY_SIZE (builtin_array); b++) + if (b->len == len && memcmp (c->name, b->name, len + 1) == 0) + { + cpp_hashnode *hp = cpp_lookup (pfile, b->name, b->len); + hp->type = NT_BUILTIN_MACRO; + if (b->always_warn_if_redefined) + hp->flags |= NODE_WARN; + hp->value.builtin = (enum cpp_builtin_type) b->value; + } +} + /* Read the builtins table above and enter them, and language-specific macros, into the hash table. HOSTED is true if this is a hosted environment. */ diff --git a/libcpp/internal.h b/libcpp/internal.h index cd1a523..e759bec 100644 --- a/libcpp/internal.h +++ b/libcpp/internal.h @@ -391,6 +391,8 @@ struct def_pragma_macro { /* Mark if we save an undefined macro. */ unsigned int is_undef : 1; + /* Nonzero if it was a builtin macro. */ + unsigned int is_builtin : 1; }; /* A cpp_reader encapsulates the "state" of a pre-processor run. @@ -722,6 +724,8 @@ extern void *_cpp_commit_buff (cpp_reader *pfile, size_t size); /* In init.c. */ extern void _cpp_maybe_push_include_file (cpp_reader *); extern const char *cpp_named_operator2name (enum cpp_ttype type); +extern void _cpp_restore_special_builtin (cpp_reader *pfile, + struct def_pragma_macro *); /* In directives.c */ extern int _cpp_test_assertion (cpp_reader *, unsigned int *); -- cgit v1.1 From b7689b962dd6536bbb2567bfdec52e35109af7ab Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Tue, 5 Nov 2019 18:56:18 -0500 Subject: Implement C++20 operator<=>. There are three major pieces to this support: scalar operator<=>, synthesis of comparison operators, and rewritten/reversed overload resolution (e.g. a < b becomes 0 > b <=> a). Unlike other defaulted functions, where we use synthesized_method_walk to semi-simulate what the definition of the function will be like, this patch determines the characteristics of a comparison operator by trying to define it. My handling of non-dependent rewritten operators in templates can still use some work: build_min_non_dep_op_overload can't understand the rewrites and crashes, so I'm avoiding it for now by clearing *overload. This means we'll do name lookup again at instantiation time, which can incorrectly mean a different result. I'll poke at this more in stage 3. I'm leaving out a fourth section ("strong structural equality") even though I've implemented it, because it seems likely to change radically tomorrow. Thanks to Tim van Deurzen and Jakub for implementing lexing of the <=> operator, and Jonathan for the initial header. gcc/cp/ * cp-tree.h (struct lang_decl_fn): Add maybe_deleted bitfield. (DECL_MAYBE_DELETED): New. (enum special_function_kind): Add sfk_comparison. (LOOKUP_REWRITTEN, LOOKUP_REVERSED): New. * call.c (struct z_candidate): Add rewritten and reversed methods. (add_builtin_candidate): Handle SPACESHIP_EXPR. (add_builtin_candidates): Likewise. (add_candidates): Don't add a reversed candidate if the parms are the same. (add_operator_candidates): Split out from build_new_op_1. Handle rewritten and reversed candidates. (add_candidate): Swap conversions of reversed candidate. (build_new_op_1): Swap them back. Build a second operation for rewritten candidates. (extract_call_expr): Handle rewritten calls. (same_fn_or_template): New. (joust): Handle rewritten and reversed candidates. * class.c (add_implicitly_declared_members): Add implicit op==. (classtype_has_op, classtype_has_defaulted_op): New. * constexpr.c (cxx_eval_binary_expression): Handle SPACESHIP_EXPR. (cxx_eval_constant_expression, potential_constant_expression_1): Likewise. * cp-gimplify.c (genericize_spaceship): New. (cp_genericize_r): Use it. * cp-objcp-common.c (cp_common_init_ts): Handle SPACESHIP_EXPR. * decl.c (finish_function): Handle deleted function. * decl2.c (grokfield): SET_DECL_FRIEND_CONTEXT on defaulted friend. (mark_used): Check DECL_MAYBE_DELETED. Remove assumption that defaulted functions are non-static members. * error.c (dump_expr): Handle SPACESHIP_EXPR. * method.c (type_has_trivial_fn): False for sfk_comparison. (enum comp_cat_tag, struct comp_cat_info_t): New types. (comp_cat_cache): New array variable. (lookup_comparison_result, lookup_comparison_category) (is_cat, cat_tag_for, spaceship_comp_cat) (spaceship_type, genericize_spaceship) (common_comparison_type, early_check_defaulted_comparison) (comp_info, build_comparison_op): New. (synthesize_method): Handle sfk_comparison. Handle deleted. (get_defaulted_eh_spec, maybe_explain_implicit_delete) (explain_implicit_non_constexpr, implicitly_declare_fn) (defaulted_late_check, defaultable_fn_check): Handle sfk_comparison. * name-lookup.c (get_std_name_hint): Add comparison categories. * tree.c (special_function_p): Add sfk_comparison. * typeck.c (cp_build_binary_op): Handle SPACESHIP_EXPR. 2019-11-05 Tim van Deurzen Add new tree code for the spaceship operator. gcc/cp/ * cp-tree.def: Add new tree code. * operators.def: New binary operator. * parser.c: Add new token and tree code. libcpp/ * cpplib.h: Add spaceship operator for C++. * lex.c: Implement conditional lexing of spaceship operator for C++20. 2019-11-05 Jonathan Wakely libstdc++-v3/ * libsupc++/compare: New header. * libsupc++/Makefile.am (std_HEADERS): Add compare. * include/std/version: Define __cpp_lib_three_way_comparison. * include/std/functional: #include . From-SVN: r277865 --- libcpp/ChangeLog | 5 +++++ libcpp/include/cpplib.h | 1 + libcpp/lex.c | 9 ++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) (limited to 'libcpp') diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index a13f750..8be8438 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,8 @@ +2019-11-05 Tim van Deurzen + + * cpplib.h: Add spaceship operator for C++. + * lex.c: Implement conditional lexing of spaceship operator for C++20. + 2019-10-31 Jakub Jelinek PR preprocessor/92296 diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index c655d3f..ed108f1 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -78,6 +78,7 @@ struct _cpp_file; OP(NOT_EQ, "!=") \ OP(GREATER_EQ, ">=") \ OP(LESS_EQ, "<=") \ + OP(SPACESHIP, "<=>") \ \ /* These two are unary + / - in preprocessor expressions. */ \ OP(PLUS_EQ, "+=") /* math */ \ diff --git a/libcpp/lex.c b/libcpp/lex.c index 3e7d1c3..e95eda3f 100644 --- a/libcpp/lex.c +++ b/libcpp/lex.c @@ -2980,7 +2980,13 @@ _cpp_lex_direct (cpp_reader *pfile) result->type = CPP_LESS; if (*buffer->cur == '=') - buffer->cur++, result->type = CPP_LESS_EQ; + { + buffer->cur++, result->type = CPP_LESS_EQ; + if (*buffer->cur == '>' + && CPP_OPTION (pfile, cplusplus) + && CPP_OPTION (pfile, lang) >= CLK_GNUCXX2A) + buffer->cur++, result->type = CPP_SPACESHIP; + } else if (*buffer->cur == '<') { buffer->cur++; @@ -3491,6 +3497,7 @@ cpp_avoid_paste (cpp_reader *pfile, const cpp_token *token1, || (CPP_OPTION (pfile, objc) && token1->val.str.text[0] == '@' && (b == CPP_NAME || b == CPP_STRING))); + case CPP_LESS_EQ: return c == '>'; case CPP_STRING: case CPP_WSTRING: case CPP_UTF8STRING: -- cgit v1.1 From 2c03d73667df53165834e9bcb5d09243db414ec3 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 7 Nov 2019 21:24:38 +0100 Subject: PR c++/91370 - Implement P1041R4 and P1139R2 - Stronger Unicode reqs PR c++/91370 - Implement P1041R4 and P1139R2 - Stronger Unicode reqs * charset.c (narrow_str_to_charconst): Add TYPE argument. For CPP_UTF8CHAR diagnose whenever number of chars is > 1, using CPP_DL_ERROR instead of CPP_DL_WARNING. (wide_str_to_charconst): For CPP_CHAR16 or CPP_CHAR32, use CPP_DL_ERROR instead of CPP_DL_WARNING when multiple char16_t or char32_t chars are needed. (cpp_interpret_charconst): Adjust narrow_str_to_charconst caller. * g++.dg/cpp1z/utf8-neg.C: Expect errors rather than -Wmultichar warnings. * g++.dg/ext/utf16-4.C: Expect errors rather than warnings. * g++.dg/ext/utf32-4.C: Likewise. * g++.dg/cpp2a/ucn2.C: New test. From-SVN: r277929 --- libcpp/ChangeLog | 11 +++++++++++ libcpp/charset.c | 16 +++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) (limited to 'libcpp') diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 8be8438..b57f265 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,14 @@ +2019-11-07 Jakub Jelinek + + PR c++/91370 - Implement P1041R4 and P1139R2 - Stronger Unicode reqs + * charset.c (narrow_str_to_charconst): Add TYPE argument. For + CPP_UTF8CHAR diagnose whenever number of chars is > 1, using + CPP_DL_ERROR instead of CPP_DL_WARNING. + (wide_str_to_charconst): For CPP_CHAR16 or CPP_CHAR32, use + CPP_DL_ERROR instead of CPP_DL_WARNING when multiple char16_t + or char32_t chars are needed. + (cpp_interpret_charconst): Adjust narrow_str_to_charconst caller. + 2019-11-05 Tim van Deurzen * cpplib.h: Add spaceship operator for C++. diff --git a/libcpp/charset.c b/libcpp/charset.c index 39af77a..0b8815a 100644 --- a/libcpp/charset.c +++ b/libcpp/charset.c @@ -1881,10 +1881,11 @@ cpp_interpret_string_notranslate (cpp_reader *pfile, const cpp_string *from, /* Subroutine of cpp_interpret_charconst which performs the conversion to a number, for narrow strings. STR is the string structure returned by cpp_interpret_string. PCHARS_SEEN and UNSIGNEDP are as for - cpp_interpret_charconst. */ + cpp_interpret_charconst. TYPE is the token type. */ static cppchar_t narrow_str_to_charconst (cpp_reader *pfile, cpp_string str, - unsigned int *pchars_seen, int *unsignedp) + unsigned int *pchars_seen, int *unsignedp, + enum cpp_ttype type) { size_t width = CPP_OPTION (pfile, char_precision); size_t max_chars = CPP_OPTION (pfile, int_precision) / width; @@ -1913,10 +1914,12 @@ narrow_str_to_charconst (cpp_reader *pfile, cpp_string str, result = c; } + if (type == CPP_UTF8CHAR) + max_chars = 1; if (i > max_chars) { i = max_chars; - cpp_error (pfile, CPP_DL_WARNING, + cpp_error (pfile, type == CPP_UTF8CHAR ? CPP_DL_ERROR : CPP_DL_WARNING, "character constant too long for its type"); } else if (i > 1 && CPP_OPTION (pfile, warn_multichar)) @@ -1980,7 +1983,9 @@ wide_str_to_charconst (cpp_reader *pfile, cpp_string str, character exactly fills a wchar_t, so a multi-character wide character constant is guaranteed to overflow. */ if (str.len > nbwc * 2) - cpp_error (pfile, CPP_DL_WARNING, + cpp_error (pfile, (CPP_OPTION (pfile, cplusplus) + && (type == CPP_CHAR16 || type == CPP_CHAR32)) + ? CPP_DL_ERROR : CPP_DL_WARNING, "character constant too long for its type"); /* Truncate the constant to its natural width, and simultaneously @@ -2038,7 +2043,8 @@ cpp_interpret_charconst (cpp_reader *pfile, const cpp_token *token, result = wide_str_to_charconst (pfile, str, pchars_seen, unsignedp, token->type); else - result = narrow_str_to_charconst (pfile, str, pchars_seen, unsignedp); + result = narrow_str_to_charconst (pfile, str, pchars_seen, unsignedp, + token->type); if (str.text != token->val.str.text) free ((void *)str.text); -- cgit v1.1 From 7c5890cc0a0ecea0e88cc39e9fba6385fb579e61 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Thu, 14 Nov 2019 20:18:33 +0000 Subject: 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 --- libcpp/ChangeLog | 7 +++++++ libcpp/charset.c | 2 ++ libcpp/init.c | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-) (limited to 'libcpp') diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index b57f265..448f954 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,10 @@ +2019-11-14 Joseph Myers + + * 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. + 2019-11-07 Jakub Jelinek PR c++/91370 - Implement P1041R4 and P1139R2 - Stronger Unicode reqs diff --git a/libcpp/charset.c b/libcpp/charset.c index 0b8815a..d457441 100644 --- a/libcpp/charset.c +++ b/libcpp/charset.c @@ -1928,6 +1928,8 @@ narrow_str_to_charconst (cpp_reader *pfile, cpp_string str, /* Multichar constants are of type int and therefore signed. */ if (i > 1) unsigned_p = 0; + else if (type == CPP_UTF8CHAR && !CPP_OPTION (pfile, cplusplus)) + unsigned_p = 1; else unsigned_p = CPP_OPTION (pfile, unsigned_char); diff --git a/libcpp/init.c b/libcpp/init.c index 32b0e70..f5f41b0 100644 --- a/libcpp/init.c +++ b/libcpp/init.c @@ -102,13 +102,13 @@ static const struct lang_flags lang_defaults[] = /* GNUC99 */ { 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0 }, /* GNUC11 */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0 }, /* GNUC17 */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0 }, - /* GNUC2X */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1 }, + /* GNUC2X */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1 }, /* STDC89 */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, /* STDC94 */ { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, /* STDC99 */ { 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, /* STDC11 */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, /* STDC17 */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, - /* STDC2X */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1 }, + /* STDC2X */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1 }, /* GNUCXX */ { 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0 }, /* CXX98 */ { 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0 }, /* GNUCXX11 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0 }, -- cgit v1.1 From ee9256409f21eab5df5076e46d220d6a0b995f79 Mon Sep 17 00:00:00 2001 From: Lewis Hyatt Date: Mon, 9 Dec 2019 20:03:47 +0000 Subject: Byte vs column awareness for diagnostic-show-locus.c (PR 49973) contrib/ChangeLog 2019-12-09 Lewis Hyatt PR preprocessor/49973 * unicode/from_glibc/unicode_utils.py: Support script from glibc (commit 464cd3) to extract character widths from Unicode data files. * unicode/from_glibc/utf8_gen.py: Likewise. * unicode/UnicodeData.txt: Unicode v. 12.1.0 data file. * unicode/EastAsianWidth.txt: Likewise. * unicode/PropList.txt: Likewise. * unicode/gen_wcwidth.py: New utility to generate libcpp/generated_cpp_wcwidth.h with help from the glibc support scripts and the Unicode data files. * unicode/unicode-license.txt: Added. * unicode/README: New explanatory file. libcpp/ChangeLog 2019-12-09 Lewis Hyatt PR preprocessor/49973 * generated_cpp_wcwidth.h: New file generated by ../contrib/unicode/gen_wcwidth.py, supports new cpp_wcwidth function. * charset.c (compute_next_display_width): New function to help implement display columns. (cpp_byte_column_to_display_column): Likewise. (cpp_display_column_to_byte_column): Likewise. (cpp_wcwidth): Likewise. * include/cpplib.h (cpp_byte_column_to_display_column): Declare. (cpp_display_column_to_byte_column): Declare. (cpp_wcwidth): Declare. (cpp_display_width): New function. gcc/ChangeLog 2019-12-09 Lewis Hyatt PR preprocessor/49973 * input.c (location_compute_display_column): New function to help with multibyte awareness in diagnostics. (test_cpp_utf8): New self-test. (input_c_tests): Call the new test. * input.h (location_compute_display_column): Declare. * diagnostic-show-locus.c: Pervasive changes to add multibyte awareness to all classes and functions. (enum column_unit): New enum. (class exploc_with_display_col): New class. (class layout_point): Convert m_column member to array m_columns[2]. (layout_range::contains_point): Add col_unit argument. (test_layout_range_for_single_point): Pass new argument. (test_layout_range_for_single_line): Likewise. (test_layout_range_for_multiple_lines): Likewise. (line_bounds::convert_to_display_cols): New function. (layout::get_state_at_point): Add col_unit argument. (make_range): Use empty filename rather than dummy filename. (get_line_width_without_trailing_whitespace): Rename to... (get_line_bytes_without_trailing_whitespace): ...this. (test_get_line_width_without_trailing_whitespace): Rename to... (test_get_line_bytes_without_trailing_whitespace): ...this. (class layout): m_exploc changed to exploc_with_display_col from plain expanded_location. (layout::get_linenum_width): New accessor member function. (layout::get_x_offset_display): Likewise. (layout::calculate_linenum_width): New subroutine for the constuctor. (layout::calculate_x_offset_display): Likewise. (layout::layout): Use the new subroutines. Add multibyte awareness. (layout::print_source_line): Add multibyte awareness. (layout::print_line): Likewise. (layout::print_annotation_line): Likewise. (line_label::line_label): Likewise. (layout::print_any_labels): Likewise. (layout::annotation_line_showed_range_p): Likewise. (get_printed_columns): Likewise. (class line_label): Rename m_length to m_display_width. (get_affected_columns): Rename to... (get_affected_range): ...this; add col_unit argument and multibyte awareness. (class correction): Add m_affected_bytes and m_display_cols members. Rename m_len to m_byte_length for clarity. Add multibyte awareness throughout. (correction::insertion_p): Add multibyte awareness. (correction::compute_display_cols): New function. (correction::ensure_terminated): Use new member name m_byte_length. (line_corrections::add_hint): Add multibyte awareness. (layout::print_trailing_fixits): Likewise. (layout::get_x_bound_for_row): Likewise. (test_one_liner_simple_caret_utf8): New self-test analogous to the one with _utf8 suffix removed, testing multibyte awareness. (test_one_liner_caret_and_range_utf8): Likewise. (test_one_liner_multiple_carets_and_ranges_utf8): Likewise. (test_one_liner_fixit_insert_before_utf8): Likewise. (test_one_liner_fixit_insert_after_utf8): Likewise. (test_one_liner_fixit_remove_utf8): Likewise. (test_one_liner_fixit_replace_utf8): Likewise. (test_one_liner_fixit_replace_non_equal_range_utf8): Likewise. (test_one_liner_fixit_replace_equal_secondary_range_utf8): Likewise. (test_one_liner_fixit_validation_adhoc_locations_utf8): Likewise. (test_one_liner_many_fixits_1_utf8): Likewise. (test_one_liner_many_fixits_2_utf8): Likewise. (test_one_liner_labels_utf8): Likewise. (test_diagnostic_show_locus_one_liner_utf8): Likewise. (test_overlapped_fixit_printing_utf8): Likewise. (test_overlapped_fixit_printing): Adapt for changes to get_affected_columns, get_printed_columns and class corrections. (test_overlapped_fixit_printing_2): Likewise. (test_linenum_sep): New constant. (test_left_margin): Likewise. (test_offset_impl): Helper function for new test. (test_layout_x_offset_display_utf8): New test. (diagnostic_show_locus_c_tests): Call new tests. gcc/testsuite/ChangeLog: 2019-12-09 Lewis Hyatt PR preprocessor/49973 * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c (test_show_locus): Tweak so that expected output is the same as before the diagnostic-show-locus.c changes. * gcc.dg/cpp/pr66415-1.c: Likewise. From-SVN: r279137 --- libcpp/ChangeLog | 15 ++++ libcpp/charset.c | 103 +++++++++++++++++++++++++++ libcpp/generated_cpp_wcwidth.h | 156 +++++++++++++++++++++++++++++++++++++++++ libcpp/include/cpplib.h | 11 +++ 4 files changed, 285 insertions(+) create mode 100644 libcpp/generated_cpp_wcwidth.h (limited to 'libcpp') diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 448f954..f4376e6 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,18 @@ +2019-12-09 Lewis Hyatt + + PR preprocessor/49973 + * generated_cpp_wcwidth.h: New file generated by + ../contrib/unicode/gen_wcwidth.py, supports new cpp_wcwidth function. + * charset.c (compute_next_display_width): New function to help + implement display columns. + (cpp_byte_column_to_display_column): Likewise. + (cpp_display_column_to_byte_column): Likewise. + (cpp_wcwidth): Likewise. + * include/cpplib.h (cpp_byte_column_to_display_column): Declare. + (cpp_display_column_to_byte_column): Declare. + (cpp_wcwidth): Declare. + (cpp_display_width): New function. + 2019-11-14 Joseph Myers * charset.c (narrow_str_to_charconst): Make CPP_UTF8CHAR constants diff --git a/libcpp/charset.c b/libcpp/charset.c index d457441..956d2da 100644 --- a/libcpp/charset.c +++ b/libcpp/charset.c @@ -2265,3 +2265,106 @@ cpp_string_location_reader::get_next () m_loc += m_offset_per_column; return result; } + +/* Helper for cpp_byte_column_to_display_column and its inverse. Given a + pointer to a UTF-8-encoded character, compute its display width. *INBUFP + points on entry to the start of the UTF-8 encoding of the character, and + is updated to point just after the last byte of the encoding. *INBYTESLEFTP + contains on entry the remaining size of the buffer into which *INBUFP + points, and this is also updated accordingly. If *INBUFP does not + point to a valid UTF-8-encoded sequence, then it will be treated as a single + byte with display width 1. */ + +static inline int +compute_next_display_width (const uchar **inbufp, size_t *inbytesleftp) +{ + cppchar_t c; + if (one_utf8_to_cppchar (inbufp, inbytesleftp, &c) != 0) + { + /* Input is not convertible to UTF-8. This could be fine, e.g. in a + string literal, so don't complain. Just treat it as if it has a width + of one. */ + ++*inbufp; + --*inbytesleftp; + return 1; + } + + /* one_utf8_to_cppchar() has updated inbufp and inbytesleftp for us. */ + return cpp_wcwidth (c); +} + +/* For the string of length DATA_LENGTH bytes that begins at DATA, compute + how many display columns are occupied by the first COLUMN bytes. COLUMN + may exceed DATA_LENGTH, in which case the phantom bytes at the end are + treated as if they have display width 1. */ + +int +cpp_byte_column_to_display_column (const char *data, int data_length, + int column) +{ + int display_col = 0; + const uchar *udata = (const uchar *) data; + const int offset = MAX (0, column - data_length); + size_t inbytesleft = column - offset; + while (inbytesleft) + display_col += compute_next_display_width (&udata, &inbytesleft); + return display_col + offset; +} + +/* For the string of length DATA_LENGTH bytes that begins at DATA, compute + the least number of bytes that will result in at least DISPLAY_COL display + columns. The return value may exceed DATA_LENGTH if the entire string does + not occupy enough display columns. */ + +int +cpp_display_column_to_byte_column (const char *data, int data_length, + int display_col) +{ + int column = 0; + const uchar *udata = (const uchar *) data; + size_t inbytesleft = data_length; + while (column < display_col && inbytesleft) + column += compute_next_display_width (&udata, &inbytesleft); + return data_length - inbytesleft + MAX (0, display_col - column); +} + +/* Our own version of wcwidth(). We don't use the actual wcwidth() in glibc, + because that will inspect the user's locale, and in particular in an ASCII + locale, it will not return anything useful for extended characters. But GCC + in other respects (see e.g. _cpp_default_encoding()) behaves as if + everything is UTF-8. We also make some tweaks that are useful for the way + GCC needs to use this data, e.g. tabs and other control characters should be + treated as having width 1. The lookup tables are generated from + contrib/unicode/gen_wcwidth.py and were made by simply calling glibc + wcwidth() on all codepoints, then applying the small tweaks. These tables + are not highly optimized, but for the present purpose of outputting + diagnostics, they are sufficient. */ + +#include "generated_cpp_wcwidth.h" +int cpp_wcwidth (cppchar_t c) +{ + if (__builtin_expect (c <= wcwidth_range_ends[0], true)) + return wcwidth_widths[0]; + + /* Binary search the tables. */ + int begin = 1; + static const int end + = sizeof wcwidth_range_ends / sizeof (*wcwidth_range_ends); + int len = end - begin; + do + { + int half = len/2; + int middle = begin + half; + if (c > wcwidth_range_ends[middle]) + { + begin = middle + 1; + len -= half + 1; + } + else + len = half; + } while (len); + + if (__builtin_expect (begin != end, true)) + return wcwidth_widths[begin]; + return 1; +} diff --git a/libcpp/generated_cpp_wcwidth.h b/libcpp/generated_cpp_wcwidth.h new file mode 100644 index 0000000..ec8b73d --- /dev/null +++ b/libcpp/generated_cpp_wcwidth.h @@ -0,0 +1,156 @@ +/* Generated by contrib/unicode/gen_wcwidth.py, with the help of glibc's + utf8_gen.py, using version 12.1.0 of the Unicode standard. */ + +static const cppchar_t wcwidth_range_ends[] = { + 0x2ff, 0x36f, 0x482, 0x489, 0x590, 0x5bd, 0x5be, 0x5bf, + 0x5c0, 0x5c2, 0x5c3, 0x5c5, 0x5c6, 0x5c7, 0x60f, 0x61a, + 0x61b, 0x61c, 0x64a, 0x65f, 0x66f, 0x670, 0x6d5, 0x6dc, + 0x6de, 0x6e4, 0x6e6, 0x6e8, 0x6e9, 0x6ed, 0x710, 0x711, + 0x72f, 0x74a, 0x7a5, 0x7b0, 0x7ea, 0x7f3, 0x7fc, 0x7fd, + 0x815, 0x819, 0x81a, 0x823, 0x824, 0x827, 0x828, 0x82d, + 0x858, 0x85b, 0x8d2, 0x8e1, 0x8e2, 0x902, 0x939, 0x93a, + 0x93b, 0x93c, 0x940, 0x948, 0x94c, 0x94d, 0x950, 0x957, + 0x961, 0x963, 0x980, 0x981, 0x9bb, 0x9bc, 0x9c0, 0x9c4, + 0x9cc, 0x9cd, 0x9e1, 0x9e3, 0x9fd, 0x9fe, 0xa00, 0xa02, + 0xa3b, 0xa3c, 0xa40, 0xa42, 0xa46, 0xa48, 0xa4a, 0xa4d, + 0xa50, 0xa51, 0xa6f, 0xa71, 0xa74, 0xa75, 0xa80, 0xa82, + 0xabb, 0xabc, 0xac0, 0xac5, 0xac6, 0xac8, 0xacc, 0xacd, + 0xae1, 0xae3, 0xaf9, 0xaff, 0xb00, 0xb01, 0xb3b, 0xb3c, + 0xb3e, 0xb3f, 0xb40, 0xb44, 0xb4c, 0xb4d, 0xb55, 0xb56, + 0xb61, 0xb63, 0xb81, 0xb82, 0xbbf, 0xbc0, 0xbcc, 0xbcd, + 0xbff, 0xc00, 0xc03, 0xc04, 0xc3d, 0xc40, 0xc45, 0xc48, + 0xc49, 0xc4d, 0xc54, 0xc56, 0xc61, 0xc63, 0xc80, 0xc81, + 0xcbb, 0xcbc, 0xcbe, 0xcbf, 0xcc5, 0xcc6, 0xccb, 0xccd, + 0xce1, 0xce3, 0xcff, 0xd01, 0xd3a, 0xd3c, 0xd40, 0xd44, + 0xd4c, 0xd4d, 0xd61, 0xd63, 0xdc9, 0xdca, 0xdd1, 0xdd4, + 0xdd5, 0xdd6, 0xe30, 0xe31, 0xe33, 0xe3a, 0xe46, 0xe4e, + 0xeb0, 0xeb1, 0xeb3, 0xebc, 0xec7, 0xecd, 0xf17, 0xf19, + 0xf34, 0xf35, 0xf36, 0xf37, 0xf38, 0xf39, 0xf70, 0xf7e, + 0xf7f, 0xf84, 0xf85, 0xf87, 0xf8c, 0xf97, 0xf98, 0xfbc, + 0xfc5, 0xfc6, 0x102c, 0x1030, 0x1031, 0x1037, 0x1038, 0x103a, + 0x103c, 0x103e, 0x1057, 0x1059, 0x105d, 0x1060, 0x1070, 0x1074, + 0x1081, 0x1082, 0x1084, 0x1086, 0x108c, 0x108d, 0x109c, 0x109d, + 0x10ff, 0x115f, 0x11ff, 0x135c, 0x135f, 0x1711, 0x1714, 0x1731, + 0x1734, 0x1751, 0x1753, 0x1771, 0x1773, 0x17b3, 0x17b5, 0x17b6, + 0x17bd, 0x17c5, 0x17c6, 0x17c8, 0x17d3, 0x17dc, 0x17dd, 0x180a, + 0x180e, 0x1884, 0x1886, 0x18a8, 0x18a9, 0x191f, 0x1922, 0x1926, + 0x1928, 0x1931, 0x1932, 0x1938, 0x193b, 0x1a16, 0x1a18, 0x1a1a, + 0x1a1b, 0x1a55, 0x1a56, 0x1a57, 0x1a5e, 0x1a5f, 0x1a60, 0x1a61, + 0x1a62, 0x1a64, 0x1a6c, 0x1a72, 0x1a7c, 0x1a7e, 0x1a7f, 0x1aaf, + 0x1abe, 0x1aff, 0x1b03, 0x1b33, 0x1b34, 0x1b35, 0x1b3a, 0x1b3b, + 0x1b3c, 0x1b41, 0x1b42, 0x1b6a, 0x1b73, 0x1b7f, 0x1b81, 0x1ba1, + 0x1ba5, 0x1ba7, 0x1ba9, 0x1baa, 0x1bad, 0x1be5, 0x1be6, 0x1be7, + 0x1be9, 0x1bec, 0x1bed, 0x1bee, 0x1bf1, 0x1c2b, 0x1c33, 0x1c35, + 0x1c37, 0x1ccf, 0x1cd2, 0x1cd3, 0x1ce0, 0x1ce1, 0x1ce8, 0x1cec, + 0x1ced, 0x1cf3, 0x1cf4, 0x1cf7, 0x1cf9, 0x1dbf, 0x1df9, 0x1dfa, + 0x1dff, 0x200a, 0x200f, 0x2029, 0x202e, 0x205f, 0x2064, 0x2065, + 0x206f, 0x20cf, 0x20f0, 0x2319, 0x231b, 0x2328, 0x232a, 0x23e8, + 0x23ec, 0x23ef, 0x23f0, 0x23f2, 0x23f3, 0x25fc, 0x25fe, 0x2613, + 0x2615, 0x2647, 0x2653, 0x267e, 0x267f, 0x2692, 0x2693, 0x26a0, + 0x26a1, 0x26a9, 0x26ab, 0x26bc, 0x26be, 0x26c3, 0x26c5, 0x26cd, + 0x26ce, 0x26d3, 0x26d4, 0x26e9, 0x26ea, 0x26f1, 0x26f3, 0x26f4, + 0x26f5, 0x26f9, 0x26fa, 0x26fc, 0x26fd, 0x2704, 0x2705, 0x2709, + 0x270b, 0x2727, 0x2728, 0x274b, 0x274c, 0x274d, 0x274e, 0x2752, + 0x2755, 0x2756, 0x2757, 0x2794, 0x2797, 0x27af, 0x27b0, 0x27be, + 0x27bf, 0x2b1a, 0x2b1c, 0x2b4f, 0x2b50, 0x2b54, 0x2b55, 0x2cee, + 0x2cf1, 0x2d7e, 0x2d7f, 0x2ddf, 0x2dff, 0x2e7f, 0x2e99, 0x2e9a, + 0x2ef3, 0x2eff, 0x2fd5, 0x2fef, 0x2ffb, 0x2fff, 0x3029, 0x302d, + 0x303e, 0x3040, 0x3096, 0x3098, 0x309a, 0x30ff, 0x3104, 0x312f, + 0x3130, 0x318e, 0x318f, 0x31ba, 0x31bf, 0x31e3, 0x31ef, 0x321e, + 0x321f, 0x4db5, 0x4dbf, 0x9fef, 0x9fff, 0xa48c, 0xa48f, 0xa4c6, + 0xa66e, 0xa672, 0xa673, 0xa67d, 0xa69d, 0xa69f, 0xa6ef, 0xa6f1, + 0xa801, 0xa802, 0xa805, 0xa806, 0xa80a, 0xa80b, 0xa824, 0xa826, + 0xa8c3, 0xa8c5, 0xa8df, 0xa8f1, 0xa8fe, 0xa8ff, 0xa925, 0xa92d, + 0xa946, 0xa951, 0xa95f, 0xa97c, 0xa97f, 0xa982, 0xa9b2, 0xa9b3, + 0xa9b5, 0xa9b9, 0xa9bb, 0xa9bd, 0xa9e4, 0xa9e5, 0xaa28, 0xaa2e, + 0xaa30, 0xaa32, 0xaa34, 0xaa36, 0xaa42, 0xaa43, 0xaa4b, 0xaa4c, + 0xaa7b, 0xaa7c, 0xaaaf, 0xaab0, 0xaab1, 0xaab4, 0xaab6, 0xaab8, + 0xaabd, 0xaabf, 0xaac0, 0xaac1, 0xaaeb, 0xaaed, 0xaaf5, 0xaaf6, + 0xabe4, 0xabe5, 0xabe7, 0xabe8, 0xabec, 0xabed, 0xabff, 0xd7a3, + 0xf8ff, 0xfa6d, 0xfa6f, 0xfad9, 0xfb1d, 0xfb1e, 0xfdff, 0xfe0f, + 0xfe19, 0xfe1f, 0xfe2f, 0xfe52, 0xfe53, 0xfe66, 0xfe67, 0xfe6b, + 0xfefe, 0xfeff, 0xff00, 0xff60, 0xffdf, 0xffe6, 0xfff8, 0xfffb, + 0x101fc, 0x101fd, 0x102df, 0x102e0, 0x10375, 0x1037a, 0x10a00, 0x10a03, + 0x10a04, 0x10a06, 0x10a0b, 0x10a0f, 0x10a37, 0x10a3a, 0x10a3e, 0x10a3f, + 0x10ae4, 0x10ae6, 0x10d23, 0x10d27, 0x10f45, 0x10f50, 0x11000, 0x11001, + 0x11037, 0x11046, 0x1107e, 0x11081, 0x110b2, 0x110b6, 0x110b8, 0x110ba, + 0x110ff, 0x11102, 0x11126, 0x1112b, 0x1112c, 0x11134, 0x11172, 0x11173, + 0x1117f, 0x11181, 0x111b5, 0x111be, 0x111c8, 0x111cc, 0x1122e, 0x11231, + 0x11233, 0x11234, 0x11235, 0x11237, 0x1123d, 0x1123e, 0x112de, 0x112df, + 0x112e2, 0x112ea, 0x112ff, 0x11301, 0x1133a, 0x1133c, 0x1133f, 0x11340, + 0x11365, 0x1136c, 0x1136f, 0x11374, 0x11437, 0x1143f, 0x11441, 0x11444, + 0x11445, 0x11446, 0x1145d, 0x1145e, 0x114b2, 0x114b8, 0x114b9, 0x114ba, + 0x114be, 0x114c0, 0x114c1, 0x114c3, 0x115b1, 0x115b5, 0x115bb, 0x115bd, + 0x115be, 0x115c0, 0x115db, 0x115dd, 0x11632, 0x1163a, 0x1163c, 0x1163d, + 0x1163e, 0x11640, 0x116aa, 0x116ab, 0x116ac, 0x116ad, 0x116af, 0x116b5, + 0x116b6, 0x116b7, 0x1171c, 0x1171f, 0x11721, 0x11725, 0x11726, 0x1172b, + 0x1182e, 0x11837, 0x11838, 0x1183a, 0x119d3, 0x119d7, 0x119d9, 0x119db, + 0x119df, 0x119e0, 0x11a00, 0x11a0a, 0x11a32, 0x11a38, 0x11a3a, 0x11a3e, + 0x11a46, 0x11a47, 0x11a50, 0x11a56, 0x11a58, 0x11a5b, 0x11a89, 0x11a96, + 0x11a97, 0x11a99, 0x11c2f, 0x11c36, 0x11c37, 0x11c3d, 0x11c3e, 0x11c3f, + 0x11c91, 0x11ca7, 0x11ca9, 0x11cb0, 0x11cb1, 0x11cb3, 0x11cb4, 0x11cb6, + 0x11d30, 0x11d36, 0x11d39, 0x11d3a, 0x11d3b, 0x11d3d, 0x11d3e, 0x11d45, + 0x11d46, 0x11d47, 0x11d8f, 0x11d91, 0x11d94, 0x11d95, 0x11d96, 0x11d97, + 0x11ef2, 0x11ef4, 0x1342f, 0x13438, 0x16aef, 0x16af4, 0x16b2f, 0x16b36, + 0x16f4e, 0x16f4f, 0x16f8e, 0x16f92, 0x16fdf, 0x16fe3, 0x16fff, 0x187f7, + 0x187ff, 0x18af2, 0x1afff, 0x1b11e, 0x1b14f, 0x1b152, 0x1b163, 0x1b167, + 0x1b16f, 0x1b2fb, 0x1bc9c, 0x1bc9e, 0x1bc9f, 0x1bca3, 0x1d166, 0x1d169, + 0x1d172, 0x1d182, 0x1d184, 0x1d18b, 0x1d1a9, 0x1d1ad, 0x1d241, 0x1d244, + 0x1d9ff, 0x1da36, 0x1da3a, 0x1da6c, 0x1da74, 0x1da75, 0x1da83, 0x1da84, + 0x1da9a, 0x1da9f, 0x1daa0, 0x1daaf, 0x1dfff, 0x1e006, 0x1e007, 0x1e018, + 0x1e01a, 0x1e021, 0x1e022, 0x1e024, 0x1e025, 0x1e02a, 0x1e12f, 0x1e136, + 0x1e2eb, 0x1e2ef, 0x1e8cf, 0x1e8d6, 0x1e943, 0x1e94a, 0x1f003, 0x1f004, + 0x1f0ce, 0x1f0cf, 0x1f18d, 0x1f18e, 0x1f190, 0x1f19a, 0x1f1ff, 0x1f202, + 0x1f20f, 0x1f23b, 0x1f23f, 0x1f248, 0x1f24f, 0x1f251, 0x1f25f, 0x1f265, + 0x1f2ff, 0x1f320, 0x1f32c, 0x1f335, 0x1f336, 0x1f37c, 0x1f37d, 0x1f393, + 0x1f39f, 0x1f3ca, 0x1f3ce, 0x1f3d3, 0x1f3df, 0x1f3f0, 0x1f3f3, 0x1f3f4, + 0x1f3f7, 0x1f43e, 0x1f43f, 0x1f440, 0x1f441, 0x1f4fc, 0x1f4fe, 0x1f53d, + 0x1f54a, 0x1f54e, 0x1f54f, 0x1f567, 0x1f579, 0x1f57a, 0x1f594, 0x1f596, + 0x1f5a3, 0x1f5a4, 0x1f5fa, 0x1f64f, 0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2, 1, 2, 1, 2, 1, 2, + 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 0, 1, 0, 1, 0, +}; diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index ed108f1..e199aec 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -1320,4 +1320,15 @@ extern bool cpp_userdef_char_p extern const char * cpp_get_userdef_suffix (const cpp_token *); +/* In charset.c */ +int cpp_byte_column_to_display_column (const char *data, int data_length, + int column); +inline int cpp_display_width (const char *data, int data_length) +{ + return cpp_byte_column_to_display_column (data, data_length, data_length); +} +int cpp_display_column_to_byte_column (const char *data, int data_length, + int display_col); +int cpp_wcwidth (cppchar_t c); + #endif /* ! LIBCPP_CPPLIB_H */ -- cgit v1.1 From d68f5d458d7df12b31d27094e8f7ed0208ccf693 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Tue, 10 Dec 2019 02:02:38 +0000 Subject: Replace label_text ctor with "borrow" and "take" libcpp's label_text class wraps a text buffer, along with a flag to determine if it "owns" the buffer. The existing ctor exposed this directly, but I found it difficult to remember the sense of flag, so this patch hides the ctor, in favor of static member functions "borrow" and "take", to make the effect on ownership explicit in the name. gcc/c-family/ChangeLog: * c-format.c (range_label_for_format_type_mismatch::get_text): Replace label_text ctor called with true with label_text::take. gcc/c/ChangeLog: * c-objc-common.c (range_label_for_type_mismatch::get_text): Replace label_text ctor calls. gcc/cp/ChangeLog: * error.c (range_label_for_type_mismatch::get_text): Replace label_text ctor calls with label_text::borrow. gcc/ChangeLog: * gcc-rich-location.c (maybe_range_label_for_tree_type_mismatch::get_text): Replace label_text ctor call with label_text::borrow. * gcc-rich-location.h (text_range_label::get_text): Replace label_text ctor called with false with label_text::borrow. libcpp/ChangeLog: * include/line-map.h (label_text::label_text): Make private. (label_text::borrow): New. (label_text::take): New. (label_text::take_or_copy): New. From-SVN: r279153 --- libcpp/ChangeLog | 7 +++++++ libcpp/include/line-map.h | 31 +++++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 4 deletions(-) (limited to 'libcpp') diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index f4376e6..2090bd7 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,10 @@ +2019-12-09 David Malcolm + + * include/line-map.h (label_text::label_text): Make private. + (label_text::borrow): New. + (label_text::take): New. + (label_text::take_or_copy): New. + 2019-12-09 Lewis Hyatt PR preprocessor/49973 diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h index 6f4cf5b..e78249f 100644 --- a/libcpp/include/line-map.h +++ b/libcpp/include/line-map.h @@ -1764,18 +1764,41 @@ public: : m_buffer (NULL), m_caller_owned (false) {} - label_text (char *buffer, bool caller_owned) - : m_buffer (buffer), m_caller_owned (caller_owned) - {} - void maybe_free () { if (m_caller_owned) free (m_buffer); } + /* Create a label_text instance that borrows BUFFER from a + longer-lived owner. */ + static label_text borrow (const char *buffer) + { + return label_text (const_cast (buffer), false); + } + + /* Create a label_text instance that takes ownership of BUFFER. */ + static label_text take (char *buffer) + { + return label_text (buffer, true); + } + + /* Take ownership of the buffer, copying if necessary. */ + char *take_or_copy () + { + if (m_caller_owned) + return m_buffer; + else + return xstrdup (m_buffer); + } + char *m_buffer; bool m_caller_owned; + +private: + label_text (char *buffer, bool owned) + : m_buffer (buffer), m_caller_owned (owned) + {} }; /* Abstract base class for labelling a range within a rich_location -- cgit v1.1