Commit Graph

1455 Commits

Author SHA1 Message Date
Alexander Monakov a8260ebeae libcpp: deduplicate definition of padding size
Tie together the two functions that ensure tail padding with
search_line_ssse3 via CPP_BUFFER_PADDING macro.

libcpp/ChangeLog:

	* internal.h (CPP_BUFFER_PADDING): New macro; use it ...
	* charset.cc (_cpp_convert_input): ...here, and ...
	* files.cc (read_file_guts): ...here, and ...
	* lex.cc (search_line_ssse3): here.
2024-08-26 16:05:48 +03:00
GCC Administrator 3ff1b91e77 Daily bump. 2024-08-24 00:18:13 +00:00
Alexander Monakov b2c1d7c457 libcpp: bump padding size in _cpp_convert_input [PR116458]
The recently introduced search_line_fast_ssse3 raised padding
requirement from 16 to 64, which was adjusted in read_file_guts,
but the corresponding ' + 16' in _cpp_convert_input was overlooked.

libcpp/ChangeLog:

	PR preprocessor/116458
	* charset.cc (_cpp_convert_input): Bump padding to 64 if
	HAVE_SSSE3.
2024-08-23 14:09:51 +03:00
GCC Administrator 2cd783be9f Daily bump. 2024-08-23 00:17:24 +00:00
Marc Poulhiès 4e905bd353 fix single argument static_assert
Single argument static_assert is C++17 only.

libcpp/ChangeLog:

	* lex.cc(search_line_ssse3): fix static_assert to use 2 arguments.
2024-08-22 13:41:40 +02:00
GCC Administrator 964c9c247c Daily bump. 2024-08-21 00:19:34 +00:00
Jakub Jelinek 447c32c514 libcpp: Adjust lang_defaults
The table over the years turned to be very wide, 147 columns
and any addition would add a couple of new ones.
We need a 28x23 bit matrix right now.

This patch changes the formatting, so that we need just 2 columns
per new feature and so we have some room for expansion.
In addition, the patch changes it to bitfields, which reduces
.rodata by 532 bytes (so 5.75x reduction of the variable) and
on x86_64-linux grows the cpp_set_lang function by 26 bytes (8.4%
growth).

2024-08-20  Jakub Jelinek  <jakub@redhat.com>

	* init.cc (struct lang_flags): Change all members from char
	typed fields to unsigned bit-fields.
	(lang_defaults): Change formatting of the initializer so that it
	fits to 68 columns rather than 147.
