Joseph Myers [Mon, 18 Nov 2024 22:24:48 +0000 (22:24 +0000)]
c: Allow bool and enum null pointer constants [PR112556]
As reported in bug 112556, GCC wrongly rejects conversion of null
pointer constants with bool or enum type to pointers in
convert_for_assignment (assignment, initialization, argument passing,
return). Fix the code there to allow BOOLEAN_TYPE and ENUMERAL_TYPE;
it already allowed INTEGER_TYPE and BITINT_TYPE.
This bug (together with -std=gnu23 meaning false has type bool rather
than int) has in turn resulted in people thinking they need to fix
code using false as a null pointer constant for C23 compatibility.
While such a usage is certainly questionable, it has nothing to do
with C23 compatibility and the right place for warnings about such
usage is -Wzero-as-null-pointer-constant. I think it would be
appropriate to extend -Wzero-as-null-pointer-constant to cover
BOOLEAN_TYPE, ENUMERAL_TYPE and BITINT_TYPE (in all the various
contexts in which that option generates warnings), though this patch
doesn't do anything about that option.
Bootstrapped with no regressions for x86-64-pc-linux-gnu.
PR c/112556
gcc/c/
* c-typeck.cc (convert_for_assignment): Allow conversion of
ENUMERAL_TYPE and BOOLEAN_TYPE null pointer constants to pointers.
gcc/testsuite/
* gcc.dg/c11-null-pointer-constant-1.c,
gcc.dg/c23-null-pointer-constant-1.c: New tests.
David Malcolm [Mon, 18 Nov 2024 22:08:37 +0000 (17:08 -0500)]
libdiagnostics: add a "sarif-replay" command-line tool [PR96032]
This patch adds a new "sarif-replay" command-line tool for
viewing .sarif files. It uses libdiagnostics to "replay"
any diagnostics found in the .sarif files in text form as if
they were GCC diagnostics.
contrib/ChangeLog:
PR other/96032
* regenerate-sarif-spec-index.py: New file.
gcc/ChangeLog:
PR other/96032
* Makefile.in (lang_checks): If libdiagnostics is enabled, add
check-sarif-replay.
(SARIF_REPLAY_OBJS): New.
(ALL_HOST_OBJS): If libdiagnostics is enabled, add
$(SARIF_REPLAY_OBJS).
(sarif-replay): New.
(install-libdiagnostics): Add sarif-replay to deps, and install
it.
* configure: Regenerate.
* configure.ac (check_languages): If libdiagnostics is enabled,
add check-sarif-replay.
(LIBDIAGNOSTICS): If libdiagnostics is enabled, add sarif-replay.
* doc/install.texi (--enable-libdiagnostics): Note that it also
enables sarif-replay.
* libsarifreplay.cc: New file.
* libsarifreplay.h: New file.
* sarif-replay.cc: New file.
* sarif-spec-urls.def: New file.
gcc/testsuite/ChangeLog:
PR other/96032
* lib/gcc-dg.exp (gcc-dg-test-1): Add "replay-sarif".
* lib/sarif-replay-dg.exp: New file.
* lib/sarif-replay.exp: New file.
* sarif-replay.dg/2.1.0-invalid/3.1-not-an-object.sarif: New test.
* sarif-replay.dg/2.1.0-invalid/3.11.11-malformed-placeholder.sarif:
New test.
* sarif-replay.dg/2.1.0-invalid/3.11.11-missing-arguments-for-placeholders.sarif:
New test.
* sarif-replay.dg/2.1.0-invalid/3.11.11-not-enough-arguments-for-placeholders.sarif:
New test.
* sarif-replay.dg/2.1.0-invalid/3.13.2-no-version.sarif: New test.
* sarif-replay.dg/2.1.0-invalid/3.13.2-version-not-a-string.sarif:
New test.
* sarif-replay.dg/2.1.0-invalid/3.13.4-bad-runs.sarif: New test.
* sarif-replay.dg/2.1.0-invalid/3.13.4-no-runs.sarif: New test.
* sarif-replay.dg/2.1.0-invalid/3.13.4-non-object-in-runs.sarif:
New test.
* sarif-replay.dg/2.1.0-invalid/3.27.10-bad-level.sarif: New test.
* sarif-replay.dg/2.1.0-unhandled/3.27.10-none-level.sarif: New test.
* sarif-replay.dg/2.1.0-valid/error-with-note.sarif: New test.
* sarif-replay.dg/2.1.0-valid/escaped-braces.sarif: New test.
* sarif-replay.dg/2.1.0-valid/null-runs.sarif: New test.
* sarif-replay.dg/2.1.0-valid/signal-1.c.sarif: New test.
* sarif-replay.dg/2.1.0-valid/spec-example-1.sarif: New test.
* sarif-replay.dg/2.1.0-valid/spec-example-2.sarif: New test.
* sarif-replay.dg/2.1.0-valid/spec-example-3.sarif: New test.
* sarif-replay.dg/2.1.0-valid/spec-example-4.sarif: New test.
* sarif-replay.dg/2.1.0-valid/tutorial-example.sarif: New test.
* sarif-replay.dg/dg.exp: New script.
* sarif-replay.dg/malformed-json/array-missing-comma.sarif: New test.
* sarif-replay.dg/malformed-json/array-with-trailing-comma.sarif:
New test.
* sarif-replay.dg/malformed-json/bad-token.sarif: New test.
* sarif-replay.dg/malformed-json/object-missing-comma.sarif: New test.
* sarif-replay.dg/malformed-json/object-with-trailing-comma.sarif:
New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
David Malcolm [Mon, 18 Nov 2024 22:08:36 +0000 (17:08 -0500)]
json: add json parsing support
This patch implements JSON parsing support.
It's based on the parsing parts of the patch I posted here:
https://gcc.gnu.org/legacy-ml/gcc-patches/2017-08/msg00417.html
with the parsing moved to a separate source file and header, heavily
rewritten to capture source location information for JSON values, and
to capture errors via a result template.
I also added optional support for C and C++ style comments, which is
extremely useful in DejaGnu tests.
David Malcolm [Mon, 18 Nov 2024 22:08:36 +0000 (17:08 -0500)]
Add libdiagnostics (v4)
This patch adds a new libdiagnostics shared library available as
part of the GCC build via --enable-libdiagnostics when
configuring GCC.
It combines the following patches from:
https://gcc.gnu.org/pipermail/gcc-patches/2024-November/668632.html
[PATCH 1/8] libdiagnostics v4: header
[PATCH 2/8] libdiagnostics v4: implementation
[PATCH 3/8] libdiagnostics: add API docs
[PATCH 4/8] libdiagnostics v4: add C++ wrapper API
[PATCH 6/8] libdiagnostics v4: test suite
gcc/ChangeLog:
* configure.ac (check_languages): Add check-libdiagnostics.
(--enable-libdiagnostics): New.
* configure: Regenerate.
* Makefile.in (enable_libdiagnostics): New.
(lang_checks): If libdiagnostics is enabled, add
check-libdiagnostics.
(ALL_HOST_OBJS): If libdiagnostics is enabled, add
$(libdiagnostics_OBJS).
(start.encap): Add LIBDIAGNOSTICS.
(libdiagnostics_OBJS): New.
(LIBDIAGNOSTICS_VERSION_NUM): New, adapted from code in
jit/Make-lang.in.
(LIBDIAGNOSTICS_MINOR_NUM): Likewise.
(LIBDIAGNOSTICS_RELEASE_NUM): Likewise.
(LIBDIAGNOSTICS_FILENAME): Likewise.
(LIBDIAGNOSTICS_IMPORT_LIB): Likewise.
(libdiagnostics): Likewise.
(LIBDIAGNOSTICS_AGE): Likewise.
(LIBDIAGNOSTICS_BASENAME): Likewise.
(LIBDIAGNOSTICS_SONAME): Likewise.
(LIBDIAGNOSTICS_LINKER_NAME): Likewise.
(LIBDIAGNOSTICS_COMMA): Likewise.
(LIBDIAGNOSTICS_VERSION_SCRIPT_OPTION): Likewise.
(LIBDIAGNOSTICS_SONAME_OPTION): Likewise.
(LIBDIAGNOSTICS_SONAME_SYMLINK): Likewise.
(LIBDIAGNOSTICS_LINKER_NAME_SYMLINK): Likewise.
(LIBDIAGNOSTICS_FILENAME): Likewise.
(libdiagnostics.serial): Likewise.
(LIBDIAGNOSTICS_EXTRA_OPTS): Likewise.
(install): If libdiagnostics is enabled, add
install-libdiagnostics.
(libdiagnostics.install-headers): New.
(libdiagnostics.install-common): New, adapted from code in
jit/Make-lang.in.
(install-libdiagnostics): New.
* diagnostic-format-text.h
(diagnostic_text_output_format::get_location_text): Make public.
* doc/install.texi (--enable-libdiagnostics): New.
* doc/libdiagnostics/Makefile: New file.
* doc/libdiagnostics/conf.py: New file.
* doc/libdiagnostics/index.rst: New file.
* doc/libdiagnostics/make.bat: New file.
* doc/libdiagnostics/topics/diagnostic-manager.rst: New file.
* doc/libdiagnostics/topics/diagnostics.rst: New file.
* doc/libdiagnostics/topics/execution-paths.rst: New file.
* doc/libdiagnostics/topics/fix-it-hints.rst: New file.
* doc/libdiagnostics/topics/index.rst: New file.
* doc/libdiagnostics/topics/logical-locations.rst: New file.
* doc/libdiagnostics/topics/message-formatting.rst: New file.
* doc/libdiagnostics/topics/metadata.rst: New file.
* doc/libdiagnostics/topics/physical-locations.rst: New file.
* doc/libdiagnostics/topics/retrofitting.rst: New file.
* doc/libdiagnostics/topics/sarif.rst: New file.
* doc/libdiagnostics/topics/text-output.rst: New file.
* doc/libdiagnostics/topics/ux.rst: New file.
* doc/libdiagnostics/tutorial/01-hello-world.rst: New file.
* doc/libdiagnostics/tutorial/02-physical-locations.rst: New file.
* doc/libdiagnostics/tutorial/03-logical-locations.rst: New file.
* doc/libdiagnostics/tutorial/04-notes.rst: New file.
* doc/libdiagnostics/tutorial/05-warnings.rst: New file.
* doc/libdiagnostics/tutorial/06-fix-it-hints.rst: New file.
* doc/libdiagnostics/tutorial/07-execution-paths.rst: New file.
* doc/libdiagnostics/tutorial/index.rst: New file.
* libdiagnostics++.h: New file.
* libdiagnostics.cc: New file.
* libdiagnostics.h: New file.
* libdiagnostics.map: New file.
gcc/testsuite/ChangeLog:
* libdiagnostics.dg/libdiagnostics.exp: New, adapted from jit.exp.
* libdiagnostics.dg/sarif.py: New.
* libdiagnostics.dg/test-dump.c: New test.
* libdiagnostics.dg/test-error-c.py: New test.
* libdiagnostics.dg/test-error-with-note-c.py: New test.
* libdiagnostics.dg/test-error-with-note.c: New test.
* libdiagnostics.dg/test-error-with-note.cc: New test.
* libdiagnostics.dg/test-error.c: New test.
* libdiagnostics.dg/test-error.cc: New test.
* libdiagnostics.dg/test-example-1.c: New test.
* libdiagnostics.dg/test-fix-it-hint-c.py: New test.
* libdiagnostics.dg/test-fix-it-hint.c: New test.
* libdiagnostics.dg/test-fix-it-hint.cc: New test.
* libdiagnostics.dg/test-helpers++.h: New test.
* libdiagnostics.dg/test-helpers.h: New test.
* libdiagnostics.dg/test-labelled-ranges.c: New test.
* libdiagnostics.dg/test-labelled-ranges.cc: New test.
* libdiagnostics.dg/test-labelled-ranges.py: New test.
* libdiagnostics.dg/test-logical-location-c.py: New test.
* libdiagnostics.dg/test-logical-location.c: New test.
* libdiagnostics.dg/test-metadata-c.py: New test.
* libdiagnostics.dg/test-metadata.c: New test.
* libdiagnostics.dg/test-multiple-lines-c.py: New test.
* libdiagnostics.dg/test-multiple-lines.c: New test.
* libdiagnostics.dg/test-no-column-c.py: New test.
* libdiagnostics.dg/test-no-column.c: New test.
* libdiagnostics.dg/test-no-diagnostics-c.py: New test.
* libdiagnostics.dg/test-no-diagnostics.c: New test.
* libdiagnostics.dg/test-note-with-fix-it-hint-c.py: New test.
* libdiagnostics.dg/test-note-with-fix-it-hint.c: New test.
* libdiagnostics.dg/test-text-sink-options.c: New test.
* libdiagnostics.dg/test-warning-c.py: New test.
* libdiagnostics.dg/test-warning-with-path-c.py: New test.
* libdiagnostics.dg/test-warning-with-path.c: New test.
* libdiagnostics.dg/test-warning.c: New test.
* libdiagnostics.dg/test-write-sarif-to-file-c.py: New test.
* libdiagnostics.dg/test-write-sarif-to-file.c: New test.
* libdiagnostics.dg/test-write-text-to-file.c: New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
David Malcolm [Mon, 18 Nov 2024 21:49:04 +0000 (16:49 -0500)]
testsuite: move dg-test cleanup code from gcc-dg.exp to its own file
I need to use this cleanup logic for the testsuite for libdiagnostics
where it's too awkward to directly use gcc-dg.exp itself.
No functional change intended.
gcc/testsuite/ChangeLog:
* lib/dg-test-cleanup.exp: New file, from material moved from
lib/gcc-dg.exp.
* lib/gcc-dg.exp: Add load_lib of dg-test-cleanup.exp.
(cleanup-after-saved-dg-test): Move to lib/dg-test-cleanup.exp.
(dg-test): Likewise for override.
(initialize_prune_notes): Likewise.
Uros Bizjak [Mon, 18 Nov 2024 21:38:46 +0000 (22:38 +0100)]
i386: Enable *rsqrtsf2_sse without TARGET_SSE_MATH [PR117357]
__builtin_ia32_rsqrtsf2 expander generates UNSPEC_RSQRT insn pattern
also when TARGET_SSE_MATH is not set. Enable *rsqrtsf2_sse without
TARGET_SSE_MATH to avoid ICE with unrecognizable insn.
PR target/117357
gcc/ChangeLog:
* config/i386/i386.md (*rsqrtsf2_sse):
Also enable for !TARGET_SSE_MATH.
At the moment, early-ra ducks out of allocating any region
that contains a register with both a strong FPR affinity and
a strong GPR affinity. The proper allocators are much better
at handling that situation.
But this means that early-ra tends not to allocate a region
of vector code that ends in a reduction to a scalar integer
if any later arithmetic is done on the scalar integer result.
Currently, if a block acts as an isolated allocation region, the pass
will try to split the block into subregions *between* instructions if
there are no live FPRs or FPR allocnos. In the reduction case described
above, it's convenient to try the same thing *within* instructions.
If a block of vector code ends in a reduction, all FPRs and FPR
allocnos will be dead between the "use phase" and the "def phase"
of the reduction: the vector input will then have died, but the
scalar result will not yet have been born.
If we split the block that way, the problematic reduction result
will be part of the second region, which we can skip allocating,
but the vector work will be part of a separate region, which we
might be able to allocate.
This avoids a MOV in the testcase and also helps a small amount
with x264.
gcc/
* config/aarch64/aarch64-early-ra.cc
(early_ra::IGNORE_REG): New flag.
(early_ra::fpr_preference): Handle it.
(early_ra::record_constraints): Fail the allocation if an
IGNORE_REG output operand is not independent of the inputs.
(defines_multi_def_pseudo): New function.
(early_ra::could_split_region_here): New member function, split
out from...
(early_ra::process_block): ...here. Try splitting a block into
multiple regions between the definition and use phases of an
instruction. Set IGNORE_REG on the output registers if we do so.
gcc/testsuite/
* gcc.target/aarch64/early_ra_1.c: New test.
aarch64: Extend early-ra splitting of single-block regions
When early-ra treats a block as an isolated allocation region,
it opportunistically splits the block into smaller regions
at points where no FPRs or FPR allocnos are live. Previously
it only did this if m_allocation_successful, since the contrary
included cases in which the live range information wasn't trustworthy.
After earlier patches, we should now be able to trust the live range
information whenever m_accurate_live_ranges is true. This means that
we can split the block into regions even if allocation failed for the
current (sub)region.
This is just something I noticed by inspection. I don't have
a particular test case for it.
gcc/
* config/aarch64/aarch64-early-ra.cc
(early_ra::process_block): Check m_accurate_live_ranges
rather than m_allocation_successful when deciding whether
to split a block into multiple regions. Skip over subregions
that we decide not to allocate.
aarch64: Relax early_ra treatment of modes_tieable_p
At least on aarch64, modes_tieable_p is a stricter condition than
can_change_mode_class. can_change_mode_class tells us whether the
subreg rules produce a sensible result for a particular mode change.
modes_tieable_p in addition tells us whether a mode change is
reasonable for optimisation purposes.
A false return from either hook should (and does) prevent early_ra
from attempting an allocation. But only a false return from
can_change_mode_class should invalidate the liveness tracking;
we can still analyse subregs for which can_change_mode_class is
true and modes_tieable_p is false.
This doesn't make a difference on its own, but it helps later
patches.
gcc/
* config/aarch64/aarch64-early-ra.cc
(early_ra::get_allocno_subgroup): Split can_change_mode_class test
out from modes_tieable_p test and only invalidate the live range
information for the former.
The early-ra pass often didn't print a dump message when aborting the
allocation. This patch uses a similar helper to the previous patch.
gcc/
* config/aarch64/aarch64-early-ra.cc
(early_ra::record_allocation_failure): New member function.
(early_ra::get_allocno_subgroup): Use it instead of setting
m_allocation_successful directly.
(early_ra::record_constraints): Likewise.
(early_ra::allocate_colors): Likewise.
So far, early_ra has used a single m_allocation_successful bool
to record whether the current region is still being allocated.
But there are (at least) two reasons why we might pull out of
attempting an allocation:
(1) We can't track the liveness of individual FP allocnos,
due to some awkward subregs.
(2) We're afraid of doing a worse job than the proper allocator.
A later patch needs to distinguish (1) from other reasons, since
(1) means that the liveness information is not trustworthy.
(Currently we assume it is not trustworthy whenever
m_allocation_successful is false, but that's too conservative.)
gcc/
* config/aarch64/aarch64-early-ra.cc
(early_ra::record_live_range_failure): New member function.
(early_ra::m_accurate_live_ranges): New member variable.
(early_ra::start_new_region): Set m_accurate_live_ranges to true.
(early_ra::get_allocno_subgroup): Use record_live_range_failure
to abort the allocation on invalid subregs.
record_insn_refs has three distinct phases: model the definitions,
model any call, and model the uses. This patch splits each phase
out into its own function.
This isn't beneficial on its own, but it helps with later patches.
David Malcolm [Mon, 18 Nov 2024 19:20:17 +0000 (14:20 -0500)]
diagnostics: add support for nested diagnostics [PR116253]
Previously the diagnostic subsystem supported a one-deep
hierarchy via auto_diagnostic_group, for associating
notes with the warning/error they annotate; this only
affects SARIF output, not text output.
This patch adds support to the diagnostics subsystem for
capturing arbitrarily deep nesting structure within
diagnostic messages.
This patch:
* adds the ability to express nesting internally when
building diagnostics
* captures the nesting in SARIF output in the form documented
in SG15's P3358R0 ("SARIF for Structured Diagnostics") via
a "nestingLevel" property
* adds a new experimental mode to text output to see the
hierarchy, via:
-fdiagnostics-set-output=text:experimental-nesting=yes
* adds test coverage via a plugin, which with the above
option emits:
• note: child 0
• note: grandchild 0 0
• note: grandchild 0 1
• note: grandchild 0 2
• note: child 1
• note: grandchild 1 0
• note: grandchild 1 1
• note: grandchild 1 2
• note: child 2
• note: grandchild 2 0
• note: grandchild 2 1
• note: grandchild 2 2
using '*' rather than '•' if the text_art::theme is ascii-only.
My hope is to eventually:
(a) use this to improve C++'s template diagnostics
(b) remove the "experimental" caveat from the the text output mode
but this patch doesn't touch the C++ frontend, leaving both of these
to followup work.
gcc/c-family/ChangeLog:
PR other/116253
* c-opts.cc (c_diagnostic_text_finalizer): Use
text_output.build_indent_prefix for prefix to
diagnostic_show_locus.
gcc/ChangeLog:
PR other/116253
* diagnostic-core.h (class auto_diagnostic_nesting_level): New.
* diagnostic-format-sarif.cc (class sarif_builder): Update leading
comment re nesting of diagnostics.
(sarif_result::on_nested_diagnostic): Add nestingLevel property.
* diagnostic-format-text.cc (on_report_diagnostic): If we're
showing nested diagnostics, then print changes of location on a
new line, indented, and update m_last_location.
(diagnostic_text_output_format::build_prefix): If m_show_nesting,
then potentially add indentation and a bullet point.
(get_bullet_point_unichar): New.
(use_unicode_p): New.
(diagnostic_text_output_format::build_indent_prefix): New.
* diagnostic-format-text.h
(diagnostic_text_output_format::diagnostic_text_output_format):
Initialize m_show_nesting and m_show_nesting_levels.
(diagnostic_text_output_format::build_indent_prefix): New decl.
(diagnostic_text_output_format::show_nesting_p): New accessor
(diagnostic_text_output_format::show_locations_in_nesting_p):
Likewise.
(diagnostic_text_output_format::set_show_nesting): New.
(diagnostic_text_output_format::set_show_locations_in_nesting):
New.
(diagnostic_text_output_format::set_show_nesting_levels): New.
(diagnostic_text_output_format::m_show_nesting): New field.
(diagnostic_text_output_format::m_show_locations_in_nesting): New
field.
(diagnostic_text_output_format::m_show_nesting_levels): New field.
* diagnostic-global-context.cc
(auto_diagnostic_nesting_level::auto_diagnostic_nesting_level):
New.
(auto_diagnostic_nesting_level::~auto_diagnostic_nesting_level):
New.
* diagnostic-show-locus.cc (layout_printer::print): Temporarily
set DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE.
* diagnostic.cc (diagnostic_context::initialize): Update for
renaming of m_nesting_depth to m_group_nesting_depth and
initialize m_diagnostic_nesting_level.
(diagnostic_context::finish): Update for renaming of
m_nesting_depth to m_group_nesting_depth.
(diagnostic_context::report_diagnostic): Likewise.
(diagnostic_context::begin_group): Likewise.
(diagnostic_context::end_group): Likewise.
(diagnostic_context::push_nesting_level): New.
(diagnostic_context::pop_nesting_level): New.
(diagnostic_context::set_diagnostic_buffer): Update for renaming
of m_nesting_depth to m_group_nesting_depth. Assert that we don't
have nested diagnostics.
* diagnostic.h (diagnostic_context::push_nesting_level): New decl.
(diagnostic_context::pop_nesting_level): New decl.
(diagnostic_context::get_diagnostic_nesting_level): New accessor.
(diagnostic_context::build_indent_prefix): New decl.
(diagnostic_context::m_diagnostic_groups): Rename m_nesting_depth
to m_group_nesting_depth and add field m_diagnostic_nesting_level.
* doc/invoke.texi (fdiagnostics-add-output): Add note about
"experimental" schemes, keys, and values. Add keys
"experimental-nesting", "experimental-nesting-show-locations",
and "experimental-nesting-show-levels" to text scheme.
* opts-diagnostic.cc (text_scheme_handler::make_sink): Add keys
"experimental-nesting", "experimental-nesting-show-locations",
and "experimental-nesting-show-levels".
gcc/testsuite/ChangeLog:
PR other/116253
* gcc.dg/plugin/diagnostic-test-nesting-sarif.c: New test.
* gcc.dg/plugin/diagnostic-test-nesting-sarif.py: New test.
* gcc.dg/plugin/diagnostic-test-nesting-text-indented-show-levels.c:
New test.
* gcc.dg/plugin/diagnostic-test-nesting-text-indented-unicode.c:
New test.
* gcc.dg/plugin/diagnostic-test-nesting-text-indented.c: New test.
* gcc.dg/plugin/diagnostic-test-nesting-text-plain.c: New test.
* gcc.dg/plugin/diagnostic_plugin_test_nesting.c: New test plugin.
* gcc.dg/plugin/plugin.exp: Add the above.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Georg-Johann Lay [Sun, 17 Nov 2024 17:19:42 +0000 (18:19 +0100)]
AVR: target/84211 - Add a post reload register optimization pass.
This introduces a new post reload pass that tracks known values held
in registers and performs optimizations based on that knowledge.
It runs between the two instances of the RTL peephole pass.
The optimizations are activated by new option -mfuse-move=<0,23>
which provides a 3:2:2:2 mixed radix value:
Digit 0: Activates try_fuse:
Tries to use a MOVW instead of two LDIs.
Digit 1: Activates try_bin_arg1:
Simplify the 2nd operand of a binary operation, for example
X xor Y can be simplified to X when Y = 0. When Y is an
expensive constant that's already held in some register R, then
the expression can be replaced by X xor R.
Digit 2: Activates try_split_any:
Split multi-byte operations like shifts into 8-bit instructions.
Digit 3: Activates try_split_ldi:
Decompose LDI-like insns into a sequence of instructions with better
performance. For example, R2[4] = 0x1ff may be performed as:
CLR R5
CLR R4
MOVW R2, R4
INC R3
DEC R2
Digit 3 can have a value of 0, 1 or 2, where value=2 may come up
with code that performs better than with value=1 at the expense of
reduced traceability of the generated assembly code.
Here are some examples:
Without optimization | With optimization
==================== | =================
Harald Anlauf [Sun, 17 Nov 2024 22:04:58 +0000 (23:04 +0100)]
Fortran: add bounds-checking for ALLOCATE of CHARACTER with type-spec [PR53357]
Fix a rejects-(potentially)-valid code for ALLOCATE of CHARACTER with
type-spec, and implement a string-length check for -fcheck=bounds.
Implement more detailed errors or warnings when character function
declarations and references do not match.
PR fortran/53357
gcc/fortran/ChangeLog:
* dependency.cc (gfc_dep_compare_expr): Return correct result if
relationship of expressions could not be determined.
* interface.cc (gfc_check_result_characteristics): Implement error
messages if character function declations and references do not
agree, else emit warning in cases where a mismatch is suspected.
* trans-stmt.cc (gfc_trans_allocate): Implement a string length
check for -fcheck=bounds.
Richard Biener [Mon, 18 Nov 2024 12:46:52 +0000 (13:46 +0100)]
tree-optimization/117594 - fix live op vectorization for length masked case
The code was passing factor == 0 to vect_get_loop_len which always
returns an unmodified length, even if the number of scalar elements
doesn't agree. It also failed to insert the eventually generated
code.
Jeff Law [Mon, 18 Nov 2024 17:55:09 +0000 (10:55 -0700)]
[committed][RISC-V][PR target/117595] Fix bogus use of simplify_gen_subreg
And stage3 begins...
Zdenek's fuzzer caught this one. Essentially using simplify_gen_subreg
directly with an offset of 0 when we just needed a lowpart.
The offset of 0 works for little endian, but for big endian it's simply wrong.
simplify_gen_subreg will return NULL_RTX because the case isn't representable.
We then embed that NULL_RTX into an insn that's later scanned during
mark_jump_label.
Scanning the port I see a couple more instances of this incorrect idiom. One
is pretty obvious to fix. The others look a bit goofy and I'll probably need
to sync with Patrick on them.
Anyway tested on riscv64-elf and riscv32-elf with no regressions. Pushing to
the trunk.
PR target/117595
gcc/
* config/riscv/sync.md (atomic_compare_and_swap<mode>): Use gen_lowpart
rather than simplify_gen_subreg.
* config/riscv/riscv.cc (riscv_legitimize_move): Similarly.
gcc/testsuite/
* gcc.target/riscv/pr117595.c: New test.
Gaius Mulley [Mon, 18 Nov 2024 17:51:37 +0000 (17:51 +0000)]
PR modula2/117660: Errors referring to variables of type array could display full declaration
This patch ensures that the tokens defining the full declaration of an
ARRAY type is stored in the symbol table and used during production of
error messages.
gcc/m2/ChangeLog:
PR modula2/117660
* gm2-compiler/P2Build.bnf (ArrayType): Update tok with the
composite token produced during array type declaration.
* gm2-compiler/P2SymBuild.mod (EndBuildArray): Create the
combinedtok and store it into the symbol table.
Also ensure combinedtok is pushed to the quad stack.
(BuildFieldArray): Preserve typetok.
* gm2-compiler/SymbolTable.def (PutArray): Rename parameters.
* gm2-compiler/SymbolTable.mod (PutArray): Rename parameters.
gcc/testsuite/ChangeLog:
PR modula2/117660
* gm2/iso/fail/arraymismatch.mod: New test.
Jeff Law [Mon, 18 Nov 2024 17:11:01 +0000 (10:11 -0700)]
Fix more c23 bool fallout
While these haven't shown up in my tester (not configs I test) and I think
we're likely going to be deprecating the nds32 target. we might as well go
ahead and fix them.
I'm going to include this under the pr117628 umbrella.
Jeff Law [Mon, 18 Nov 2024 16:59:54 +0000 (09:59 -0700)]
[RFA] Fix csky and c6x build failures
csky fails to build libgcc after the c23 changes because it has a typedef for
bool. AFAICT it's internal to the file, so removing the typedef isn't an ABI
change.
Similiarly for c6x which includes unwind-arm-common.inc. I suspect most, if
not all of the arm-v7 and older targets are failing to build right now.
I've built and regression tested both csky-linux-gnu and c6x-elf with this
change. OK for the trunk?
Eric Botcazou [Sun, 10 Nov 2024 18:20:13 +0000 (19:20 +0100)]
ada: Fix interaction of aspect Predicate and static case expressions
The semantics of the GNAT-specific Predicate aspect should be equivalent
to those of the Static_Predicate aspect when the predicate expression is
static, but that is not correctly implemented for static case expressions.
gcc/ada/ChangeLog:
* exp_ch4.adb (Expand_N_Case_Expression): Remove the test on
enclosing predicate function for the return optimization.
Rewrite it in the general case to catch all nondynamic predicates.
(Expand_N_If_Expression): Remove the test on enclosing predicate
function for the return optimization.
Bob Duff [Sun, 10 Nov 2024 11:39:57 +0000 (06:39 -0500)]
ada: Atomic_Synchronization is not a user-visible check
Remove all user-level documentation of the check name
"Atomic_Synchronization". The documentation was confusing because
this check should never be used in source code, and because it
raises the question of whether All_Checks applies to it (it does
not).
Change the name Atomic_Synchronization to be _Atomic_Synchronization
(with a leading underscore) so that it cannot be used in source code.
This "check" is not really a check at all; it is used only internally in
the implementation of Disable/Enable_Atomic_Synchronization, because the
placement and scope of these pragmas match pragma Suppress.
gcc/ada/ChangeLog:
* doc/gnat_rm/implementation_defined_characteristics.rst:
Remove Atomic_Synchronization.
* doc/gnat_ugn/building_executable_programs_with_gnat.rst:
Likewise.
* doc/gnat_rm/implementation_defined_pragmas.rst: DRY.
Consolidate documentation of Disable/Enable_Atomic_Synchronization.
* checks.adb: Comment fix.
* exp_util.ads: Likewise.
* targparm.ads: Likewise.
* types.ads: Likewise.
* gnat1drv.adb: Likewise. DRY.
* sem_prag.adb (Process_Disable_Enable_Atomic_Sync):
Change name of Atomic_Synchronization to start with
underscore.
(Process_Suppress_Unsuppress): No need to check Comes_From_Source for
Atomic_Synchronization anymore; _Atomic_Synchronization can never
come from source. (Anyway, it shouldn't be ignored; it should be
an error.)
* snames.ads-tmpl (Atomic_Synchronization):
Change name to start with underscore.
* switch-c.adb (Scan_Front_End_Switches):
Minor cleanup: Use 'in'.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.
Eric Botcazou [Fri, 8 Nov 2024 14:35:27 +0000 (15:35 +0100)]
ada: Fix small oversight in removal of N_Unchecked_Expression node
In addition to Resolve_Indexed_Component, Eval_Indexed_Component can also
set the Do_Range_Check flag on the expressions of an N_Indexed_Component
node through the call on Check_Non_Static_Context, so this also needs to
be blocked by the Kill_Range_Check flag.
gcc/ada/ChangeLog:
* sem_eval.adb (Eval_Indexed_Component): Clear Do_Range_Check on
the expressions if Kill_Range_Check is set on the node.
Eric Botcazou [Fri, 8 Nov 2024 10:01:11 +0000 (11:01 +0100)]
ada: Fix another minor fallout of previous changes to aggregate expansion
This is another glitch associated with Initialization_Statements.
gcc/ada/ChangeLog:
* exp_util.adb (Remove_Init_Call): Rewrite a compound statement in
the Initialization_Statements of the variable as a null statement
instead of removing it.
* freeze.adb (Explode_Initialization_Compound_Statement): Small
comment tweaks.
Eric Botcazou [Thu, 7 Nov 2024 18:23:39 +0000 (19:23 +0100)]
ada: Fix another minor fallout of previous changes to aggregate expansion
The processing of static array aggregates in Exp_Aggr requires that their
bounds be representable as Int(eger) values for practical purposes, and
the previous changes have exposed another path where this is not checked.
This introduces a UI_Are_In_Int_Range local predicate for convenience.
gcc/ada/ChangeLog:
* exp_aggr.adb (UI_Are_In_Int_Range): New predicate.
(Aggr_Size_OK): Use it.
(Flatten): Likewise.
(Packed_Array_Aggregate_Handled): Likewise.
(Static_Array_Aggregate): Likewise.
Eric Botcazou [Thu, 7 Nov 2024 17:50:49 +0000 (18:50 +0100)]
ada: Fix minor fallout of previous changes to aggregate expansion
The problem occurs for an anonymous array object declared with an aspect and
when pragma {Initialize,Normalize}_Scalars is in effect: in this case, the
synthesized aggregate is attached to the Initialization_Statements field by
Convert_Aggr_In_Object_Decl, but Explode_Initialization_Compound_Statement
puts it back at the point of declaration instead of the freeze point, thus
voiding the effects of the mechanism.
This was previously hidden because of a bypass in Freeze_Entity which drops
the freeze node on the floor in this case, so the change fixes the issue and
removes the bypass in the process.
gcc/ada/ChangeLog:
* freeze.ads (Explode_Initialization_Compound_Statement): Adjust the
description.
* freeze.adb (Explode_Initialization_Compound_Statement): If the
entity has its freezing delayed, append the initialization actions
to its freeze actions.
(Freeze_Object_Declaration): Remove commented out code.
(Freeze_Entity): Remove bypass for object of anonymous array type.
Eric Botcazou [Thu, 31 Oct 2024 10:21:56 +0000 (11:21 +0100)]
ada: Small cleanup and refactoring in expansion of asynchronous select
The exception handler that catches Abort_Signal does nothing nowadays.
This refactors the code to use Build_Abort_Block more consistently and
also makes it simpler by dropping the identifier on the abort block.
No functional changes.
gcc/ada/ChangeLog:
* exp_sel.ads (Build_Abort_Block): Remove second parameter and
rename the third.
(Build_Abort_Block_Handler): Fix description.
* exp_sel.adb (Build_Abort_Block): Remove second parameter, rename
the third and adjust accordingly.
* exp_ch9.adb (Expand_N_Asynchronous_Select): Fix the description
of the exception handler throughout. Remove Abort_Block_Ent and
Hdle local variables. Call Build_Abort_Block consistently to build
the abort block and adjust existing calls.
Eric Botcazou [Wed, 6 Nov 2024 15:09:28 +0000 (16:09 +0100)]
ada: Cleanup in expansion of array aggregates in object declarations
This mainly decouples the handling of the declaration case from that of the
assignment case in Expand_Array_Aggregate, as well as moves the expansion
in the case of an aggregate that can be processed by the back end to the
Build_Array_Aggr_Code routine.
gcc/ada/ChangeLog:
* exp_aggr.adb (Build_Array_Aggr_Code): Build the simple assignment
for the case of an aggregate that can be handled by the back end.
(Expand_Array_Aggregate): Adjust description of the processing.
Move handling of declaration case to STEP 4 and remove handling of
the case of an aggregate that can be processed by the back end.
(Late_Expansion): Likewise for the second part.
* exp_ch3.adb (Expand_N_Object_Declaration): Deal with a delayed
aggregate synthesized for the default initialization, if any.
* sem_eval.adb (Eval_Indexed_Component): Bail out for the name of
an assignment statement.
Eric Botcazou [Tue, 5 Nov 2024 14:46:45 +0000 (15:46 +0100)]
ada: Further cleanup in expansion of array aggregates in allocators
This mainly decouples the handling of the allocator case from that of the
assignment case in Expand_Array_Aggregate and also makes Must_Slide a bit
more forgiving.
gcc/ada/ChangeLog:
* exp_aggr.adb (In_Place_Assign_OK): Remove handling of allocators
and call Must_Slide instead of implementing the check manually.
(Convert_To_Assignments): Adjust outdated comment.
(Expand_Array_Aggregate): Move handling of allocator case to STEP 3
and call Must_Slide directly for it.
(Must_Slide): Replace tests based on Is_OK_Static_Expression with
tests based on Compile_Time_Known_Value.
Eric Botcazou [Tue, 5 Nov 2024 10:24:06 +0000 (11:24 +0100)]
ada: Small cleanup in expansion of array aggregates in allocators
Convert_Array_Aggr_In_Allocator does nothing that Late_Expansion cannot do,
so this deletes the former and moves its support code for Storage_Model to
the latter. No functional changes.
gcc/ada/ChangeLog:
* exp_aggr.adb (Convert_Array_Aggr_In_Allocator): Delete.
(Convert_Aggr_In_Allocator): Do not call above procedure.
(Late_Expansion): Deal with a target that is the dereference of a
prefix with a Storage_Model. Remove an useless actual parameter
in the call to Build_Array_Aggr_Code.
Javier Miranda [Sun, 20 Oct 2024 12:13:03 +0000 (12:13 +0000)]
ada: Constraint error not raised in ACATS test c413007
Reverse the meaning of switch -gnatd_P; that is, enable by default
the generating of a runtime check when the prefix of the call is
an access-to-subprogram type with a null value.
gcc/ada/ChangeLog:
* sem_res.adb (Resolve_Actuals): Add by default a null-exclusion
check on the prefix of the call when it is an access-type; it can
be disabled using -gnatd_P.
* debug.adb (gnatd_P): Update documentation.
squirek [Thu, 24 Oct 2024 17:02:53 +0000 (17:02 +0000)]
ada: Crash on 'Access for Stream_Element_Array object
This patch fixes a crash in the compiler when the actual for an anonymous
access type formal is an 'Access of a Sream_Element_Array object during
the calculation of said actual's accessibility level.
gcc/ada/ChangeLog:
* accessibility.adb (Accessibility_Level): Handle the Input attribute
case
Robin Dapp [Thu, 8 Aug 2024 08:30:58 +0000 (10:30 +0200)]
aarch64: Add masked-load else operands.
This adds zero else operands to masked loads and their intrinsics.
I needed to adjust more than initially thought because we rely on
combine for several instructions and a change in a "base" pattern
needs to propagate to all those.
Robin Dapp [Thu, 8 Aug 2024 12:29:05 +0000 (14:29 +0200)]
vect: Add maskload else value support.
This patch adds an else operand to vectorized masked load calls.
The current implementation adds else-value arguments to the respective
target-querying functions that is used to supply the vectorizer with the
proper else value.
We query the target for its supported else operand and uses that for the
maskload call. If necessary, i.e. if the mode has padding bits and if
the else operand is nonzero, a VEC_COND enforcing a zero else value is
emitted.
Robin Dapp [Thu, 8 Aug 2024 10:54:36 +0000 (12:54 +0200)]
tree-ifcvt: Add zero maskload else value.
When predicating a load we implicitly assume that the else value is
zero. This matters in case the loaded value is padded (like e.g.
a Bool) and we must ensure that the padding bytes are zero on targets
that don't implicitly zero inactive elements.
A former version of this patch still had this handling in ifcvt but
the latest version defers it to the vectorizer.
gcc/ChangeLog:
* tree-if-conv.cc (predicate_load_or_store): Add zero else
operand and comment.
Robin Dapp [Thu, 8 Aug 2024 08:32:25 +0000 (10:32 +0200)]
docs: Document maskload else operand and behavior.
This patch amends the documentation for masked loads (maskload,
vec_mask_load_lanes, and mask_gather_load as well as their len
counterparts) with an else operand.
Tobias Burnus [Mon, 18 Nov 2024 10:06:58 +0000 (11:06 +0100)]
libgomp/plugin/plugin-nvptx.c: Change false to NULL to fix C23 wrong-return-type error [PR117626]
libgomp/ChangeLog:
PR libgomp/117626
* plugin/plugin-nvptx.c (nvptx_open_device): Use 'CUDA_CALL_ERET'
with 'NULL' as error return instead of 'CUDA_CALL' that returns false.
Andrew Pinski [Mon, 18 Nov 2024 04:21:58 +0000 (20:21 -0800)]
match: Fix the `max<a,b>==0` pattern for pointers [PR117646]
For pointers I forgot that BIT_IOR_EXPR is not valid so when
I added the pattern to convert `max<a,b> != 0` (r15-5356), GCC
would start to ICEing saying pointer types were not valid for
BIT_IOR_EXPR.
This fixes the problem by casting to the unsigned type of the
inner type. There was another way of fixing this to handling it
as `a == 0 & b == 0` but both match and reassoication (for pointers)
will then convert it back into the form I am creating here so
let's just use that form instead.
Bootstrapped and tested on x86_64-linux-gnu.
PR tree-optimization/117646
gcc/ChangeLog:
* match.pd (`max<a,b>==0`): Add casts to `unsigned type`.
gcc/testsuite/ChangeLog:
* gcc.dg/torture/minmaxneeqptr-1.c: New test.
Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
Jonathan Wakely [Thu, 14 Nov 2024 14:25:52 +0000 (14:25 +0000)]
libstdc++: Fix invalid casts in unordered container merge functions
François pointed out that static_cast<__node_ptr>(&_M_before_begin) is
invalid, because _M_before_begin is only a node-base not a node.
Refactor the new merge overloads to only cast when we know we have a
valid node.
He also pointed out some optimizations to allow reusing hash codes that
might be cached in the node. The _M_src_hash_code function already has
the right logic to decide when a cached hash code can be reused by a
different _Hashtable object.
libstdc++-v3/ChangeLog:
* include/bits/hashtable.h (_Hashtable::_M_src_hash_code):
Improve comments.
(_Hashtable::_M_merge_unique(_Hashtable&)): Use pointer_traits
to get before-begin pointer. Only use static_cast on valid
nodes, not the before-begin pointer. Reuse a hash code cached in
the node when possible.
(_Hashtable::_M_merge_multi(_Hashtable&)): Likewise.
Reviewed-by: François Dumont <fdumont@gcc.gnu.org>
Jason Merrill [Wed, 5 Jun 2024 01:15:02 +0000 (21:15 -0400)]
libcpp: add .c++-header-unit target
The dependency output for header unit modules is based on the absolute
pathname of the header file, but that's not something that a makefile can
portably refer to. This patch adds a .c++-header-unit target based on the
header name relative to an element of the include path.
libcpp/ChangeLog:
* internal.h (_cpp_get_file_dir): Declare.
* files.cc (_cpp_get_file_dir): New fn.
* mkdeps.cc (make_write): Use it.
Instead of doing a dg-run with a specific target check for linux.
Use signal as the effective-target since this requires the use
of ALARM signal to do the testing.
Also use check_vect in the main and renames main to main1 to make sure
we don't use the registers.
Tested on x86_64-linux-gnu.
PR testsuite/117494
gcc/testsuite/ChangeLog:
* gcc.dg/vect/pr101145inf.c: Remove dg-do and replace
with dg-require-effective-target of signal.
* gcc.dg/vect/pr101145inf_1.c: Likewise.
* gcc.dg/vect/pr101145inf.inc: Rename main to main1
and mark as noinline.
Include tree-vect.h. Have main call check_vect and main1.
Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
Jeff Law [Sun, 17 Nov 2024 23:44:09 +0000 (16:44 -0700)]
Improve ext-dce's ability to eliminate more extensions
I was looking at a regression in ext-dce's behavior just before Cauldron.
Essentially a bugfix in ext-dce ended up causing us to fail to eliminate some
useless extensions.
When we have a SUBREG object with SUBREG_PROMOTED_VAR* flags set, we generally
have to be more conservative in how we process bit group liveness, making bits
live that wouldn't obviously be live otherwise.
That's not always necessary though. For example, if we're storing a promoted
subreg into memory, we may not care about those extra live bits on this
instance of the subreg object (remember subregs are not shared!). Essentially
if the mode of the memory reference is not wider than the mode of the inner
REG, then we can clear the promoted state which in turn may allow more
extension elimination.
So at the start of ext-dce we do a simple pass over the IL and remove promoted
subreg state when it's obviously safe to do so (memory stores when the modes
allow it). That prevents extra bits from being live and ultimately allows us
to remove more useless extensions.
The testcase is in theory generic, but many targets won't have an opportunity
to optimize this case. So rather then build out a large inclusion/exclusion
list, I've just made the test risc-v specific.
Bootstrapped and regression tested on aarch64, riscv64, s390x, etc in my tester.
gcc/
* ext-dce.cc (maybe_clear_subreg_promoted_p): New function.
(ext_dce_execute): Call it.
gcc/testsuite
* gcc.target/riscv/ext-dce-1.c: New test.
2024-11-17 John David Anglin <danglin@gcc.gnu.org>
gcc/ChangeLog:
PR target/69374
* doc/install.texi (Specific) <hppa*-hp-hpux11>: Update anchor
and heading to reflect removal of 32-bit hppa support on HP-UX.
Trim 32-bit related text.
Florian Weimer [Sun, 17 Nov 2024 18:42:33 +0000 (19:42 +0100)]
c: Implement -Wdeprecated-non-prototype
This warning covers the C23 incompibilities resulting from using
() as parameter lists in function declarations.
The warning name comes from Clang. The implementation is not
perfect because GCC treats these two declarations as equivalent:
void f ();
void f (not_a_type);
This is a bit confusing because they are clearly visually distinct.
However, as of GCC 14, the second form is an error by default, so
treating both the same as far as -Wdeprecated-non-prototype does
not seem so bad from a user experience view.
PR c/95445
* c-decl.cc (start_function): Warn about parameters
after parameter-less declaration.
* c-typeck.cc (build_function_call_vec): Pass fntype
to convert_arguments.
(convert_arguments): Change argument to fntype and
compute typelist. Warn about parameter list mismatches
on first parameter.
PR c/95445
* gcc.dg/Wdeprecated-non-prototype-1.c: New test.
* gcc.dg/Wdeprecated-non-prototype-2.c: New test.
* gcc.dg/Wdeprecated-non-prototype-3.c: New test.
* gcc.dg/Wdeprecated-non-prototype-4.c: New test.
Jason Merrill [Sat, 16 Nov 2024 20:25:04 +0000 (15:25 -0500)]
c++: -M and modules again
While experimenting with testing module std I noticed that gcc -M broke on
it; it seems I need to set directives_only even sooner than I did in
r15-4219.
gcc/c-family/ChangeLog:
* c-ppoutput.cc (preprocess_file): Don't set directives_only here.
gcc/cp/ChangeLog:
* module.cc (module_preprocess_options): Set directives_only here.
Jason Merrill [Fri, 17 May 2024 01:43:20 +0000 (21:43 -0400)]
c-family: add -fsearch-include-path
The C++ modules code has a -fmodule-header (or -x c++-{user,system}-header)
option to specify looking up headers to compile to header units on the usual
include paths. I'd like to have the same functionality for full C++20
modules such as module std, which I proposed to live on the include path at
bits/std.cc. But this behavior doesn't seem necessarily connected to
modules, so I'm proposing a general C/C++ option to specify the behavior of
looking in the include path for the input files specified on the command
line.
Other ideas for the name of the option are very welcome.
The libcpp change is to allow -fsearch-include-path{,=user} to find files in
the current working directory, like -include. This can be handy for a quick
compile of both std.cc and a file that imports it, e.g.
Jason Merrill [Thu, 10 Oct 2024 21:27:50 +0000 (17:27 -0400)]
libstdc++: add module std [PR106852]
This patch introduces an installed source form of module std and std.compat.
To help a build system find them, we install a libstdc++.modules.json file
alongside libstdc++.so, which tells the build system where the files are and
any special flags it should use when compiling them (none, in this case).
The format is from a proposal in SG15. The build system can find this file
with 'gcc -print-file-name=libstdc++.modules.json'.
It seems preferable to use a relative path from this file to the sources so
that moving the installation doesn't break the reference, but I didn't see
any obvious way to compute that without relying on coreutils, perl, or
python, so I wrote a POSIX shell script for it. The .. canonicalization
bits aren't necessary since I discovered $(abspath), but I guess I might as
well leave them in.
Currently this installs the sources under $(gxx_include_dir)/bits/,
i.e. /usr/include/c++/15/bits. So with my -fsearch-include-path change,
std.cc can be compiled with g++ -fsearch-include-path bits/std.cc. Note
that if someone actually tries to #include <bits/std.cc> it will fail with
"error: module control-line cannot be in included file".
Any ideas about a more user-friendly way to express "compile module std" are
welcome.
The sources currently have the extension .cc, like other source files.
std.cc started with m.cencora's implementation in PR114600. I've made some
adjustments, but more is probably desirable, e.g. of the <algorithm>
handling of namespace ranges, and to remove exports of templates that are
only specialized in a particular header. I've filled in a bunch of missing
exports, and added some FIXMEs where I noticed bits that are not implemented
yet.
Since bits/stdc++.h also intends to include the whole standard library, I
include it rather than duplicate it. But stdc++.h comments out <execution>,
due to TBB issues; I include it separately and suppress TBB usage, so module
std won't currently provide parallel execution.
It seemed most convenient for the two files to be monolithic so we don't
need to worry about include paths. So the C library names that module
std.compat exports in both namespace std and :: are a block of code that is
appended to both files, adjusted based on whether the macro STD_COMPAT is
defined before the block.
In this implementation std.compat imports std; it would also be valid for it
to duplicate everything in std. I see the libc++ std.compat also imports
std.
As discussed in the PR, module std is supported in C++20 mode even though it
was added in C++23.
Changes to test module std will follow in a separate patch. In my testing
I've noticed a few compiler bugs that break various testcases, so I don't
expect to enable module std testing by default at first.
PR libstdc++/106852
libstdc++-v3/ChangeLog:
* include/bits/version.def: Add __cpp_lib_modules.
* include/bits/version.h: Regenerate.
* src/c++23/Makefile.am: Add modules std and std.compat.
* src/c++23/Makefile.in: Regenerate.
* src/c++23/std-clib.cc.in: New file.
* src/c++23/std.cc.in: New file.
* src/c++23/std.compat.cc.in: New file.
* src/c++23/libstdc++.modules.json.in: New file.
Jan Hubicka [Sun, 17 Nov 2024 14:48:29 +0000 (15:48 +0100)]
Mark asm statements as necessary in ipa-fnsummary
I forgot to mark asm statements as necessary in ipa-fnsummary. This should
mask failure of gcc.dg/guality/pr36728-2.c where the patch enabled
cloning which breaks debug info.
gcc/ChangeLog:
* ipa-fnsummary.cc (find_necessary_statements): ASM statements are
necessary.
Jan Hubicka [Sun, 17 Nov 2024 10:54:10 +0000 (11:54 +0100)]
ipa-modref bits for unsequenced and reproducible
C attributes reproducible and unsequenced implies that calling function twice
leads to same effect if parameters are otherwise unchanged (function call
itself does not count). This is bit bit stronger that modref's notion of
nondeterminism that says that same inputs will yield same outputs (function
call itself does count).
This patch makes reproducible/unsequenced imply determinism and cleans up
determinism handling. By itself it is not useful, since we can not make use of it
unless we know what are the inputs/outputs of the function which I plan to handle
by the "fn spec" attribute.
gcc/ChangeLog:
* ipa-modref.cc (modref_summary::useful_p): const/pure implies
determinism.
(modref_summary_lto::useful_p): Likewise.
(ignore_nondeterminism_p): Add CALLEE_FNTYPE parameter; check for
reproducible/unsequenced
(modref_access_analysis::record_access_p): Use ignore_nondeterminism_p
when handling volatile accesses.
(modref_access_analysis::get_access_for_fnspec): Update.
(modref_access_analysis::process_fnspec): Cleanup handling of NOVOPS.
(modref_access_analysis::analyze_call): Use ignore_nondeterminism_p
when handling asm statements.
(modref_access_analysis::analyze_stmt): Update.
(propagate_unknown_call): Update.
(modref_propagate_in_scc): Update.
(ipa_merge_modref_summary_after_inlining): Update.
Jan Hubicka [Sun, 17 Nov 2024 00:21:04 +0000 (01:21 +0100)]
Add __builtion_unreachable to vector::size(), vector::capacity()
This patch makes it clear that vector sizes and capacities are not
negative. With recent change to ipa-fnsummary this should not affect
inlining and improves codegen of some vector manipulation functions.
I tested clang build. Looking for throw_bad calls there are only 3
called considerably often (bad_allloc, bad_array_new_length and
function_callv).
The patch seems to reduce bad_alloc and bad_array_new_length calls
considerably:
bad_alloc 380->147
bad_array_new_length 832->128
libstdc++-v3/ChangeLog:
PR tree-optimization/109442
* include/bits/stl_vector.h: (vector::size(),
vector::capacity()): Add __builtin_unreachable call to announce
that size and capacity are non-negative.
gcc/testsuite/ChangeLog:
PR tree-optimization/109442
* g++.dg/tree-ssa/pr109442.C: New test.
Jan Hubicka [Sat, 16 Nov 2024 22:45:57 +0000 (23:45 +0100)]
Avoid expicit builtion list in tree-ssa-dce
while working on -fmalloc-dce I noticed that tree-ssa-dce.cc still has an
outdated list of builtions that are known to not read memory that can be
replaced by query to fnspec and modref.
If I get things right, dce does some dead store removal, but only on those
memory object that are non-aliased (automatic variabels with no address taken)
and for all other memory addresses it resorts to
mark_all_reaching_defs_necessary expecting DSE to do the rest. So we really
want to only check if there are no memory reads at all rather then trying to
understand them by parsing fnspec or modref summary.
I did run testsuite ensuring that all builtins matched previously are
still matched. There are few testcases where this check fails, due to
type incompatibility. New code uses gimple_call_builtin while other
just checked callee_decl.
We test things like calling free() without parmeter which I don't think
we want to care about, but there is also testase declaring
void * calloc (long, long)
where builtin declaration expects unsigned long. I am not sure if this
case should not be allowed by gimple_call_builtin?
Bootstrappe/regtested x86_64-linux. OK?
gcc/ChangeLog:
* ipa-modref.cc (ipa_modref_callee_reads_no_memory_p): New function.
* ipa-modref.h (ipa_modref_callee_reads_no_memory_p): Declare
* tree-ssa-dce.cc (propagate_necessity): Use it.
Jan Hubicka [Sat, 16 Nov 2024 22:44:13 +0000 (23:44 +0100)]
Minor cleanup to cxx_init_decl_processing
gcc/cp/ChangeLog:
* decl.cc (cxx_build_operator_new): Break out from ...
(cxx_build_operator_delete): Break out from ...
(cxx_init_operator_new_delete_decls): Break out from ...
(cxx_init_decl_processing): ... here.
Georg-Johann Lay [Sat, 16 Nov 2024 21:12:05 +0000 (22:12 +0100)]
AVR: Fix building LibF7 after switching to C23.
Since r15-5327, GNU-C23 is being used as C language default.
libf7.h doesn't assume headers like stdbool.h are present
and defines bool, true and false on its own.
libgcc/config/avr/libf7/
* libf7.h (bool, true, false): Don't define in C23 or higher.
Andrew Pinski [Sat, 16 Nov 2024 07:20:42 +0000 (23:20 -0800)]
match: Optimize `max(a,b) == 0` to `(a|b) == 0` for unsigned [PR115275]
For unsigned types, you can optimize `max<a,b> == 0` into
`(a|b) == 0` (that is both have to be zero). A similar thing happens for `!= 0`.
This optimization fixes the missed optimization (g++.dg/tree-ssa/pr115275.C)
that was reported exposed by adding phiprop early.
Bootstrapped and tested on x86_64-linux-gnu.
PR tree-optimization/115275
gcc/ChangeLog:
* match.pd (umax(a,b) ==/!= 0): New pattern.
gcc/testsuite/ChangeLog:
* g++.dg/tree-ssa/pr115275.C: New test.
* gcc.dg/tree-ssa/max_eqne-1.c: New test.
* gcc.dg/tree-ssa/max_eqne-2.c: New test.
Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
Eikansh Gupta [Mon, 11 Nov 2024 11:55:45 +0000 (17:25 +0530)]
MATCH: Simplify `min(a, b) op max(a, b)` to `a op b` [PR109401]
This patch simplify `min(a,b) op max(a,b)` to `a op b`. This optimization
will work for all the binary commutative operations. So, the `op` here can
be one of {plus, mult, bit_and, bit_xor, bit_ior, eq, ne, min, max}.
PR tree-optimization/109401
gcc/ChangeLog:
* match.pd (min(a,b) op max(a,b) -> a op b): New pattern.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/pr109401.c: New test.
* gcc.dg/tree-ssa/pr109401-1.c: New test.
Georg-Johann Lay [Sat, 16 Nov 2024 13:26:02 +0000 (14:26 +0100)]
AVR: target/116781 - Fix ICE due to (clobber (match_dup)) in tablejump.
This patch avoids (clobber (match_dup)) in insn patterns for tablejump.
The machine description now uses a scratch_operand instead which is
possible since the clobbered entity is known in advance:
3-byte PC : REG_Z
2-byte PC + JMP : REG_Z
2-byte PC + RJMP : None, hence scratch:HI is used.
The avr-casesi pass and optimization has to be adjusted to the new patterns.
PR target/116781
gcc/
* config/avr/avr.md (*tablejump_split, *tablejump): Add
operand 2 as a "scratch_operand" instead of a match_dup.
(casesi): Adjust expander operands accordingly. Use a scratch:HI
when the jump address is not clobbered. This is the case for a
2-byte PC + has no JMP instruction. In all the other cases, the
affected operand is REG_Z (reg:HI 30).
(casesi_<mode>_sequence): Adjust matcher to new anatomy.
* config/avr/avr-passes.cc (avr_is_casesi_sequence)
(avr_is_casesi_sequence, avr_optimize_casesi)
(avr_casei_sequence_check_operands): Adjust to new anatomy.
AVR: Add an RTL peephole to tweak lower_reg:QI o= cst.
For operations like X o= CST, regalloc may spill l-reg X to a d-reg:
D = X
D o= CST
X = D
where it is better to instead
D = CST
X o= D
This patch adds an according RTL peephole.
gcc/
* config/avr/avr.md: Add a peephole2 that improves bit operations
with a lower register and a constant.
Jakub Jelinek [Sat, 16 Nov 2024 16:04:38 +0000 (17:04 +0100)]
libgcc: Fix a warning/error in libgcc2.c [PR117624]
Since the switch to -std=gnu23 by default, float.h (included from
tsystem.h) defines INFINITY macro (to __builtin_inff ()), which now
results in a warning when compiling libgcc2.c which defines it
to something else (and, worse aarch64 compiles it with -Werror and
build fails).
libgcc2.c asserts INFINITY has the expected type which depends on
the macros with which libgcc2.c is being compiled, so guarding
the define with #ifndef INFINITY wouldn't work.
So this patch instead #undefs the macro before defining it.
2024-11-16 Jakub Jelinek <jakub@redhat.com>
PR libgcc/117624
* libgcc2.c (INFINITY): Add #undef before #define.
Paul Thomas [Sat, 16 Nov 2024 15:56:10 +0000 (15:56 +0000)]
Fortran: Fix segmentation fault in defined assignment [PR109066]
2024-11-16 Paul Thomas <pault@gcc.gnu.org>
gcc/fortran
PR fortran/109066
* resolve.cc (generate_component_assignments): If the temporary
for 'var' is a pointer and 'expr' is neither a constant or
a variable, change its attribute from pointer to allocatable.
This avoids assignment to a temporary point that has neither
been allocated or associated.
gcc/testsuite/
PR fortran/109066
* gfortran.dg/defined_assignment_12.f90: New test.
Jeff Law [Sat, 16 Nov 2024 15:42:01 +0000 (08:42 -0700)]
Fix various sh tests to work with c23
A few SH tests want to create a bool typedef which doesn't work for c23.
Easiest fix which should have no impact on the test behavior would be to just
change the name of the typedef so that doesn't conflict.
One test has a crazy function signature (similar to the PRU test someone just
fixed up). For that I'm using -std=gnu17.
Pushing to the trunk.
testsuite/
* gcc.target/sh/pr51244-15.c: Use "mybool" rather than "bool".
* gcc.target/sh/pr52933-1.c: Similarly.
* gcc.target/sh/pr54089-1.c: Similarly.
* gcc.target/sh/pr54089-7.c: Similarly.
* gcc.target/sh/pr54089-8.c: Similarly.
* gcc.target/sh/pr54089-9.c: Similarly.
* gcc.target/sh/pr64366.c: Use -std=gnu17.
Jeff Law [Sat, 16 Nov 2024 15:24:20 +0000 (08:24 -0700)]
[committed] Fix compilation of testglue wrapper after c23 changes
testglue.c (which is used for exit/abort wrappers in the testsuite) isn't c23
compatible. The testing harness tries to build testglue.c and use it, but
doesn't report a failure if the build fails, instead it's just not used. As a
result we get all kinds of failures on targets which depend on testglue to
report back simulator status -- like tens of thousands of execution failures.
This patch just adds -std=gnu17 to the command line to build testglue.c.
There's other fallout from the c23 change.. My tester is chewing through
things right now...
Installing on the trunk.
testsuite
* lib/wrapper.exp (${tool}_maybe_build_wrapper): Pass -std=gnu17 flag
to build testglue wrapper.
Richard Biener [Fri, 15 Nov 2024 09:08:11 +0000 (10:08 +0100)]
Flip vectorization to forced SLP
The following flips the vectorizer to forced SLP, there is almost
no expected fallout at this point, the remains should be target
specific cost modeling issues.
Richard Biener [Fri, 15 Nov 2024 09:04:23 +0000 (10:04 +0100)]
tree-optimization/117606 - SLP and single element interleaving
The following tries to reduce the amount of difference between
SLP and non-SLP for single-element interleaving load classification.
This fixes another fallout of --param vect-force-slp=1
PR tree-optimization/117606
* tree-vect-stmts.cc (get_group_load_store_type): For single
element interleaving also fall back to VMAT_ELEMENTWISE if
a left-over permutation isn't supported.
Richard Biener [Fri, 15 Nov 2024 08:22:37 +0000 (09:22 +0100)]
tree-optimization/117605 - SLP with large negative single-element interleaving
We fail to demote this to VMAT_ELEMENTWISE and thus run into the three
vector permutation limit (and would not consider to use strided loads
or gathers).
This resolves another bunch of SVE regressions with --param
vect-force-slp=1
PR tree-optimization/117605
* tree-vect-stmts.cc (get_group_load_store_type): Also
apply group size limit for single-element interleaving
to VMAT_CONTIGUOUS_REVERSE.
Richard Biener [Fri, 15 Nov 2024 07:42:04 +0000 (08:42 +0100)]
tree-optimization/117558 - peeling for gaps and VL vectors
The following ensures that peeling a single iteration for gaps is
sufficient by enforcing niter masking (partial vector use) given
we cannot (always) statically decide when the vector size isn't known.
The condition guarding this and thus statically giving a pass in
some cases for VL vectors is questionable, the patch doesn't address
this.
This fixes a set of known failout from enabling
--param vect-force-slp=1 by default.
PR tree-optimization/117558
* tree-vectorizer.h (_loop_vec_info::must_use_partial_vectors_p): New.
(LOOP_VINFO_MUST_USE_PARTIAL_VECTORS_P): Likewise.
* tree-vect-loop.cc (_loop_vec_info::_loop_vec_info): Initialize
must_use_partial_vectors_p.
(vect_determine_partial_vectors_and_peeling): Enforce it.
(vect_analyze_loop_2): Reset before restarting.
* tree-vect-stmts.cc (get_group_load_store_type): When peeling
a single gap iteration cannot be determined safe statically
enforce the use of partial vectors.
Jan Hubicka [Sat, 16 Nov 2024 13:04:32 +0000 (14:04 +0100)]
Ignore conditions guarding __builtin_unreachable in inliner metrics
This extends my last year attempt to make inliner metric ignore
conditionals guarding __builtin_unreachable. Compared to previous
patch, this one implements a "mini-dce" in ipa-fnsummary to avoid
accounting all statements that are only used to determine conditionals
guarding __builtin_unnecesary. These will be removed later once value
ranges are determined.
While working on this, I noticed that we do have a lot of dead code while
computing fnsummary for early inline. Those are only used to apply
large-function growth, but it seems there is enough dead code to make this
valud kind of irrelevant. Also there seems to be quite a lot of const/pure
calls that can be cheaply removed before we inline them. So I wonder if we
want to run one DCE before early inlining.
gcc/ChangeLog:
PR tree-optimization/109442
* ipa-fnsummary.cc (builtin_unreachable_bb_p): New function.
(guards_builtin_unreachable): New function.
(STMT_NECESSARY): New macro.
(mark_stmt_necessary): New function.
(mark_operand_necessary): New function.
(find_necessary_statements): New function.
(analyze_function_body): Use it.
Martin Uecker [Thu, 14 Nov 2024 19:54:33 +0000 (20:54 +0100)]
c: fix ICE when forming composite type for two structures / unions [PR117548]
When forming the composite type from two tagged type, we need to find the
original type for a typedecl to get the correct tag.
PR c/117548
gcc/c/ChangeLog:
* c-decl.cc (finish_struct): Add checking assertion.
* c-typeck.cc (c_type_original): New function.
(composite_types_internal): Get tag from original type.
gcc/testsuite/ChangeLog:
* gcc.dg/pr117548.c: New test.
Sam James [Sat, 16 Nov 2024 03:14:19 +0000 (03:14 +0000)]
testsuite: i386: adapt to -std=gnu23 default change
r15-5327-g55e3bd376b2214 changes the default to -std=gnu23 but this
test relies on unprototyped functions. Follow Joseph's advice
in that commit and tweak the test accordingly.