Commit Graph

1283 Commits (master)

Author SHA1 Message Date
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