2024-08-20 22:33:13 +02:00
Alexander Monakov 20a5b48249 libcpp: replace SSE4.2 helper with an SSSE3 one
Since the characters we are searching for (CR, LF, '\', '?') all have
distinct ASCII codes mod 16, PSHUFB can help match them all at once.

Directly use the new helper if __SSSE3__ is defined. It makes the other
helpers unused, so mark them inline to prevent warnings.

Rewrite and simplify init_vectorized_lexer.

libcpp/ChangeLog:

	* config.in: Regenerate.
	* configure: Regenerate.
	* configure.ac: Check for SSSE3 instead of SSE4.2.
	* files.cc (read_file_guts): Bump padding to 64 if HAVE_SSSE3.
	* lex.cc (search_line_acc_char): Mark inline, not "unused".
	(search_line_sse2): Mark inline.
	(search_line_sse42): Replace with...
	(search_line_ssse3): ... this new function.  Adjust the use...
	(init_vectorized_lexer): ... here.  Simplify.
2024-08-20 14:09:12 +03:00
GCC Administrator b120ca0c1d Daily bump. 2024-08-07 00:16:52 +00:00
Andi Kleen eac63be1d4 Remove MMX code path in lexer
Host systems with only MMX and no SSE2 should be really rare now.
Let's remove the MMX code path to keep the number of custom
implementations the same.

The SSE2 code path is also somewhat dubious now (nearly everything
should have SSE4 4.2 which is >15 years old now), but the SSE2
code path is used as fallback for others and also apparently
Solaris uses it due to tool chain deficiencies.

libcpp/ChangeLog:

	* lex.cc (search_line_mmx): Remove function.
	(init_vectorized_lexer): Remove search_line_mmx.
2024-08-06 11:41:57 -07:00
GCC Administrator 18eb6ca136 Daily bump. 2024-07-26 00:17:23 +00:00
Jakub Jelinek 29341f21ce c++: Implement C++26 P2558R2 - Add @, $, and ` to the basic character set [PR110343]
The following patch implements the easy parts of the paper.
When @$` are added to the basic character set, it means that
R"@$`()@$`" should now be valid (here I've noticed most of the
raw string tests were tested solely with -std=c++11 or -std=gnu++11
and I've tried to change that), and on the other side even if
by extension $ is allowed in identifiers, \u0024 or \U00000024
or \u{24} should not be, similarly how \u0041 is not allowed.

The paper in 3.1 claims though that
 #include <stdio.h>

 #define STR(x) #x

int main()
{
  printf("%s", STR(\u0060)); // U+0060 is ` GRAVE ACCENT
}
should have been accepted before this paper (and rejected after it),
but g++ rejects it.

I've tried to understand it, but am confused on what is the right
behavior and why.

Consider
 #define STR(x) #x
const char *a = "\u00b7";
const char *b = STR(\u00b7);
const char *c = "\u0041";
const char *d = STR(\u0041);
const char *e = STR(a\u00b7);
const char *f = STR(a\u0041);
const char *g = STR(a \u00b7);
const char *h = STR(a \u0041);
const char *i = "\u066d";
const char *j = STR(\u066d);
const char *k = "\u0040";
const char *l = STR(\u0040);
const char *m = STR(a\u066d);
const char *n = STR(a\u0040);
const char *o = STR(a \u066d);
const char *p = STR(a \u0040);

Neither clang nor gcc emit any diagnostics on the a, c, i and k
initializers, those are certainly valid (c is invalid in C23 though).  g++
emits with -pedantic-errors errors on all the others, while clang++ on the
ones with STR involving \u0041, \u0040 and a\u0066d.  The chosen values are
\u0040 '@' as something being changed by this paper, \u0041 'A' as basic
character set char valid in identifiers before/after, \u00b7 as an example
of character which is pedantically valid in identifiers if not at the start
and \u066d s something pedantically not valid in identifiers.

Now, https://eel.is/c++draft/lex.charset#6 says that UCN used outside of a
string/character literal which corresponds to basic character set character
(or control character) is ill-formed, that would make d, f, h cases invalid
for C++ and l, n, p cases invalid for C++26.

https://eel.is/c++draft/lex.name states which characters can appear at the
start of the identifier and which can appear after the start.  And
https://eel.is/c++draft/lex.pptoken states that preprocessing-token is
either identifier, or tons of other things, or "each non-whitespace
character that cannot be one of the above"

Then https://eel.is/c++draft/lex.pptoken#1 says that this last category is
invalid if the preprocessing token is being converted into token.

And https://eel.is/c++draft/lex.pptoken#2 includes "If any character not in
the basic character set matches the last category, the program is
ill-formed."

Now, e.g.  for the C++23 STR(\u0040) case, \u0040 is there not in the basic
character set, so valid outside of the literals (not the case anymore in
C++26), but it isn't nondigit and doesn't have XID_Start property, so it
isn't IMHO an identifier and so must be the "each non-whitespace character
that cannot be one of the above" case.  Why doesn't the above mentioned
https://eel.is/c++draft/lex.pptoken#2 sentence make that invalid?  Ignoring
that, I'd say it would be then stringized and that feels like it is what
clang++ is doing.  Now, e.g.  for the STR(a\u066d) case, I wonder why that
isn't lexed as a identifier followed by \u066d "each non-whitespace
character that cannot be one of the above" token and stringified similarly,
clang++ rejects that.

What GCC libcpp seems to be doing is that if that forms_identifier_p calls
_cpp_valid_utf8 or _cpp_valid_ucn with an argument which tells it is first
or second+ in identifier, and e.g.  _cpp_valid_ucn then for UCNs valid in
string literals calls
  else if (identifier_pos)
    {
      int validity = ucn_valid_in_identifier (pfile, result, nst);

      if (validity == 0)
        cpp_error (pfile, CPP_DL_ERROR,
                   "universal character %.*s is not valid in an identifier",
                   (int) (str - base), base);
      else if (validity == 2 && identifier_pos == 1)
        cpp_error (pfile, CPP_DL_ERROR,
   "universal character %.*s is not valid at the start of an identifier",
                   (int) (str - base), base);
    }
so basically all those invalid in identifiers cases emit an error and
pretend to be valid in identifiers, rather than what e.g.  _cpp_valid_utf8
does for C but not for C++ and only for the chars completely invalid in
identifiers rather than just valid in identifiers but not at the start:
          /* In C++, this is an error for invalid character in an identifier
             because logically, the UTF-8 was converted to a UCN during
             translation phase 1 (even though we don't physically do it that
             way).  In C, this byte rather becomes grammatically a separate
             token.  */

          if (CPP_OPTION (pfile, cplusplus))
            cpp_error (pfile, CPP_DL_ERROR,
                       "extended character %.*s is not valid in an identifier",
                       (int) (*pstr - base), base);
          else
            {
              *pstr = base;
              return false;
            }
The comment doesn't really match what is done in recent C++ versions because
there UCNs are translated to characters and not the other way around.

2024-07-25  Jakub Jelinek  <jakub@redhat.com>

	PR c++/110343
libcpp/
	* lex.cc: C++26 P2558R2 - Add @, $, and ` to the basic character set.
	(lex_raw_string): For C++26 allow $@` characters in prefix.
	* charset.cc (_cpp_valid_ucn): For C++26 reject \u0024 in identifiers.
gcc/testsuite/
	* c-c++-common/raw-string-1.c: Use { c || c++11 } effective target,
	remove c++ specific dg-options.
	* c-c++-common/raw-string-2.c: Likewise.
	* c-c++-common/raw-string-4.c: Likewise.
	* c-c++-common/raw-string-5.c: Likewise.  Expect some diagnostics
	only for non-c++26, for c++26 expect different.
	* c-c++-common/raw-string-6.c: Use { c || c++11 } effective target,
	remove c++ specific dg-options.
	* c-c++-common/raw-string-11.c: Likewise.
	* c-c++-common/raw-string-13.c: Likewise.
	* c-c++-common/raw-string-14.c: Likewise.
	* c-c++-common/raw-string-15.c: Use { c || c++11 } effective target,
	change c++ specific dg-options to just -Wtrigraphs.
	* c-c++-common/raw-string-16.c: Likewise.
	* c-c++-common/raw-string-17.c: Use { c || c++11 } effective target,
	remove c++ specific dg-options.
	* c-c++-common/raw-string-18.c: Use { c || c++11 } effective target,
	remove -std=c++11 from c++ specific dg-options.
	* c-c++-common/raw-string-19.c: Likewise.
	* g++.dg/cpp26/raw-string1.C: New test.
	* g++.dg/cpp26/raw-string2.C: New test.
2024-07-25 21:36:31 +02:00
GCC Administrator 25256af1da Daily bump. 2024-07-25 00:19:51 +00:00
David Malcolm 148066bd05 diagnostics: SARIF output: potentially add escaped renderings of source (§3.3.4)
This patch adds support to our SARIF output for cases where
rich_loc.escape_on_output_p () is true, such as for -Wbidi-chars.

In such cases, the pertinent SARIF "location" object gains a property
bag with property "gcc/escapeNonAscii": true, and the "artifactContent"
within the location's physical location's snippet" gains a "rendered"
property (§3.3.4) that escapes non-ASCII text in the snippet, such as:

"rendered": {"text":

where "text" has a string value such as (for a "trojan source" attack):

  "9 |     /*<U+202E> } <U+2066>if (isAdmin)<U+2069> <U+2066> begin admins only */\n"
  "  |       ~~~~~~~~                                ~~~~~~~~                    ^\n"
  "  |       |                                       |                           |\n"
  "  |       |                                       |                           end of bidirectional context\n"
  "  |       U+202E (RIGHT-TO-LEFT OVERRIDE)         U+2066 (LEFT-TO-RIGHT ISOLATE)\n"

where the escaping is affected by -fdiagnostics-escape-format=; with
-fdiagnostics-escape-format=bytes, the rendered text of the above is:

  "9 |     /*<e2><80><ae> } <e2><81><a6>if (isAdmin)<e2><81><a9> <e2><81><a6> begin admins only */\n"
  "  |       ~~~~~~~~~~~~                                        ~~~~~~~~~~~~                    ^\n"
  "  |       |                                                   |                               |\n"
  "  |       U+202E (RIGHT-TO-LEFT OVERRIDE)                     U+2066 (LEFT-TO-RIGHT ISOLATE)  end of bidirectional context\n"

The patch also refactors/adds enough selftest machinery to be able to
test the snippet generation from within the selftest framework, rather
than just within DejaGnu (where the regex-based testing isn't
sophisticated enough to verify such properties as the above).

gcc/ChangeLog:
	* Makefile.in (OBJS-libcommon): Add selftest-json.o.
	* diagnostic-format-sarif.cc: Include "selftest.h",
	"selftest-diagnostic.h", "selftest-diagnostic-show-locus.h",
	"selftest-json.h", and "text-range-label.h".
	(class content_renderer): New.
	(sarif_builder::m_rules_arr): Convert to std::unique_ptr.
	(sarif_builder::make_location_object): Add class
	escape_nonascii_renderer.  If rich_loc.escape_on_output_p (),
	pass a nonnull escape_nonascii_renderer to
	maybe_make_physical_location_object as its snippet_renderer, and
	add a property bag property "gcc/escapeNonAscii" to the SARIF
	location object.  For other overloads of make_location_object,
	pass nullptr for the snippet_renderer.
	(sarif_builder::maybe_make_region_object_for_context): Add
	"snippet_renderer" param and pass it to
	maybe_make_artifact_content_object.
	(sarif_builder::make_tool_object): Drop "const".
	(sarif_builder::make_driver_tool_component_object): Likewise.
	Use typesafe unique_ptr variant of object::set for setting "rules"
	property on driver_obj.
	(sarif_builder::maybe_make_artifact_content_object): Add param "r"
	and use it to potentially set the "rendered" property (§3.3.4).
	(selftest::test_make_location_object): New.
	(selftest::diagnostic_format_sarif_cc_tests): New.
	* diagnostic-show-locus.cc: Include "text-range-label.h" and
	"selftest-diagnostic-show-locus.h".
	(selftests::diagnostic_show_locus_fixture::diagnostic_show_locus_fixture):
	New.
	(selftests::test_layout_x_offset_display_utf8): Use
	diagnostic_show_locus_fixture to simplify and consolidate setup
	code.
	(selftests::test_diagnostic_show_locus_one_liner): Likewise.
	(selftests::test_one_liner_colorized_utf8): Likewise.
	(selftests::test_diagnostic_show_locus_one_liner_utf8): Likewise.
	* gcc-rich-location.h (class text_range_label): Move to new file
	text-range-label.h.
	* selftest-diagnostic-show-locus.h: New file, based on material in
	diagnostic-show-locus.cc.
	* selftest-json.cc: New file.
	* selftest-json.h: New file.
	* selftest-run-tests.cc (selftest::run_tests): Call
	selftest::diagnostic_format_sarif_cc_tests.
	* selftest.h (selftest::diagnostic_format_sarif_cc_tests): New decl.

gcc/testsuite/ChangeLog:
	* c-c++-common/diagnostic-format-sarif-file-Wbidi-chars.c: Verify
	that we have a property bag with property "gcc/escapeNonAscii": true.
	Verify that we have a "rendered" property for a snippet.
	* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c: Include
	"text-range-label.h".

gcc/ChangeLog:
	* text-range-label.h: New file, taking class text_range_label from
	gcc-rich-location.h.

libcpp/ChangeLog:
	* include/rich-location.h
	(semi_embedded_vec::semi_embedded_vec): Add copy ctor.
	(rich_location::rich_location): Remove "= delete" from decl of
	copy ctor.  Add deleted decl of move ctor.
	(rich_location::operator=): Remove "= delete" from decl of
	copy assignment.  Add deleted decl of move assignment.
	(fixit_hint::fixit_hint): Add copy ctor decl.  Add deleted decl of
	move.
	(fixit_hint::operator=): Add copy assignment decl.  Add deleted
	decl of move assignment.
	* line-map.cc (rich_location::rich_location): New copy ctor.
	(fixit_hint::fixit_hint): New copy ctor.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-07-24 18:07:54 -04:00
GCC Administrator 944e4251b6 Daily bump. 2024-07-14 00:16:33 +00:00
David Malcolm 7d73c01ce6 diagnostics: add highlight-a vs highlight-b in colorization and pp_markup
Since r6-4582-g8a64515099e645 (which added class rich_location), ranges
of quoted source code have been colorized using the following rules:
- the primary range used the same color of the kind of the diagnostic
i.e. "error" vs "warning" etc (defaulting to bold red and bold magenta
respectively)
- secondary ranges alternate between "range1" and "range2" (defaulting
to green and blue respectively)

This works for cases with large numbers of highlighted ranges, but is
suboptimal for common cases.

The following patch adds a pair of color names: "highlight-a" and
"highlight-b", and uses them whenever it makes sense to highlight and
contrast two different things in the source code (e.g. a type mismatch).
These are used by diagnostic-show-locus.cc for highlighting quoted
source.  In addition the patch adds colorization to fragments within the
corresponding diagnostic messages themselves, using consistent
colorization between the message and the quoted source code for the two
different things being contrasted.

For example, consider:

demo.c: In function ‘test_bad_format_string_args’:
../../src/demo.c:25:18: warning: format ‘%i’ expects argument of
  type ‘int’, but argument 2 has type ‘const char *’ [-Wformat=]
   25 |   printf("hello %i", msg);
      |                 ~^   ~~~
      |                  |   |
      |                  int const char *
      |                 %s

Previously, the types within the message in quotes would be in bold but
not colorized, and the labelled ranges of quoted source code would use
bold magenta for the "int" and non-bold green for the "const char *".

With this patch:
- the "%i" and "int" in the message and the "int" in the quoted source
  are all colored bold green
- the "const char *" in the message and in the quoted source are both
  colored bold blue
so that the consistent use of contrasting color draws the reader's eyes
to the relationships between the diagnostic message and the source.

I've tried this with gnome-terminal with many themes, including a
variety of light versus dark backgrounds, solarized versus non-solarized
themes, etc, and it was readable in all.

My initial version of the patch used the existing %r and %R facilities
within pretty-print.cc for the messages, but this turned out to be very
uncomfortable, leading to error-prone format strings such as:

  error_at (richloc,
            "invalid operands to binary %s (have %<%r%T%R%> and %<%r%T%R%>)",
            opname,
            "highlight-a", type0,
            "highlight-b", type1);

To avoid requiring monstrosities such as the above, the patch adds a new
"%e" format code to pretty-print.cc, which expects a pp_element *, where
pp_element is a new abstract base class (actually a pp_markup::element),
along with various useful subclasses.  This lets the above be written
as:

  pp_markup::element_quoted_type element_0 (type0, highlight_colors::lhs);
  pp_markup::element_quoted_type element_1 (type1, highlight_colors::rhs);
  error_at (richloc,
            "invalid operands to binary %s (have %e and %e)",
            opname, &element_0, &element_1);

which I feel is maintainable and clear to translators; the use of %e and
pp_element * captures the type-unsafe part of the variadic call, and the
subclasses allow for type-safety (so e.g. an element_quoted_type expects
a type and a highlighting color).  This approach allows for some nice
simplifications within c-format.cc.

The patch also extends -Wformat to "teach" it about the new %e and
pp_element *.  Doing so requires c-format.cc to be able to determine
if a T * is a pp_element * (i.e. if T is a subclass).  To do so I added
a new comp_types callback for comparing types, where the C++ frontend
supplies a suitable implementation (and %e will always be wrong for C).

I've manually tested this on many diagnostics with both C and C++ and it
seems a subtle but significant improvement in readability.

I've added a new option -fno-diagnostics-show-highlight-colors in case
people prefer the old behavior.

gcc/c-family/ChangeLog:
	* c-common.cc: Include "tree-pretty-print-markup.h".
	(binary_op_error): Use pp_markup::element_quoted_type and %e.
	(check_function_arguments): Add "comp_types" param and pass it to
	check_function_format.
	* c-common.h (check_function_arguments): Add "comp_types" param.
	(check_function_format): Likewise.
	* c-format.cc: Include "tree-pretty-print-markup.h".
	(local_pp_element_ptr_node): New.
	(PP_FORMAT_CHAR_TABLE): Add entry for %e.
	(struct format_check_context): Add "m_comp_types" field.
	(check_function_format): Add "comp_types" param and pass it to
	check_format_info.
	(check_format_info): Likewise, passing it to format_ctx's ctor.
	(check_format_arg): Extract m_comp_types from format_ctx and
	pass it to check_format_info_main.
	(check_format_info_main): Add "comp_types" param and pass it to
	arg_parser's ctor.
	(class argument_parser): Add "m_comp_types" field.
	(argument_parser::check_argument_type): Pass m_comp_types to
	check_format_types.
	(handle_subclass_of_pp_element_p): New.
	(check_format_types): Add "comp_types" param, and use it to
	call handle_subclass_of_pp_element_p.
	(class element_format_substring): New.
	(class element_expected_type_with_indirection): New.
	(format_type_warning): Use element_expected_type_with_indirection
	to unify the if (wanted_type_name) branches, reducing from four
	emit_warning calls to two.  Simplify these further using %e.
	Doing so also gives suitable colorization of the text within the
	diagnostics.
	(init_dynamic_diag_info): Initialize local_pp_element_ptr_node.
	(selftest::test_type_mismatch_range_labels): Add nullptr for new
	param of gcc_rich_location label overload.
	* c-format.h (T_PP_ELEMENT_PTR): New.
	* c-type-mismatch.cc: Include "diagnostic-highlight-colors.h".
	(binary_op_rich_location::binary_op_rich_location): Use
	highlight_colors::lhs and highlight_colors::rhs for the ranges.
	* c-type-mismatch.h (class binary_op_rich_location): Add comment
	about highlight_colors.

gcc/c/ChangeLog:
	* c-objc-common.cc: Include "tree-pretty-print-markup.h".
	(print_type): Add optional "highlight_color" param and use it
	to show highlight colors in "aka" text.
	(pp_markup::element_quoted_type::print_type): New.
	* c-typeck.cc: Include "tree-pretty-print-markup.h".
	(comp_parm_types): New.
	(build_function_call_vec): Pass it to check_function_arguments.
	(inform_for_arg): Use %e and highlight colors to contrast actual
	versus expected.
	(convert_for_assignment): Use highlight_colors::actual for the
	rhs_label.
	(build_binary_op): Use highlight_colors::lhs and highlight_colors::rhs
	for the ranges.

gcc/ChangeLog:
	* common.opt (fdiagnostics-show-highlight-colors): New option.
	* common.opt.urls: Regenerate.
	* coretypes.h (pp_markup::element): New forward decl.
	(pp_element): New typedef.
	* diagnostic-color.cc (gcc_color_defaults): Add "highlight-a"
	and "highlight-b".
	* diagnostic-format-json.cc (diagnostic_output_format_init_json):
	Disable highlight colors.
	* diagnostic-format-sarif.cc (diagnostic_output_format_init_sarif):
	Likewise.
	* diagnostic-highlight-colors.h: New file.
	* diagnostic-path.cc (struct event_range): Pass nullptr for
	highlight color of m_rich_loc.
	* diagnostic-show-locus.cc (colorizer::set_range): Handle ranges
	with m_highlight_color.
	(colorizer::STATE_NAMED_COLOR): New.
	(colorizer::m_richloc): New field.
	(colorizer::colorizer): Add richloc param for initializing
	m_richloc.
	(colorizer::set_named_color): New.
	(colorizer::begin_state): Add case STATE_NAMED_COLOR.
	(layout::layout): Pass richloc to m_colorizer's ctor.
	(selftest::test_one_liner_labels): Pass nullptr for new param of
	gcc_rich_location ctor for labels.
	(selftest::test_one_liner_labels_utf8): Likewise.
	* diagnostic.h (diagnostic_context::set_show_highlight_colors):
	New.
	* doc/invoke.texi: Add option -fdiagnostics-show-highlight-colors
	and highlight-a and highlight-b color caps.
	* doc/ux.texi
	(Use color consistently when highlighting mismatches): New
	subsection.
	* gcc-rich-location.cc (gcc_rich_location::add_expr): Add
	"highlight_color" param.
	(gcc_rich_location::maybe_add_expr): Likewise.
	* gcc-rich-location.h (gcc_rich_location::gcc_rich_location):
	Split out into a pair of ctors, where if a range_label is supplied
	the caller must also supply a highlight color.
	(gcc_rich_location::add_expr): Add "highlight_color" param.
	(gcc_rich_location::maybe_add_expr): Likewise.
	* gcc.cc (driver_handle_option): Handle
	OPT_fdiagnostics_show_highlight_colors.
	* lto-wrapper.cc (merge_and_complain): Likewise.
	(append_compiler_options): Likewise.
	(append_diag_options): Likewise.
	(run_gcc): Likewise.
	* opts-common.cc (decode_cmdline_options_to_array): Add comment
	about -fno-diagnostics-show-highlight-colors.
	* opts-global.cc (init_options_once): Preserve
	pp_show_highlight_colors in case the global_dc's printer is
	recreated.
	* opts.cc (common_handle_option): Handle
	OPT_fdiagnostics_show_highlight_colors.
	(gen_command_line_string): Likewise.
	* pretty-print-markup.h: New file.
	* pretty-print.cc: Include "pretty-print-markup.h" and
	"diagnostic-highlight-colors.h".
	(pretty_printer::format): Handle %e.
	(pretty_printer::pretty_printer): Handle new field
	m_show_highlight_colors.
	(pp_string_n): New.
	(pp_markup::context::begin_quote): New.
	(pp_markup::context::end_quote): New.
	(pp_markup::context::begin_color): New.
	(pp_markup::context::end_color): New.
	(highlight_colors::expected): New.
	(highlight_colors::actual): New.
	(highlight_colors::lhs): New.
	(highlight_colors::rhs): New.
	(class selftest::test_element): New.
	(selftest::test_pp_format): Add tests of %e.
	(selftest::test_urlification): Likewise.
	* pretty-print.h (pp_markup::context): New forward decl.
	(class chunk_info): Add friend class pp_markup::context.
	(class pretty_printer): Add friend pp_show_highlight_colors.
	(pretty_printer::m_show_highlight_colors): New field.
	(pp_show_highlight_colors): New inline function.
	(pp_string_n): New decl.
	* substring-locations.cc: Include "diagnostic-highlight-colors.h".
	(format_string_diagnostic_t::highlight_color_format_string): New.
	(format_string_diagnostic_t::highlight_color_param): New.
	(format_string_diagnostic_t::emit_warning_n_va): Use highlight
	colors.
	* substring-locations.h
	(format_string_diagnostic_t::highlight_color_format_string): New.
	(format_string_diagnostic_t::highlight_color_param): New.
	* toplev.cc (general_init): Initialize global_dc's
	show_highlight_colors.
	* tree-pretty-print-markup.h: New file.

gcc/cp/ChangeLog:
	* call.cc: Include "tree-pretty-print-markup.h".
	(implicit_conversion_error): Use highlight_colors::percent_h for
	the labelled range.
	(op_error_string): Split out into...
	(concat_op_error_string): ...this.
	(binop_error_string): New.
	(op_error): Use %e, binop_error_string, highlight_colors::lhs,
	and highlight_colors::rhs.
	(maybe_inform_about_fndecl_for_bogus_argument_init): Add
	"highlight_color" param; use it for the richloc.
	(convert_like_internal): Use highlight_colors::percent_h for the
	labelled_range, and highlight_colors::percent_i for the call to
	maybe_inform_about_fndecl_for_bogus_argument_init.
	(build_over_call): Pass cp_comp_parm_types for new "comp_types"
	param of check_function_arguments.
	(complain_about_bad_argument): Use highlight_colors::percent_h for
	the labelled_range, and highlight_colors::percent_i for the call
	to maybe_inform_about_fndecl_for_bogus_argument_init.
	* cp-tree.h (maybe_inform_about_fndecl_for_bogus_argument_init):
	Add optional highlight_color param.
	(cp_comp_parm_types): New decl.
	(highlight_colors::const percent_h): New decl.
	(highlight_colors::const percent_i): New decl.
	* error.cc: Include "tree-pretty-print-markup.h".
	(highlight_colors::const percent_h): New defn.
	(highlight_colors::const percent_i): New defn.
	(type_to_string): Add param "highlight_color" and use it.
	(print_nonequal_arg): Likewise.
	(print_template_differences): Add params "highlight_color_a" and
	"highlight_color_b".
	(type_to_string_with_compare): Add params "this_highlight_color"
	and "peer_highlight_color".
	(print_template_tree_comparison): Add params "highlight_color_a"
	and "highlight_color_b".
	(cxx_format_postprocessor::handle):
	Use highlight_colors::percent_h and highlight_colors::percent_i.
	(pp_markup::element_quoted_type::print_type): New.
	(range_label_for_type_mismatch::get_text): Pass nullptr for new
	params of type_to_string_with_compare.
	* typeck.cc (cp_comp_parm_types): New.
	(cp_build_function_call_vec): Pass it to check_function_arguments.
	(convert_for_assignment): Use highlight_colors::percent_h for the
	labelled_range.

gcc/testsuite/ChangeLog:
	* g++.dg/diagnostic/bad-binary-ops-highlight-colors.C: New test.
	* g++.dg/diagnostic/bad-binary-ops-no-highlight-colors.C: New test.
	* g++.dg/plugin/plugin.exp (plugin_test_list): Add
	show-template-tree-color-no-highlight-colors.C to
	show_template_tree_color_plugin.c.
	* g++.dg/plugin/show-template-tree-color-labels.C: Update expected
	output to reflect use of highlight-a and highlight-b to contrast
	mismatches.
	* g++.dg/plugin/show-template-tree-color-no-elide-type.C:
	Likewise.
	* g++.dg/plugin/show-template-tree-color-no-highlight-colors.C:
	New test.
	* g++.dg/plugin/show-template-tree-color.C: Update expected output
	to reflect use of highlight-a and highlight-b to contrast
	mismatches.
	* g++.dg/warn/Wformat-gcc_diag-1.C: New test.
	* g++.dg/warn/Wformat-gcc_diag-2.C: New test.
	* g++.dg/warn/Wformat-gcc_diag-3.C: New test.
	* gcc.dg/bad-binary-ops-highlight-colors.c: New test.
	* gcc.dg/format/colors.c: New test.
	* gcc.dg/plugin/diagnostic_plugin_show_trees.c (show_tree): Pass
	nullptr for new param of gcc_rich_location::add_expr.

libcpp/ChangeLog:
	* include/rich-location.h (location_range::m_highlight_color): New
	field.
	(rich_location::rich_location): Add optional label_highlight_color
	param.
	(rich_location::set_highlight_color): New decl.
	(rich_location::add_range): Add optional label_highlight_color
	param.
	(rich_location::set_range): Likewise.
	* line-map.cc (rich_location::rich_location): Add
	"label_highlight_color" param and pass it to add_range.
	(rich_location::set_highlight_color): New.
	(rich_location::add_range): Add "label_highlight_color" param.
	(rich_location::set_range): Add "highlight_color" param.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-07-13 10:34:51 -04:00
GCC Administrator 69fdcd0c57 Daily bump. 2024-06-22 00:18:44 +00:00
David Malcolm 9f4fdc3ace diagnostics: fixes to SARIF output [PR109360]
When adding validation of .sarif files against the schema
(PR testsuite/109360) I discovered various issues where we were
generating invalid .sarif files.

Specifically, in
  c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c
the relatedLocations for the "note" diagnostics were missing column
numbers, leading to validation failure due to non-unique elements,
such as multiple:
	"message": {"text": "invalid UTF-8 character <bf>"}},
on line 25 with no column information.

Root cause is that for some diagnostics in libcpp we have a location_t
representing the line as a whole, setting a column_override on the
rich_location (since the line hasn't been fully read yet).  We were
handling this column override for plain text output, but not for .sarif
output.

Similarly, in diagnostic-format-sarif-file-pr111700.c there is a warning
emitted on "line 0" of the file, whereas SARIF requires line numbers to
be positive.

We also use column == 0 internally to mean "the line as a whole",
whereas SARIF required column numbers to be positive.

This patch fixes these various issues.

gcc/ChangeLog:
	PR testsuite/109360
	* diagnostic-format-sarif.cc
	(sarif_builder::make_location_object): Pass any column override
	from rich_loc to maybe_make_physical_location_object.
	(sarif_builder::maybe_make_physical_location_object): Add
	"column_override" param and pass it to maybe_make_region_object.
	(sarif_builder::maybe_make_region_object): Add "column_override"
	param and use it when the location has 0 for a column.  Don't
	add "startLine", "startColumn", "endLine", or "endColumn" if
	the values aren't positive.
	(sarif_builder::maybe_make_region_object_for_context): Don't
	add "startLine" or "endLine" if the values aren't positive.

libcpp/ChangeLog:
	PR testsuite/109360
	* include/rich-location.h (rich_location::get_column_override):
	New accessor.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-06-21 08:46:13 -04:00
GCC Administrator 7fa4b335b1 Daily bump. 2024-06-12 00:18:21 +00:00
Joseph Myers 0cf68222d2 c: Add -std=c2y, -std=gnu2y, -Wc23-c2y-compat, C2Y _Generic with type operand
The first new C2Y feature, _Generic where the controlling operand is a
type name rather than an expression (as defined in N3260), was voted
into C2Y today.  (In particular, this form of _Generic allows
distinguishing qualified and unqualified versions of a type.)  This
feature also includes allowing the generic associations to specify
incomplete and function types.

Add this feature to GCC, along with the -std=c2y, -std=gnu2y and
-Wc23-c2y-compat options to control when and how it is diagnosed.  As
usual, the feature is allowed by default in older standards modes,
subject to diagnosis with -pedantic, -pedantic-errors or
-Wc23-c2y-compat.

Bootstrapped with no regressions on x86_64-pc-linux-gnu.

gcc/
	* doc/cpp.texi (__STDC_VERSION__): Document C2Y handling.
	* doc/invoke.texi (-Wc23-c2y-compat, -std=c2y, -std=gnu2y):
	Document options.
	(-std=gnu23): Update documentation.
	* doc/standards.texi (C Language): Document C2Y.  Update C23
	description.
	* config/rl78/rl78.cc (rl78_option_override): Handle "GNU C2Y"
	language name.
	* dwarf2out.cc (highest_c_language, gen_compile_unit_die):
	Likewise.

gcc/c-family/
	* c-common.cc (flag_isoc2y): New.
	(flag_isoc99, flag_isoc11, flag_isoc23): Update comments.
	* c-common.h (flag_isoc2y): New.
	(clk_c, flag_isoc23): Update comments.
	* c-opts.cc (set_std_c2y): New.
	(c_common_handle_option): Handle OPT_std_c2y and OPT_std_gnu2y.
	(set_std_c89, set_std_c99, set_std_c11, set_std_c17, set_std_c23):
	Set flag_isoc2y.
	(set_std_c23): Update comment.
	* c.opt (Wc23-c2y-compat, std=c2y, std=gnu2y): New.
	* c.opt.urls: Regenerate.

gcc/c/
	* c-errors.cc (pedwarn_c23): New.
	* c-parser.cc (disable_extension_diagnostics)
	(restore_extension_diagnostics): Save and restore
	warn_c23_c2y_compat.
	(c_parser_generic_selection): Handle type name as controlling
	operand.  Allow incomplete and function types subject to
	pedwarn_c23 calls.
	* c-tree.h (pedwarn_c23): New.

gcc/testsuite/
	* gcc.dg/c23-generic-1.c, gcc.dg/c23-generic-2.c,
	gcc.dg/c23-generic-3.c, gcc.dg/c23-generic-4.c,
	gcc.dg/c2y-generic-1.c, gcc.dg/c2y-generic-2.c,
	gcc.dg/c2y-generic-3.c, gcc.dg/gnu2y-generic-1.c: New tests.
	* gcc.dg/c23-tag-6.c: Use -pedantic-errors.

libcpp/
	* include/cpplib.h (CLK_GNUC2Y, CLK_STDC2Y): New.
	* init.cc (lang_defaults): Add GNUC2Y and STDC2Y entries.
	(cpp_init_builtins): Define __STDC_VERSION__ to 202500L for GNUC2Y
	and STDC2Y.
2024-06-11 23:00:04 +00:00
GCC Administrator 6e5f77fdc7 Daily bump. 2024-06-08 00:18:05 +00:00
Jason Merrill a29f481bbc c++: -include and header unit translation
Within a source file, #include is translated to import if a suitable header
 unit is available, but this wasn't working with -include.  This turned out
 to be because we suppressed the translation before the beginning of the
 main file.  After removing that, I had to tweak libcpp file handling to
 accommodate the way it moves from an -include to the main file.

gcc/ChangeLog:

	* doc/invoke.texi (C++ Modules): Mention -include.

gcc/cp/ChangeLog:

	* module.cc (maybe_translate_include): Allow before the main file.

libcpp/ChangeLog:

	* files.cc (_cpp_stack_file): LC_ENTER for -include header unit.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/dashinclude-1_b.C: New test.
	* g++.dg/modules/dashinclude-1_a.H: New test.
2024-06-07 14:29:46 -04:00
GCC Administrator d815d9ad89 Daily bump. 2024-05-30 00:16:44 +00:00
Jason Merrill ff41abdca0 c++: add module extensions
There is a trend in the broader C++ community to use a different extension
for module interface units, even though (in GCC) they are compiled in the
same way as other source files.  Let's recognize these extensions as C++.

.ixx is the MSVC standard, while the .c*m are supported by Clang.  libc++
standard headers use .cppm, as their other source files use .cpp.
Perhaps libstdc++ might use .ccm for parallel consistency?

One issue with .c++m is that libcpp/mkdeps.cc has been using it for the
phony dependencies to express module dependencies, so I'm changing mkdeps to
something less likely to be an actual file, ".c++-module".

gcc/cp/ChangeLog:

	* lang-specs.h: Add module interface extensions.

gcc/ChangeLog:

	* doc/invoke.texi: Update module extension docs.

libcpp/ChangeLog:

	* mkdeps.cc (make_write): Change .c++m to .c++-module.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/dep-1_a.C
	* g++.dg/modules/dep-1_b.C
	* g++.dg/modules/dep-2.C: Change .c++m to .c++-module.
2024-05-29 09:48:05 -04:00
GCC Administrator 2b84169724 Daily bump. 2024-05-29 00:17:16 +00:00
David Malcolm 9bda2c4c81 libcpp: move label_text to its own header
No functional change intended.

libcpp/ChangeLog:
	* Makefile.in (TAGS_SOURCES): Add include/label-text.h.
	* include/label-text.h: New file.
	* include/rich-location.h: Include "label-text.h".
	(class label_text): Move to label-text.h.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-05-28 15:55:24 -04:00
GCC Administrator 56d0d0dfa9 Daily bump. 2024-05-27 00:16:35 +00:00
Peter Damianov 87463737b9 [PATCH] libcpp: Correct typo 'r' -> '\r'
libcpp/ChangeLog:
	* lex.cc (do_peek_prev): Correct typo in argument to __builtin_expect()

Signed-off-by: Peter Damianov <peter0x44@disroot.org>
2024-05-26 08:06:14 -06:00
GCC Administrator 8713d5eec2 Daily bump. 2024-05-19 18:15:28 +00:00
David Malcolm 770657d02c diagnostics, analyzer: add CFG edge visualization to path-printing
This patch adds some ability for links between labelled ranges when
quoting the user's source code, and uses this to add links between
events when printing diagnostic_paths, chopping them up further into
event ranges that can be printed together.
It adds links to the various "from..." - "...to" events in the
analyzer.

For example, previously we emitted this for
c-c++-common/analyzer/infinite-loop-linked-list.c's
while_loop_missing_next':

infinite-loop-linked-list.c:30:10: warning: infinite loop [CWE-835] [-Wanalyzer-infinite-loop]
   30 |   while (n)
      |          ^
  'while_loop_missing_next': events 1-5
   30 |   while (n)
      |          ^
      |          |
      |          (1) infinite loop here
      |          (2) when 'n' is non-NULL: always following 'true' branch...
      |          (5) ...to here
   31 |     {
   32 |       sum += n->val;
      |       ~~~~~~~~~~~~~
      |           |   |
      |           |   (3) ...to here
      |           (4) looping back...

whereas with the patch we now emit:

infinite-loop-linked-list.c:30:10: warning: infinite loop [CWE-835] [-Wanalyzer-infinite-loop]
   30 |   while (n)
      |          ^
  'while_loop_missing_next': events 1-3
   30 |   while (n)
      |          ^
      |          |
      |          (1) infinite loop here
      |          (2) when 'n' is non-NULL: always following 'true' branch... ->-+
      |                                                                         |
      |                                                                         |
      |+------------------------------------------------------------------------+
   31 ||    {
   32 ||      sum += n->val;
      ||             ~~~~~~
      ||              |
      |+------------->(3) ...to here
  'while_loop_missing_next': event 4
   32 |       sum += n->val;
      |       ~~~~^~~~~~~~~
      |           |
      |           (4) looping back... ->-+
      |                                  |
  'while_loop_missing_next': event 5
      |                                  |
      |+---------------------------------+
   30 ||  while (n)
      ||         ^
      ||         |
      |+-------->(5) ...to here

which I believe is easier to understand.

The patch also implements the use of unicode characters and colorization
for the lines (not shown in the above example).

There is a new option -fno-diagnostics-show-event-links for getting
back the old behavior (added to -fdiagnostics-plain-output).

gcc/analyzer/ChangeLog:
	* checker-event.h (checker_event::connect_to_next_event_p):
	Implement new diagnostic_event::connect_to_next_event_p vfunc.
	(start_cfg_edge_event::connect_to_next_event_p): Likewise.
	(start_consolidated_cfg_edges_event::connect_to_next_event_p):
	Likewise.
	* infinite-loop.cc (class looping_back_event): New subclass.
	(infinite_loop_diagnostic::add_final_event): Use it.

gcc/ChangeLog:
	* common.opt (fdiagnostics-show-event-links): New option.
	* diagnostic-label-effects.h: New file.
	* diagnostic-path.h (diagnostic_event::connect_to_next_event_p):
	New pure virtual function.
	(simple_diagnostic_event::connect_to_next_event_p): Implement it.
	(simple_diagnostic_event::connect_to_next_event): New.
	(simple_diagnostic_event::m_connected_to_next_event): New field.
	(simple_diagnostic_path::connect_to_next_event): New decl.
	* diagnostic-show-locus.cc: Include "text-art/theme.h" and
	"diagnostic-label-effects.h".
	(colorizer::set_cfg_edge): New.
	(layout::m_fallback_theme): New field.
	(layout::m_theme): New field.
	(layout::m_effect_info): New field.
	(layout::m_link_lhs_state): New enum and field.
	(layout::m_link_rhs_column): New field.
	(layout_range::has_in_edge): New.
	(layout_range::has_out_edge): New.
	(layout::layout): Add "effect_info" optional param.  Initialize
	m_theme, m_link_lhs_state, and m_link_rhs_column.
	(layout::maybe_add_location_range): Remove stray "FIXME" from
	leading comment.
	(layout::print_source_line): Replace space after margin with a
	call to print_leftmost_column.
	(layout::print_leftmost_column): New.
	(layout::start_annotation_line): Make non-const.  Gain
	responsibility for printing the leftmost column after the margin.
	(layout::print_annotation_line): Drop pp_space, as this is now
	added by start_annotation_line.
	(line_label::line_label): Add "has_in_edge" and "has_out_edge"
	params and initialize...
	(line_label::m_has_in_edge): New field.
	(line_label::m_has_out_edge): New field.
	(layout::print_any_labels): Pass edge information to line_label
	ctor.  Keep track of in-edges and out-edges, adding visualizations
	of these links between labels.
	(layout::print_leading_fixits):  Drop pp_character, as this is now
	added by start_annotation_line.
	(layout::print_trailing_fixits): Fix off-by-one errors in column
	calculation.
	(layout::move_to_column): Add comment about debugging.
	(layout::show_ruler): Make non-const.  Drop pp_space calls, as
	this is now added by start_annotation_line.
	(layout::print_line): Call print_any_right_to_left_edge_lines.
	(layout::print_any_right_to_left_edge_lines): New.
	(layout::update_any_effects): New.
	(gcc_rich_location::add_location_if_nearby): Initialize
	loc_range.m_label.
	(diagnostic_context::maybe_show_locus): Add "effects" param and
	pass it to diagnostic_context::show_locus.
	(diagnostic_context::show_locus): Add "effects" param, passing it
	to layout's ctor.  Call update_any_effects on the layout after
	printing the lines.
	(selftest::test_layout_x_offset_display_utf8): Update expected
	result for eliminated trailing newline.
	(selftest::test_layout_x_offset_display_utf8): Likewise.
	(selftest::test_layout_x_offset_display_tab): Likewise.
	* diagnostic.cc (diagnostic_context::initialize): Initialize
	m_source_printing.show_event_links_p.
	(simple_diagnostic_path::connect_to_next_event): New.
	(simple_diagnostic_event::simple_diagnostic_event): Initialize
	m_connected_to_next_event.
	* diagnostic.h (class diagnostic_source_effect_info): New forward
	decl.
	(diagnostic_source_printing_options::show_event_links_p): New
	field.
	(diagnostic_context::maybe_show_locus): Add optional "effect_info"
	param.
	(diagnostic_context::show_locus): Add "effect_info" param.
	(diagnostic_show_locus): Add optional "effect_info" param.
	* doc/invoke.texi: Add -fno-diagnostics-show-event-links.
	* lto-wrapper.cc (merge_and_complain): Add
	OPT_fdiagnostics_show_event_links to switch.
	(append_compiler_options): Likewise.
	(append_diag_options): Likewise.
	* opts-common.cc (decode_cmdline_options_to_array): Add
	"-fno-diagnostics-show-event-links" to -fdiagnostics-plain-output.
	* opts.cc (common_handle_option): Add case for
	OPT_fdiagnostics_show_event_links.
	* text-art/theme.cc (ascii_theme::get_cppchar): Handle
	cell_kind::CFG_*.
	(unicode_theme::get_cppchar): Likewise.
	* text-art/theme.h (theme::cell_kind): Add CFG_*.
	* toplev.cc (general_init): Initialize
	global_dc->m_source_printing.show_event_links_p.
	* tree-diagnostic-path.cc: Define INCLUDE_ALGORITHM,
	INCLUDE_MEMORY, and INCLUDE_STRING.  Include
	"diagnostic-label-effects.h".
	(path_label::path_label): Initialize m_effects.
	(path_label::get_effects): New.
	(class path_label::path_label_effects): New.
	(path_label::m_effects): New field.
	(class per_thread_summary): Add "friend struct event_range;".
	(per_thread_summary::per_thread_summary): Initialize m_last_event.
	(per_thread_summary::m_last_event): New field.
	(struct event_range::per_source_line_info): New.
	(event_range::event_range): Make "t" non-const.  Add
	"show_event_links" param and use it to initialize
	m_show_event_links.  Add info for initial event.
	(event_range::get_per_source_line_info): New.
	(event_range::maybe_add_event): Verify compatibility of the new
	label and existing labels with respect to the link-printing code.
	Update per-source-line info when an event is added.
	(event_range::print): Add"effect_info" param and pass to
	diagnostic_show_locus.
	(event_range::m_per_thread_summary): Make non-const.
	(event_range::m_source_line_info_map): New field.
	(event_range::m_show_event_links): New field.
	(path_summary::path_summary): Add "show_event_links" optional
	param, passing it to event_range ctor calls. Update
	pts.m_last_event.
	(thread_event_printer::print_swimlane_for_event_range): Add
	"effect_info" param and pass it to range->print.
	(print_path_summary_as_text): Keep track of the column for any
	out-edges at the end of printing each event_range and use as
	the leading in-edge for the next event_range.
	(default_tree_diagnostic_path_printer): Pass in show_event_links_p
	to path_summary ctor.
	(selftest::path_events_have_column_data_p): New.
	(class selftest::control_flow_test): New.
	(selftest::test_control_flow_1): New.
	(selftest::test_control_flow_2): New.
	(selftest::test_control_flow_3): New.
	(selftest::assert_cfg_edge_path_streq): New.
	(ASSERT_CFG_EDGE_PATH_STREQ): New macro.
	(selftest::test_control_flow_4): New.
	(selftest::test_control_flow_5): New.
	(selftest::test_control_flow_6): New.
	(selftest::control_flow_tests): New.
	(selftest::tree_diagnostic_path_cc_tests): Disable colorization on
	global_dc's printer.  Convert event_pp to a std::unique_ptr. Call
	control_flow_tests via for_each_line_table_case.
	(gen_command_line_string): Likewise.

gcc/testsuite/ChangeLog:
	* gcc.dg/analyzer/event-links-ascii.c: New test.
	* gcc.dg/analyzer/event-links-color.c: New test.
	* gcc.dg/analyzer/event-links-disabled.c: New test.
	* gcc.dg/analyzer/event-links-unicode.c: New test.

libcpp/ChangeLog:
	* include/rich-location.h (class label_effects): New forward decl.
	(range_label::get_effects): New vfunc.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2024-05-17 14:51:47 -04:00
GCC Administrator 610415bb7d Daily bump. 2024-05-01 00:17:56 +00:00
Jakub Jelinek a2452a6891 libcpp: Adjust __STDC_VERSION__ for C23
While the C23 standard isn't officially release yet,
in 2011 we've changed __STDC_VERSION__ value for C11 already
in the month in which the new __STDC_VERSION__ value has been
finalized, so we want to change this now or wait
until we implement all the C23 features?

Note, seems Clang up to 17 also used 202000L for -std=c2x but
Clang 18+ uses 202311L as specified in the latest C23 drafts.

2024-04-30  Jakub Jelinek  <jakub@redhat.com>

	* init.cc (cpp_init_builtins): Change __STDC_VERSION__
	for C23 from 202000L to 202311L.

	* doc/cpp.texi (__STDC_VERSION__): Document 202311L value
	for -std=c23/-std=gnu23.
2024-04-30 08:58:39 +02:00
GCC Administrator 69576bc01c Daily bump. 2024-04-18 00:17:43 +00:00
Christophe Lyon a9fefbf717 libcpp: Regenerate aclocal.m4 and configure [PR 114748]
As discussed in the PR, aclocal.m4 and configure were incorrectly
regenerated at some point.

2024-04-17  Christophe Lyon  <christophe.lyon@linaro.org>

	PR preprocessor/114748
	libcpp/
	* aclocal.m4: Regenerate.
	* configure: Regenerate.
2024-04-17 14:08:34 +00:00
GCC Administrator c1f6690b82 Daily bump. 2024-03-15 00:17:52 +00:00
Lewis Hyatt 942497ad74 libcpp: Fix macro expansion for argument of __has_include [PR110558]
When the file name for a #include directive is the result of stringifying a
macro argument, libcpp needs to take some care to get the whitespace
correct; in particular stringify_arg() needs to see a CPP_PADDING token
between macro tokens so that it can figure out when to output space between
tokens. The CPP_PADDING tokens are not normally generated when handling a
preprocessor directive, but for #include-like directives, libcpp sets the
state variable pfile->state.directive_wants_padding to TRUE so that the
CPP_PADDING tokens will be output, and then everything works fine for
computed includes.

As the PR points out, things do not work fine for __has_include. Fix that by
setting the state variable the same as is done for #include.

libcpp/ChangeLog:

	PR preprocessor/110558
	* macro.cc (builtin_has_include): Set
	pfile->state.directive_wants_padding prior to lexing the
	file name, in case it comes from macro expansion.

gcc/testsuite/ChangeLog:

	PR preprocessor/110558
	* c-c++-common/cpp/has-include-2.c: New test.
	* c-c++-common/cpp/has-include-2.h: New test.
2024-03-14 07:33:02 -04:00
Lewis Hyatt 6c166e55b1 libcpp: Fix __has_include_next ICE in the last directory of the path [PR80755]
In libcpp/files.cc, the function _cpp_has_header(), which implements
__has_include and __has_include_next, does not check for a NULL return value
from search_path_head(), leading to an ICE tripping an assert when
_cpp_find_file() tries to use it. Fix it by checking for that case and
silently returning false instead.

As suggested by the PR author, it is easiest to make a testcase by using
the -idirafter option. To enable that, also modify the dg-additional-options
testsuite procedure to make the global $srcdir available, since -idirafter
requires the full path.

libcpp/ChangeLog:

	PR preprocessor/80755
	* files.cc (search_path_head): Add SUPPRESS_DIAGNOSTIC argument
	defaulting to false.
	(_cpp_has_header): Silently return false if the search path has been
	exhausted, rather than issuing a diagnostic and then hitting an
	assert.

gcc/testsuite/ChangeLog:

	* lib/gcc-defs.exp (dg-additional-options): Make $srcdir usable in a
	dg-additional-options directive.
	* c-c++-common/cpp/has-include-next-2-dir/has-include-next-2.h: New test.
	* c-c++-common/cpp/has-include-next-2.c: New test.
2024-03-14 07:33:02 -04:00
GCC Administrator 77de8b722d Daily bump. 2024-02-23 00:16:46 +00:00
Jakub Jelinek 37127ed975 c: Handle scoped attributes in __has*attribute and scoped attribute parsing changes in -std=c11 etc. modes [PR114007]
We aren't able to parse __has_attribute (vendor::attr) (and __has_c_attribute
and __has_cpp_attribute) in strict C < C23 modes.  While in -std=gnu* modes
or in -std=c23 there is CPP_SCOPE token, in -std=c* (except for -std=c23)
there are is just a pair of CPP_COLON tokens.
The c-lex.cc hunk adds support for that.

That leads to a question if we should return 1 or 0 from
__has_attribute (gnu::unused) or not, because while
[[gnu::unused]] is parsed fine in -std=gnu*/-std=c23 modes (sure, with
pedwarn for < C23), we do not parse it at all in -std=c* (except for
-std=c23), we only parse [[__extension__ gnu::unused]] there.  While
the __extension__ in there helps to avoid the pedwarn, I think it is
better to be consistent between GNU and strict C < C23 modes and
parse [[gnu::unused]] too; on the other side, I think parsing
[[__extension__ gnu : : unused]] is too weird and undesirable.

So, the following patch adds a flag during preprocessing at the point
where we normally create CPP_SCOPE tokens out of 2 consecutive colons
on the first CPP_COLON to mark the consecutive case (as we are tight
on the bits, I've reused the PURE_ZERO flag, which is used just by the
C++ FE and only ever set (both C and C++) on CPP_NUMBER tokens, this
new flag has the same value and is only ever used on CPP_COLON tokens)
and instead of checking loose_scope_p argument (i.e. whether it is
[[__extension__ ...]] or not), it just parses CPP_SCOPE or CPP_COLON
with CLONE_SCOPE flag followed by another CPP_COLON the same.
The latter will never appear in >= C23 or -std=gnu* modes, though
guarding its use say with flag_iso && !flag_isoc23 && doesn't really
work because the __extension__ case temporarily clears flag_iso flag.

This makes the -std=c11 etc. behavior more similar to -std=gnu11 or
-std=c23, the only difference I'm aware of are the
 #define JOIN2(A, B) A##B
 [[vendor JOIN2(:,:) attr]]
 [[__extension__ vendor JOIN2(:,:) attr]]
cases, which are accepted in the latter modes, but results in error
in -std=c11; but the error is during preprocessing that :: doesn't
form a valid preprocessing token, which is true, so just don't do that if
you try to have __STRICT_ANSI__ && __STDC_VERSION__ <= 201710L
compatibility.

2024-02-22  Jakub Jelinek  <jakub@redhat.com>

	PR c/114007
gcc/
	* doc/extend.texi: (__extension__): Remove comments about scope
	tokens vs. two colons.
gcc/c-family/
	* c-lex.cc (c_common_has_attribute): Parse 2 CPP_COLONs with
	the first one with COLON_SCOPE flag the same as CPP_SCOPE.
gcc/c/
	* c-parser.cc (c_parser_std_attribute): Remove loose_scope_p argument.
	Instead of checking it, parse 2 CPP_COLONs with the first one with
	COLON_SCOPE flag the same as CPP_SCOPE.
	(c_parser_std_attribute_list): Remove loose_scope_p argument, don't
	pass it to c_parser_std_attribute.
	(c_parser_std_attribute_specifier): Adjust c_parser_std_attribute_list
	caller.
gcc/testsuite/
	* gcc.dg/c23-attr-syntax-6.c: Adjust testcase for :: being valid
	even in -std=c11 even without __extension__ and : : etc. not being
	valid anymore even with __extension__.
	* gcc.dg/c23-attr-syntax-7.c: Likewise.
	* gcc.dg/c23-attr-syntax-8.c: New test.
libcpp/
	* include/cpplib.h (COLON_SCOPE): Define to PURE_ZERO.
	* lex.cc (_cpp_lex_direct): When lexing CPP_COLON with another
	colon after it, if !CPP_OPTION (pfile, scope) set COLON_SCOPE
	flag on the first CPP_COLON token.
2024-02-22 19:32:02 +01:00
GCC Administrator 98004ca00e Daily bump. 2024-02-22 00:18:58 +00:00
Joseph Myers a257671340 Update cpplib de.po
* de.po: Update.
2024-02-21 23:26:15 +00:00
GCC Administrator b4c88cc717 Daily bump. 2024-02-21 00:17:26 +00:00
Joseph Myers 3b3f3f6642 Update cpplib sv.po
* sv.po: Update.
2024-02-20 22:54:28 +00:00
GCC Administrator 5249027846 Daily bump. 2024-02-20 00:17:58 +00:00
Joseph Myers 238f93ae94 Update cpplib es.po
* es.po: Update.
2024-02-19 18:13:11 +00:00
Joseph Myers 558f392c09 Update .po files
gcc/po/
	* be.po, da.po, de.po, el.po, es.po, fi.po, fr.po, hr.po, id.po,
	ja.po, nl.po, ru.po, sr.po, sv.po, tr.po, uk.po, vi.po, zh_CN.po,
	zh_TW.po: Update.

libcpp/po/
	* be.po, ca.po, da.po, de.po, el.po, eo.po, es.po, fi.po, fr.po,
	id.po, ja.po, ka.po, nl.po, pt_BR.po, ro.po, ru.po, sr.po, sv.po,
	tr.po, uk.po, vi.po, zh_CN.po, zh_TW.po: Update.
2024-02-19 17:45:19 +00:00
GCC Administrator d70f155b07 Daily bump. 2024-02-17 00:17:08 +00:00
Joseph Myers 69efea3e24 Regenerate .pot files
gcc/po/
	* gcc.pot: Regenerate.

libcpp/po/
	* cpplib.pot: Regenerate.
2024-02-16 21:36:19 +00:00
GCC Administrator e255454046 Daily bump. 2024-02-02 00:18:18 +00:00
Lewis Hyatt 019dc63819 libcpp: Stabilize the location for macros restored after PCH load [PR105608]
libcpp currently lacks the infrastructure to assign correct locations to
macros that were defined prior to loading a PCH and then restored
afterwards. While I plan to address that fully for GCC 15, this patch
improves things by using at least a valid location, even if it's not the
best one. Without this change, libcpp uses pfile->directive_line as the
location for the restored macros, but this location_t applies to the old
line map, not the one that was just restored from the PCH, so the resulting
location is unpredictable and depends on what was stored in the line maps
before. With this change, all restored macros get assigned locations at the
line of the #include that triggered the PCH restore. A future patch will
store the actual file name and line number of each definition and then
synthesize locations in the new line map pointing to the right place.

gcc/c-family/ChangeLog:

	PR preprocessor/105608
	* c-pch.cc (c_common_read_pch): Adjust line map so that libcpp
	assigns a location to restored macros which is the same location
	that triggered the PCH include.

libcpp/ChangeLog:

	PR preprocessor/105608
	* pch.cc (cpp_read_state): Set a valid location for restored
	macros.
2024-02-01 09:07:17 -05:00
GCC Administrator 81d1a6e971 Daily bump. 2024-01-05 00:18:48 +00:00
Raiki Tamura 00dea7e8c4 libcpp: add function to check XID properties
This commit adds a new function intended for checking the XID properties
of a possibly unicode character, as well as the accompanying enum
describing the possible properties.

libcpp/ChangeLog:

	* charset.cc (cpp_check_xid_property): New.
	* include/cpplib.h
	(cpp_check_xid_property): New.
	(enum cpp_xid_property): New.

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
2024-01-04 16:30:01 +01:00
Jakub Jelinek a945c346f5 Update copyright years. 2024-01-03 12:19:35 +01:00
Jakub Jelinek 6a720d41ff Update Copyright year in ChangeLog files
2023 -> 2024
2024-01-03 11:35:18 +01:00
GCC Administrator e8018ccff9 Daily bump. 2023-12-14 00:18:00 +00:00
Jakub Jelinek 819bc4f670 libcpp: Fix valgrind errors on pr88974.c [PR112956]
On the c-c++-common/cpp/pr88974.c testcase I'm seeing
==600549== Conditional jump or move depends on uninitialised value(s)
==600549==    at 0x1DD3A05: cpp_get_token_1(cpp_reader*, unsigned int*) (macro.cc:3050)
==600549==    by 0x1DBFC7F: _cpp_parse_expr (expr.cc:1392)
==600549==    by 0x1DB9471: do_if(cpp_reader*) (directives.cc:2087)
==600549==    by 0x1DBB4D8: _cpp_handle_directive (directives.cc:572)
==600549==    by 0x1DCD488: _cpp_lex_token (lex.cc:3682)
==600549==    by 0x1DD3A97: cpp_get_token_1(cpp_reader*, unsigned int*) (macro.cc:2936)
==600549==    by 0x7F7EE4: scan_translation_unit (c-ppoutput.cc:350)
==600549==    by 0x7F7EE4: preprocess_file(cpp_reader*) (c-ppoutput.cc:106)
==600549==    by 0x7F6235: c_common_init() (c-opts.cc:1280)
==600549==    by 0x704C8B: lang_dependent_init (toplev.cc:1837)
==600549==    by 0x704C8B: do_compile (toplev.cc:2135)
==600549==    by 0x704C8B: toplev::main(int, char**) (toplev.cc:2306)
==600549==    by 0x7064BA: main (main.cc:39)
error.  The problem is that _cpp_lex_direct can leave result->src_loc
uninitialized in some cases and later on we use that location_t.

_cpp_lex_direct essentially does:
  cppchar_t c;
...
  cpp_token *result = pfile->cur_token++;

 fresh_line:
  result->flags = 0;
...
  if (buffer->need_line)
    {
      if (pfile->state.in_deferred_pragma)
        {
          result->type = CPP_PRAGMA_EOL;
          ... // keeps result->src_loc uninitialized;
          return result;
        }
      if (!_cpp_get_fresh_line (pfile))
        {
          result->type = CPP_EOF;
          if (!pfile->state.in_directive && !pfile->state.parsing_args)
            {
              result->src_loc = pfile->line_table->highest_line;
              ...
            }
          ... // otherwise result->src_loc is sometimes uninitialized here
          return result;
        }
      ...
    }
...
  result->src_loc = pfile->line_table->highest_line;
...
  c = *buffer->cur++;
  switch (c)
    {
...
    case '\n':
...
      buffer->need_line = true;
      if (pfile->state.in_deferred_pragma)
        {
          result->type = CPP_PRAGMA_EOL;
...
          return result;
        }
      goto fresh_line;
...
    }
...
So, if _cpp_lex_direct is called without buffer->need_line initially set,
result->src_loc is always initialized (and actually hundreds of tests rely
on that exact value it has), even when c == '\n' and we set that flag later
on and goto fresh_line.  For CPP_PRAGMA_EOL case we have in that case
separate handling and don't goto.
But if _cpp_lex_direct is called with buffer->need_line initially set and
either decide to return a CPP_PRAGMA_EOL token or if getting a new line fails
for some reason and we return an CPP_ERROR token and we are in directive
or parsing args state, it is kept uninitialized and can be whatever the
allocation left it there as.

The following patch attempts to keep the status quo, use value that was
returned previously if it was initialized (i.e. we went through the
goto fresh_line; statement in c == '\n' handling) and only initialize
result->src_loc if it was uninitialized before.

2023-12-13  Jakub Jelinek  <jakub@redhat.com>

	PR preprocessor/112956
	* lex.cc (_cpp_lex_direct): Initialize c to 0.
	For CPP_PRAGMA_EOL tokens and if c == 0 also for CPP_EOF
	set result->src_loc to highest locus.
2023-12-13 21:16:14 +01:00
GCC Administrator 6c85b8a987 Daily bump. 2023-11-29 00:17:27 +00:00
Lewis Hyatt ce52f1f707 libcpp: Fix unsigned promotion for unevaluated divide by zero [PR112701]
When libcpp encounters a divide by zero while processing a constant
expression "x/y", it returns "x" as a fallback. The value of the fallback is
not normally important, since an error will be generated anyway, but if the
expression appears in an unevaluated context, such as "0 ? 0/0u : -1", then
there will be no error, and the fallback value will be meaningful to the
extent that it may cause promotion from signed to unsigned of an operand
encountered later. As the PR notes, libcpp does not do the unsigned
promotion correctly in this case; fix it by making the fallback return value
unsigned as necessary.

libcpp/ChangeLog:

	PR preprocessor/112701
	* expr.cc (num_div_op): Set unsignedp appropriately when returning a
	stub value for divide by 0.

gcc/testsuite/ChangeLog:

	PR preprocessor/112701
	* gcc.dg/cpp/expr.c: Add additional tests to cover divide by 0 in an
	unevaluated context, where the unsignedness still matters.
2023-11-27 21:19:31 -05:00
GCC Administrator ad3e759c17 Daily bump. 2023-11-28 00:17:28 +00:00
Alex Coplan 06280a906c c-family: Implement __has_feature and __has_extension [PR60512]
This patch implements clang's __has_feature and __has_extension in GCC.
Currently the patch aims to implement all documented features (and some
undocumented ones) following the documentation at
https://clang.llvm.org/docs/LanguageExtensions.html with the exception
of the legacy features for C++ type traits.  These are omitted, since as
the clang documentation notes, __has_builtin is the correct "modern" way
to query for these (which GCC already implements).

gcc/c-family/ChangeLog:

	PR c++/60512
	* c-common.cc (struct hf_feature_info): New.
	(c_common_register_feature): New.
	(init_has_feature): New.
	(has_feature_p): New.
	* c-common.h (c_common_has_feature): New.
	(c_family_register_lang_features): New.
	(c_common_register_feature): New.
	(has_feature_p): New.
	* c-lex.cc (init_c_lex): Plumb through has_feature callback.
	(c_common_has_builtin): Generalize and move common part ...
	(c_common_lex_availability_macro): ... here.
	(c_common_has_feature): New.
	* c-ppoutput.cc (init_pp_output): Plumb through has_feature.

gcc/c/ChangeLog:

	PR c++/60512
	* c-lang.cc (c_family_register_lang_features): New.
	* c-objc-common.cc (struct c_feature_info): New.
	(c_register_features): New.
	* c-objc-common.h (c_register_features): New.

gcc/cp/ChangeLog:

	PR c++/60512
	* cp-lang.cc (c_family_register_lang_features): New.
	* cp-objcp-common.cc (struct cp_feature_selector): New.
	(cp_feature_selector::has_feature): New.
	(struct cp_feature_info): New.
	(cp_register_features): New.
	* cp-objcp-common.h (cp_register_features): New.

gcc/ChangeLog:

	PR c++/60512
	* doc/cpp.texi: Document __has_{feature,extension}.

gcc/objc/ChangeLog:

	PR c++/60512
	* objc-act.cc (struct objc_feature_info): New.
	(objc_nonfragile_abi_p): New.
	(objc_common_register_features): New.
	* objc-act.h (objc_common_register_features): New.
	* objc-lang.cc (c_family_register_lang_features): New.

gcc/objcp/ChangeLog:

	PR c++/60512
	* objcp-lang.cc (c_family_register_lang_features): New.

libcpp/ChangeLog:

	PR c++/60512
	* include/cpplib.h (struct cpp_callbacks): Add has_feature.
	(enum cpp_builtin_type): Add BT_HAS_{FEATURE,EXTENSION}.
	* init.cc: Add __has_{feature,extension}.
	* macro.cc (_cpp_builtin_macro_text): Handle
	BT_HAS_{FEATURE,EXTENSION}.

gcc/testsuite/ChangeLog:

	PR c++/60512
	* c-c++-common/has-feature-common.c: New test.
	* c-c++-common/has-feature-pedantic.c: New test.
	* g++.dg/ext/has-feature.C: New test.
	* gcc.dg/asan/has-feature-asan.c: New test.
	* gcc.dg/has-feature.c: New test.
	* gcc.dg/ubsan/has-feature-ubsan.c: New test.
	* obj-c++.dg/has-feature.mm: New test.
	* objc.dg/has-feature.m: New test.

Co-Authored-By: Iain Sandoe <iain@sandoe.co.uk>
2023-11-27 10:42:55 +00:00
GCC Administrator 77cf1dba78 Daily bump. 2023-11-25 00:17:46 +00:00
Alexander Monakov ab78426ae7 libcpp: configure: drop unused Valgrind detection
When top-level configure has either --enable-checking=valgrind or
--enable-valgrind-annotations, we want to activate a couple of workarounds
in libcpp. They do not use anything from the Valgrind API, so just
delete all detection.

libcpp/ChangeLog:

	* config.in: Regenerate.
	* configure: Regenerate.
	* configure.ac (ENABLE_VALGRIND_CHECKING): Delete.
	(ENABLE_VALGRIND_ANNOTATIONS): Rename to
	ENABLE_VALGRIND_WORKAROUNDS.  Delete Valgrind header checks.
	* lex.cc (new_buff): Adjust for renaming.
	(_cpp_free_buff): Ditto.
2023-11-24 16:13:56 +03:00
GCC Administrator 30d8188e6d Daily bump. 2023-11-21 00:17:53 +00:00
Marc Poulhiès 721cdcd1dd Trivial typo fix in variadic
Fix all occurences of varadic, except for Rust (will be part of another change).

gcc/ChangeLog:

	* config/nvptx/nvptx.h (struct machine_function): Fix typo in variadic.
	* config/nvptx/nvptx.cc (nvptx_function_arg_advance): Adjust to use fixed name.
	(nvptx_declare_function_name): Likewise.
	(nvptx_call_args): Likewise.
	(nvptx_expand_call): Likewise.

gcc/cp/ChangeLog:

	* lambda.cc (compare_lambda_sig): Fix typo in variadic.

libcpp/ChangeLog:

	* macro.cc (parse_params): Fix typo in variadic.
	(create_iso_definition): Likewise.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
2023-11-20 21:39:15 +01:00
GCC Administrator b54b3800f7 Daily bump. 2023-11-20 00:17:10 +00:00
David Malcolm 78d132d73e libcpp: split decls out to rich-location.h
The various decls relating to rich_location are in
libcpp/include/line-map.h, but they don't relate to line maps.

Split them out to their own header: libcpp/include/rich-location.h

No functional change intended.

gcc/ChangeLog:
	* Makefile.in (CPPLIB_H): Add libcpp/include/rich-location.h.
	* coretypes.h (class rich_location): New forward decl.

gcc/analyzer/ChangeLog:
	* analyzer.h: Include "rich-location.h".

gcc/c-family/ChangeLog:
	* c-lex.cc: Include "rich-location.h".

gcc/cp/ChangeLog:
	* mapper-client.cc: Include "rich-location.h".

gcc/ChangeLog:
	* diagnostic.h: Include "rich-location.h".
	* edit-context.h (class fixit_hint): New forward decl.
	* gcc-rich-location.h: Include "rich-location.h".
	* genmatch.cc: Likewise.
	* pretty-print.h: Likewise.

gcc/rust/ChangeLog:
	* rust-location.h: Include "rich-location.h".

libcpp/ChangeLog:
	* Makefile.in (TAGS_SOURCES): Add "include/rich-location.h".
	* include/cpplib.h (class rich_location): New forward decl.
	* include/line-map.h (class range_label)
	(enum range_display_kind, struct location_range)
	(class semi_embedded_vec, class rich_location, class label_text)
	(class range_label, class fixit_hint): Move to...
	* include/rich-location.h: ...this new file.
	* internal.h: Include "rich-location.h".

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2023-11-19 06:26:40 -05:00
GCC Administrator eaedb56a0f Daily bump. 2023-11-15 00:16:41 +00:00
Jakub Jelinek d64b7c82da libcpp, contrib: Update to Unicode 15.1
The following patch (in plaintext just a pseudo-patch where I've left out
the too big parts of either wget downloaded or regenerated files out with
..., full patch attached compressed) updates to Unicode 15.1 from 15.0
we had last year.  Apparently Unicode forgot to add a new range to 4-8 Table
we are using, but from the other files it is clear what should have been
added; I've filed a bugreport against Unicode.

2023-11-14  Jakub Jelinek  <jakub@redhat.com>

contrib/
	* unicode/README: Adjust glibc git commit hash, number of Unicode
	data files to be updated and latest Unicode version.
	* unicode/from_glibc/utf8_gen.py: Update from glibc.
	* unicode/UnicodeData.txt: Update from Unicode 15.1.
	* unicode/EastAsianWidth.txt: Likewise.
	* unicode/DerivedNormalizationProps.txt: Likewise.
	* unicode/NameAliases.txt: Likewise.
	* unicode/DerivedCoreProperties.txt: Likewise.
	* unicode/PropList.txt: Likewise.
libcpp/
	* makeucnid.cc (write_copyright): Update copyright year.
	* makeuname2c.cc (write_copyright): Likewise.
	(struct generated): Update latest Unicode version.
	(generated_ranges): Add 2ebf0-2ee5d CJK UNIFIED IDEOGRAPH
	range which was forgotten to be added to 4-8 table, but
	clearly is expected to be there from the 15.1 additions.
	* ucnid.h: Regenerated.
	* uname2c.h: Regenerated.
	* generated_cpp_wcwidth.h: Regenerated.
2023-11-14 18:32:37 +01:00
Jakub Jelinek 194825f206 c++: Implement C++26 P1854R4 - Making non-encodable string literals ill-formed [PR110341]
This paper voted in as DR makes some multi-character literals ill-formed.
'abcd' stays valid, but e.g. 'á' is newly invalid in UTF-8 exec charset
while valid e.g. in ISO-8859-1, because it is a single character which needs
2 bytes to be encoded.

The following patch does that by checking (only pedantically, especially
because it is a DR) if we'd emit a -Wmultichar warning because character
constant has more than one byte in it whether the number of source characters
is equal to the number of bytes in the multichar string.
If it is, it is normal multi-character literal constant
and is diagnosed normally with -Wmultichar, otherwise at least one of the
c-chars in the sequence was encoded as 2+ bytes.

2023-11-14  Jakub Jelinek  <jakub@redhat.com>

	PR c++/110341
libcpp/
	* charset.cc: Implement C++26 P1854R4 - Making non-encodable string
	literals ill-formed.
	(one_count_chars, convert_count_chars, count_source_chars): New
	functions.
	(narrow_str_to_charconst): Change last arg type from cpp_ttype to
	const cpp_token *.  For C++ if pedantic and i > 1 in CPP_CHAR
	interpret token also as CPP_STRING32 and if number of characters
	in the CPP_STRING32 is larger than number of bytes in CPP_CHAR,
	pedwarn on it.  Make the diagnostics more detailed.
	(wide_str_to_charconst): Change last arg type from cpp_ttype to
	const cpp_token *.  Make the diagnostics more detailed.
	(cpp_interpret_charconst): Adjust narrow_str_to_charconst and
	wide_str_to_charconst callers.
gcc/testsuite/
	* g++.dg/cpp26/literals1.C: New test.
	* g++.dg/cpp26/literals2.C: New test.
	* g++.dg/cpp23/wchar-multi1.C: Adjust expected diagnostic wordings.
	* g++.dg/cpp23/wchar-multi2.C: Likewise.
	* gcc.dg/c23-utf8char-3.c: Likewise.
	* gcc.dg/cpp/charconst-4.c: Likewise.
	* gcc.dg/cpp/charconst.c: Likewise.
	* gcc.dg/cpp/if-2.c: Likewise.
	* gcc.dg/utf16-4.c: Likewise.
	* gcc.dg/utf32-4.c: Likewise.
	* g++.dg/cpp1z/utf8-neg.C: Likewise.
	* g++.dg/cpp2a/ucn2.C: Likewise.
	* g++.dg/ext/utf16-4.C: Likewise.
	* g++.dg/ext/utf32-4.C: Likewise.
2023-11-14 18:28:34 +01:00
GCC Administrator b9fd8399ec Daily bump. 2023-11-14 12:23:39 +00:00
Arsen Arsenović 5ee4349fa9
libcpp: Regenerate config.in
The previous commit did not include regenerating files maintained by
autoheader.

libcpp/ChangeLog:

	* config.in: Regenerate.
2023-11-14 01:02:22 +01:00
Arsen Arsenović db50aea625
*: add modern gettext
This patch updates gettext.m4 and related .m4 files and adds
gettext-runtime as a gmp/mpfr/... style host library, allowing newer
libintl to be used.

This patch /does not/ add build-time tools required for
internationalizing (msgfmt et al), instead, it just updates the runtime
library.  The result should be a distribution that acts exactly the same
when a copy of gettext is present, and disables internationalization
otherwise.

There should be no changes in behavior when gettext is included in-tree.
When gettext is not included in tree, nor available on the system, the
programs will be built without localization.

ChangeLog:

	PR bootstrap/12596
	* .gitignore: Add '/gettext*'.
	* configure.ac (host_libs): Replace intl with gettext.
	(hbaseargs, bbaseargs, baseargs): Split baseargs into
	{h,b}baseargs.
	(skip_barg): New flag.  Skips appending current flag to
	bbaseargs.
	<library exemptions>: Exempt --with-libintl-{type,prefix} from
	target and build machine argument passing.
	* configure: Regenerate.
	* Makefile.def (host_modules): Replace intl module with gettext
	module.
	(configure-ld): Depend on configure-gettext.
	* Makefile.in: Regenerate.

config/ChangeLog:

	* intlmacosx.m4: Import from gettext-0.22 (serial 8).
	* gettext.m4: Sync with gettext-0.22 (serial 77).
	* gettext-sister.m4 (ZW_GNU_GETTEXT_SISTER_DIR): Load gettext's
	uninstalled-config.sh, or call AM_GNU_GETTEXT if missing.
	* iconv.m4: Sync with gettext-0.22 (serial 26).

contrib/ChangeLog:

	* prerequisites.sha512: Add gettext.
	* prerequisites.md5: Add gettext.
	* download_prerequisites: Add gettext.

gcc/ChangeLog:

	* configure: Regenerate.
	* aclocal.m4: Regenerate.
	* Makefile.in (LIBDEPS): Remove (potential) ./ prefix from
	LIBINTL_DEP.
	* doc/install.texi: Document new (notable) flags added by the
	optional gettext tree and by AM_GNU_GETTEXT.  Document libintl/libc
	with gettext dependency.

libcpp/ChangeLog:

	* configure: Regenerate.
	* aclocal.m4: Regenerate.

libstdc++-v3/ChangeLog:

	* configure: Regenerate.
2023-11-14 00:47:11 +01:00
David Malcolm 8625aa2466 diagnostics: cleanups to diagnostic-show-locus.cc
Reduce implicit usage of line_table global, and move source printing to
within diagnostic_context.

gcc/ChangeLog:
	* diagnostic-show-locus.cc (layout::m_line_table): New field.
	(compatible_locations_p): Convert to...
	(layout::compatible_locations_p): ...this, replacing uses of
	line_table global with m_line_table.
	(layout::layout): Convert "richloc" param from a pointer to a
	const reference.  Initialize m_line_table member.
	(layout::maybe_add_location_range):  Replace uses of line_table
	global with m_line_table.  Pass the latter to
	linemap_client_expand_location_to_spelling_point.
	(layout::print_leading_fixits): Pass m_line_table to
	affects_line_p.
	(layout::print_trailing_fixits): Likewise.
	(gcc_rich_location::add_location_if_nearby): Update for change
	to layout ctor params.
	(diagnostic_show_locus): Convert to...
	(diagnostic_context::maybe_show_locus): ...this, converting
	richloc param from a pointer to a const reference.  Make "loc"
	const.  Split out printing part of function to...
	(diagnostic_context::show_locus): ...this.
	(selftest::test_offset_impl): Update for change to layout ctor
	params.
	(selftest::test_layout_x_offset_display_utf8): Likewise.
	(selftest::test_layout_x_offset_display_tab): Likewise.
	(selftest::test_tab_expansion): Likewise.
	* diagnostic.h (diagnostic_context::maybe_show_locus): New decl.
	(diagnostic_context::show_locus): New decl.
	(diagnostic_show_locus): Convert from a decl to an inline function.
	* gdbinit.in (break-on-diagnostic): Update from a breakpoint
	on diagnostic_show_locus to one on
	diagnostic_context::maybe_show_locus.
	* genmatch.cc (linemap_client_expand_location_to_spelling_point):
	Add "set" param and use it in place of line_table global.
	* input.cc (expand_location_1): Likewise.
	(expand_location): Update for new param of expand_location_1.
	(expand_location_to_spelling_point): Likewise.
	(linemap_client_expand_location_to_spelling_point): Add "set"
	param and use it in place of line_table global.
	* tree-diagnostic-path.cc (event_range::print): Pass line_table
	for new param of linemap_client_expand_location_to_spelling_point.

libcpp/ChangeLog:
	* include/line-map.h (rich_location::get_expanded_location): Make
	const.
	(rich_location::get_line_table): New accessor.
	(rich_location::m_line_table): Make the pointer be const.
	(rich_location::m_have_expanded_location): Make mutable.
	(rich_location::m_expanded_location): Likewise.
	(fixit_hint::affects_line_p): Add const line_maps * param.
	(linemap_client_expand_location_to_spelling_point): Likewise.
	* line-map.cc (rich_location::get_expanded_location): Make const.
	Pass m_line_table to
	linemap_client_expand_location_to_spelling_point.
	(rich_location::maybe_add_fixit): Likewise.
	(fixit_hint::affects_line_p): Add set param and pass to
	linemap_client_expand_location_to_spelling_point.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2023-11-09 17:22:52 -05:00
GCC Administrator c48f105685 Daily bump. 2023-11-08 00:17:35 +00:00
Joseph Myers 094a609c69 c: Refer more consistently to C23 not C2X
Continuing the move to refer to C23 in place of C2X throughout the
source tree, update documentation, diagnostics, comments, variable and
function names, etc., to use the C23 name.

Testsuite updates are left for a future patch, except for testcases
that test diagnostics that previously mentioned C2X (but in those
testcases, sometimes other comments are updated, not just the
diagnostic expectations).

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

gcc/
	* builtins.def (DEF_C2X_BUILTIN): Rename to DEF_C23_BUILTIN and
	use flag_isoc23 and function_c23_misc.
	* config/rl78/rl78.cc (rl78_option_override): Compare
	lang_hooks.name with "GNU C23" not "GNU C2X".
	* coretypes.h (function_c2x_misc): Rename to function_c23_misc.
	* doc/cpp.texi (@code{__has_attribute}): Refer to C23 instead of
	C2x.
	* doc/extend.texi: Likewise.
	* doc/invoke.texi: Likewise.
	* dwarf2out.cc (highest_c_language, gen_compile_unit_die): Compare
	against and return "GNU C23" language string instead of "GNU C2X".
	* ginclude/float.h: Refer to C23 instead of C2X in comments.
	* ginclude/stdint-gcc.h: Likewise.
	* glimits.h: Likewise.
	* tree.h: Likewise.

gcc/ada/
	* gcc-interface/utils.cc (flag_isoc2x): Rename to flag_isoc23.

gcc/c-family/
	* c-common.cc (flag_isoc2x): Rename to flag_isoc23.
	(c_common_reswords): Use D_C23 instead of D_C2X.
	* c-common.h: Refer throughout to C23 instead of C2X in comments.
	(D_C2X): Rename to D_C23.
	(flag_isoc2x): Rename to flag_isoc23.
	* c-cppbuiltin.cc (builtin_define_float_constants): Use
	flag_isoc23 instead of flag_isoc2x.  Refer to C23 instead of C2x
	in comments.
	* c-format.cc: Use STD_C23 instead of STD_C2X and flag_isoc23
	instead of flag_isoc2x.  Refer to C23 instead of C2X in comments.
	* c-format.h: Use STD_C23 instead of STD_C2X.
	* c-lex.cc: Use warn_c11_c23_compat instead of warn_c11_c2x_compat
	and flag_isoc23 instead of flag_isoc2x.  Refer to C23 instead of
	C2X in diagnostics.
	* c-opts.cc: Use flag_isoc23 instead of flag_isoc2x.  Refer to C23
	instead of C2X in comments.
	(set_std_c2x): Rename to set_std_c23.
	* c.opt (Wc11-c23-compat): Use CPP(cpp_warn_c11_c23_compat)
	CppReason(CPP_W_C11_C23_COMPAT) Var(warn_c11_c23_compat) instead
	of CPP(cpp_warn_c11_c2x_compat) CppReason(CPP_W_C11_C2X_COMPAT)
	Var(warn_c11_c2x_compat).

gcc/c/
	* c-decl.cc: Use flag_isoc23 instead of flag_isoc2x and c23_auto_p
	instead of c2x_auto_p.  Refer to C23 instead of C2X in diagnostics
	and comments.
	* c-errors.cc: Use flag_isoc23 instead of flag_isoc2x and
	warn_c11_c23_compat instead of warn_c11_c2x_compat.  Refer to C23
	instead of C2X in comments.
	* c-parser.cc: Use flag_isoc23 instead of flag_isoc2x,
	warn_c11_c23_compat instead of warn_c11_c2x_compat, c23_auto_p
	instead of c2x_auto_p and D_C23 instead of D_C2X.  Refer to C23
	instead of C2X in diagnostics and comments.
	* c-tree.h: Refer to C23 instead of C2X in comments.
	(struct c_declspecs): Rename c2x_auto_p to c23_auto_p.
	* c-typeck.cc: Use flag_isoc23 instead of flag_isoc2x and
	warn_c11_c23_compat instead of warn_c11_c2x_compat.  Refer to C23
	instead of C2X in diagnostics and comments.

gcc/fortran/
	* gfortran.h (gfc_real_info): Refer to C23 instead of C2X in
	comment.

gcc/lto/
	* lto-lang.cc (flag_isoc2x): Rename to flag_isoc23.

gcc/testsuite/
	* gcc.dg/binary-constants-2.c: Refer to C23 instead of C2X.
	* gcc.dg/binary-constants-3.c: Likewise.
	* gcc.dg/bitint-23.c: Likewise.
	* gcc.dg/bitint-26.c: Likewise.
	* gcc.dg/bitint-27.c: Likewise.
	* gcc.dg/c11-attr-syntax-1.c: Likewise.
	* gcc.dg/c11-attr-syntax-2.c: Likewise.
	* gcc.dg/c11-floatn-1.c: Likewise.
	* gcc.dg/c11-floatn-2.c: Likewise.
	* gcc.dg/c11-floatn-3.c: Likewise.
	* gcc.dg/c11-floatn-4.c: Likewise.
	* gcc.dg/c11-floatn-5.c: Likewise.
	* gcc.dg/c11-floatn-6.c: Likewise.
	* gcc.dg/c11-floatn-7.c: Likewise.
	* gcc.dg/c11-floatn-8.c: Likewise.
	* gcc.dg/c2x-attr-syntax-4.c: Likewise.
	* gcc.dg/c2x-attr-syntax-6.c: Likewise.
	* gcc.dg/c2x-attr-syntax-7.c: Likewise.
	* gcc.dg/c2x-binary-constants-2.c: Likewise.
	* gcc.dg/c2x-floatn-5.c: Likewise.
	* gcc.dg/c2x-floatn-6.c: Likewise.
	* gcc.dg/c2x-floatn-7.c: Likewise.
	* gcc.dg/c2x-floatn-8.c: Likewise.
	* gcc.dg/c2x-nullptr-4.c: Likewise.
	* gcc.dg/c2x-qual-2.c: Likewise.
	* gcc.dg/c2x-qual-3.c: Likewise.
	* gcc.dg/c2x-qual-6.c: Likewise.
	* gcc.dg/cpp/c11-warning-1.c: Likewise.
	* gcc.dg/cpp/c11-warning-2.c: Likewise.
	* gcc.dg/cpp/c11-warning-3.c: Likewise.
	* gcc.dg/cpp/c2x-warning-2.c: Likewise.
	* gcc.dg/cpp/gnu11-elifdef-3.c: Likewise.
	* gcc.dg/cpp/gnu11-elifdef-4.c: Likewise.
	* gcc.dg/cpp/gnu11-warning-1.c: Likewise.
	* gcc.dg/cpp/gnu11-warning-2.c: Likewise.
	* gcc.dg/cpp/gnu11-warning-3.c: Likewise.
	* gcc.dg/cpp/gnu2x-warning-2.c: Likewise.
	* gcc.dg/dfp/c11-constants-1.c: Likewise.
	* gcc.dg/dfp/c11-constants-2.c: Likewise.
	* gcc.dg/dfp/c2x-constants-2.c: Likewise.
	* gcc.dg/dfp/constants-pedantic.c: Likewise.
	* gcc.dg/pr30260.c: Likewise.
	* gcc.dg/system-binary-constants-1.c: Likewise.

libcpp/
	* directives.cc: Refer to C23 instead of C2X in diagnostics and
	comments.
	(STDC2X): Rename to STDC23.
	* expr.cc: Use cpp_warn_c11_c23_compat instead of
	cpp_warn_c11_c2x_compat and CPP_W_C11_C23_COMPAT instead of
	CPP_W_C11_C2X_COMPAT.  Refer to C23 instead of C2X in diagnostics
	and comments.
	* include/cpplib.h: Refer to C23 instead of C2X in diagnostics and
	comments.
	(CLK_GNUC2X): Rename to CLK_GNUC23.
	(CLK_STDC2X): Rename to CLK_STDC23.
	(CPP_W_C11_C2X_COMPAT): Rename to CPP_W_C11_C23_COMPAT.
	* init.cc: Use GNUC23 instead of GNUC2X, STDC23 instead of STDC2X
	and cpp_warn_c11_c23_compat instead of cpp_warn_c11_c2x_compat.
	* lex.cc (maybe_va_opt_error): Refer to C23 instead of C2X in
	diagnostic.
	* macro.cc (_cpp_arguments_ok): Refer to C23 instead of C2X in
	comment.
2023-11-07 14:20:30 +00:00
GCC Administrator 9daed0b538 Daily bump. 2023-11-03 00:16:58 +00:00
Jakub Jelinek 1c58566450 c++: Implement C++26 P2361R6 - Unevaluated strings [PR110342]
The following patch implements C++26 unevaluated-string.
As it seems to me just extra pedanticity, it is implemented only for
-std=c++26 or -std=gnu++26 and later and only if -pedantic/-pedantic-errors.
Nothing is done for inline asm, while the spec changes those, it changes it
to a balanced token sequence with implementation defined rules on what is
and isn't allowed (so pedantically accepting asm ("" : "+m" (x));
was accepts-invalid before C++26, but we didn't diagnose anything).
For the other spots mentioned in the paper, static_assert message,
linkage specification, deprecated/nodiscard attributes it enforces the
requirements (no prefixes, udlit suffixes, no octal/hexadecimal escapes
(conditional escape sequences were rejected with pedantic already before).
For the deprecated operator "" identifier case I've kept things as is,
because everything seems to have been diagnosed already (a lot being implied
from the string having to be empty).

2023-11-02  Jakub Jelinek  <jakub@redhat.com>

	PR c++/110342
gcc/cp/
	* parser.cc: Implement C++26 P2361R6 - Unevaluated strings.
	(uneval_string_attr): New enumerator.
	(cp_parser_string_literal_common): Add UNEVAL argument.  If true,
	pass CPP_UNEVAL_STRING rather than CPP_STRING to
	cpp_interpret_string_notranslate.
	(cp_parser_string_literal, cp_parser_userdef_string_literal): Adjust
	callers of cp_parser_string_literal_common.
	(cp_parser_unevaluated_string_literal): New function.
	(cp_parser_parenthesized_expression_list): Handle uneval_string_attr.
	(cp_parser_linkage_specification): Use
	cp_parser_unevaluated_string_literal for C++26.
	(cp_parser_static_assert): Likewise.
	(cp_parser_std_attribute): Use uneval_string_attr for standard
	deprecated and nodiscard attributes.
gcc/testsuite/
	* g++.dg/cpp26/unevalstr1.C: New test.
	* g++.dg/cpp26/unevalstr2.C: New test.
	* g++.dg/cpp0x/udlit-error1.C (lol): Expect an error for C++26
	about user-defined literal in deprecated attribute.
libcpp/
	* include/cpplib.h (TTYPE_TABLE): Add CPP_UNEVAL_STRING literal
	entry.  Use C++11 instead of C++-0x in comments.
	* charset.cc (convert_escape): Add UNEVAL argument, if true,
	pedantically diagnose numeric escape sequences.
	(cpp_interpret_string_1): Formatting fix.  Adjust convert_escape
	caller.
	(cpp_interpret_string): Formatting string.
	(cpp_interpret_string_notranslate): Pass type through to
	cpp_interpret_string if it is CPP_UNEVAL_STRING.
2023-11-02 07:44:24 +01:00
GCC Administrator eac0917bd3 Daily bump. 2023-11-01 00:17:52 +00:00
David Malcolm b0f19336f2 libcpp: eliminate MACRO_MAP_EXPANSION_POINT_LOCATION
This patch eliminates the function "MACRO_MAP_EXPANSION_POINT_LOCATION"
(which hasn't been a macro since r6-739-g0501dbd932a7e9) in favor of
a new line_map_macro::get_expansion_point_location accessor.

No functional change intended.

gcc/c-family/ChangeLog:
	* c-warn.cc (warn_for_multistatement_macros): Update for removal
	of MACRO_MAP_EXPANSION_POINT_LOCATION.

gcc/cp/ChangeLog:
	* module.cc (ordinary_loc_of): Update for removal of
	MACRO_MAP_EXPANSION_POINT_LOCATION.
	(module_state::note_location): Update for renaming of field.
	(module_state::write_macro_maps): Likewise.

gcc/ChangeLog:
	* input.cc (dump_location_info): Update for removal of
	MACRO_MAP_EXPANSION_POINT_LOCATION.
	* tree-diagnostic.cc (maybe_unwind_expanded_macro_loc):
	Likewise.

libcpp/ChangeLog:
	* include/line-map.h
	(line_map_macro::get_expansion_point_location): New accessor.
	(line_map_macro::expansion): Rename field to...
	(line_map_macro::mexpansion): Rename field to...
	(MACRO_MAP_EXPANSION_POINT_LOCATION): Delete this function.
	* line-map.cc (linemap_enter_macro): Update for renaming of field.
	(linemap_macro_map_loc_to_exp_point): Update for removal of
	MACRO_MAP_EXPANSION_POINT_LOCATION.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2023-10-31 17:05:41 -04:00
GCC Administrator 9cf2e7441e Daily bump. 2023-10-24 00:17:34 +00:00
Lewis Hyatt cb05acdcea libcpp: Improve the diagnostic for poisoned identifiers [PR36887]
The PR requests an enhancement to the diagnostic issued for the use of a
poisoned identifier. Currently, we show the location of the usage, but not
the location which requested the poisoning, which would be helpful for the
user if the decision to poison an identifier was made externally, such as
in a library header.

In order to output this information, we need to remember a location_t for
each identifier that has been poisoned, and that data needs to be preserved
as well in a PCH. One option would be to add a field to struct cpp_hashnode,
but there is no convenient place to add it without increasing the size of
the struct for all identifiers. Given this facility will be needed rarely,
it seemed better to add a second hash map, which is handled PCH-wise the
same as the current one in gcc/stringpool.cc. This hash map associates a new
struct cpp_hashnode_extra with each identifier that needs one. Currently
that struct only contains the new location_t, but it could be extended in
the future if there is other ancillary data that may be convenient to put
there for other purposes.

libcpp/ChangeLog:

	PR preprocessor/36887
	* directives.cc (do_pragma_poison): Store in the extra hash map the
	location from which an identifier has been poisoned.
	* lex.cc (identifier_diagnostics_on_lex): When issuing a diagnostic
	for the use of a poisoned identifier, also add a note indicating the
	location from which it was poisoned.
	* identifiers.cc (alloc_node): Convert to template function.
	(_cpp_init_hashtable): Handle the new extra hash map.
	(_cpp_destroy_hashtable): Likewise.
	* include/cpplib.h (struct cpp_hashnode_extra): New struct.
	(cpp_create_reader): Update prototype to...
	* init.cc (cpp_create_reader): ...accept an argument for the extra
	hash table and pass it to _cpp_init_hashtable.
	* include/symtab.h (ht_lookup): New overload for convenience.
	* internal.h (struct cpp_reader): Add EXTRA_HASH_TABLE member.
	(_cpp_init_hashtable): Adjust prototype.

gcc/c-family/ChangeLog:

	PR preprocessor/36887
	* c-opts.cc (c_common_init_options): Pass new extra hash map
	argument to cpp_create_reader().

gcc/ChangeLog:

	PR preprocessor/36887
	* toplev.h (ident_hash_extra): Declare...
	* stringpool.cc (ident_hash_extra): ...this new global variable.
	(init_stringpool): Handle ident_hash_extra as well as ident_hash.
	(ggc_mark_stringpool): Likewise.
	(ggc_purge_stringpool): Likewise.
	(struct string_pool_data_extra): New struct.
	(spd2): New GC root variable.
	(gt_pch_save_stringpool): Use spd2 to handle ident_hash_extra,
	analogous to how spd is used to handle ident_hash.
	(gt_pch_restore_stringpool): Likewise.

gcc/testsuite/ChangeLog:

	PR preprocessor/36887
	* c-c++-common/cpp/diagnostic-poison.c: New test.
	* g++.dg/pch/pr36887.C: New test.
	* g++.dg/pch/pr36887.Hs: New test.
2023-10-23 18:35:26 -04:00
GCC Administrator 00c67d6297 Daily bump. 2023-10-09 00:17:27 +00:00
David Malcolm 0a0ceb7a72 libcpp: eliminate LINEMAPS_{ORDINARY,MACRO}_MAPS
libcpp/ChangeLog:
	* include/line-map.h (LINEMAPS_ORDINARY_MAPS): Delete.
	(LINEMAPS_MACRO_MAPS): Delete.
	* line-map.cc (linemap_tracks_macro_expansion_locs_p): Update for
	deletion of LINEMAPS_MACRO_MAPS.
	(linemap_get_statistics): Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2023-10-08 18:43:17 -04:00
David Malcolm 45bae1809c libcpp: eliminate LINEMAPS_{,ORDINARY_,MACRO_}CACHE
It's simpler to use field access than to go through these inline
functions that look as if they are macros.

No functional change intended.

libcpp/ChangeLog:
	* include/line-map.h (maps_info_ordinary::cache): Rename to...
	(maps_info_ordinary::m_cache): ...this.
	(maps_info_macro::cache): Rename to...
	(maps_info_macro::m_cache): ...this.
	(LINEMAPS_CACHE): Delete.
	(LINEMAPS_ORDINARY_CACHE): Delete.
	(LINEMAPS_MACRO_CACHE): Delete.
	* init.cc (read_original_filename): Update for adding "m_" prefix.
	* line-map.cc (linemap_add): Eliminate LINEMAPS_ORDINARY_CACHE in
	favor of a simple field access.
	(linemap_enter_macro): Likewise for LINEMAPS_MACRO_CACHE.
	(linemap_ordinary_map_lookup): Likewise for
	LINEMAPS_ORDINARY_CACHE, twice.
	(linemap_lookup_macro_index): Likewise for LINEMAPS_MACRO_CACHE.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2023-10-08 18:43:17 -04:00
David Malcolm a73c80d997 libcpp: eliminate LINEMAPS_LAST_ALLOCATED{,_ORDINARY,_MACRO}_MAP
Nothing uses these; delete them.

libcpp/ChangeLog:
	* include/line-map.h (LINEMAPS_LAST_ALLOCATED_MAP): Delete.
	(LINEMAPS_LAST_ALLOCATED_ORDINARY_MAP): Delete.
	(LINEMAPS_LAST_ALLOCATED_MACRO_MAP): Delete.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2023-10-08 18:43:17 -04:00
David Malcolm 1f68a3e872 libcpp: eliminate COMBINE_LOCATION_DATA
This patch eliminates the function "COMBINE_LOCATION_DATA" (which hasn't
been a macro since r6-739-g0501dbd932a7e9) and the function
"get_combined_adhoc_loc" in favor of a new
line_maps::get_or_create_combined_loc member function.

No functional change intended.

gcc/cp/ChangeLog:
	* module.cc (module_state::read_location): Update for renaming of
	get_combined_adhoc_loc.

gcc/ChangeLog:
	* genmatch.cc (main): Update for "m_" prefix of some fields of
	line_maps.
	* input.cc (make_location): Update for removal of
	COMBINE_LOCATION_DATA.
	(dump_line_table_statistics): Update for "m_" prefix of some
	fields of line_maps.
	(location_with_discriminator): Update for removal of
	COMBINE_LOCATION_DATA.
	(line_table_test::line_table_test): Update for "m_" prefix of some
	fields of line_maps.
	* toplev.cc (general_init): Likewise.
	* tree.cc (set_block): Update for removal of
	COMBINE_LOCATION_DATA.
	(set_source_range): Likewise.

libcpp/ChangeLog:
	* include/line-map.h (line_maps::reallocator): Rename to...
	(line_maps::m_reallocator): ...this.
	(line_maps::round_alloc_size): Rename to...
	(line_maps::m_round_alloc_size): ...this.
	(line_maps::location_adhoc_data_map): Rename to...
	(line_maps::m_location_adhoc_data_map): ...this.
	(line_maps::num_optimized_ranges): Rename to...
	(line_maps::m_num_optimized_ranges): ..this.
	(line_maps::num_unoptimized_ranges): Rename to...
	(line_maps::m_num_unoptimized_ranges): ...this.
	(get_combined_adhoc_loc): Delete decl.
	(COMBINE_LOCATION_DATA): Delete.
	* lex.cc (get_location_for_byte_range_in_cur_line): Update for
	removal of COMBINE_LOCATION_DATA.
	(warn_about_normalization): Likewise.
	(_cpp_lex_direct): Likewise.
	* line-map.cc (line_maps::~line_maps): Update for "m_" prefix of
	some fields of line_maps.
	(rebuild_location_adhoc_htab): Likewise.
	(can_be_stored_compactly_p): Convert to...
	(line_maps::can_be_stored_compactly_p): ...this private member
	function.
	(get_combined_adhoc_loc): Convert to...
	(line_maps::get_or_create_combined_loc): ...this public member
	function.
	(line_maps::make_location): Update for removal of
	COMBINE_LOCATION_DATA.
	(get_data_from_adhoc_loc): Update for "m_" prefix of some fields
	of line_maps.
	(get_discriminator_from_adhoc_loc): Likewise.
	(get_location_from_adhoc_loc): Likewise.
	(get_range_from_adhoc_loc): Convert to...
	(line_maps::get_range_from_adhoc_loc): ...this private member
	function.
	(line_maps::get_range_from_loc): Update for conversion of
	get_range_from_adhoc_loc to a member function.
	(linemap_init): Update for "m_" prefix of some fields of
	line_maps.
	(line_map_new_raw): Likewise.
	(linemap_enter_macro): Likewise.
	(linemap_get_statistics): Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2023-10-08 18:43:16 -04:00
David Malcolm 25af7c1a80 libcpp: "const" and other cleanups
No functional change intended.

gcc/ChangeLog:
	* input.cc (make_location): Move implementation to
	line_maps::make_location.

libcpp/ChangeLog:
	* include/line-map.h (line_maps::pure_location_p): New decl.
	(line_maps::get_pure_location): New decl.
	(line_maps::get_range_from_loc): New decl.
	(line_maps::get_start): New.
	(line_maps::get_finish): New.
	(line_maps::make_location): New decl.
	(get_range_from_loc): Make line_maps param const.
	(get_discriminator_from_loc): Likewise.
	(pure_location_p): Likewise.
	(get_pure_location): Likewise.
	(linemap_check_files_exited): Likewise.
	(linemap_tracks_macro_expansion_locs_p): Likewise.
	(linemap_location_in_system_header_p): Likewise.
	(linemap_location_from_macro_definition_p): Likewise.
	(linemap_macro_map_loc_unwind_toward_spelling): Likewise.
	(linemap_included_from_linemap): Likewise.
	(first_map_in_common): Likewise.
	(linemap_compare_locations): Likewise.
	(linemap_location_before_p): Likewise.
	(linemap_resolve_location): Likewise.
	(linemap_unwind_toward_expansion): Likewise.
	(linemap_unwind_to_first_non_reserved_loc): Likewise.
	(linemap_expand_location): Likewise.
	(linemap_get_file_highest_location): Likewise.
	(linemap_get_statistics): Likewise.
	(linemap_dump_location): Likewise.
	(linemap_dump): Likewise.
	(line_table_dump): Likewise.
	* internal.h (linemap_get_expansion_line): Likewise.
	(linemap_get_expansion_filename): Likewise.
	* line-map.cc (can_be_stored_compactly_p): Likewise.
	(get_data_from_adhoc_loc): Drop redundant "class".
	(get_discriminator_from_adhoc_loc): Likewise.
	(get_location_from_adhoc_loc): Likewise.
	(get_range_from_adhoc_loc): Likewise.
	(get_range_from_loc): Make const and move implementation to...
	(line_maps::get_range_from_loc): ...this new function.
	(get_discriminator_from_loc): Make line_maps param const.
	(pure_location_p): Make const and move implementation to...
	(line_maps::pure_location_p): ...this new function.
	(get_pure_location): Make const and move implementation to...
	(line_maps::get_pure_location): ...this new function.
	(linemap_included_from_linemap): Make line_maps param const.
	(linemap_check_files_exited): Likewise.
	(linemap_tracks_macro_expansion_locs_p): Likewise.
	(linemap_macro_map_loc_unwind_toward_spelling): Likewise.
	(linemap_get_expansion_line): Likewise.
	(linemap_get_expansion_filename): Likewise.
	(linemap_location_in_system_header_p): Likewise.
	(first_map_in_common_1): Likewise.
	(linemap_compare_locations): Likewise.
	(linemap_macro_loc_to_spelling_point): Likewise.
	(linemap_macro_loc_to_def_point): Likewise.
	(linemap_macro_loc_to_exp_point): Likewise.
	(linemap_resolve_location): Likewise.
	(linemap_location_from_macro_definition_p): Likewise.
	(linemap_unwind_toward_expansion): Likewise.
	(linemap_unwind_to_first_non_reserved_loc): Likewise.
	(linemap_expand_location): Likewise.
	(linemap_dump): Likewise.
	(linemap_dump_location): Likewise.
	(linemap_get_file_highest_location): Likewise.
	(linemap_get_statistics): Likewise.
	(line_table_dump): Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2023-10-08 18:43:16 -04:00
GCC Administrator 4907d220be Daily bump. 2023-09-21 00:17:49 +00:00
Lewis Hyatt 601dbf2a79 libcpp: Fix ICE on #include after a line marker directive [PR61474]
As noted in the PR, GCC will segfault if a file name is first seen in a
linemarker directive, and then later seen in a normal #include.  This is
because the fake include process adds the file to the cache with a null PATH
member. The normal #include finds this file in the cache and then attempts
to use the null PATH.  Resolve by adding the file to the cache with a unique
starting directory, so that the fake entry will only be found by a
subsequent fake include, not by a real one.

libcpp/ChangeLog:

	PR preprocessor/61474
	* files.cc (_cpp_find_file): Set DONT_READ to TRUE for fake
	include files.
	(_cpp_fake_include): Pass a unique cpp_dir* address so
	the fake file will not be found when looked up for real.

gcc/testsuite/ChangeLog:

	PR preprocessor/61474
	* c-c++-common/cpp/pr61474-2.h: New test.
	* c-c++-common/cpp/pr61474.c: New test.
	* c-c++-common/cpp/pr61474.h: New test.
2023-09-20 16:44:24 -04:00
GCC Administrator 590a8bec3e Daily bump. 2023-09-20 00:17:55 +00:00
Ben Boeckel 024f135a1e p1689r5: initial support
This patch implements support for [P1689R5][] to communicate to a build
system the C++20 module dependencies to build systems so that they may
build `.gcm` files in the proper order.

Support is communicated through the following three new flags:

- `-fdeps-format=` specifies the format for the output. Currently named
  `p1689r5`.

- `-fdeps-file=` specifies the path to the file to write the format to.

- `-fdeps-target=` specifies the `.o` that will be written for the TU
  that is scanned. This is required so that the build system can
  correlate the dependency output with the actual compilation that will
  occur.

CMake supports this format as of 17 Jun 2022 (to be part of 3.25.0)
using an experimental feature selection (to allow for future usage
evolution without committing to how it works today). While it remains
experimental, docs may be found in CMake's documentation for
experimental features.

Future work may include using this format for Fortran module
dependencies as well, however this is still pending work.

[P1689R5]: https://isocpp.org/files/papers/P1689R5.html
[cmake-experimental]: https://gitlab.kitware.com/cmake/cmake/-/blob/master/Help/dev/experimental.rst

TODO:

- header-unit information fields

Header units (including the standard library headers) are 100%
unsupported right now because the `-E` mechanism wants to import their
BMIs. A new mode (i.e., something more workable than existing `-E`
behavior) that mocks up header units as if they were imported purely
from their path and content would be required.

- non-utf8 paths

The current standard says that paths that are not unambiguously
represented using UTF-8 are not supported (because these cases are rare
and the extra complication is not worth it at this time). Future
versions of the format might have ways of encoding non-UTF-8 paths. For
now, this patch just doesn't support non-UTF-8 paths (ignoring the
"unambiguously representable in UTF-8" case).

- figure out why junk gets placed at the end of the file

Sometimes it seems like the file gets a lot of `NUL` bytes appended to
it. It happens rarely and seems to be the result of some
`ftruncate`-style call which results in extra padding in the contents.
Noting it here as an observation at least.

libcpp/

	* include/cpplib.h: Add cpp_fdeps_format enum.
	(cpp_options): Add fdeps_format field
	(cpp_finish): Add structured dependency fdeps_stream parameter.
	* include/mkdeps.h (deps_add_module_target): Add flag for
	whether a module is exported or not.
	(fdeps_add_target): Add function.
	(deps_write_p1689r5): Add function.
	* init.cc (cpp_finish): Add new preprocessor parameter used for C++
	module tracking.
	* mkdeps.cc (mkdeps): Implement P1689R5 output.

gcc/

	* doc/invoke.texi: Document -fdeps-format=, -fdeps-file=, and
	-fdeps-target= flags.
	* gcc.cc: add defaults for -fdeps-target= and -fdeps-file= when
	only -fdeps-format= is specified.
	* json.h: Add a TODO item to refactor out to share with
	`libcpp/mkdeps.cc`.

gcc/c-family/

	* c-opts.cc (c_common_handle_option): Add fdeps_file variable and
	-fdeps-format=, -fdeps-file=, and -fdeps-target= parsing.
	* c.opt: Add -fdeps-format=, -fdeps-file=, and -fdeps-target=
	flags.

gcc/cp/

	* module.cc (preprocessed_module): Pass whether the module is
	exported to dependency tracking.

gcc/testsuite/

	* g++.dg/modules/depflags-f-MD.C: New test.
	* g++.dg/modules/depflags-f.C: New test.
	* g++.dg/modules/depflags-fi.C: New test.
	* g++.dg/modules/depflags-fj-MD.C: New test.
	* g++.dg/modules/depflags-fj.C: New test.
	* g++.dg/modules/depflags-fjo-MD.C: New test.
	* g++.dg/modules/depflags-fjo.C: New test.
	* g++.dg/modules/depflags-fo-MD.C: New test.
	* g++.dg/modules/depflags-fo.C: New test.
	* g++.dg/modules/depflags-j-MD.C: New test.
	* g++.dg/modules/depflags-j.C: New test.
	* g++.dg/modules/depflags-jo-MD.C: New test.
	* g++.dg/modules/depflags-jo.C: New test.
	* g++.dg/modules/depflags-o-MD.C: New test.
	* g++.dg/modules/depflags-o.C: New test.
	* g++.dg/modules/p1689-1.C: New test.
	* g++.dg/modules/p1689-1.exp.ddi: New test expectation.
	* g++.dg/modules/p1689-2.C: New test.
	* g++.dg/modules/p1689-2.exp.ddi: New test expectation.
	* g++.dg/modules/p1689-3.C: New test.
	* g++.dg/modules/p1689-3.exp.ddi: New test expectation.
	* g++.dg/modules/p1689-4.C: New test.
	* g++.dg/modules/p1689-4.exp.ddi: New test expectation.
	* g++.dg/modules/p1689-5.C: New test.
	* g++.dg/modules/p1689-5.exp.ddi: New test expectation.
	* g++.dg/modules/modules.exp: Load new P1689 library routines.
	* g++.dg/modules/test-p1689.py: New tool for validating P1689 output.
	* lib/modules.exp: Support for validating P1689 outputs.

Signed-off-by: Ben Boeckel <ben.boeckel@kitware.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
2023-09-19 17:32:23 -04:00
GCC Administrator a134b6ce8e Daily bump. 2023-09-07 00:17:36 +00:00
Jakub Jelinek f76ae4369c C _BitInt incremental fixes [PR102989]
On Wed, Aug 09, 2023 at 09:17:57PM +0000, Joseph Myers wrote:
> > - _Complex _BitInt(N) isn't supported; again mainly because none of the psABIs
> >   mention how those should be passed/returned; in a limited way they are
> >   supported internally because the internal functions into which
> >   __builtin_{add,sub,mul}_overflow{,_p} is lowered return COMPLEX_TYPE as a
> >   hack to return 2 values without using references/pointers
>
> What happens when the usual arithmetic conversions are applied to
> operands, one of which is a complex integer type and the other of which is
> a wider _BitInt type?  I don't see anything in the code to disallow this
> case (which would produce an expression with a _Complex _BitInt type), or
> any testcases for it.

I've added a sorry for that case (+ return the narrower COMPLEX_TYPE).
Also added testcase to verify we don't create VECTOR_TYPEs of BITINT_TYPE
even if they have mode precision and suitable size (others were rejected
already before).

> Other testcases I think should be present (along with any corresponding
> changes needed to the code itself):
>
> * Verifying that the new integer constant suffix is rejected for C++.

Done.

> * Verifying appropriate pedwarn-if-pedantic for the new constant suffix
> for versions of C before C2x (and probably for use of _BitInt type
> specifiers before C2x as well) - along with the expected -Wc11-c2x-compat
> handling (in C2x mode) / -pedantic -Wno-c11-c2x-compat in older modes.

Done.

Here is an incremental patch which does that.

2023-09-06  Jakub Jelinek  <jakub@redhat.com>

	PR c/102989
gcc/c/
	* c-decl.cc (finish_declspecs): Emit pedwarn_c11 on _BitInt.
	* c-typeck.cc (c_common_type): Emit sorry for common type between
	_Complex integer and larger _BitInt and return the _Complex integer.
gcc/c-family/
	* c-attribs.cc (type_valid_for_vector_size): Reject vector types
	with BITINT_TYPE elements even if they have mode precision and
	suitable size.
gcc/testsuite/
	* gcc.dg/bitint-19.c: New test.
	* gcc.dg/bitint-20.c: New test.
	* gcc.dg/bitint-21.c: New test.
	* gcc.dg/bitint-22.c: New test.
	* gcc.dg/bitint-23.c: New test.
	* gcc.dg/bitint-24.c: New test.
	* gcc.dg/bitint-25.c: New test.
	* gcc.dg/bitint-26.c: New test.
	* gcc.dg/bitint-27.c: New test.
	* g++.dg/ext/bitint1.C: New test.
	* g++.dg/ext/bitint2.C: New test.
	* g++.dg/ext/bitint3.C: New test.
	* g++.dg/ext/bitint4.C: New test.
libcpp/
	* expr.cc (cpp_classify_number): Diagnose wb literal suffixes
	for -pedantic* before C2X or -Wc11-c2x-compat.
2023-09-06 17:39:15 +02:00
Jakub Jelinek 8c984a1c36 C _BitInt support [PR102989]
This patch adds the C FE support, c-family support, small libcpp change
so that 123wb and 42uwb suffixes are handled plus glimits.h change
to define BITINT_MAXWIDTH macro.

The previous patches really do nothing without this, which enables
all the support.

2023-09-06  Jakub Jelinek  <jakub@redhat.com>

	PR c/102989
gcc/
	* glimits.h (BITINT_MAXWIDTH): Define if __BITINT_MAXWIDTH__ is
	predefined.
gcc/c-family/
	* c-common.cc (c_common_reswords): Add _BitInt as keyword.
	(unsafe_conversion_p): Handle BITINT_TYPE like INTEGER_TYPE.
	(c_common_signed_or_unsigned_type): Handle BITINT_TYPE.
	(c_common_truthvalue_conversion, c_common_get_alias_set,
	check_builtin_function_arguments): Handle BITINT_TYPE like
	INTEGER_TYPE.
	(sync_resolve_size): Add ORIG_FORMAT argument.  If
	FETCH && !ORIG_FORMAT, type is BITINT_TYPE, return -1 if size isn't
	one of 1, 2, 4, 8 or 16 or if it is 16 but TImode is not supported.
	(atomic_bitint_fetch_using_cas_loop): New function.
	(resolve_overloaded_builtin): Adjust sync_resolve_size caller.  If
	-1 is returned, use atomic_bitint_fetch_using_cas_loop to lower it.
	Formatting fix.
	(keyword_begins_type_specifier): Handle RID_BITINT.
	* c-common.h (enum rid): Add RID_BITINT enumerator.
	* c-cppbuiltin.cc (c_cpp_builtins): For C call
	targetm.c.bitint_type_info and predefine __BITINT_MAXWIDTH__
	and for -fbuilding-libgcc also __LIBGCC_BITINT_LIMB_WIDTH__ and
	__LIBGCC_BITINT_ORDER__ macros if _BitInt is supported.
	* c-lex.cc (interpret_integer): Handle CPP_N_BITINT.
	* c-pretty-print.cc (c_pretty_printer::simple_type_specifier,
	c_pretty_printer::direct_abstract_declarator,
	c_pretty_printer::direct_declarator, c_pretty_printer::declarator):
	Handle BITINT_TYPE.
	(pp_c_integer_constant): Handle printing of large precision wide_ints
	which would buffer overflow digit_buffer.
	* c-warn.cc (conversion_warning, warnings_for_convert_and_check,
	warnings_for_convert_and_check): Handle BITINT_TYPE like
	INTEGER_TYPE.
gcc/c/
	* c-convert.cc (c_convert): Handle BITINT_TYPE like INTEGER_TYPE.
	* c-decl.cc (check_bitfield_type_and_width): Allow BITINT_TYPE
	bit-fields.
	(finish_struct): Prefer to use BITINT_TYPE for BITINT_TYPE bit-fields
	if possible.
	(declspecs_add_type): Formatting fixes.  Handle cts_bitint.  Adjust
	for added union in *specs.  Handle RID_BITINT.
	(finish_declspecs): Handle cts_bitint.  Adjust for added union
	in *specs.
	* c-parser.cc (c_keyword_starts_typename, c_token_starts_declspecs,
	c_parser_declspecs, c_parser_gnu_attribute_any_word): Handle
	RID_BITINT.
	(c_parser_omp_clause_schedule): Handle BITINT_TYPE like INTEGER_TYPE.
	* c-tree.h (enum c_typespec_keyword): Mention _BitInt in comment.
	Add cts_bitint enumerator.
	(struct c_declspecs): Move int_n_idx and floatn_nx_idx into a union
	and add bitint_prec there as well.
	* c-typeck.cc (c_common_type, comptypes_internal):
	Handle BITINT_TYPE.
	(perform_integral_promotions): Promote BITINT_TYPE bit-fields to
	their declared type.
	(build_array_ref, build_unary_op, build_conditional_expr,
	build_c_cast, convert_for_assignment, digest_init, build_binary_op):
	Handle BITINT_TYPE.
	* c-fold.cc (c_fully_fold_internal): Handle BITINT_TYPE like
	INTEGER_TYPE.
	* c-aux-info.cc (gen_type): Handle BITINT_TYPE.
libcpp/
	* expr.cc (interpret_int_suffix): Handle wb and WB suffixes.
	* include/cpplib.h (CPP_N_BITINT): Define.
2023-09-06 17:34:49 +02:00
GCC Administrator 4b92dba78d Daily bump. 2023-08-08 00:17:37 +00:00
Alan Modra 1d6c6dc947
egrep in binutils
Apparently some distros have a nagging egrep that helpfully tells you
egrep is deprecated and to use "grep -E".  The nag message causes a ld
testsuite failure.  What's more the advice isn't that good.  The "-E"
flag may not be available with older versions of grep.

This patch fixes bare invocation of egrep within binutils, replacing
it with the autoconf $EGREP or with grep.

config/ChangeLog:

	* lib-ld.m4 (AC_LIB_PROG_LD_GNU): Require AC_PROG_EGREP and
	invoke $EGREP.
	(AC_LIB_PROG_LD): Likewise.

gcc/ChangeLog:

	* configure: Regenerate.

intl/ChangeLog:

	* configure: Regenerate.

libcpp/ChangeLog:

	* configure: Regenerate.

libgcc/ChangeLog:

	* configure: Regenerate.

libstdc++-v3/ChangeLog:

	* configure: Regenerate.
2023-08-07 22:59:40 +02:00
GCC Administrator 49bed11d96 Daily bump. 2023-07-20 00:17:53 +00:00
Lewis Hyatt 1d3e4f4e2d libcpp: Handle extended characters in user-defined literal suffix [PR103902]
The PR complains that we do not handle UTF-8 in the suffix for a user-defined
literal, such as:

bool operator ""_π (unsigned long long);

In fact we don't handle any extended identifier characters there, whether
UTF-8, UCNs, or the $ sign. We do handle it fine if the optional space after
the "" tokens is included, since then the identifier is lexed in the
"normal" way as its own token. But when it is lexed as part of the string
token, this is handled in lex_string() with a one-off loop that is not aware
of extended characters.

This patch fixes it by adding a new function scan_cur_identifier() that can
be used to lex an identifier while in the middle of lexing another token.

BTW, the other place that has been mis-lexing identifiers is
lex_identifier_intern(), which is used to implement #pragma push_macro
and #pragma pop_macro. This does not support extended characters either.
I will add that in a subsequent patch, because it can't directly reuse the
new function, but rather needs to lex from a string instead of a cpp_buffer.

With scan_cur_identifier(), we do also correctly warn about bidi and
normalization issues in the extended identifiers comprising the suffix.

libcpp/ChangeLog:

	PR preprocessor/103902
	* lex.cc (identifier_diagnostics_on_lex): New function refactoring
	some common code.
	(lex_identifier_intern): Use the new function.
	(lex_identifier): Don't run identifier diagnostics here, rather let
	the call site do it when needed.
	(_cpp_lex_direct): Adjust the call sites of lex_identifier ()
	acccordingly.
	(struct scan_id_result): New struct.
	(scan_cur_identifier): New function.
	(create_literal2): New function.
	(lit_accum::create_literal2): New function.
	(is_macro): Folded into new function...
	(maybe_ignore_udl_macro_suffix): ...here.
	(is_macro_not_literal_suffix): Folded likewise.
	(lex_raw_string): Handle UTF-8 in UDL suffix via
	scan_cur_identifier ().
	(lex_string): Likewise.

gcc/testsuite/ChangeLog:

	PR preprocessor/103902
	* g++.dg/cpp0x/udlit-extended-id-1.C: New test.
	* g++.dg/cpp0x/udlit-extended-id-2.C: New test.
	* g++.dg/cpp0x/udlit-extended-id-3.C: New test.
	* g++.dg/cpp0x/udlit-extended-id-4.C: New test.
2023-07-18 22:37:55 -04:00
GCC Administrator 738808bd9a Daily bump. 2023-07-07 00:17:17 +00:00
Thomas Schwinge 62db795a8f GTY: Enhance 'string_length' option documentation
We're (currently) not aware of any actual use of 'ht_identifier's with NUL
characters embedded; its 'len' field appears to exist for optimization
purposes, since "forever".  Before 'struct ht_identifier' was added in
commit 2a967f3d3a (Subversion r42334), we had in
'gcc/cpplib.h:struct cpp_hashnode': 'unsigned short len', or earlier 'length',
earlier in 'gcc/cpphash.h:struct hashnode': 'unsigned short length', earlier
'size_t length' with comment: "length of token, for quick comparison", earlier
'int length', ever since the 'gcc/cpp*' files were added in
commit 7f2935c734 (Subversion r9191).

This amends commit f3b957ea8b
"pch: Fix streaming of strings with embedded null bytes".

	gcc/
	* doc/gty.texi (GTY Options) <string_length>: Enhance.
	libcpp/
	* include/symtab.h (struct ht_identifier): Document different
	rationale.
2023-07-06 11:59:08 +02:00
GCC Administrator 6f78df4cdb Daily bump. 2023-06-24 00:17:01 +00:00
Marek Polacek 5388a43f6a c++: Add support for -std={c,gnu}++2{c,6}
It seems prudent to add C++26 now that the first C++26 papers have been
approved.  I followed commit r11-6920 as well as r8-3237.

Since C++23 is essentially finished and its __cplusplus value has
settled to 202302L, I've updated cpp_init_builtins and marked
-std=c++2b Undocumented and made -std=c++23 no longer Undocumented.

As for __cplusplus, I've chosen 202400L:

  $ xg++ -std=c++26 -dM -E -x c++ - < /dev/null | grep cplusplus
  #define __cplusplus 202400L

I've verified the patch with a simple test, exercising the new
directives.  Don't forget to update your GXX_TESTSUITE_STDS!

This patch does not add -Wc++26-extensions.

gcc/c-family/ChangeLog:

	* c-common.h (cxx_dialect): Add cxx26 as a dialect.
	* c-opts.cc (set_std_cxx26): New.
	(c_common_handle_option): Set options when -std={c,gnu}++2{c,6} is
	enabled.
	(c_common_post_options): Adjust comments.
	* c.opt: Add options for -std=c++26, std=c++2c, -std=gnu++26,
	and -std=gnu++2c.
	(std=c++2b): Mark as Undocumented.
	(std=c++23): No longer Undocumented.

gcc/ChangeLog:

	* doc/cpp.texi (__cplusplus): Document value for -std=c++26 and
	-std=gnu++26.  Document that for C++23, its value is 202302L.
	* doc/invoke.texi: Document -std=c++26 and -std=gnu++26.
	* dwarf2out.cc (highest_c_language): Handle GNU C++26.
	(gen_compile_unit_die): Likewise.

libcpp/ChangeLog:

	* include/cpplib.h (c_lang): Add CXX26 and GNUCXX26.
	* init.cc (lang_defaults): Add rows for CXX26 and GNUCXX26.
	(cpp_init_builtins): Set __cplusplus to 202400L for C++26.
	Set __cplusplus to 202302L for C++23.

gcc/testsuite/ChangeLog:

	* lib/target-supports.exp (check_effective_target_c++23): Return
	1 also if check_effective_target_c++26.
	(check_effective_target_c++23_down): New.
	(check_effective_target_c++26_only): New.
	(check_effective_target_c++26): New.
	* g++.dg/cpp23/cplusplus.C: Adjust expected value.
	* g++.dg/cpp26/cplusplus.C: New test.
2023-06-23 16:46:29 -04:00
Ben Boeckel b7fc0a3be5 libcpp: allow UCS_LIMIT codepoints in UTF-8 strings
Fixes r14-1954 (libcpp: reject codepoints above 0x10FFFF, 2023-06-06)

libcpp/

	* charset.cc: Allow `UCS_LIMIT` in UTF-8 strings.

Reported-by: Damien Guibouret <damien.guibouret@partition-saving.com>
Signed-off-by: Ben Boeckel <ben.boeckel@kitware.com>
2023-06-23 16:04:12 -04:00
GCC Administrator 270742ceb5 Daily bump. 2023-06-23 00:16:38 +00:00
David Malcolm 4f01ae3761 diagnostics: add support for "text art" diagrams
Existing text output in GCC has to be implemented by writing
sequentially to a pretty_printer instance.  This makes it
hard to implement some kinds of diagnostic output (see e.g.
diagnostic-show-locus.cc).

This patch adds more flexible ways of creating text output:
- a canvas class, which can be "painted" to via random-access (rather
that sequentially)
- a table class for 2D grid layout, supporting items that span
multiple rows/columns
- a widget class for organizing diagrams hierarchically.

The patch also expands GCC's diagnostics subsystem so that diagnostics
can have "text art" diagrams - think ASCII art, but potentially
including some Unicode characters, such as box-drawing chars.

The new code is in a new "gcc/text-art" subdirectory and "text_art"
namespace.

The patch adds a new "-fdiagnostics-text-art-charset=VAL" option, with
values:
- "none": don't emit diagrams (added to -fdiagnostics-plain-output)
- "ascii": use pure ASCII in diagrams
- "unicode": allow for conservative use of unicode drawing characters
(such as box-drawing characters).
- "emoji" (the default): as "unicode", but potentially allow for
conservative use of emoji in the output (such as U+26A0 WARNING SIGN).
I made it possible to disable emoji separately from unicode as I believe
there's a generation gap in acceptance of these characters (some older
programmers have a visceral reaction against them, whereas younger
programmers may have no problem with them).

Diagrams are emitted to stderr by default.  With SARIF output they are
captured as a location in "relatedLocations", with the diagram as a
code block in Markdown within a "markdown" property of a message.

This patch doesn't add any such diagram usage to GCC, saving that for
followups, apart from adding a plugin to the test suite to exercise the
functionality.

contrib/ChangeLog:
	* unicode/gen-box-drawing-chars.py: New file.
	* unicode/gen-combining-chars.py: New file.
	* unicode/gen-printable-chars.py: New file.

gcc/ChangeLog:
	* Makefile.in (OBJS-libcommon): Add text-art/box-drawing.o,
	text-art/canvas.o, text-art/ruler.o, text-art/selftests.o,
	text-art/style.o, text-art/styled-string.o, text-art/table.o,
	text-art/theme.o, and text-art/widget.o.
	* color-macros.h (COLOR_FG_BRIGHT_BLACK): New.
	(COLOR_FG_BRIGHT_RED): New.
	(COLOR_FG_BRIGHT_GREEN): New.
	(COLOR_FG_BRIGHT_YELLOW): New.
	(COLOR_FG_BRIGHT_BLUE): New.
	(COLOR_FG_BRIGHT_MAGENTA): New.
	(COLOR_FG_BRIGHT_CYAN): New.
	(COLOR_FG_BRIGHT_WHITE): New.
	(COLOR_BG_BRIGHT_BLACK): New.
	(COLOR_BG_BRIGHT_RED): New.
	(COLOR_BG_BRIGHT_GREEN): New.
	(COLOR_BG_BRIGHT_YELLOW): New.
	(COLOR_BG_BRIGHT_BLUE): New.
	(COLOR_BG_BRIGHT_MAGENTA): New.
	(COLOR_BG_BRIGHT_CYAN): New.
	(COLOR_BG_BRIGHT_WHITE): New.
	* common.opt (fdiagnostics-text-art-charset=): New option.
	(diagnostic-text-art.h): New SourceInclude.
	(diagnostic_text_art_charset) New Enum and EnumValues.
	* configure: Regenerate.
	* configure.ac (gccdepdir): Add text-art to loop.
	* diagnostic-diagram.h: New file.
	* diagnostic-format-json.cc (json_emit_diagram): New.
	(diagnostic_output_format_init_json): Wire it up to
	context->m_diagrams.m_emission_cb.
	* diagnostic-format-sarif.cc: Include "diagnostic-diagram.h" and
	"text-art/canvas.h".
	(sarif_result::on_nested_diagnostic): Move code to...
	(sarif_result::add_related_location): ...this new function.
	(sarif_result::on_diagram): New.
	(sarif_builder::emit_diagram): New.
	(sarif_builder::make_message_object_for_diagram): New.
	(sarif_emit_diagram): New.
	(diagnostic_output_format_init_sarif): Set
	context->m_diagrams.m_emission_cb to sarif_emit_diagram.
	* diagnostic-text-art.h: New file.
	* diagnostic.cc: Include "diagnostic-text-art.h",
	"diagnostic-diagram.h", and "text-art/theme.h".
	(diagnostic_initialize): Initialize context->m_diagrams and
	call diagnostics_text_art_charset_init.
	(diagnostic_finish): Clean up context->m_diagrams.m_theme.
	(diagnostic_emit_diagram): New.
	(diagnostics_text_art_charset_init): New.
	* diagnostic.h (text_art::theme): New forward decl.
	(class diagnostic_diagram): Likewise.
	(diagnostic_context::m_diagrams): New field.
	(diagnostic_emit_diagram): New decl.
	* doc/invoke.texi (Diagnostic Message Formatting Options): Add
	-fdiagnostics-text-art-charset=.
	(-fdiagnostics-plain-output): Add
	-fdiagnostics-text-art-charset=none.
	* gcc.cc: Include "diagnostic-text-art.h".
	(driver_handle_option): Handle OPT_fdiagnostics_text_art_charset_.
	* opts-common.cc (decode_cmdline_options_to_array): Add
	"-fdiagnostics-text-art-charset=none" to expanded_args for
	-fdiagnostics-plain-output.
	* opts.cc: Include "diagnostic-text-art.h".
	(common_handle_option): Handle OPT_fdiagnostics_text_art_charset_.
	* pretty-print.cc (pp_unicode_character): New.
	* pretty-print.h (pp_unicode_character): New decl.
	* selftest-run-tests.cc: Include "text-art/selftests.h".
	(selftest::run_tests): Call text_art_tests.
	* text-art/box-drawing-chars.inc: New file, generated by
	contrib/unicode/gen-box-drawing-chars.py.
	* text-art/box-drawing.cc: New file.
	* text-art/box-drawing.h: New file.
	* text-art/canvas.cc: New file.
	* text-art/canvas.h: New file.
	* text-art/ruler.cc: New file.
	* text-art/ruler.h: New file.
	* text-art/selftests.cc: New file.
	* text-art/selftests.h: New file.
	* text-art/style.cc: New file.
	* text-art/styled-string.cc: New file.
	* text-art/table.cc: New file.
	* text-art/table.h: New file.
	* text-art/theme.cc: New file.
	* text-art/theme.h: New file.
	* text-art/types.h: New file.
	* text-art/widget.cc: New file.
	* text-art/widget.h: New file.

gcc/testsuite/ChangeLog:
	* gcc.dg/plugin/diagnostic-test-text-art-ascii-bw.c: New test.
	* gcc.dg/plugin/diagnostic-test-text-art-ascii-color.c: New test.
	* gcc.dg/plugin/diagnostic-test-text-art-none.c: New test.
	* gcc.dg/plugin/diagnostic-test-text-art-unicode-bw.c: New test.
	* gcc.dg/plugin/diagnostic-test-text-art-unicode-color.c: New test.
	* gcc.dg/plugin/diagnostic_plugin_test_text_art.c: New test plugin.
	* gcc.dg/plugin/plugin.exp (plugin_test_list): Add them.

libcpp/ChangeLog:
	* charset.cc (get_cppchar_property): New function template, based
	on...
	(cpp_wcwidth): ...this function.  Rework to use the above.
	Include "combining-chars.inc".
	(cpp_is_combining_char): New function
	Include "printable-chars.inc".
	(cpp_is_printable_char): New function
	* combining-chars.inc: New file, generated by
	contrib/unicode/gen-combining-chars.py.
	* include/cpplib.h (cpp_is_combining_char): New function decl.
	(cpp_is_printable_char): New function decl.
	* printable-chars.inc: New file, generated by
	contrib/unicode/gen-printable-chars.py.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2023-06-21 21:49:00 -04:00
GCC Administrator bfc6d29f8b Daily bump. 2023-06-21 00:17:14 +00:00
Lewis Hyatt 4f3be7cbeb libcpp: Improve location for macro names [PR66290]
When libcpp reports diagnostics whose locus is a macro name (such as for
-Wunused-macros), it uses the location in the cpp_macro object that was
stored by _cpp_new_macro. This is currently set to pfile->directive_line,
which contains the line number only and no column information. This patch
changes the stored location to the src_loc for the token defining the macro
name, which includes the location and range information.

libcpp/ChangeLog:

	PR c++/66290
	* macro.cc (_cpp_create_definition): Add location argument.
	* internal.h (_cpp_create_definition): Adjust prototype.
	* directives.cc (do_define): Pass new location argument to
	_cpp_create_definition.
	(do_undef): Stop passing inferior location to cpp_warning_with_line;
	the default from cpp_warning is better.
	(cpp_pop_definition): Pass new location argument to
	_cpp_create_definition.
	* pch.cc (cpp_read_state): Likewise.

gcc/testsuite/ChangeLog:

	PR c++/66290
	* c-c++-common/cpp/macro-ranges.c: New test.
	* c-c++-common/cpp/line-2.c: Adapt to check for column information
	on macro-related libcpp warnings.
	* c-c++-common/cpp/line-3.c: Likewise.
	* c-c++-common/cpp/macro-arg-count-1.c: Likewise.
	* c-c++-common/cpp/pr58844-1.c: Likewise.
	* c-c++-common/cpp/pr58844-2.c: Likewise.
	* c-c++-common/cpp/warning-zero-location.c: Likewise.
	* c-c++-common/pragma-diag-14.c: Likewise.
	* c-c++-common/pragma-diag-15.c: Likewise.
	* g++.dg/modules/macro-2_d.C: Likewise.
	* g++.dg/modules/macro-4_d.C: Likewise.
	* g++.dg/modules/macro-4_e.C: Likewise.
	* g++.dg/spellcheck-macro-ordering.C: Likewise.
	* gcc.dg/builtin-redefine.c: Likewise.
	* gcc.dg/cpp/Wunused.c: Likewise.
	* gcc.dg/cpp/redef2.c: Likewise.
	* gcc.dg/cpp/redef3.c: Likewise.
	* gcc.dg/cpp/redef4.c: Likewise.
	* gcc.dg/cpp/ucnid-11-utf8.c: Likewise.
	* gcc.dg/cpp/ucnid-11.c: Likewise.
	* gcc.dg/cpp/undef2.c: Likewise.
	* gcc.dg/cpp/warn-redefined-2.c: Likewise.
	* gcc.dg/cpp/warn-redefined.c: Likewise.
	* gcc.dg/cpp/warn-unused-macros-2.c: Likewise.
	* gcc.dg/cpp/warn-unused-macros.c: Likewise.
2023-06-20 16:58:12 -04:00
GCC Administrator e517d3f571 Daily bump. 2023-06-20 00:17:14 +00:00
Ben Boeckel c1dbaa6656 libcpp: reject codepoints above 0x10FFFF
Unicode does not support such values because they are unrepresentable in
UTF-16.

libcpp/

	* charset.cc: Reject encodings of codepoints above 0x10FFFF.
	UTF-16 does not support such codepoints and therefore all
	Unicode rejects such values.

Signed-off-by: Ben Boeckel <ben.boeckel@kitware.com>
2023-06-19 17:20:41 -04:00
GCC Administrator 7ff793415f Daily bump. 2023-06-16 00:17:18 +00:00
Marek Polacek b6cb10af12 configure: Implement --enable-host-pie
[ This is my third attempt to add this configure option.  The first
version was approved but it came too late in the development cycle.
The second version was also approved, but I had to revert it:
<https://gcc.gnu.org/pipermail/gcc-patches/2022-November/607082.html>.
I've fixed the problem (by moving $(PICFLAG) from INTERNAL_CFLAGS to
ALL_COMPILERFLAGS).  Another change is that since r13-4536 I no longer
need to touch Makefile.def, so this patch is simplified. ]

This patch implements the --enable-host-pie configure option which
makes the compiler executables PIE.  This can be used to enhance
protection against ROP attacks, and can be viewed as part of a wider
trend to harden binaries.

It is similar to the option --enable-host-shared, except that --e-h-s
won't add -shared to the linker flags whereas --e-h-p will add -pie.
It is different from --enable-default-pie because that option just
adds an implicit -fPIE/-pie when the compiler is invoked, but the
compiler itself isn't PIE.

Since r12-5768-gfe7c3ecf, PCH works well with PIE, so there are no PCH
regressions.

When building the compiler, the build process may use various in-tree
libraries; these need to be built with -fPIE so that it's possible to
use them when building a PIE.  For instance, when --with-included-gettext
is in effect, intl object files must be compiled with -fPIE.  Similarly,
when building in-tree gmp, isl, mpfr and mpc, they must be compiled with
-fPIE.

With this patch and --enable-host-pie used to configure gcc:

$ file gcc/cc1{,plus,obj,gm2} gcc/f951 gcc/lto1 gcc/cpp gcc/go1 gcc/rust1 gcc/gnat1
gcc/cc1:     ELF 64-bit LSB pie executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=98e22cde129d304aa6f33e61b1c39e144aeb135e, for GNU/Linux 3.2.0, with debug_info, not stripped
gcc/cc1plus: ELF 64-bit LSB pie executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=859d1ea37e43dfe50c18fd4e3dd9a34bb1db8f77, for GNU/Linux 3.2.0, with debug_info, not stripped
gcc/cc1obj:  ELF 64-bit LSB pie executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=1964f8ecee6163182bc26134e2ac1f324816e434, for GNU/Linux 3.2.0, with debug_info, not stripped
gcc/cc1gm2:  ELF 64-bit LSB pie executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=a396672c7ff913d21855829202e7b02ecf42ff4c, for GNU/Linux 3.2.0, with debug_info, not stripped
gcc/f951:    ELF 64-bit LSB pie executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=59c523db893186547ac75c7a71f48be0a461c06b, for GNU/Linux 3.2.0, with debug_info, not stripped
gcc/lto1:    ELF 64-bit LSB pie executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=084a7b77df7be2d63c2d4c655b5bbc3fcdb6038d, for GNU/Linux 3.2.0, with debug_info, not stripped
gcc/cpp:     ELF 64-bit LSB pie executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=3503bf8390d219a10d6653b8560aa21158132168, for GNU/Linux 3.2.0, with debug_info, not stripped
gcc/go1:     ELF 64-bit LSB pie executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=988cc673af4fba5dcb482f4b34957b99050a68c5, for GNU/Linux 3.2.0, with debug_info, not stripped
gcc/rust1:   ELF 64-bit LSB pie executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=b6a5d3d514446c4dcdee0707f086ab9b274a8a3c, for GNU/Linux 3.2.0, with debug_info, not stripped
gcc/gnat1:   ELF 64-bit LSB pie executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=bb11ccdc2c366fe3fe0980476bcd8ca19b67f9dc, for GNU/Linux 3.2.0, with debug_info, not stripped

I plan to add an option to link with -Wl,-z,now.

Bootstrapped on x86_64-pc-linux-gnu with --with-included-gettext
--enable-host-pie as well as without --enable-host-pie.  Also tested
on a Debian system where the system gcc was configured with
--enable-default-pie.

Co-Authored by: Iain Sandoe  <iain@sandoe.co.uk>

ChangeLog:

	* configure.ac (--enable-host-pie): New check.  Set PICFLAG after this
	check.
	* configure: Regenerate.

c++tools/ChangeLog:

	* Makefile.in: Rename PIEFLAG to PICFLAG.  Set LD_PICFLAG.  Use it.
	Use pic/libiberty.a if PICFLAG is set.
	* configure.ac (--enable-default-pie): Set PICFLAG instead of PIEFLAG.
	(--enable-host-pie): New check.
	* configure: Regenerate.

fixincludes/ChangeLog:

	* Makefile.in: Set and use PICFLAG and LD_PICFLAG.  Use the "pic"
	build of libiberty if PICFLAG is set.
	* configure.ac:
	* configure: Regenerate.

gcc/ChangeLog:

	* Makefile.in: Set LD_PICFLAG.  Use it.  Set enable_host_pie.
	Remove NO_PIE_CFLAGS and NO_PIE_FLAG.  Pass LD_PICFLAG to
	ALL_LINKERFLAGS.  Use the "pic" build of libiberty if --enable-host-pie.
	* configure.ac (--enable-host-shared): Don't set PICFLAG here.
	(--enable-host-pie): New check.  Set PICFLAG and LD_PICFLAG after this
	check.
	* configure: Regenerate.
	* doc/install.texi: Document --enable-host-pie.

gcc/ada/ChangeLog:

	* gcc-interface/Make-lang.in (ALL_ADAFLAGS): Remove NO_PIE_CFLAGS.  Add
	PICFLAG.  Use PICFLAG when building ada/b_gnat1.o and ada/b_gnatb.o.
	* gcc-interface/Makefile.in: Use pic/libiberty.a if PICFLAG is set.
	Remove NO_PIE_FLAG.

gcc/m2/ChangeLog:

	* Make-lang.in: New var, GM2_PICFLAGS.  Use it.

gcc/d/ChangeLog:

	* Make-lang.in: Remove NO_PIE_CFLAGS.

intl/ChangeLog:

	* Makefile.in: Use @PICFLAG@ in COMPILE as well.
	* configure.ac (--enable-host-shared): Don't set PICFLAG here.
	(--enable-host-pie): New check.  Set PICFLAG after this check.
	* configure: Regenerate.

libcody/ChangeLog:

	* Makefile.in: Pass LD_PICFLAG to LDFLAGS.
	* configure.ac (--enable-host-shared): Don't set PICFLAG here.
	(--enable-host-pie): New check.  Set PICFLAG and LD_PICFLAG after this
	check.
	* configure: Regenerate.

libcpp/ChangeLog:

	* configure.ac (--enable-host-shared): Don't set PICFLAG here.
	(--enable-host-pie): New check.  Set PICFLAG after this check.
	* configure: Regenerate.

libdecnumber/ChangeLog:

	* configure.ac (--enable-host-shared): Don't set PICFLAG here.
	(--enable-host-pie): New check.  Set PICFLAG after this check.
	* configure: Regenerate.

libiberty/ChangeLog:

	* configure.ac: Also set shared when enable_host_pie.
	* configure: Regenerate.

zlib/ChangeLog:

	* configure.ac (--enable-host-shared): Don't set PICFLAG here.
	(--enable-host-pie): New check.  Set PICFLAG after this check.
	* configure: Regenerate.
2023-06-15 16:51:27 -04:00
Jakub Jelinek 37f373e974 libcpp: Diagnose #include after failed __has_include [PR80753]
As can be seen in the testcase, we don't diagnose #include/#include_next
of a non-existent header if __has_include/__has_include_next is done for
that header first.
The problem is that we normally error the first time some header is not
found, but in the _cpp_FFK_HAS_INCLUDE case obviously don't want to diagnose
it, just expand it to 0.  And libcpp caches both successful includes and
unsuccessful ones.

The following patch fixes that by remembering that we haven't diagnosed
error when using __has_include* on it, and diagnosing it when using the
cache entry in normal mode the first time.

I think _cpp_FFK_NORMAL is the only mode in which we normally diagnose
errors, for _cpp_FFK_PRE_INCLUDE that open_file_failed isn't reached
and for _cpp_FFK_FAKE neither.

2023-06-15  Jakub Jelinek  <jakub@redhat.com>

	PR preprocessor/80753
libcpp/
	* files.cc (struct _cpp_file): Add deferred_error bitfield.
	(_cpp_find_file): When finding a file in cache with deferred_error
	set in _cpp_FFK_NORMAL mode, call open_file_failed and clear the flag.
	Set deferred_error in _cpp_FFK_HAS_INCLUDE mode if open_file_failed
	hasn't been called.
gcc/testsuite/
	* c-c++-common/missing-header-5.c: New test.
2023-06-15 14:16:17 +02:00
GCC Administrator 35e324da03 Daily bump. 2023-05-10 00:17:49 +00:00
Joseph Myers 955172f0d4 Update cpplib ru.po
* ru.po: Update.
2023-05-09 20:47:59 +00:00
GCC Administrator 4d68c7f7b5 Daily bump. 2023-05-01 00:16:44 +00:00
Jeff Law 33b6b79197 Revert "[PATCH] libcpp: suppress builtin macro redefined warnings for __LINE__"
This reverts commit e7ce7c4905.
2023-04-30 17:12:19 -06:00
Longjun Luo e7ce7c4905 [PATCH] libcpp: suppress builtin macro redefined warnings for __LINE__
From 0821df518b264e754d698d399f98be1a62945e32 Mon Sep 17 00:00:00 2001
From: Longjun Luo <luolongjuna@gmail.com>
Date: Thu, 12 Jan 2023 23:59:54 +0800
Subject: [PATCH] libcpp: suppress builtin macro redefined warnings for
 __LINE__

As implied in
gcc.gnu.org/legacy-ml/gcc-patches/2008-09/msg00076.html,
gcc provides -Wno-builtin-macro-redefined to suppress warning when
redefining builtin macro. However, at that time, there was no
scenario for __LINE__ macro.

But, when we try to build a live-patch, we compare sections by using
-ffunction-sections. Some same functions are considered changed because
of __LINE__ macro.

At present, to detect such a changed caused by __LINE__ macro, we
have to analyse code and maintain a function list. For example,
in kpatch, check this commit
github.com/dynup/kpatch/commit/0e1b95edeafa36edb7bcf11da6d1c00f76d7e03d.

So, in this scenario, when we try to compared sections, it would
be better to support suppress builtin macro redefined warnings for
__LINE__ macro.

libcpp:
	* init.cc (builtin_array): Do not always warn for a redefinition
	of __LINE__.

gcc/testsuite

	* gcc.dg/builtin-redefine.c: Test for redefintion warnings
	for __LINE__.
	* gcc.dg/builtin-redefine-1.c: New test.
2023-04-30 12:28:06 -06:00
GCC Administrator 810b924f75 Daily bump. 2023-03-26 00:16:45 +00:00
David Malcolm d495ea2b23 diagnostics: ensure that .sarif files are UTF-8 encoded [PR109098]
PR analyzer/109098 notes that the SARIF spec mandates that .sarif
files are UTF-8 encoded, but -fdiagnostics-format=sarif-file naively
assumes that the source files are UTF-8 encoded when quoting source
artefacts in the .sarif output, which can lead to us writing out
.sarif files with non-UTF-8 bytes in them (which break my reporting
scripts).

The root cause is that sarif_builder::maybe_make_artifact_content_object
was using maybe_read_file to load the file content as bytes, and
assuming they were UTF-8 encoded.

This patch reworks both overloads of this function (one used for the
whole file, the other for snippets of quoted lines) so that they go
through input.cc's file cache, which attempts to decode the input files
according to the input charset, and then encode as UTF-8.  They also
check that the result actually is UTF-8, for cases where the input
charset is missing, or incorrectly specified, and omit the quoted
source for such awkward cases.

Doing so fixes all of the cases I've encountered.

The patch adds a new:
  { dg-final { verify-sarif-file } }
directive to all SARIF test cases in the test suite, which verifies
that the output is UTF-8 encoded, and is valid JSON.  In particular
it verifies that when we complain about encoding problems, the .sarif
report we emit is itself correctly encoded.

gcc/ChangeLog:
	PR analyzer/109098
	* diagnostic-format-sarif.cc (read_until_eof): Delete.
	(maybe_read_file): Delete.
	(sarif_builder::maybe_make_artifact_content_object): Use
	get_source_file_content rather than maybe_read_file.
	Reject it if it's not valid UTF-8.
	* input.cc (file_cache_slot::get_full_file_content): New.
	(get_source_file_content): New.
	(selftest::check_cpp_valid_utf8_p): New.
	(selftest::test_cpp_valid_utf8_p): New.
	(selftest::input_cc_tests): Call selftest::test_cpp_valid_utf8_p.
	* input.h (get_source_file_content): New prototype.

gcc/testsuite/ChangeLog:
	PR analyzer/109098
	* c-c++-common/diagnostic-format-sarif-file-1.c: Add
	verify-sarif-file directive.
	* c-c++-common/diagnostic-format-sarif-file-2.c: Likewise.
	* c-c++-common/diagnostic-format-sarif-file-3.c: Likewise.
	* c-c++-common/diagnostic-format-sarif-file-4.c: Likewise.
	* c-c++-common/diagnostic-format-sarif-file-Wbidi-chars.c: New
	test case, adapted from Wbidi-chars-1.c.
	* c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c:
	New test case.
	* c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-2.c:
	New test case.
	* c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c:
	New test case, adapted from cpp/Winvalid-utf8-1.c.
	* c-c++-common/diagnostic-format-sarif-file-valid-CP850.c: New
	test case, adapted from gcc.dg/diagnostic-input-charset-1.c.
	* gcc.dg/plugin/crash-test-ice-sarif.c: Add verify-sarif-file
	directive.
	* gcc.dg/plugin/crash-test-write-though-null-sarif.c: Likewise.
	* gcc.dg/plugin/diagnostic-test-paths-5.c: Likewise.
	* lib/scansarif.exp (verify-sarif-file): New procedure.
	* lib/verify-sarif-file.py: New support script.

libcpp/ChangeLog:
	PR analyzer/109098
	* charset.cc (cpp_valid_utf8_p): New function.
	* include/cpplib.h (cpp_valid_utf8_p): New prototype.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2023-03-24 20:52:34 -04:00
GCC Administrator 5c389a5c36 Daily bump. 2023-03-17 00:17:03 +00:00
Jakub Jelinek 99bae6ee66 libcpp: Update Unicode copyright years
I've noticed I forgot to update copyright years when updating from
Unicode 15.0.0 (and makeucnid.cc had it hopelessly obsolete).

2023-03-16  Jakub Jelinek  <jakub@redhat.com>

	* makeucnid.cc (write_copyright): Update Unicode copyright years
	up to 2022.
	* makeuname2c.cc (write_copyright): Likewise.
	* ucnid.h: Regenerated.
	* uname2c.h: Regenerated.
2023-03-16 10:19:04 +01:00
GCC Administrator a9835599fd Daily bump. 2023-03-14 00:17:05 +00:00
Lewis Hyatt 336ce497fb libcpp: Fix ICE on directive inside _Pragma() operator [PR67046]
get__Pragma_string() in directives.cc is responsible for lexing the parens
and the string argument from a _Pragma("...") operator. This function does
not handle the case when the closing paren is not on the same line as the
string; in that case, libcpp will by default reuse the token buffer it
previously used for the string, so that the string token returned by
get__Pragma_string() may be corrupted, as shown in the testcase. Fix using
the existing keep_tokens mechanism that temporarily disables the reuse of
token buffers.

libcpp/ChangeLog:

	PR preprocessor/67046
	* directives.cc (_cpp_do__Pragma): Increment pfile->keep_tokens to
	ensure the returned string token is valid.

gcc/testsuite/ChangeLog:

	PR preprocessor/67046
	* c-c++-common/cpp/pr67046.c: New test.
2023-03-13 07:40:50 -04:00
Lewis Hyatt 73dd5c6c88 libcpp: Update cpp_wcwidth() to Unicode 15
Updates cpp_wcwidth() to Unicode 15, following the procedure in
contrib/unicode/README mechanically without incident.

contrib/ChangeLog:

	* unicode/DerivedCoreProperties.txt: Update to Unicode 15.
	* unicode/DerivedNormalizationProps.txt: Likewise.
	* unicode/EastAsianWidth.txt: Likwise.
	* unicode/PropList.txt: Likewise.
	* unicode/README: Likewise.
	* unicode/UnicodeData.txt: Likewise.

libcpp/ChangeLog:

	* generated_cpp_wcwidth.h: Regenerated for Unicode 15.
2023-03-13 07:40:50 -04:00
GCC Administrator 6f9e2f144e Daily bump. 2023-03-01 00:18:20 +00:00
Joseph Myers be0ea4af0c Update cpplib sr.po, sv.po
* sr.po, sv.po: Update.
2023-02-28 01:18:28 +00:00
GCC Administrator 4341106354 Daily bump. 2023-02-25 00:17:49 +00:00
Joseph Myers c8373dc8bf Update .po files
gcc/po/
	* be.po, da.po, de.po, el.po, es.po, fi.po, fr.po, hr.po, id.po,
	ja.po, nl.po, ru.po, sr.po, sv.po, tr.po, uk.po, vi.po, zh_CN.po,
	zh_TW.po: Update.

libcpp/po/
	* be.po, ca.po, da.po, de.po, el.po, eo.po, es.po, fi.po, fr.po,
	id.po, ja.po, ka.po, nl.po, pt_BR.po, ro.po, ru.po, sr.po, sv.po,
	tr.po, uk.po, vi.po, zh_CN.po, zh_TW.po: Update.
2023-02-24 22:46:33 +00:00
GCC Administrator d7a47ed17a Daily bump. 2023-02-11 00:17:31 +00:00
Joseph Myers 305037ee3e Regenerate .pot files
gcc/po/
	* gcc.pot: Regenerate.

libcpp/po/
	* cpplib.pot: Regenerate.
2023-02-10 22:42:43 +00:00
GCC Administrator f457a62e63 Daily bump. 2023-01-17 00:18:06 +00:00
Joseph Myers 8ed40069e7 Add cpplib ka.po
* ka.po: New.
2023-01-16 22:43:24 +00:00
Jakub Jelinek 83ffe9cde7 Update copyright years. 2023-01-16 11:52:17 +01:00
GCC Administrator 84723acaa0 Daily bump. 2023-01-10 00:18:07 +00:00
Joseph Myers 150d4b0283 Update cpplib eo.po
* eo.po: Update.
2023-01-09 20:16:41 +00:00
Jakub Jelinek 68127a8e87 Update Copyright year in ChangeLog files
2022 -> 2023
2023-01-02 09:23:36 +01:00
GCC Administrator 4bc2d9f6cb Daily bump. 2022-12-08 00:17:45 +00:00
Joseph Myers ce53cf7b61 preprocessor: Enable __VA_OPT__ for C2x
C2x supports __VA_OPT__, so adjust libcpp not to pedwarn for uses of
it (or of not passing any variable arguments to a variable-arguments
macro) in standard C2x mode.

I didn't try to duplicate existing tests for the details of the
feature, just verified -pedantic-errors handling is as expected.  And
there's a reasonable argument (bug 98859) that __VA_OPT__ shouldn't be
diagnosed in older standard modes at all (as opposed to not passing
any variable arguments to a variable-arguments macro, for which older
versions of the C standard require a diagnostic as a constraint
violation); that argument applies to C as much as to C++, but I
haven't made any changes in that regard.

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

libcpp/
	* init.cc (lang_defaults): Enable va_opt for STDC2X.
	* lex.cc (maybe_va_opt_error): Adjust diagnostic message for C.
	* macro.cc (_cpp_arguments_ok): Update comment.

gcc/testsuite/
	* gcc.dg/cpp/c11-vararg-1.c, gcc.dg/cpp/c2x-va-opt-1.c: New tests.
2022-12-07 19:18:06 +00:00
GCC Administrator 8761284fd7 Daily bump. 2022-11-24 00:17:47 +00:00
Marek Polacek 04711f5189 Revert "configure: Implement --enable-host-pie"
This reverts commit 251c72a68a.
2022-11-22 21:10:31 -05:00
Marek Polacek 251c72a68a configure: Implement --enable-host-pie
This patch implements the --enable-host-pie configure option which
makes the compiler executables PIE.  This can be used to enhance
protection against ROP attacks, and can be viewed as part of a wider
trend to harden binaries.

It is similar to the option --enable-host-shared, except that --e-h-s
won't add -shared to the linker flags whereas --e-h-p will add -pie.
It is different from --enable-default-pie because that option just
adds an implicit -fPIE/-pie when the compiler is invoked, but the
compiler itself isn't PIE.

Since r12-5768-gfe7c3ecf, PCH works well with PIE, so there are no PCH
regressions.

When building the compiler, the build process may use various in-tree
libraries; these need to be built with -fPIE so that it's possible to
use them when building a PIE.  For instance, when --with-included-gettext
is in effect, intl object files must be compiled with -fPIE.  Similarly,
when building in-tree gmp, isl, mpfr and mpc, they must be compiled with
-fPIE.

I plan to add an option to link with -Wl,-z,now.

ChangeLog:

	* Makefile.def: Pass $(PICFLAG) to AM_CFLAGS for gmp, mpfr, mpc, and
	isl.
	* Makefile.in: Regenerate.
	* Makefile.tpl: Set PICFLAG.
	* configure.ac (--enable-host-pie): New check.  Set PICFLAG after this
	check.
	* configure: Regenerate.

c++tools/ChangeLog:

	* Makefile.in: Rename PIEFLAG to PICFLAG.  Set LD_PICFLAG.  Use it.
	Use pic/libiberty.a if PICFLAG is set.
	* configure.ac (--enable-default-pie): Set PICFLAG instead of PIEFLAG.
	(--enable-host-pie): New check.
	* configure: Regenerate.

fixincludes/ChangeLog:

	* Makefile.in: Set and use PICFLAG and LD_PICFLAG.  Use the "pic"
	build of libiberty if PICFLAG is set.
	* configure.ac:
	* configure: Regenerate.

gcc/ChangeLog:

	* Makefile.in: Set LD_PICFLAG.  Use it.  Set enable_host_pie.
	Remove NO_PIE_CFLAGS and NO_PIE_FLAG.  Pass LD_PICFLAG to
	ALL_LINKERFLAGS.  Use the "pic" build of libiberty if --enable-host-pie.
	* configure.ac (--enable-host-shared): Don't set PICFLAG here.
	(--enable-host-pie): New check.  Set PICFLAG and LD_PICFLAG after this
	check.
	* configure: Regenerate.
	* doc/install.texi: Document --enable-host-pie.

gcc/d/ChangeLog:

	* Make-lang.in: Remove NO_PIE_CFLAGS.

intl/ChangeLog:

	* Makefile.in: Use @PICFLAG@ in COMPILE as well.
	* configure.ac (--enable-host-shared): Don't set PICFLAG here.
	(--enable-host-pie): New check.  Set PICFLAG after this check.
	* configure: Regenerate.

libcody/ChangeLog:

	* Makefile.in: Pass LD_PICFLAG to LDFLAGS.
	* configure.ac (--enable-host-shared): Don't set PICFLAG here.
	(--enable-host-pie): New check.  Set PICFLAG and LD_PICFLAG after this
	check.
	* configure: Regenerate.

libcpp/ChangeLog:

	* configure.ac (--enable-host-shared): Don't set PICFLAG here.
	(--enable-host-pie): New check.  Set PICFLAG after this check.
	* configure: Regenerate.

libdecnumber/ChangeLog:

	* configure.ac (--enable-host-shared): Don't set PICFLAG here.
	(--enable-host-pie): New check.  Set PICFLAG after this check.
	* configure: Regenerate.

libiberty/ChangeLog:

	* configure.ac: Also set shared when enable_host_pie.
	* configure: Regenerate.

zlib/ChangeLog:

	* configure.ac (--enable-host-shared): Don't set PICFLAG here.
	(--enable-host-pie): New check.  Set PICFLAG after this check.
	* configure: Regenerate.
2022-11-22 20:32:18 -05:00
GCC Administrator 8b7fee1de9 Daily bump. 2022-11-22 00:17:49 +00:00
Lewis Hyatt 6f46d14d49 libcpp: Fix paste error with unknown pragma after macro expansion
In directives.cc, do_pragma() contains logic to handle a case such as the new
testcase pragma-omp-unknown.c, where an unknown pragma was the result of macro
expansion (for pragma namespaces that permit expansion). This no longer works
correctly as shown by the testcase, fixed by adding PREV_WHITE to the flags on
the second token to prevent an unwanted paste.  Also fixed the memory leak,
since the temporary tokens are pushed on their own context, nothing prevents
freeing of the buffer that holds them when the context is eventually popped.

libcpp/ChangeLog:

	* directives.cc (do_pragma): Fix memory leak in token buffer.  Fix
	unwanted paste between two tokens.

gcc/testsuite/ChangeLog:

	* c-c++-common/gomp/pragma-omp-unknown.c: New test.
2022-11-21 17:47:19 -05:00
Torbjörn SVENSSON 711f56ad90 libcpp/remap: Only override if string matched
For systems with HAVE_DOS_BASED_FILE_SYSTEM set, only override the
pointer if the backslash pattern matches.

Output without this patch:
.../gcc/testsuite/gcc.dg/cpp/pr71681-2.c:5:10: fatal error: a/t2.h: No such file or directory

With patch applied, no output and the test case succeeds.

libcpp/ChangeLog

	* files.cc: Ensure pattern matches before use.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
2022-11-21 13:37:05 +01:00
Martin Liska 139ffc7771 build: re-configure 2 files
libcpp/ChangeLog:

	* config.in: Re-configure.

libstdc++-v3/ChangeLog:

	* src/experimental/Makefile.in: Re-configure.
2022-11-21 09:03:35 +01:00
GCC Administrator fb98ede8ca Daily bump. 2022-11-21 00:16:46 +00:00
Bernhard Reutner-Fischer 5a6c698ea3 libcpp: Add missing config for --enable-valgrind-annotations [PR107691]
r7-912 copied (parts of) the valgrind annotation checks from gcc
to libcpp. The above copies the missing pieces to libcpp to diagnose
when libcpp is configured with --enable-valgrind-annotations but
valgrind is not installed.

libcpp/ChangeLog:

	PR preprocessor/107691
	* configure.ac: Add valgrind header checks.
	* configure: Regenerate.
2022-11-19 12:17:48 +01:00
Richard Purdie 11543b27fe libcpp: Avoid remapping filenames within directives
Code such as:

 #include __FILE__

can interact poorly with the *-prefix-map options when cross compiling. In
general you're after to remap filenames for use in target context but the
local paths should be used to find include files at compile time. Ingoring
filename remapping for directives allows avoiding such failures.

Fix this to improve such usage and then document this against file-prefix-map
(referenced by the other *-prefix-map options) to make the behaviour clear
and defined.

libcpp/ChangeLog:

	* macro.cc (_cpp_builtin_macro_text): Don't remap filenames within
	directives.

gcc/ChangeLog:

	* doc/invoke.texi: Document prefix-maps don't affect directives.
2022-11-18 13:13:50 -07:00
GCC Administrator 05788e9b95 Daily bump. 2022-11-06 11:05:22 +00:00
Lewis Hyatt 3ad2167bba c++: libcpp: Support raw strings with newlines in directives [PR55971]
It's not currently possible to use a C++11 raw string containing a newline as
part of the definition of a macro, or in any other preprocessing directive,
such as:

 #define X R"(two
lines)"

 #error R"(this error has
two lines)"

Add support for that by relaxing the conditions under which
_cpp_get_fresh_line() refuses to get a new line. For the case of lexing a raw
string, it's OK to do so as long as there is another line within the current
buffer. The code in cpp_get_fresh_line() was refactored into a new function
get_fresh_line_impl(), so that the new logic is applied only when processing a
raw string and not any other times.

libcpp/ChangeLog:

	PR preprocessor/55971
	* lex.cc (get_fresh_line_impl): New function refactoring the code
	from...
	(_cpp_get_fresh_line): ...here.
	(lex_raw_string): Use the new version of get_fresh_line_impl() to
	support raw strings containing new lines when processing a directive.

gcc/testsuite/ChangeLog:

	PR preprocessor/55971
	* c-c++-common/raw-string-directive-1.c: New test.
	* c-c++-common/raw-string-directive-2.c: New test.

gcc/c-family/ChangeLog:

	PR preprocessor/55971
	* c-ppoutput.cc (adjust_for_newlines): Update comment.
2022-11-05 10:23:20 -04:00
Jakub Jelinek 2662d537b0 libcpp: Update to Unicode 15
The following pseudo-patch regenerates the libcpp tables with Unicode 15.0.0
which added 4489 new characters.

As mentioned previously, this isn't just a matter of running the
two libcpp/make*.cc programs on the new Unicode files, but one needs
to manually update a table inside of makeuname2c.cc according to
a table in Unicode text (which is partially reflected in the text
files, but e.g. in Unicode 14.0.0 not 100% accurately, in 15.0.0
actually accurately).
I've also added some randomly chosen subset of those 4489 new
characters to a testcase.

2022-11-04  Jakub Jelinek  <jakub@redhat.com>

gcc/testsuite/
	* c-c++-common/cpp/named-universal-char-escape-1.c: Add tests for some
	characters newly added in Unicode 15.0.0.
libcpp/
	* makeuname2c.cc (struct generated): Update from Unicode 15.0.0
	table 4-8.
	* ucnid.h: Regenerated for Unicode 15.0.0.
	* uname2c.h: Likewise.
2022-11-04 18:18:42 +01:00
GCC Administrator 87f9c4a433 Daily bump. 2022-10-20 00:17:52 +00:00
Lewis Hyatt f3b957ea8b pch: Fix streaming of strings with embedded null bytes
When a GTY'ed struct is streamed to PCH, any plain char* pointers it contains
(whether they live in GC-controlled memory or not) will be marked for PCH
output by the routine gt_pch_note_object in ggc-common.cc. This routine
special-cases plain char* strings, and in particular it uses strlen() to get
their length. Thus it does not handle strings with embedded null bytes, but it
is possible for something PCH cares about (such as a string literal token in a
macro definition) to contain such embedded nulls. To fix that up, add a new
GTY option "string_length" so that gt_pch_note_object can be informed the
actual length it ought to use, and use it in the relevant libcpp structs
(cpp_string and ht_identifier) accordingly.

gcc/ChangeLog:

	* gengtype.cc (output_escaped_param): Add missing const.
	(get_string_option): Add missing check for option type.
	(walk_type): Support new "string_length" GTY option.
	(write_types_process_field): Likewise.
	* ggc-common.cc (gt_pch_note_object): Add optional length argument.
	* ggc.h (gt_pch_note_object): Adjust prototype for new argument.
	(gt_pch_n_S2): Declare...
	* stringpool.cc (gt_pch_n_S2): ...new function.
	* doc/gty.texi: Document new GTY((string_length)) option.

libcpp/ChangeLog:

	* include/cpplib.h (struct cpp_string): Use new "string_length" GTY.
	* include/symtab.h (struct ht_identifier): Likewise.

gcc/testsuite/ChangeLog:

	* g++.dg/pch/pch-string-nulls.C: New test.
	* g++.dg/pch/pch-string-nulls.Hs: New test.
2022-10-19 09:26:09 -04:00
GCC Administrator baeec7cc83 Daily bump. 2022-10-15 00:17:38 +00:00
Joseph Myers 36d20fa4a8 preprocessor: C2x identifier rules
C2x has, like C++, adopted rules for identifiers based directly on an
unversioned normative reference to Unicode.  Make libcpp follow those
rules for c2x / gnu2x standards (this involves bringing back a flag
separate from the C++ one for whether to use these identifier rules,
but this time enabled for all C++ language versions since that was the
conclusion adopted for C++ identifier handling).

There is one change here that affects C++.  I believe the new
normative requirement for NFC only applies to identifiers, not to the
use of identifier-continue characters in pp-numbers, where there is no
such requirement and so the diagnostic ought to be a warning not a
pedwarn in pp-numbers, and that this is the case for both C and C++.

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

libcpp/
	* 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.

gcc/testsuite/
	* gcc.dg/cpp/c2x-ucnid-1-utf8.c, gcc.dg/cpp/c2x-ucnid-1.c: New
	tests.
2022-10-14 23:07:50 +00:00
Jakub Jelinek c2565a31c1 middle-end, c++, i386, libgcc: std::bfloat16_t and __bf16 arithmetic support
Here is a complete patch to add std::bfloat16_t support on
x86 (AArch64 and ARM left for later).  Almost no BFmode optabs
are added by the patch, so for binops/unops it extends to SFmode
first and then truncates back to BFmode.
For {HF,SF,DF,XF,TF}mode -> BFmode conversions libgcc has implementations
of all those conversions so that we avoid double rounding, for
BFmode -> {DF,XF,TF}mode conversions to avoid growing libgcc too much
it emits BFmode -> SFmode conversion first and then converts to the even
wider mode, neither step should be imprecise.
For BFmode -> HFmode, it first emits a precise BFmode -> SFmode conversion
and then SFmode -> HFmode, because neither format is subset or superset
of the other, while SFmode is superset of both.
expr.cc then contains a -ffast-math optimization of the BF -> SF and
SF -> BF conversions if we don't optimize for space (and for the latter
if -frounding-math isn't enabled either).
For x86, perhaps truncsfbf2 optab could be defined for TARGET_AVX512BF16
but IMNSHO should FAIL if !flag_finite_math || flag_rounding_math
|| !flag_unsafe_math_optimizations, because I think the insn doesn't
raise on sNaNs, hardcodes round to nearest and flushes denormals to zero.
By default (unless x86 -fexcess-precision=16) we use float excess
precision for BFmode, so truncate only on explicit casts and assignments.
The patch introduces a single __bf16 builtin - __builtin_nansf16b,
because (__bf16) __builtin_nansf ("") will drop the sNaN into qNaN,
and uses f16b suffix instead of bf16 because there would be ambiguity on
log vs. logb - __builtin_logbf16 could be either log with bf16 suffix
or logb with f16 suffix.  In other cases libstdc++ should mostly use
__builtin_*f for std::bfloat16_t overloads (we have a problem with
std::nextafter though but that one we have also for std::float16_t).

2022-10-14  Jakub Jelinek  <jakub@redhat.com>

gcc/
	* tree-core.h (enum tree_index): Add TI_BFLOAT16_TYPE.
	* tree.h (bfloat16_type_node): Define.
	* tree.cc (excess_precision_type): Promote bfloat16_type_mode
	like float16_type_mode.
	(build_common_tree_nodes): Initialize bfloat16_type_node if
	BFmode is supported.
	* expmed.h (maybe_expand_shift): Declare.
	* expmed.cc (maybe_expand_shift): No longer static.
	* expr.cc (convert_mode_scalar): Don't ICE on BF -> HF or HF -> BF
	conversions.  If there is no optab, handle BF -> {DF,XF,TF,HF}
	conversions as separate BF -> SF -> {DF,XF,TF,HF} conversions, add
	-ffast-math generic implementation for BF -> SF and SF -> BF
	conversions.
	* builtin-types.def (BT_BFLOAT16, BT_FN_BFLOAT16_CONST_STRING): New.
	* builtins.def (BUILT_IN_NANSF16B): New builtin.
	* fold-const-call.cc (fold_const_call): Handle CFN_BUILT_IN_NANSF16B.
	* config/i386/i386.cc (classify_argument): Handle E_BCmode.
	(ix86_libgcc_floating_mode_supported_p): Also return true for BFmode
	for -msse2.
	(ix86_mangle_type): Mangle BFmode as DF16b.
	(ix86_invalid_conversion, ix86_invalid_unary_op,
	ix86_invalid_binary_op): Remove.
	(TARGET_INVALID_CONVERSION, TARGET_INVALID_UNARY_OP,
	TARGET_INVALID_BINARY_OP): Don't redefine.
	* config/i386/i386-builtins.cc (ix86_bf16_type_node): Remove.
	(ix86_register_bf16_builtin_type): Use bfloat16_type_node rather than
	ix86_bf16_type_node, only create it if still NULL.
	* config/i386/i386-builtin-types.def (BFLOAT16): Likewise.
	* config/i386/i386.md (cbranchbf4, cstorebf4): New expanders.
gcc/c-family/
	* c-cppbuiltin.cc (c_cpp_builtins): If bfloat16_type_node,
	predefine __BFLT16_*__ macros and for C++23 also
	__STDCPP_BFLOAT16_T__.  Predefine bfloat16_type_node related
	macros for -fbuilding-libgcc.
	* c-lex.cc (interpret_float): Handle CPP_N_BFLOAT16.
gcc/c/
	* c-typeck.cc (convert_arguments): Don't promote __bf16 to
	double.
gcc/cp/
	* cp-tree.h (extended_float_type_p): Return true for
	bfloat16_type_node.
	* typeck.cc (cp_compare_floating_point_conversion_ranks): Set
	extended{1,2} if mv{1,2} is bfloat16_type_node.  Adjust comment.
gcc/testsuite/
	* lib/target-supports.exp (check_effective_target_bfloat16,
	check_effective_target_bfloat16_runtime, add_options_for_bfloat16):
	New.
	* gcc.dg/torture/bfloat16-basic.c: New test.
	* gcc.dg/torture/bfloat16-builtin.c: New test.
	* gcc.dg/torture/bfloat16-builtin-issignaling-1.c: New test.
	* gcc.dg/torture/bfloat16-complex.c: New test.
	* gcc.dg/torture/builtin-issignaling-1.c: Allow to be includable
	from bfloat16-builtin-issignaling-1.c.
	* gcc.dg/torture/floatn-basic.h: Allow to be includable from
	bfloat16-basic.c.
	* gcc.target/i386/vect-bfloat16-typecheck_2.c: Adjust expected
	diagnostics.
	* gcc.target/i386/sse2-bfloat16-scalar-typecheck.c: Likewise.
	* gcc.target/i386/vect-bfloat16-typecheck_1.c: Likewise.
	* g++.target/i386/bfloat_cpp_typecheck.C: Likewise.
libcpp/
	* include/cpplib.h (CPP_N_BFLOAT16): Define.
	* expr.cc (interpret_float_suffix): Handle bf16 and BF16 suffixes for
	C++.
libgcc/
	* config/i386/t-softfp (softfp_extensions): Add bfsf.
	(softfp_truncations): Add tfbf xfbf dfbf sfbf hfbf.
	(CFLAGS-extendbfsf2.c, CFLAGS-truncsfbf2.c, CFLAGS-truncdfbf2.c,
	CFLAGS-truncxfbf2.c, CFLAGS-trunctfbf2.c, CFLAGS-trunchfbf2.c): Add
	-msse2.
	* config/i386/libgcc-glibc.ver (GCC_13.0.0): Export
	__extendbfsf2 and __trunc{s,d,x,t,h}fbf2.
	* config/i386/sfp-machine.h (_FP_NANSIGN_B): Define.
	* config/i386/64/sfp-machine.h (_FP_NANFRAC_B): Define.
	* config/i386/32/sfp-machine.h (_FP_NANFRAC_B): Define.
	* soft-fp/brain.h: New file.
	* soft-fp/truncsfbf2.c: New file.
	* soft-fp/truncdfbf2.c: New file.
	* soft-fp/truncxfbf2.c: New file.
	* soft-fp/trunctfbf2.c: New file.
	* soft-fp/trunchfbf2.c: New file.
	* soft-fp/truncbfhf2.c: New file.
	* soft-fp/extendbfsf2.c: New file.
libiberty/
	* cp-demangle.h (D_BUILTIN_TYPE_COUNT): Increment.
	* cp-demangle.c (cplus_demangle_builtin_types): Add std::bfloat16_t
	entry.
	(cplus_demangle_type): Demangle DF16b.
	* testsuite/demangle-expected (_Z3xxxDF16b): New test.
2022-10-14 09:37:01 +02:00
GCC Administrator 27bfe54e97 Daily bump. 2022-10-11 00:17:00 +00:00
Joseph Myers 7af6a8043e Add cpplib ro.po
* ro.po: New.
2022-10-10 22:58:34 +00:00
GCC Administrator 9e79a25b66 Daily bump. 2022-09-29 00:16:38 +00:00
Eugene Rozenfeld f1adf45b17 Add instruction level discriminator support.
This is the first in a series of patches to enable discriminator support
in AutoFDO.

This patch switches to tracking discriminators per statement/instruction
instead of per basic block. Tracking per basic block was problematic since
not all statements in a basic block needed a discriminator and, also, later
optimizations could move statements between basic blocks making correlation
during AutoFDO compilation unreliable. Tracking per statement also allows
us to assign different discriminators to multiple function calls in the same
basic block. A subsequent patch will add that support.

The idea of this patch is based on commit 4c311d95cf
by Dehao Chen in vendors/google/heads/gcc-4_8 but uses a slightly different
approach. In Dehao's work special (normally unused) location ids and side tables
were used to keep track of locations with discriminators. Things have changed
since then and I don't think we have unused location ids anymore. Instead,
I made discriminators a part of ad-hoc locations.

The difference from Dehao's work also includes support for discriminator
reading/writing in lto streaming and in modules.

Tested on x86_64-pc-linux-gnu.

gcc/ChangeLog:

	* basic-block.h: Remove discriminator from basic blocks.
	* cfghooks.cc (split_block_1): Remove discriminator from basic blocks.
	* final.cc (final_start_function_1): Switch from per-bb to per statement
	discriminator.
	(final_scan_insn_1): Don't keep track of basic block discriminators.
	(compute_discriminator): Switch from basic block discriminators to
	instruction discriminators.
	(insn_discriminator): New function to return instruction discriminator.
	(notice_source_line): Use insn_discriminator.
	* gimple-pretty-print.cc (dump_gimple_bb_header): Remove dumping of
	basic block discriminators.
	* gimple-streamer-in.cc (input_bb): Remove reading of basic block
	discriminators.
	* gimple-streamer-out.cc (output_bb): Remove writing of basic block
	discriminators.
	* input.cc (make_location): Pass 0 discriminator to COMBINE_LOCATION_DATA.
	(location_with_discriminator): New function to combine locus with
	a discriminator.
	(has_discriminator): New function to check if a location has a discriminator.
	(get_discriminator_from_loc): New function to get the discriminator
	from a location.
	* input.h: Declarations of new functions.
	* lto-streamer-in.cc (cmp_loc): Use discriminators in location comparison.
	(apply_location_cache): Keep track of current discriminator.
	(input_location_and_block): Read discriminator from stream.
	* lto-streamer-out.cc (clear_line_info): Set current discriminator to
	UINT_MAX.
	(lto_output_location_1): Write discriminator to stream.
	* lto-streamer.h: Add discriminator to cached_location.
	Add current_discr to lto_location_cache.
	Add current_discr to output_block.
	* print-rtl.cc (print_rtx_operand_code_i): Print discriminator.
	* rtl.h: Add extern declaration of insn_discriminator.
	* tree-cfg.cc (assign_discriminator): New function to assign a unique
	discriminator value to all statements in a basic block that have the given
	line number.
	(assign_discriminators): Assign discriminators to statement locations.
	* tree-pretty-print.cc (dump_location): Dump discriminators.
	* tree.cc (set_block): Preserve discriminator when setting block.
	(set_source_range): Preserve discriminator when setting source range.

gcc/cp/ChangeLog:
	* module.cc (write_location): Write discriminator.
	(read_location): Read discriminator.

libcpp/ChangeLog:

	* include/line-map.h: Add discriminator to location_adhoc_data.
	(get_combined_adhoc_loc): Add discriminator parameter.
	(get_discriminator_from_adhoc_loc): Add external declaration.
	(get_discriminator_from_loc): Add external declaration.
	(COMBINE_LOCATION_DATA): Add discriminator parameter.
	* lex.cc (get_location_for_byte_range_in_cur_line) Pass 0 discriminator
	in a call to COMBINE_LOCATION_DATA.
	(warn_about_normalization): Pass 0 discriminator in a call to
	COMBINE_LOCATION_DATA.
	(_cpp_lex_direct): Pass 0 discriminator in a call to
	COMBINE_LOCATION_DATA.
	* line-map.cc (location_adhoc_data_hash): Use discriminator compute
	location_adhoc_data hash.
	(location_adhoc_data_eq): Use discriminator when comparing
	location_adhoc_data.
	(can_be_stored_compactly_p): Check discriminator to determine
	compact storage.
	(get_combined_adhoc_loc): Add discriminator parameter.
	(get_discriminator_from_adhoc_loc): New function to get the discriminator
	from an ad-hoc location.
	(get_discriminator_from_loc): New function to get the discriminator
	from a location.

gcc/testsuite/ChangeLog:

	* c-c++-common/ubsan/pr85213.c: Pass -gno-statement-frontiers.
2022-09-28 14:25:18 -07:00
GCC Administrator 1f16a020ac Daily bump. 2022-09-28 00:17:27 +00:00
Jakub Jelinek b04208895f c++: Implement P1467R9 - Extended floating-point types and standard names compiler part except for bfloat16 [PR106652]
The following patch implements the compiler part of C++23
P1467R9 - Extended floating-point types and standard names compiler part
by introducing _Float{16,32,64,128} as keywords and builtin types
like they are implemented for C already since GCC 7, with DF{16,32,64,128}_
mangling.
It also introduces _Float{32,64,128}x for C++ with the
https://github.com/itanium-cxx-abi/cxx-abi/pull/147
proposed mangling of DF{32,64,128}x.
The patch doesn't add anything for bfloat16_t support, as right now
__bf16 type refuses all conversions and arithmetic operations.
The patch wants to keep backwards compatibility with how __float128 has
been handled in C++ before, both for mangling and behavior in binary
operations, overload resolution etc.  So, there are some backend changes
where for C __float128 and _Float128 are the same type (float128_type_node
and float128t_type_node are the same pointer), but for C++ they are distinct
types which mangle differently and _Float128 is treated as extended
floating-point type while __float128 is treated as non-standard floating
point type.  The various C++23 changes about how floating-point types
are changed are actually implemented as written in the spec only if at least
one of the types involved is _Float{16,32,64,128,32x,64x,128x} (_FloatNx are
also treated as extended floating-point types) and kept previous behavior
otherwise.  For float/double/long double the rules are actually written that
they behave the same as before.
There is some backwards incompatibility at least on x86 regarding _Float16,
because that type was already used by that name and with the DF16_ mangling
(but only since GCC 12 and I think it isn't that widely used in the wild
yet).  E.g. config/i386/avx512fp16intrin.h shows the issues, where
in C or in GCC 12 in C++ one could pass 0.0f to a builtin taking _Float16
argument, but with the changes that is not possible anymore, one needs
to either use 0.0f16 or (_Float16) 0.0f.
We have also a problem with glibc headers, where since glibc 2.27
math.h and complex.h aren't compilable with these changes.  One gets
errors like:
In file included from /usr/include/math.h:43,
                 from abc.c:1:
/usr/include/bits/floatn.h:86:9: error: multiple types in one declaration
   86 | typedef __float128 _Float128;
      |         ^~~~~~~~~~
/usr/include/bits/floatn.h:86:20: error: declaration does not declare anything [-fpermissive]
   86 | typedef __float128 _Float128;
      |                    ^~~~~~~~~
In file included from /usr/include/bits/floatn.h:119:
/usr/include/bits/floatn-common.h:214:9: error: multiple types in one declaration
  214 | typedef float _Float32;
      |         ^~~~~
/usr/include/bits/floatn-common.h:214:15: error: declaration does not declare anything [-fpermissive]
  214 | typedef float _Float32;
      |               ^~~~~~~~
/usr/include/bits/floatn-common.h:251:9: error: multiple types in one declaration
  251 | typedef double _Float64;
      |         ^~~~~~
/usr/include/bits/floatn-common.h:251:16: error: declaration does not declare anything [-fpermissive]
  251 | typedef double _Float64;
      |                ^~~~~~~~
This is from snippets like:
 /* The remaining of this file provides support for older compilers.  */
 # if __HAVE_FLOAT128

 /* The type _Float128 exists only since GCC 7.0.  */
 #  if !__GNUC_PREREQ (7, 0) || defined __cplusplus
 typedef __float128 _Float128;
 #  endif
where it hardcodes that C++ doesn't have _Float{16,32,64,128,32x,64x,128x} support nor
{f,F}{16,32,64,128}{,x} literal suffixes nor _Complex _Float{16,32,64,128,32x,64x,128x}.
The patch fixincludes this for now and hopefully if this is committed, then
glibc can change those.  The patch changes those
 #  if !__GNUC_PREREQ (7, 0) || defined __cplusplus
conditions to
 #  if !__GNUC_PREREQ (7, 0) || (defined __cplusplus && !__GNUC_PREREQ (13, 0))
Another thing is mangling, as said above, Itanium C++ ABI specifies
DF <number> _ as _Float{16,32,64,128} mangling, but GCC was implementing
a mangling incompatible with that starting with DF for fixed point types.
Fixed point was never supported in C++ though, I believe the reason why
the mangling has been added was that due to a bug it would leak into the
C++ FE through decltype (0.0r) etc.  But that has been shortly after the
mangling was added fixed (I think in the same GCC release cycle), so we
now reject 0.0r etc. in C++.  If we ever need the fixed point mangling,
I think it can be readded but better with a different prefix so that it
doesn't conflict with the published standard manglings.  So, this patch
also kills the fixed point mangling and implements the DF <number> _
demangling.
The patch predefines __STDCPP_FLOAT{16,32,64,128}_T__ macros when
those types are available, but only for C++23, while the underlying types
are available in C++98 and later including the {f,F}{16,32,64,128} literal
suffixes (but those with a pedwarn for C++20 and earlier).  My understanding
is that it needs to be predefined by the compiler, on the other side
predefining even for older modes when <stdfloat> is a new C++23 header
would be weird.  One can find out if _Float{16,32,64,128,32x,64x,128x} is
supported in C++ by
__GNUC__ >= 13 && defined(__FLT{16,32,64,128,32X,64X,128X}_MANT_DIG__)
(but that doesn't work well with older G++ 13 snapshots).

As for std::bfloat16_t, three targets (aarch64, arm and x86) apparently
"support" __bf16 type which has the bfloat16 format, but isn't really
usable, e.g. {aarch64,arm,ix86}_invalid_conversion disallow any conversions
from or to type with BFmode, {aarch64,arm,ix86}_invalid_unary_op disallows
any unary operations on those except for ADDR_EXPR and
{aarch64,arm,ix86}_invalid_binary_op disallows any binary operation on
those.  So, I think we satisfy:
"If the implementation supports an extended floating-point type with the
properties, as specified by ISO/IEC/IEEE 60559, of radix (b) of 2, storage
width in bits (k) of 16, precision in bits (p) of 8, maximum exponent (emax)
of 127, and exponent field width in bits (w) of 8, then the typedef-name
std::bfloat16_t is defined in the header <stdfloat> and names such a type,
the macro __STDCPP_BFLOAT16_T__ is defined, and the floating-point literal
suffixes bf16 and BF16 are supported."
because we don't really support those right now.

2022-09-27  Jakub Jelinek  <jakub@redhat.com>

	PR c++/106652
	PR c++/85518
gcc/
	* tree-core.h (enum tree_index): Add TI_FLOAT128T_TYPE
	enumerator.
	* tree.h (float128t_type_node): Define.
	* tree.cc (build_common_tree_nodes): Initialize float128t_type_node.
	* builtins.def (DEF_FLOATN_BUILTIN): Adjust comment now that
	_Float<N> is supported in C++ too.
	* config/i386/i386.cc (ix86_mangle_type): Only mangle as "g"
	float128t_type_node.
	* config/i386/i386-builtins.cc (ix86_init_builtin_types): Use
	float128t_type_node for __float128 instead of float128_type_node
	and create it if NULL.
	* config/i386/avx512fp16intrin.h (_mm_setzero_ph, _mm256_setzero_ph,
	_mm512_setzero_ph, _mm_set_sh, _mm_load_sh): Use 0.0f16 instead of
	0.0f.
	* config/ia64/ia64.cc (ia64_init_builtins): Use
	float128t_type_node for __float128 instead of float128_type_node
	and create it if NULL.
	* config/rs6000/rs6000-c.cc (is_float128_p): Also return true
	for float128t_type_node if non-NULL.
	* config/rs6000/rs6000.cc (rs6000_mangle_type): Don't mangle
	float128_type_node as "u9__ieee128".
	* config/rs6000/rs6000-builtin.cc (rs6000_init_builtins): Use
	float128t_type_node for __float128 instead of float128_type_node
	and create it if NULL.
gcc/c-family/
	* c-common.cc (c_common_reswords): Change _Float{16,32,64,128} and
	_Float{32,64,128}x flags from D_CONLY to 0.
	(shorten_binary_op): Punt if common_type returns error_mark_node.
	(shorten_compare): Likewise.
	(c_common_nodes_and_builtins): For C++ record _Float{16,32,64,128}
	and _Float{32,64,128}x builtin types if available.  For C++
	clear float128t_type_node.
	* c-cppbuiltin.cc (c_cpp_builtins): Predefine
	__STDCPP_FLOAT{16,32,64,128}_T__ for C++23 if supported.
	* c-lex.cc (interpret_float): For q/Q suffixes prefer
	float128t_type_node over float128_type_node.  Allow
	{f,F}{16,32,64,128} suffixes for C++ if supported with pedwarn
	for C++20 and older.  Allow {f,F}{32,64,128}x suffixes for C++
	with pedwarn.  Don't call excess_precision_type for C++.
gcc/cp/
	* cp-tree.h (cp_compare_floating_point_conversion_ranks): Implement
	P1467R9 - Extended floating-point types and standard names except
	for std::bfloat16_t for now.  Declare.
	(extended_float_type_p): New inline function.
	* mangle.cc (write_builtin_type): Mangle float{16,32,64,128}_type_node
	as DF{16,32,64,128}_.  Mangle float{32,64,128}x_type_node as
	DF{32,64,128}x.  Remove FIXED_POINT_TYPE mangling that conflicts
	with that.
	* typeck2.cc (check_narrowing): If one of ftype or type is extended
	floating-point type, compare floating-point conversion ranks.
	* parser.cc (cp_keyword_starts_decl_specifier_p): Handle
	CASE_RID_FLOATN_NX.
	(cp_parser_simple_type_specifier): Likewise and diagnose missing
	_Float<N> or _Float<N>x support if not supported by target.
	* typeck.cc (cp_compare_floating_point_conversion_ranks): New function.
	(cp_common_type): If both types are REAL_TYPE and one or both are
	extended floating-point types, select common type based on comparison
	of floating-point conversion ranks and subranks.
	(cp_build_binary_op): Diagnose operation with floating point arguments
	with unordered conversion ranks.
	* call.cc (standard_conversion): For floating-point conversion, if
	either from or to are extended floating-point types, set conv->bad_p
	for implicit conversion from larger to smaller conversion rank or
	with unordered conversion ranks.
	(convert_like_internal): Emit a pedwarn on such conversions.
	(build_conditional_expr): Diagnose operation with floating point
	arguments with unordered conversion ranks.
	(convert_arg_to_ellipsis): Don't promote extended floating-point types
	narrower than double to double.
	(compare_ics): Implement P1467R9 [over.ics.rank]/4 changes.
gcc/testsuite/
	* g++.dg/cpp23/ext-floating1.C: New test.
	* g++.dg/cpp23/ext-floating2.C: New test.
	* g++.dg/cpp23/ext-floating3.C: New test.
	* g++.dg/cpp23/ext-floating4.C: New test.
	* g++.dg/cpp23/ext-floating5.C: New test.
	* g++.dg/cpp23/ext-floating6.C: New test.
	* g++.dg/cpp23/ext-floating7.C: New test.
	* g++.dg/cpp23/ext-floating8.C: New test.
	* g++.dg/cpp23/ext-floating9.C: New test.
	* g++.dg/cpp23/ext-floating10.C: New test.
	* g++.dg/cpp23/ext-floating.h: New file.
	* g++.target/i386/float16-1.C: Adjust expected diagnostics.
libcpp/
	* expr.cc (interpret_float_suffix): Allow {f,F}{16,32,64,128} and
	{f,F}{32,64,128}x suffixes for C++.
include/
	* demangle.h (enum demangle_component_type): Add
	DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE.
	(struct demangle_component): Add u.s_extended_builtin member.
libiberty/
	* cp-demangle.c (d_dump): Handle
	DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE.  Don't handle
	DEMANGLE_COMPONENT_FIXED_TYPE.
	(d_make_extended_builtin_type): New function.
	(cplus_demangle_builtin_types): Add _Float entry.
	(cplus_demangle_type): For DF demangle it as _Float<N> or
	_Float<N>x rather than fixed point which conflicts with it.
	(d_count_templates_scopes): Handle
	DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE.  Just break; for
	DEMANGLE_COMPONENT_FIXED_TYPE.
	(d_find_pack): Handle DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE.
	Don't handle DEMANGLE_COMPONENT_FIXED_TYPE.
	(d_print_comp_inner): Likewise.
	* cp-demangle.h (D_BUILTIN_TYPE_COUNT): Bump.
	* testsuite/demangle-expected: Replace _Z3xxxDFyuVb test
	with _Z3xxxDF16_DF32_DF64_DF128_CDF16_Vb.  Add
	_Z3xxxDF32xDF64xDF128xCDF32xVb test.
fixincludes/
	* inclhack.def (glibc_cxx_floatn_1, glibc_cxx_floatn_2,
	glibc_cxx_floatn_3): New fixes.
	* tests/base/bits/floatn.h: New file.
	* fixincl.x: Regenerated.
2022-09-27 08:18:00 +02:00
GCC Administrator 2e7ad70c4a Daily bump. 2022-09-09 00:18:05 +00:00
Lewis Hyatt 95c7d58995 pch: Fix the reconstruction of adhoc data hash table
The function rebuild_location_adhoc_htab() was meant to reconstruct the
adhoc location hash map after restoring a line_maps instance from a
PCH. However, the function has never performed as intended because it
missed the last step of adding the data into the newly reconstructed hash
map. This patch fixes that.

It does not seem possible to construct a test case such that the current
incorrect behavior is observable as a compiler issue. It would be
observable, if it were possible for a precompiled header to contain an
adhoc location with a non-zero custom data pointer. But currently, such
data pointers are used only by the middle end to track inlining
information, and this happens later, too late to show up in a PCH.

I also noted that location_adhoc_data_update, which updates the hash map
pointers in a different scenario, was relying on undefined pointer
arithmetic behavior. I'm not aware of this having caused any issue in
practice, but in this patch I have also changed it to use defined pointer
operations instead.

libcpp/ChangeLog:

	* line-map.cc (location_adhoc_data_update): Remove reliance on
	undefined behavior.
	(get_combined_adhoc_loc): Likewise.
	(rebuild_location_adhoc_htab): Fix issue where the htab was not
	properly updated.
2022-09-08 08:20:29 -04:00
GCC Administrator fe2a8ce93c Daily bump. 2022-09-08 00:18:33 +00:00
Joseph Myers 0a91bdaf17 c: New C2x keywords
C2x follows C++ in making alignas, alignof, bool, false,
static_assert, thread_local and true keywords; implement this
accordingly.  This implementation makes them normal keywords in C2x
mode just like any other keyword (C2x leaves open the possibility of
implementation using predefined macros instead - thus, there aren't
any testcases asserting that they aren't macros).  As in C++ and
previous versions of C, true and false are handled like signed 1 and 0
in #if (there was an intermediate state in some C2x drafts where they
had different macro expansions that were unsigned in #if).

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

As with the removal of unprototyped functions, this change has a high
risk of breaking some old code and people doing GNU/Linux distribution
builds may wish to see how much is broken in a build with a -std=gnu2x
default.

gcc/
	* ginclude/stdalign.h [defined __STDC_VERSION__ &&
	__STDC_VERSION__ > 201710L]: Disable all content.
	* ginclude/stdbool.h [defined __STDC_VERSION__ && __STDC_VERSION__
	> 201710L] (bool, true, false): Do not define.

gcc/c-family/
	* c-common.cc (c_common_reswords): Use D_C2X instead of D_CXXONLY
	for alignas, alignof, bool, false, static_assert, thread_local and
	true.

gcc/c/
	* c-parser.cc (c_parser_static_assert_declaration_no_semi)
	(c_parser_alignas_specifier, c_parser_alignof_expression): Allow
	for C2x spellings of keywords.
	(c_parser_postfix_expression): Handle RID_TRUE and RID_FALSE.

gcc/testsuite/
	* gcc.dg/c11-keywords-1.c, gcc.dg/c2x-align-1.c,
	gcc.dg/c2x-align-6.c, gcc.dg/c2x-bool-2.c,
	gcc.dg/c2x-static-assert-3.c, gcc.dg/c2x-static-assert-4.c,
	gcc.dg/c2x-thread-local-1.c: New tests.
	* gcc.dg/c2x-bool-1.c: Update expectations.

libcpp/
	* include/cpplib.h (struct cpp_options): Add true_false.
	* expr.cc (eval_token): Check true_false not cplusplus to
	determine whether to handle true and false keywords.
	* init.cc (struct lang_flags): Add true_false.
	(lang_defaults): Update.
	(cpp_set_lang): Set true_false.
2022-09-07 13:56:46 +00:00
Jakub Jelinek 572f5e1bc6 libcpp: Named universal character escapes and delimited escape sequence tweaks
On Tue, Aug 30, 2022 at 09:10:37PM +0000, Joseph Myers wrote:
> I'm seeing build failures of glibc for powerpc64, as illustrated by the
> following C code:
>
> #if 0
> \NARG
> #endif
>
> (the actual sysdeps/powerpc/powerpc64/sysdep.h code is inside #ifdef
> __ASSEMBLER__).
>
> This shows some problems with this feature - and with delimited escape
> sequences - as it affects C.  It's fine to accept it as an extension
> inside string and character literals, because \N or \u{...} would be
> invalid in the absence of the feature (i.e. the syntax for such literals
> fails to match, meaning that the rule about undefined behavior for a
> single ' or " as a pp-token applies).  But outside string and character
> literals, the usual lexing rules apply, the \ is a pp-token on its own and
> the code is valid at the preprocessing level, and with expansion of macros
> appearing before or after the \ (e.g. u defined as a macro in the \u{...}
> case) it may be valid code at the language level as well.  I don't know
> what older C++ versions say about this, but for C this means e.g.
>
> #define z(x) 0
> #define a z(
> int x = a\NARG);
>
> needs to be accepted as expanding to "int x = 0;", not interpreted as
> using the \N feature in an identifier and produce an error.

The following patch changes this, so that:
1) outside of string/character literals, \N without following { is never
   treated as an error nor warning, it is silently treated as \ separate
   token followed by whatever is after it
2) \u{123} and \N{LATIN SMALL LETTER A WITH ACUTE} are not handled as
   extension at all outside of string/character literals in the strict
   standard modes (-std=c*) except for -std=c++{23,2b}, only in the
   -std=gnu* modes, because it changes behavior on valid sources, e.g.
   #define z(x) 0
   #define a z(
   int x = a\u{123});
   int y = a\N{LATIN SMALL LETTER A WITH ACUTE});
