diff options
Diffstat (limited to 'libcpp')
-rw-r--r-- | libcpp/ChangeLog | 17 | ||||
-rw-r--r-- | libcpp/charset.cc | 4 | ||||
-rw-r--r-- | libcpp/expr.cc | 23 | ||||
-rw-r--r-- | libcpp/include/cpplib.h | 5 | ||||
-rw-r--r-- | libcpp/init.cc | 52 | ||||
-rw-r--r-- | libcpp/lex.cc | 13 |
6 files changed, 77 insertions, 37 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 3b41845..3a1b499 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,20 @@ +2022-10-14 Joseph Myers <joseph@codesourcery.com> + + * charset.cc (ucn_valid_in_identifier): Check xid_identifiers not + cplusplus to determine whether to use CXX23 and NXX23 flags. + * include/cpplib.h (struct cpp_options): Add xid_identifiers. + * init.cc (struct lang_flags, lang_defaults): Add xid_identifiers. + (cpp_set_lang): Set xid_identifiers. + * lex.cc (warn_about_normalization): Add parameter identifier. + Only pedwarn about non-NFC for identifiers, not pp-numbers. + (_cpp_lex_direct): Update calls to warn_about_normalization. + +2022-10-14 Jakub Jelinek <jakub@redhat.com> + + * include/cpplib.h (CPP_N_BFLOAT16): Define. + * expr.cc (interpret_float_suffix): Handle bf16 and BF16 suffixes for + C++. + 2022-09-28 Eugene Rozenfeld <erozen@microsoft.com> * include/line-map.h: Add discriminator to location_adhoc_data. diff --git a/libcpp/charset.cc b/libcpp/charset.cc index 6834969..12a398e 100644 --- a/libcpp/charset.cc +++ b/libcpp/charset.cc @@ -1291,7 +1291,7 @@ ucn_valid_in_identifier (cpp_reader *pfile, cppchar_t c, valid_flags = C99 | CXX | C11 | CXX23; if (CPP_PEDANTIC (pfile)) { - if (CPP_OPTION (pfile, cplusplus)) + if (CPP_OPTION (pfile, xid_identifiers)) valid_flags = CXX23; else if (CPP_OPTION (pfile, c11_identifiers)) valid_flags = C11; @@ -1355,7 +1355,7 @@ ucn_valid_in_identifier (cpp_reader *pfile, cppchar_t c, return 2; } - if (CPP_OPTION (pfile, cplusplus)) + if (CPP_OPTION (pfile, xid_identifiers)) invalid_start_flags = NXX23; else if (CPP_OPTION (pfile, c11_identifiers)) invalid_start_flags = N11; diff --git a/libcpp/expr.cc b/libcpp/expr.cc index 1d68064..5ee28c4 100644 --- a/libcpp/expr.cc +++ b/libcpp/expr.cc @@ -91,10 +91,10 @@ interpret_float_suffix (cpp_reader *pfile, const uchar *s, size_t len) size_t orig_len = len; const uchar *orig_s = s; size_t flags; - size_t f, d, l, w, q, i, fn, fnx, fn_bits; + size_t f, d, l, w, q, i, fn, fnx, fn_bits, bf16; flags = 0; - f = d = l = w = q = i = fn = fnx = fn_bits = 0; + f = d = l = w = q = i = fn = fnx = fn_bits = bf16 = 0; /* The following decimal float suffixes, from TR 24732:2009, TS 18661-2:2015 and C2X, are supported: @@ -131,7 +131,8 @@ interpret_float_suffix (cpp_reader *pfile, const uchar *s, size_t len) w, W - machine-specific type such as __float80 (GNU extension). q, Q - machine-specific type such as __float128 (GNU extension). fN, FN - _FloatN (TS 18661-3:2015). - fNx, FNx - _FloatNx (TS 18661-3:2015). */ + fNx, FNx - _FloatNx (TS 18661-3:2015). + bf16, BF16 - std::bfloat16_t (ISO C++23). */ /* Process decimal float suffixes, which are two letters starting with d or D. Order and case are significant. */ @@ -239,6 +240,19 @@ interpret_float_suffix (cpp_reader *pfile, const uchar *s, size_t len) fn++; } break; + case 'b': case 'B': + if (len > 2 + /* Except for bf16 / BF16 where case is significant. */ + && s[1] == (s[0] == 'b' ? 'f' : 'F') + && s[2] == '1' + && s[3] == '6') + { + bf16++; + len -= 3; + s += 3; + break; + } + return 0; case 'd': case 'D': d++; break; case 'l': case 'L': l++; break; case 'w': case 'W': w++; break; @@ -257,7 +271,7 @@ interpret_float_suffix (cpp_reader *pfile, const uchar *s, size_t len) of N larger than can be represented in the return value. The caller is responsible for rejecting _FloatN suffixes where _FloatN is not supported on the chosen target. */ - if (f + d + l + w + q + fn + fnx > 1 || i > 1) + if (f + d + l + w + q + fn + fnx + bf16 > 1 || i > 1) return 0; if (fn_bits > CPP_FLOATN_MAX) return 0; @@ -295,6 +309,7 @@ interpret_float_suffix (cpp_reader *pfile, const uchar *s, size_t len) q ? CPP_N_MD_Q : fn ? CPP_N_FLOATN | (fn_bits << CPP_FLOATN_SHIFT) : fnx ? CPP_N_FLOATNX | (fn_bits << CPP_FLOATN_SHIFT) : + bf16 ? CPP_N_BFLOAT16 : CPP_N_DEFAULT)); } diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index 2db1e9c..d5ef12a 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -496,6 +496,10 @@ struct cpp_options in C11. */ unsigned char c11_identifiers; + /* Nonzero means extended identifiers allow the characters specified + by Unicode XID_Start and XID_Continue properties. */ + unsigned char xid_identifiers; + /* Nonzero for C++ 2014 Standard binary constants. */ unsigned char binary_constants; @@ -1275,6 +1279,7 @@ struct cpp_num #define CPP_N_USERDEF 0x1000000 /* C++11 user-defined literal. */ #define CPP_N_SIZE_T 0x2000000 /* C++23 size_t literal. */ +#define CPP_N_BFLOAT16 0x4000000 /* std::bfloat16_t type. */ #define CPP_N_WIDTH_FLOATN_NX 0xF0000000 /* _FloatN / _FloatNx value of N, divided by 16. */ diff --git a/libcpp/init.cc b/libcpp/init.cc index d3b4f00..5f34e35 100644 --- a/libcpp/init.cc +++ b/libcpp/init.cc @@ -82,6 +82,7 @@ struct lang_flags char extended_numbers; char extended_identifiers; char c11_identifiers; + char xid_identifiers; char std; char digraphs; char uliterals; @@ -102,31 +103,31 @@ struct lang_flags }; static const struct lang_flags lang_defaults[] = -{ /* c99 c++ xnum xid c11 std digr ulit rlit udlit bincst digsep trig u8chlit vaopt scope dfp szlit elifdef warndir delim trufal */ - /* GNUC89 */ { 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0 }, - /* GNUC99 */ { 1, 0, 1, 1, 0, 0, 1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1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1 }, - /* GNUCXX14 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1 }, - /* CXX14 */ { 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1 }, - /* GNUCXX17 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1 }, - /* CXX17 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1 }, - /* GNUCXX20 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1 }, - /* CXX20 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1 }, - /* GNUCXX23 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1 }, - /* CXX23 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1 }, - /* ASM */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } +{ /* c99 c++ xnum xid c11 xidid std digr ulit rlit udlit bincst digsep trig u8chlit vaopt scope dfp szlit elifdef warndir delim trufal */ + /* GNUC89 */ { 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0 }, + /* GNUC99 */ { 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0 }, + /* GNUC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, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1 }, + /* GNUCXX14 */ { 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1 }, + /* CXX14 */ { 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1 }, + /* GNUCXX17 */ { 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1 }, + /* CXX17 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1 }, + /* GNUCXX20 */ { 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1 }, + /* CXX20 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1 }, + /* GNUCXX23 */ { 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1 }, + /* CXX23 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1 }, + /* ASM */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }; /* Sets internal flags correctly for a given language. */ @@ -142,6 +143,7 @@ cpp_set_lang (cpp_reader *pfile, enum c_lang lang) CPP_OPTION (pfile, extended_numbers) = l->extended_numbers; CPP_OPTION (pfile, extended_identifiers) = l->extended_identifiers; CPP_OPTION (pfile, c11_identifiers) = l->c11_identifiers; + CPP_OPTION (pfile, xid_identifiers) = l->xid_identifiers; CPP_OPTION (pfile, std) = l->std; CPP_OPTION (pfile, digraphs) = l->digraphs; CPP_OPTION (pfile, uliterals) = l->uliterals; diff --git a/libcpp/lex.cc b/libcpp/lex.cc index a429a3d..cc12a52d 100644 --- a/libcpp/lex.cc +++ b/libcpp/lex.cc @@ -2007,7 +2007,8 @@ name_p (cpp_reader *pfile, const cpp_string *string) static void warn_about_normalization (cpp_reader *pfile, const cpp_token *token, - const struct normalize_state *s) + const struct normalize_state *s, + bool identifier) { if (CPP_OPTION (pfile, warn_normalize) < NORMALIZE_STATE_RESULT (s) && !pfile->state.skipping) @@ -2043,7 +2044,7 @@ warn_about_normalization (cpp_reader *pfile, if (NORMALIZE_STATE_RESULT (s) == normalized_C) cpp_warning_at (pfile, CPP_W_NORMALIZE, &rich_loc, "`%.*s' is not in NFKC", (int) sz, buf); - else if (CPP_OPTION (pfile, cplusplus)) + else if (identifier && CPP_OPTION (pfile, xid_identifiers)) cpp_pedwarning_at (pfile, CPP_W_NORMALIZE, &rich_loc, "`%.*s' is not in NFC", (int) sz, buf); else @@ -3839,7 +3840,7 @@ _cpp_lex_direct (cpp_reader *pfile) struct normalize_state nst = INITIAL_NORMALIZE_STATE; result->type = CPP_NUMBER; lex_number (pfile, &result->val.str, &nst); - warn_about_normalization (pfile, result, &nst); + warn_about_normalization (pfile, result, &nst, false); break; } @@ -3888,7 +3889,7 @@ _cpp_lex_direct (cpp_reader *pfile) result->val.node.node = lex_identifier (pfile, buffer->cur - 1, false, &nst, &result->val.node.spelling); - warn_about_normalization (pfile, result, &nst); + warn_about_normalization (pfile, result, &nst, true); } /* Convert named operators to their proper types. */ @@ -4101,7 +4102,7 @@ _cpp_lex_direct (cpp_reader *pfile) struct normalize_state nst = INITIAL_NORMALIZE_STATE; result->type = CPP_NUMBER; lex_number (pfile, &result->val.str, &nst); - warn_about_normalization (pfile, result, &nst); + warn_about_normalization (pfile, result, &nst, false); } else if (*buffer->cur == '.' && buffer->cur[1] == '.') buffer->cur += 2, result->type = CPP_ELLIPSIS; @@ -4192,7 +4193,7 @@ _cpp_lex_direct (cpp_reader *pfile) result->type = CPP_NAME; result->val.node.node = lex_identifier (pfile, base, true, &nst, &result->val.node.spelling); - warn_about_normalization (pfile, result, &nst); + warn_about_normalization (pfile, result, &nst, true); break; } |