3) introduces -Wunicode warning (on by default) and warns for cases
   of what looks like invalid delimited escape sequence or named
   universal character escape outside of string/character literals
   and is treated as separate tokens

2022-09-07  Jakub Jelinek  <jakub@redhat.com>

libcpp/
	* include/cpplib.h (struct cpp_options): Add cpp_warn_unicode member.
	(enum cpp_warning_reason): Add CPP_W_UNICODE.
	* init.cc (cpp_create_reader): Initialize cpp_warn_unicode.
	* charset.cc (_cpp_valid_ucn): In possible identifier contexts, don't
	handle \u{ or \N{ specially in -std=c* modes except -std=c++2{3,b}.
	In possible identifier contexts, don't emit an error and punt
	if \N isn't followed by {, or if \N{} surrounds some lower case
	letters or _.  In possible identifier contexts when not C++23, don't
	emit an error but warning about unknown character names and treat as
	separate tokens.  When treating as separate tokens \u{ or \N{, emit
	warnings.
gcc/
	* doc/invoke.texi (-Wno-unicode): Document.
gcc/c-family/
	* c.opt (Winvalid-utf8): Use ObjC instead of objC.  Remove
	" in comments" from description.
	(Wunicode): New option.
gcc/testsuite/
	* c-c++-common/cpp/delimited-escape-seq-4.c: New test.
	* c-c++-common/cpp/delimited-escape-seq-5.c: New test.
	* c-c++-common/cpp/delimited-escape-seq-6.c: New test.
	* c-c++-common/cpp/delimited-escape-seq-7.c: New test.
	* c-c++-common/cpp/named-universal-char-escape-5.c: New test.
	* c-c++-common/cpp/named-universal-char-escape-6.c: New test.
	* c-c++-common/cpp/named-universal-char-escape-7.c: New test.
	* g++.dg/cpp23/named-universal-char-escape1.C: New test.
	* g++.dg/cpp23/named-universal-char-escape2.C: New test.
2022-09-07 08:44:38 +02:00
GCC Administrator 47d2dcd139 Daily bump. 2022-09-06 00:17:07 +00:00
Joseph Myers 5f38bf14bc preprocessor: Disable trigraphs for C2x
ISO C2x removes trigraphs, so disable them accordingly for -std=c2x
(they can still be enabled using -trigraphs).

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

libcpp/
	* init.cc (lang_defaults): Disable trigraphs for C2x.

gcc/testsuite/
	* gcc.dg/cpp/c11-trigraphs-1.c, gcc.dg/cpp/c2x-trigraphs-1.c,
	gcc.dg/cpp/c2x-trigraphs-2.c: New tests.
2022-09-05 22:05:06 +00:00
GCC Administrator c64b09471a Daily bump. 2022-09-03 00:17:21 +00:00
David Malcolm bedfca647a c/c++: new warning: -Wxor-used-as-pow [PR90885]
PR c/90885 notes various places in real-world code where people have
written C/C++ code that uses ^ (exclusive or) where presumbably they
meant exponentiation.

For example
  https://codesearch.isocpp.org/cgi-bin/cgi_ppsearch?q=2%5E32&search=Search
currently finds 11 places using "2^32", and all of them appear to be
places where the user means 2 to the power of 32, rather than 2
exclusive-orred with 32 (which is 34).

This patch adds a new -Wxor-used-as-pow warning to the C and C++
frontends to complain about ^ when the left-hand side is the decimal
constant 2 or the decimal constant 10.

This is the same name as the corresponding clang warning:
  https://clang.llvm.org/docs/DiagnosticsReference.html#wxor-used-as-pow

As per the clang warning, the warning suggests converting the left-hand
side to a hexadecimal constant if you really mean xor, which suppresses
the warning (though this patch implements a fix-it hint for that, whereas
the clang implementation only has a fix-it hint for the initial
suggestion of exponentiation).

I initially tried implementing this without checking for decimals, but
this version had lots of false positives.  Checking for decimals
requires extending the lexer to capture whether or not a CPP_NUMBER
token was decimal.  I added a new DECIMAL_INT flag to cpplib.h for this.
Unfortunately, c_token and cp_tokens both have only an unsigned char for
their flags (as captured by c_lex_with_flags), whereas this would add
the 12th flag to cpp_tokens.  Of the first 8 flags, all but BOL are used
in the C or C++ frontends, but BOL is not, so I moved that to a higher
position, using its old value for the new DECIMAL_INT flag, so that it
is representable within an unsigned char.

Example output:

demo.c:5:13: warning: result of '2^8' is 10; did you mean '1 << 8' (256)? [-Wxor-used-as-pow]
    5 | int t2_8 = 2^8;
      |             ^
      |            --
      |            1<<
demo.c:5:12: note: you can silence this warning by using a hexadecimal constant (0x2 rather than 2)
    5 | int t2_8 = 2^8;
      |            ^
      |            0x2
demo.c:21:15: warning: result of '10^6' is 12; did you mean '1e6'? [-Wxor-used-as-pow]
   21 | int t10_6 = 10^6;
      |               ^
      |             ---
      |             1e
demo.c:21:13: note: you can silence this warning by using a hexadecimal constant (0xa rather than 10)
   21 | int t10_6 = 10^6;
      |             ^~
      |             0xa

gcc/c-family/ChangeLog:
	PR c/90885
	* c-common.h (check_for_xor_used_as_pow): New decl.
	* c-lex.cc (c_lex_with_flags): Add DECIMAL_INT to flags as appropriate.
	* c-warn.cc (check_for_xor_used_as_pow): New.
	* c.opt (Wxor-used-as-pow): New.

gcc/c/ChangeLog:
	PR c/90885
	* c-parser.cc (c_parser_string_literal): Clear ret.m_decimal.
	(c_parser_expr_no_commas): Likewise.
	(c_parser_conditional_expression): Likewise.
	(c_parser_binary_expression): Clear m_decimal when popping the
	stack.
	(c_parser_unary_expression): Clear ret.m_decimal.
	(c_parser_has_attribute_expression): Likewise for result.
	(c_parser_predefined_identifier): Likewise for expr.
	(c_parser_postfix_expression): Likewise for expr.
	Set expr.m_decimal when handling a CPP_NUMBER that was a decimal
	token.
	* c-tree.h (c_expr::m_decimal): New bitfield.
	* c-typeck.cc (parser_build_binary_op): Clear result.m_decimal.
	(parser_build_binary_op): Call check_for_xor_used_as_pow.

gcc/cp/ChangeLog:
	PR c/90885
	* cp-tree.h (class cp_expr): Add bitfield m_decimal.  Clear it in
	existing ctors.  Add ctor that allows specifying its value.
	(cp_expr::decimal_p): New accessor.
	* parser.cc (cp_parser_expression_stack_entry::flags): New field.
	(cp_parser_primary_expression): Set m_decimal of cp_expr when
	handling numbers.
	(cp_parser_binary_expression): Extract flags from token when
	populating stack.  Call check_for_xor_used_as_pow.

gcc/ChangeLog:
	PR c/90885
	* doc/invoke.texi (Warning Options): Add -Wxor-used-as-pow.

gcc/testsuite/ChangeLog:
	PR c/90885
	* c-c++-common/Wxor-used-as-pow-1.c: New test.
	* c-c++-common/Wxor-used-as-pow-fixits.c: New test.
	* g++.dg/parse/expr3.C: Convert 2 to 0x2 to suppress
	-Wxor-used-as-pow.
	* g++.dg/warn/Wparentheses-10.C: Likewise.
	* g++.dg/warn/Wparentheses-18.C: Likewise.
	* g++.dg/warn/Wparentheses-19.C: Likewise.
	* g++.dg/warn/Wparentheses-9.C: Likewise.
	* g++.dg/warn/Wxor-used-as-pow-named-op.C: New test.
	* gcc.dg/Wparentheses-6.c: Convert 2 to 0x2 to suppress
	-Wxor-used-as-pow.
	* gcc.dg/Wparentheses-7.c: Likewise.
	* gcc.dg/precedence-1.c: Likewise.

libcpp/ChangeLog:
	PR c/90885
	* include/cpplib.h (BOL): Move macro to 1 << 12 since it is
	not used by C/C++'s unsigned char token flags.
	(DECIMAL_INT): New, using 1 << 6, so that it is visible as
	part of C/C++'s 8 bits of token flags.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2022-09-02 18:29:33 -04:00
GCC Administrator bb0a1556df Daily bump. 2022-09-02 00:16:33 +00:00
Jakub Jelinek 0b8c57ed40 libcpp: Add -Winvalid-utf8 warning [PR106655]
The following patch introduces a new warning - -Winvalid-utf8 similarly
to what clang now has - to diagnose invalid UTF-8 byte sequences in
comments, but not just in those, but also in string/character literals
and outside of them.

The warning is on by default when explicit -finput-charset=UTF-8 is
used and C++23 compilation is requested and if -{,W}pedantic or
-pedantic-errors it is actually a pedwarn.

The reason it is on by default only for -finput-charset=UTF-8 is
that the sources often are UTF-8, but sometimes could be some ASCII
compatible single byte encoding where non-ASCII characters only
appear in comments.  So having the warning off by default
is IMO desirable.  The C++23 pedantic mode for when the source code
is UTF-8 is -std=c++23 -pedantic-errors -finput-charset=UTF-8.

2022-09-01  Jakub Jelinek  <jakub@redhat.com>

	PR c++/106655
libcpp/
	* include/cpplib.h (struct cpp_options): Implement C++23
	P2295R6 - Support for UTF-8 as a portable source file encoding.
	Add cpp_warn_invalid_utf8 and cpp_input_charset_explicit fields.
	(enum cpp_warning_reason): Add CPP_W_INVALID_UTF8 enumerator.
	* init.cc (cpp_create_reader): Initialize cpp_warn_invalid_utf8
	and cpp_input_charset_explicit.
	* charset.cc (_cpp_valid_utf8): Adjust function comment.
	* lex.cc (UCS_LIMIT): Define.
	(utf8_continuation): New const variable.
	(utf8_signifier): Move earlier in the file.
	(_cpp_warn_invalid_utf8, _cpp_handle_multibyte_utf8): New functions.
	(_cpp_skip_block_comment): Handle -Winvalid-utf8 warning.
	(skip_line_comment): Likewise.
	(lex_raw_string, lex_string): Likewise.
	(_cpp_lex_direct): Likewise.
gcc/
	* doc/invoke.texi (-Winvalid-utf8): Document it.
gcc/c-family/
	* c.opt (-Winvalid-utf8): New warning.
	* c-opts.cc (c_common_handle_option) <case OPT_finput_charset_>:
	Set cpp_opts->cpp_input_charset_explicit.
	(c_common_post_options): If -finput-charset=UTF-8 is explicit
	in C++23, enable -Winvalid-utf8 by default and if -pedantic
	or -pedantic-errors, make it a pedwarn.
gcc/testsuite/
	* c-c++-common/cpp/Winvalid-utf8-1.c: New test.
	* c-c++-common/cpp/Winvalid-utf8-2.c: New test.
	* c-c++-common/cpp/Winvalid-utf8-3.c: New test.
	* g++.dg/cpp23/Winvalid-utf8-1.C: New test.
	* g++.dg/cpp23/Winvalid-utf8-2.C: New test.
	* g++.dg/cpp23/Winvalid-utf8-3.C: New test.
	* g++.dg/cpp23/Winvalid-utf8-4.C: New test.
	* g++.dg/cpp23/Winvalid-utf8-5.C: New test.
	* g++.dg/cpp23/Winvalid-utf8-6.C: New test.
	* g++.dg/cpp23/Winvalid-utf8-7.C: New test.
	* g++.dg/cpp23/Winvalid-utf8-8.C: New test.
	* g++.dg/cpp23/Winvalid-utf8-9.C: New test.
	* g++.dg/cpp23/Winvalid-utf8-10.C: New test.
	* g++.dg/cpp23/Winvalid-utf8-11.C: New test.
	* g++.dg/cpp23/Winvalid-utf8-12.C: New test.
2022-09-01 09:56:44 +02:00
GCC Administrator 542c60c4fb Daily bump. 2022-09-01 00:17:39 +00:00
Jakub Jelinek b3048b6ffb libcpp: Make static checkers happy about makeuname2c [PR106778]
The assertion ensures that we point within the image and at a byte
we haven't touched yet (or at least that it isn't the first byte
of an already stored tree), some static checker was unhappy about
first checking that it is zero and only afterwards checking that it
is within bounds.

2022-08-31  Jakub Jelinek  <jakub@redhat.com>

	PR preprocessor/106778
	* makeuname2c.cc (write_nodes): Reverse order of && operands in
	assert.
2022-08-31 10:22:36 +02:00
GCC Administrator 16f542d6b8 Daily bump. 2022-08-27 00:17:09 +00:00
Jakub Jelinek dad2d3e003 libcpp: Implement P2362R3 - Remove non-encodable wide character literals and multicharacter [PR106647]
My understanding of the paper is that we just want to promote the CPP_WCHAR
"character constant too long for its type" warning to error as it is already
error for u8, u and U literals.

2022-08-26  Jakub Jelinek  <jakub@redhat.com>

	PR c++/106647
	* charset.cc (wide_str_to_charconst): Implement P2362R3 - Remove
	non-encodable wide character literals and multicharacter.  For
	C++23 use CPP_DL_ERROR instead of CPP_DL_WARNING for
	"character constant too long for its type" diagnostics on CPP_WCHAR
	literals.

	* g++.dg/cpp23/wchar-multi1.C: New test.
	* g++.dg/cpp23/wchar-multi2.C: New test.
2022-08-26 16:06:20 +02:00
Jakub Jelinek eb4879ab90 c++: Implement C++23 P2071R2 - Named universal character escapes [PR106648]
The following patch implements the
C++23 P2071R2 - Named universal character escapes
paper to support \N{LATIN SMALL LETTER E} etc.
I've used Unicode 14.0, there are 144803 character name properties
(including the ones generated by Unicode NR1 and NR2 rules)
and correction/control/alternate aliases, together with zero terminators
that would be 3884745 bytes, which is clearly unacceptable for libcpp.
This patch instead contains a generator which from the UnicodeData.txt
and NameAliases.txt files emits a space optimized radix tree (208765
bytes long for 14.0), a single string literal dictionary (59418 bytes),
maximum name length (currently 88 chars) and two small helper arrays
for the NR1/NR2 name generation.
The radix tree needs 2 to 9 bytes per node, the exact format is
described in the generator program.  There could be ways to shrink
the dictionary size somewhat at the expense of slightly slower lookups.

Currently the patch implements strict matching (that is what is needed
to actually implement it on valid code) and Unicode UAX44-LM2 algorithm
loose matching to provide hints (that algorithm essentially ignores
hyphens in between two alphanumeric characters, spaces and underscores
(with one exception for hyphen) and does case insensitive matching).
In the attachment is a WIP patch that shows how to implement also
spellcheck.{h,cc} style discovery of misspellings, but I'll need to talk
to David Malcolm about it, as spellcheck.{h,cc} is in gcc/ subdir
(so the WIP incremental patch instead prints all the names to stderr).

2022-08-26  Jakub Jelinek  <jakub@redhat.com>

	PR c++/106648
libcpp/
	* charset.cc: Implement C++23 P2071R2 - Named universal character
	escapes.  Include uname2c.h.
	(hangul_syllables, hangul_count): New variables.
	(struct uname2c_data): New type.
	(_cpp_uname2c, _cpp_uname2c_uax44_lm2): New functions.
	(_cpp_valid_ucn): Use them.  Handle named universal character escapes.
	(convert_ucn): Adjust comment.
	(convert_escape): Call convert_ucn even for \N.
	(_cpp_interpret_identifier): Handle named universal character escapes.
	* lex.cc (get_bidi_ucn): Fix up function comment formatting.
	(get_bidi_named): New function.
	(forms_identifier_p, lex_string): Handle named universal character
	escapes.
	* makeuname2c.cc: New file.  Small parts copied from makeucnid.cc.
	* uname2c.h: New generated file.
gcc/c-family/
	* c-cppbuiltin.cc (c_cpp_builtins): Predefine
	__cpp_named_character_escapes to 202207L.
gcc/testsuite/
	* c-c++-common/cpp/named-universal-char-escape-1.c: New test.
	* c-c++-common/cpp/named-universal-char-escape-2.c: New test.
	* c-c++-common/cpp/named-universal-char-escape-3.c: New test.
	* c-c++-common/cpp/named-universal-char-escape-4.c: New test.
	* c-c++-common/Wbidi-chars-25.c: New test.
	* gcc.dg/cpp/named-universal-char-escape-1.c: New test.
	* gcc.dg/cpp/named-universal-char-escape-2.c: New test.
	* g++.dg/cpp/named-universal-char-escape-1.C: New test.
	* g++.dg/cpp/named-universal-char-escape-2.C: New test.
	* g++.dg/cpp23/feat-cxx2b.C: Test __cpp_named_character_escapes.
2022-08-26 09:27:39 +02:00
GCC Administrator e8fc33aabc Daily bump. 2022-08-25 00:16:33 +00:00
Jakub Jelinek 365202625d preprocessor: Implement C++23 P2437R1 - Support for #warning [PR106646]
On Thu, Aug 18, 2022 at 11:02:44PM +0000, Joseph Myers wrote:
> ISO C2x standardizes the existing #warning extension.  Arrange
> accordingly for it not to be diagnosed with -std=c2x -pedantic, but to
> be diagnosed with -Wc11-c2x-compat.

And here is the corresponding C++ version.
Don't pedwarn about this for C++23/GNU++23 and tweak the diagnostics
for C++ otherwise, + testsuite coverage.
The diagnostic wording is similar e.g. to the #elifdef diagnostics.

2022-08-24  Jakub Jelinek  <jakub@redhat.com>

	PR c++/106646
	* init.cc: Implement C++23 P2437R1 - Support for #warning.
	(lang_defaults): Set warning_directive for GNUCXX23 and CXX23.
	* directives.cc (directive_diagnostics): Use different wording of
	#warning pedwarn for C++.

	* g++.dg/cpp/warning-1.C: New test.
	* g++.dg/cpp/warning-2.C: New test.
	* g++.dg/cpp/warning-3.C: New test.
2022-08-24 09:55:57 +02:00
GCC Administrator d6a39c25c0 Daily bump. 2022-08-21 00:16:33 +00:00
Jakub Jelinek e9dd050e0c libcpp: Implement C++23 P2290R3 - Delimited escape sequences [PR106645]
The following patch implements the C++23 P2290R3 paper.

2022-08-20  Jakub Jelinek  <jakub@redhat.com>

	PR c++/106645
libcpp/
	* include/cpplib.h (struct cpp_options): Implement
	P2290R3 - Delimited escape sequences.  Add delimite_escape_seqs
	member.
	* init.cc (struct lang_flags): Likewise.
	(lang_defaults): Add delim column.
	(cpp_set_lang): Copy over delimite_escape_seqs.
	* charset.cc (extend_char_range): New function.
	(_cpp_valid_ucn): Use it.  Handle delimited escape sequences.
	(convert_hex): Likewise.
	(convert_oct): Likewise.
	(convert_ucn): Use extend_char_range.
	(convert_escape): Call convert_oct even for \o.
	(_cpp_interpret_identifier): Handle delimited escape sequences.
	* lex.cc (get_bidi_ucn_1): Likewise.  Add end argument, fill it in.
	(get_bidi_ucn): Adjust get_bidi_ucn_1 caller.  Use end argument to
	compute num_bytes.
gcc/testsuite/
	* c-c++-common/cpp/delimited-escape-seq-1.c: New test.
	* c-c++-common/cpp/delimited-escape-seq-2.c: New test.
	* c-c++-common/cpp/delimited-escape-seq-3.c: New test.
	* c-c++-common/Wbidi-chars-24.c: New test.
	* gcc.dg/cpp/delimited-escape-seq-1.c: New test.
	* gcc.dg/cpp/delimited-escape-seq-2.c: New test.
	* g++.dg/cpp/delimited-escape-seq-1.C: New test.
	* g++.dg/cpp/delimited-escape-seq-2.C: New test.
2022-08-20 10:26:55 +02:00
GCC Administrator 30afe5e763 Daily bump. 2022-08-19 00:16:27 +00:00
Joseph Myers d7c3000147 preprocessor: Support #warning for standard C2x
ISO C2x standardizes the existing #warning extension.  Arrange
accordingly for it not to be diagnosed with -std=c2x -pedantic, but to
be diagnosed with -Wc11-c2x-compat.

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

gcc/testsuite/
	* gcc.dg/cpp/c11-warning-1.c, gcc.dg/cpp/c11-warning-2.c,
	gcc.dg/cpp/c11-warning-3.c, gcc.dg/cpp/c11-warning-4.c,
	gcc.dg/cpp/c2x-warning-1.c, gcc.dg/cpp/c2x-warning-2.c,
	gcc.dg/cpp/gnu11-warning-1.c, gcc.dg/cpp/gnu11-warning-2.c,
	gcc.dg/cpp/gnu11-warning-3.c, gcc.dg/cpp/gnu11-warning-4.c,
	gcc.dg/cpp/gnu2x-warning-1.c, gcc.dg/cpp/gnu2x-warning-2.c: New
	tests.

libcpp/
	* include/cpplib.h (struct cpp_options): Add warning_directive.
	* init.cc (struct lang_flags, lang_defaults): Add
	warning_directive.
	* directives.cc (DIRECTIVE_TABLE): Mark #warning as STDC2X not
	EXTENSION.
	(directive_diagnostics): Diagnose #warning with -Wc11-c2x-compat,
	or with -pedantic for a standard not supporting #warning.
2022-08-18 23:01:01 +00:00
GCC Administrator 47a61e6514 Daily bump. 2022-08-17 00:17:17 +00:00
Tom Honermann 60468d6cd4 c++: Fix pragma suppression of -Wc++20-compat diagnostics [PR106423]
Gcc's '#pragma GCC diagnostic' directives are processed in "early mode"
(see handle_pragma_diagnostic_early) for the C++ frontend and, as such,
require that the target diagnostic option be enabled for the preprocessor
(see c_option_is_from_cpp_diagnostics).  This change modifies the
-Wc++20-compat option definition to register it as a preprocessor option
so that its associated diagnostics can be suppressed.  The changes also
implicitly disable the option in C++20 and later modes.  These changes
are consistent with the definition of the -Wc++11-compat option.

This support is motivated by the need to suppress the following diagnostic
otherwise issued in C++17 and earlier modes due to the char8_t typedef
present in the uchar.h header file in glibc 2.36.
  warning: identifier ‘char8_t’ is a keyword in C++20 [-Wc++20-compat]

Tests are added to validate suppression of both -Wc++11-compat and
-Wc++20-compat related diagnostics (fixes were only needed for the C++20
case).

	PR c++/106423

gcc/c-family/ChangeLog:
	* c-opts.cc (c_common_post_options): Disable -Wc++20-compat
	diagnostics in C++20 and later.
	* c.opt (Wc++20-compat): Enable hooks for the preprocessor.

gcc/cp/ChangeLog:
	* parser.cc (cp_lexer_saving_tokens): Add comment regarding
	diagnostic requirements.

gcc/testsuite/ChangeLog:
	* g++.dg/cpp0x/keywords2.C: New test.
	* g++.dg/cpp2a/keywords2.C: New test.

libcpp/ChangeLog:
	* include/cpplib.h (cpp_warning_reason): Add CPP_W_CXX20_COMPAT.
	* init.cc (cpp_create_reader): Add cpp_warn_cxx20_compat.
2022-08-16 15:15:38 -04:00
GCC Administrator 5f17badb64 Daily bump. 2022-08-09 00:16:47 +00:00
Tom Honermann 053876cdbe preprocessor/106426: Treat u8 character literals as unsigned in char8_t modes.
This patch corrects handling of UTF-8 character literals in preprocessing
directives so that they are treated as unsigned types in char8_t enabled
C++ modes (C++17 with -fchar8_t or C++20 without -fno-char8_t). Previously,
UTF-8 character literals were always treated as having the same type as
ordinary character literals (signed or unsigned dependent on target or use
of the -fsigned-char or -funsigned char options).

	PR preprocessor/106426

gcc/c-family/ChangeLog:
	* c-opts.cc (c_common_post_options): Assign cpp_opts->unsigned_utf8char
	subject to -fchar8_t, -fsigned-char, and/or -funsigned-char.

gcc/testsuite/ChangeLog:
	* g++.dg/ext/char8_t-char-literal-1.C: Check signedness of u8 literals.
	* g++.dg/ext/char8_t-char-literal-2.C: Check signedness of u8 literals.

libcpp/ChangeLog:
	* charset.cc (narrow_str_to_charconst): Set signedness of CPP_UTF8CHAR
	literals based on unsigned_utf8char.
	* include/cpplib.h (cpp_options): Add unsigned_utf8char.
	* init.cc (cpp_create_reader): Initialize unsigned_utf8char.
2022-08-08 19:50:40 +00:00
GCC Administrator bdc7b765f8 Daily bump. 2022-07-16 00:16:30 +00:00
Jonathan Wakely f858fe7a8b libcpp: Improve encapsulation of label_text
This adjusts the API of label_text so that the data members are private
and cannot be modified by callers.  Add accessors for them instead, and
make the accessors const-correct.  Also rename moved_from () to the more
idiomatic release ().  Also remove the unused take_or_copy () member
function which has confusing ownership semantics.

gcc/analyzer/ChangeLog:

	* call-info.cc (call_info::print): Adjust to new label_text API.
	* checker-path.cc (checker_event::dump): Likewise.
	(region_creation_event::get_desc): Likewise.
	(state_change_event::get_desc): Likewise.
	(superedge_event::should_filter_p): Likewise.
	(start_cfg_edge_event::get_desc): Likewise.
	(call_event::get_desc): Likewise.
	(return_event::get_desc): Likewise.
	(warning_event::get_desc): Likewise.
	(checker_path::dump): Likewise.
	(checker_path::debug): Likewise.
	* diagnostic-manager.cc (diagnostic_manager::prune_for_sm_diagnostic):
	Likewise.
	(diagnostic_manager::prune_interproc_events): Likewise.
	* engine.cc (feasibility_state::maybe_update_for_edge):
	Likewise.
	* program-state.cc (sm_state_map::to_json): Likewise.
	* region-model-impl-calls.cc (region_model::impl_call_analyzer_describe): Likewise.
	(region_model::impl_call_analyzer_dump_capacity): Likewise.
	* region.cc (region::to_json): Likewise.
	* sm-malloc.cc (inform_nonnull_attribute): Likewise.
	* store.cc (binding_map::to_json): Likewise.
	(store::to_json): Likewise.
	* supergraph.cc (superedge::dump): Likewise.
	* svalue.cc (svalue::to_json): Likewise.

gcc/c-family/ChangeLog:

	* c-format.cc (class range_label_for_format_type_mismatch):
	Adjust to new label_text API.

gcc/ChangeLog:

	* diagnostic-format-json.cc (json_from_location_range): Adjust
	to new label_text API.
	* diagnostic-format-sarif.cc (sarif_builder::make_location_object):
	Likewise.
	* diagnostic-show-locus.cc (struct pod_label_text): Likewise.
	(layout::print_any_labels): Likewise.
	* tree-diagnostic-path.cc (class path_label): Likewise.
	(struct event_range): Likewise.
	(default_tree_diagnostic_path_printer): Likewise.
	(default_tree_make_json_for_path): Likewise.

libcpp/ChangeLog:

	* include/line-map.h (label_text::take_or_copy): Remove.
	(label_text::moved_from): Rename to release.
	(label_text::m_buffer, label_text::m_owned): Make private.
	(label_text::get, label_text::is_owned): New accessors.
2022-07-15 09:40:47 +01:00
GCC Administrator cff72485b1 Daily bump. 2022-07-14 00:16:48 +00:00
Marek Polacek 86a15b266a libcpp: Avoid pessimizing std::move [PR106272]
std::move in a return statement can prevent the NRVO:
<https://developers.redhat.com/blog/2019/04/12/understanding-when-not-to-stdmove-in-c>

PR106272 reports that we have two such cases in class label_text's
member functions.  We have -Wpessimizing-move that's supposed to detect
problematic std::move uses, but in this case it didn't trigger.  I've filed
PR106276 to track that.

	PR preprocessor/106272

libcpp/ChangeLog:

	* include/line-map.h (class label_text): Don't std::move in a return
	statement.
2022-07-13 14:22:09 -04:00
GCC Administrator b53ebbc541 Daily bump. 2022-07-11 00:16:25 +00:00
Lewis Hyatt 0587cef3d7 c: Fix location for _Pragma tokens [PR97498]
The handling of #pragma GCC diagnostic uses input_location, which is not always
as precise as needed; in particular the relative location of some tokens and a
_Pragma directive will crucially determine whether a given diagnostic is enabled
or suppressed in the desired way. PR97498 shows how the C frontend ends up with
input_location pointing to the beginning of the line containing a _Pragma()
directive, resulting in the wrong behavior if the diagnostic to be modified
pertains to some tokens found earlier on the same line. This patch fixes that by
addressing two issues:

    a) libcpp was not assigning a valid location to the CPP_PRAGMA token
    generated by the _Pragma directive.
    b) C frontend was not setting input_location to something reasonable.

With this change, the C frontend is able to change input_location to point to
the _Pragma token as needed.

This is just a two-line fix (one for each of a) and b)), the testsuite changes
were needed only because the location on the tested warnings has been somewhat
improved, so the tests need to look for the new locations.

gcc/c/ChangeLog:

	PR preprocessor/97498
	* c-parser.cc (c_parser_pragma): Set input_location to the
	location of the pragma, rather than the start of the line.

libcpp/ChangeLog:

	PR preprocessor/97498
	* directives.cc (destringize_and_run): Override the location of
	the CPP_PRAGMA token from a _Pragma directive to the location of
	the expansion point, as is done for the tokens lexed from it.

gcc/testsuite/ChangeLog:

	PR preprocessor/97498
	* c-c++-common/pr97498.c: New test.
	* c-c++-common/gomp/pragma-3.c: Adapt for improved warning locations.
	* c-c++-common/gomp/pragma-5.c: Likewise.
	* gcc.dg/pragma-message.c: Likewise.

libgomp/ChangeLog:

	* testsuite/libgomp.oacc-c-c++-common/reduction-5.c: Adapt for
	improved warning locations.
	* testsuite/libgomp.oacc-c-c++-common/vred2d-128.c: Likewise.
2022-07-10 16:50:03 -04:00
GCC Administrator 6345c41454 Daily bump. 2022-07-08 00:16:22 +00:00
David Malcolm a8dce13c07 Convert label_text to C++11 move semantics
libcpp's class label_text stores a char * for a string and a flag saying
whether it owns the buffer.  I added this class before we could use
C++11, and so to avoid lots of copying it required an explicit call
to label_text::maybe_free to potentially free the buffer.

Now that we can use C++11, this patch removes label_text::maybe_free in
favor of doing the cleanup in the destructor, and using C++ move
semantics to avoid any copying.  This allows lots of messy cleanup code
to be eliminated in favor of implicit destruction (mostly in the
analyzer).

No functional change intended.

gcc/analyzer/ChangeLog:
	* call-info.cc (call_info::print): Update for removal of
	label_text::maybe_free in favor of automatic memory management.
	* checker-path.cc (checker_event::dump): Likewise.
	(checker_event::prepare_for_emission): Likewise.
	(state_change_event::get_desc): Likewise.
	(superedge_event::should_filter_p): Likewise.
	(start_cfg_edge_event::get_desc): Likewise.
	(warning_event::get_desc): Likewise.
	(checker_path::dump): Likewise.
	(checker_path::debug): Likewise.
	* diagnostic-manager.cc
	(diagnostic_manager::prune_for_sm_diagnostic): Likewise.
	(diagnostic_manager::prune_interproc_events): Likewise.
	* program-state.cc (sm_state_map::to_json): Likewise.
	* region.cc (region::to_json): Likewise.
	* sm-malloc.cc (inform_nonnull_attribute): Likewise.
	* store.cc (binding_map::to_json): Likewise.
	(store::to_json): Likewise.
	* svalue.cc (svalue::to_json): Likewise.

gcc/c-family/ChangeLog:
	* c-format.cc (range_label_for_format_type_mismatch::get_text):
	Update for removal of label_text::maybe_free in favor of automatic
	memory management.

gcc/ChangeLog:
	* diagnostic-format-json.cc (json_from_location_range): Update for
	removal of label_text::maybe_free in favor of automatic memory
	management.
	* diagnostic-format-sarif.cc
	(sarif_builder::make_location_object): Likewise.
	* diagnostic-show-locus.cc (struct pod_label_text): New.
	(class line_label): Convert m_text from label_text to pod_label_text.
	(layout::print_any_labels): Move "text" to the line_label.
	* tree-diagnostic-path.cc (path_label::get_text): Update for
	removal of label_text::maybe_free in favor of automatic memory
	management.
	(event_range::print): Likewise.
	(default_tree_diagnostic_path_printer): Likewise.
	(default_tree_make_json_for_path): Likewise.

libcpp/ChangeLog:
	* include/line-map.h: Include <utility>.
	(class label_text): Delete maybe_free method in favor of a
	destructor.  Add move ctor and assignment operator.  Add deletion
	of the copy ctor and copy-assignment operator.  Rename field
	m_caller_owned to m_owned.  Add std::move where necessary; add
	moved_from member function.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2022-07-07 15:50:26 -04:00
GCC Administrator fb29fdea9c Daily bump. 2022-06-29 00:17:00 +00:00
Lewis Hyatt 4fda776a2f libcpp: Update ucnid.h to Unicode 14
This patch updates ucnid.h from Unicode 13 to Unicode 14.  Additionally, the
procedure detailed in contrib/unicode/README, which updates
generated_wcwidth.h, has been expanded with instructions for updating this
file as well, so that both may be done at the same time conveniently.  Two
additional Unicode data files which are needed to create ucnid.h are also
added to source control in contrib/unicode.

contrib/ChangeLog:

	* unicode/README: Added instructions for updating ucnid.h.
	* unicode/DerivedCoreProperties.txt: New file added to source
	control from Unicode 14.0 release.
	* unicode/DerivedNormalizationProps.txt: Likewise.

libcpp/ChangeLog:

	* ucnid.h: Regenerated for Unicode 14.0.
2022-06-28 17:33:37 -04:00
GCC Administrator b2b72757b2 Daily bump. 2022-06-27 00:16:20 +00:00
Lewis Hyatt 57988cbe73 libcpp: Update cpp_wcwidth() to Unicode 14.0.0
The procedure detailed in contrib/unicode/README was followed with nothing
notable coming up. The glibc scripts did not require any update, so the
only change was retrieving new versions of the Unicode data files and
rerunning gen_wcwidth.py.

contrib/ChangeLog:

	* unicode/EastAsianWidth.txt: Update to Unicode 14.0.0.
	* unicode/PropList.txt: Likewise.
	* unicode/README: Likewise.
	* unicode/UnicodeData.txt: Likewise.

libcpp/ChangeLog:

	* generated_cpp_wcwidth.h: Generated from updated Unicode data files.
2022-06-26 14:13:26 -04:00