Commit graph

209566 commits

Author SHA1 Message Date
Tejas Belagod
81f3d963e0 vect: Call vect_convert_output with the right vecitype [PR114108]
This patch fixes a bug where vect_recog_abd_pattern called vect_convert_output
with the incorrect vecitype for the corresponding pattern_stmt.
vect_convert_output expects vecitype to be the vector form of the scalar type
of the LHS of pattern_stmt, but we were passing in the vector form of the LHS
of the new impending conversion statement.  This caused a skew in ABD's
pattern_stmt having the vectype of the following gimple pattern_stmt.

	2024-03-06  Tejas Belagod  <tejas.belagod@arm.com>

gcc/ChangeLog:

	PR middle-end/114108
	* tree-vect-patterns.cc (vect_recog_abd_pattern): Call
	vect_convert_output with the correct vecitype.

gcc/testsuite/ChangeLog:
	* gcc.dg/vect/pr114108.c: New test.
2024-03-15 11:40:24 +05:30
Chenghui Pan
d7d05824ae LoongArch: Remove masking process for operand 3 of xvpermi.q.
The behavior of non-zero unused bits in xvpermi.q instruction's
third operand is undefined on LoongArch, according to our
discussion (https://github.com/llvm/llvm-project/pull/83540),
we think that keeping original insn operand as unmodified
state is better solution.

This patch partially reverts 7b158e036a.

gcc/ChangeLog:

	* config/loongarch/lasx.md (lasx_xvpermi_q_<LASX:mode>):
	Remove masking of operand 3.

gcc/testsuite/ChangeLog:

	* gcc.target/loongarch/vector/lasx/lasx-xvpermi_q.c:
	Reposition operand 3's value into instruction's defined accept range.
2024-03-15 09:08:53 +08:00
GCC Administrator
c1f6690b82 Daily bump. 2024-03-15 00:17:52 +00:00
Jason Merrill
efab88888c tree-core: clarify clobber comments
It came up on the mailing list that OBJECT_BEGIN/END are described as
marking object lifetime, but mark the beginning of the constructor and end
of the destructor, whereas the C++ notion of lifetime is between the end of
the constructor and beginning of the destructor.  So let's fix the comments.

gcc/ChangeLog:

	* tree-core.h (enum clobber_kind): Clarify CLOBBER_OBJECT_*
	comments.
2024-03-14 17:14:19 -04:00
Gaius Mulley
6dbf0d252f PR modula2/114294 expression causes ICE
This patch fixes an ICE when encountering an expression:
1 + HIGH (a[0]).  The fix was to assign a type to the constant
created by BuildConstHighFromSym in M2Quads.mod.

gcc/m2/ChangeLog:

	PR modula2/114294
	* gm2-compiler/M2Quads.mod (BuildConstHighFromSym):
	Call PutConst to assign the type Cardinal in the result
	constant.

gcc/testsuite/ChangeLog:

	PR modula2/114294
	* gm2/pim/pass/log: Removed.
	* gm2/pim/pass/highexp.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2024-03-14 19:09:34 +00:00
John David Anglin
53fd0f5b1f hppa: Fix REG+D address support before reload
When generating PA 1.x code or code for GNU ld, floating-point
accesses only support 5-bit displacements but integer accesses
support 14-bit displacements.  I mistakenly assumed reload
could fix an invalid 14-bit displacement in a floating-point
access but this is not the case.

2024-03-14  John David Anglin  <danglin@gcc.gnu.org>

gcc/ChangeLog:

	PR target/114288
	* config/pa/pa.cc (pa_legitimate_address_p): Don't allow
	14-bit displacements before reload for modes that may use
	a floating-point load or store.
2024-03-14 18:32:56 +00:00
David Faust
6cf4286ff9 bpf: define INT8_TYPE as signed char
Change the BPF backend to define INT8_TYPE with an explicit sign, rather
than a plain char.  This is in line with other targets and removes the
risk of int8_t being affected by the signedness of the plain char type
of the host system.

The motivation for this change is that even if `char' is defined to be
signed in BPF targets, some BPF programs use the (mal)practice of
including internal libc headers, either directly or indirectly via
kernel headers, which in turn may trigger compilation errors regarding
redefinitions of types.

gcc/

	* config/bpf/bpf.h (INT8_TYPE): Change to signed char.
2024-03-14 10:57:20 -07:00
Max Filippov
bc5a9dab55 gcc: xtensa: reorder movsi_internal patterns for better code generation during LRA
After switching to LRA xtensa backend generates the following code for
saving/loading registers:

    movi     a9, 0x190
    add      a9, a9, sp
    s32i.n   a3, a9, 0

instead of the shorter and more efficient

    s32i     a3, a9, 0x190

E.g. the following code can be used to reproduce it:

    int f1(int a, int b, int c, int d, int e, int f, int *p);
    int f2(int a, int b, int c, int d, int e, int f, int *p);
    int f3(int a, int b, int c, int d, int e, int f, int *p);

    int foo(int a, int b, int c, int d, int e, int f)
    {
        int g[100];
        return
            f1(a, b, c, d, e, f, g) +
            f2(a, b, c, d, e, f, g) +
            f3(a, b, c, d, e, f, g);
    }

This happens in the LRA pass because s32i.n and l32i.n are listed before
the s32i and l32i in the movsi_internal pattern and alternative
consideration loop stops early.

gcc/

	* config/xtensa/xtensa.md (movsi_internal): Move l32i and s32i
	patterns ahead of the l32i.n and s32i.n.
2024-03-14 10:27:08 -07:00
Jonathan Wakely
f89cfdb2f2 libstdc++: Fix std::format("{}", negative_integer) [PR114325]
The fast path for "{}" format strings has a bug for negative integers
where the length passed to std::to_chars is too long.

libstdc++-v3/ChangeLog:

	PR libstdc++/114325
	* include/std/format (_Scanner::_M_scan): Pass correct length to
	__to_chars_10_impl.
	* testsuite/std/format/functions/format.cc: Check negative
	integers with empty format-spec.
2024-03-14 16:58:15 +00:00
Jonathan Wakely
df483ebd24 libstdc++: Add nodiscard in <algorithm>
Add the [[nodiscard]] attribute to several functions in <algorithm>.
These all have no side effects and are only called for their return
value (e.g. std::count) or produce a result that must not be discarded
for correctness (e.g. std::remove).

I was intending to add the attribute to a number of other functions like
std::copy_if, std::unique_copy, std::set_union, and std::set_difference.
I stopped when I noticed that MSVC doesn't use it on those functions,
which I suspect is because they're often used with an insert iterator
(e.g. std::back_insert_iterator). In that case it doesn't matter if
you discard the result, because you have the container to tell you how
many elements were copied to the output range.

libstdc++-v3/ChangeLog:

	* include/bits/stl_algo.h (find_end, all_of, none_of, any_of)
	(find_if_not, is_partitioned, partition_point, remove)
	(remove_if, unique, lower_bound, upper_bound, equal_range)
	(binary_search, includes, is_sorted, is_sorted_until, minmax)
	(minmax_element, is_permutation, clamp, find_if, find_first_of)
	(adjacent_find, count, count_if, search, search_n, min_element)
	(max_element): Add nodiscard attribute.
	* include/bits/stl_algobase.h (min, max, lower_bound, equal)
	(lexicographical_compare, lexicographical_compare_three_way)
	(mismatch): Likewise.
	* include/bits/stl_heap.h (is_heap, is_heap_until): Likewise.
	* testsuite/25_algorithms/equal/debug/1_neg.cc: Add dg-warning.
	* testsuite/25_algorithms/equal/debug/2_neg.cc: Likewise.
	* testsuite/25_algorithms/equal/debug/3_neg.cc: Likewise.
	* testsuite/25_algorithms/find_first_of/concept_check_1.cc:
	Likewise.
	* testsuite/25_algorithms/is_permutation/2.cc: Likewise.
	* testsuite/25_algorithms/lexicographical_compare/71545.cc:
	Likewise.
	* testsuite/25_algorithms/lower_bound/33613.cc: Likewise.
	* testsuite/25_algorithms/lower_bound/debug/irreflexive.cc:
	Likewise.
	* testsuite/25_algorithms/lower_bound/debug/partitioned_neg.cc:
	Likewise.
	* testsuite/25_algorithms/lower_bound/debug/partitioned_pred_neg.cc:
	Likewise.
	* testsuite/25_algorithms/minmax/3.cc: Likewise.
	* testsuite/25_algorithms/search/78346.cc: Likewise.
	* testsuite/25_algorithms/search_n/58358.cc: Likewise.
	* testsuite/25_algorithms/unique/1.cc: Likewise.
	* testsuite/25_algorithms/unique/11480.cc: Likewise.
	* testsuite/25_algorithms/upper_bound/33613.cc: Likewise.
	* testsuite/25_algorithms/upper_bound/debug/partitioned_neg.cc:
	Likewise.
	* testsuite/25_algorithms/upper_bound/debug/partitioned_pred_neg.cc:
	Likewise.
	* testsuite/ext/concept_checks.cc: Likewise.
	* testsuite/ext/is_heap/47709.cc: Likewise.
	* testsuite/ext/is_sorted/cxx0x.cc: Likewise.
2024-03-14 16:58:15 +00:00
Jakub Jelinek
fd71043884 gcn: Fix a comment typo
I've noticed a typo in the comment above ABI_VERSION_SPEC.

Fixed thusly.

2024-03-14  Jakub Jelinek  <jakub@redhat.com>

	* config/gcn/gcn-hsa.h (ABI_VERSION_SPEC): Fix comment typo.
2024-03-14 17:51:32 +01:00
Jakub Jelinek
7580e39452 icf: Reset SSA_NAME_{PTR,RANGE}_INFO in successfully merged functions [PR113907]
AFAIK we have no code in LTO streaming to stream out or in
SSA_NAME_{RANGE,PTR}_INFO, so LTO effectively throws it all away
and let vrp1 and alias analysis after IPA recompute that.  There is
just one spot, for IPA VRP and IPA bit CCP we save/restore ranges
and set SSA_NAME_{PTR,RANGE}_INFO e.g. on parameters depending on what
we saved and propagated, but that is after streaming in bodies for the
post IPA optimizations.

Now, without LTO SSA_NAME_{RANGE,PTR}_INFO is already computed from
earlier in many cases (er.g. evrp and early alias analysis but other spots
too), but IPA ICF is ignoring the ranges and points-to details when
comparing the bodies.  I think ignoring that is just fine, that is
effectively what we do for LTO where we throw that information away
before the analysis, and not ignoring it could lead to fewer ICF merging
possibilities.

So, the following patch instead verifies that for LTO SSA_NAME_{PTR,RANGE}_INFO
just isn't there on SSA_NAMEs in functions into which other functions have
been ICFed, and for non-LTO throws that information away (which matches the
LTO behavior).

Another possibility would be to remember the SSA_NAME <-> SSA_NAME mapping
vector (just one of the 2) on successful sem_function::equals on the
sem_function which is not the chosen leader (e.g. how SSA_NAMEs in the
leader map to SSA_NAMEs in the other function) and use that vector
to union the ranges in sem_function::merge.  I can implement that for
comparison, but wanted to post this first if there is an agreement on
doing that or if Honza thinks we should take SSA_NAME_{RANGE,PTR}_INFO
into account.  I think we can compare SSA_NAME_RANGE_INFO, but have
no idea how to try to compare points to info.  And I think it will result
in less effective ICF for non-LTO vs. LTO unnecessarily.

2024-03-12  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/113907
	* ipa-icf.cc (sem_item_optimizer::merge_classes): Reset
	SSA_NAME_RANGE_INFO and SSA_NAME_PTR_INFO on successfully ICF merged
	functions.

	* gcc.dg/pr113907-1.c: New test.
2024-03-14 17:48:30 +01:00
Gaius Mulley
7aeedff6a4 PR modula2/114333 set type comparison against cardinal should cause error addendum
This patch applies the new stricter type checking procedure function to
the remaining 6 comparisons: less, greater, lessequ, greequ, ifin and
ifnotin.

gcc/m2/ChangeLog:

	PR modula2/114333
	* gm2-compiler/M2GenGCC.mod (CodeStatement): Remove op1, op2 and
	op3 parameters to CodeIfLess, CodeIfLessEqu, CodeIfGreEqu, CodeIfGre,
	CodeIfIn, CodeIfNotIn.
	(CodeIfLess): Rewrite.
	(PerformCodeIfLess): New procedure.
	(CodeIfLess): Rewrite.
	(PerformCodeIfLess): New procedure.
	(CodeIfLessEqu): Rewrite.
	(PerformCodeIfLessEqu): New procedure.
	(CodeIfGreEqu): Rewrite.
	(PerformCodeIfGreEqu): New procedure.
	(CodeIfGre): Rewrite.
	(PerformCodeIfGre): New procedure.
	(CodeIfIn): Rewrite.
	(PerformCodeIfIn): New procedure.
	(CodeIfNotIn): Rewrite.
	(PerformCodeIfNotIn): New procedure.

gcc/testsuite/ChangeLog:

	PR modula2/114333
	* gm2/pim/fail/badset5.mod: New test.
	* gm2/pim/fail/badset6.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2024-03-14 15:34:36 +00:00
Xi Ruoyao
f98b85b1ef
LoongArch: Remove unused and incorrect "sge<u>_<X:mode><GPR:mode>" define_insn
If this insn is really used, we'll have something like

    slti $r4,$r0,$r5

in the code.  The assembler will reject it because slti wants 2
register operands and 1 immediate operand.  But we've not got any bug
report for this, indicating this define_insn is unused at all.

Note that do_store_flag (in expr.cc) is already converting x >= 1 to
x > 0 unconditionally, so this define_insn is indeed unused and we can
just remove it.

gcc/ChangeLog:

	* config/loongarch/loongarch.md (any_ge): Remove.
	(sge<u>_<X:mode><GPR:mode>): Remove.
2024-03-14 23:22:05 +08:00
xndcn
0adc8c5f14 libstdc++: Add missing clear_padding in __atomic_float constructor
For 80-bit long double we need to clear the padding bits on
construction.

libstdc++-v3/ChangeLog:

	* include/bits/atomic_base.h (__atomic_float::__atomic_float(Fp)):
	Clear padding.
	* testsuite/29_atomics/atomic_float/compare_exchange_padding.cc:
	New test.

Signed-off-by: xndcn <xndchn@gmail.com>

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2024-03-14 15:06:47 +00:00
Thomas Schwinge
38958ac987 OpenACC 2.7: front-end support for readonly modifier: Add basic OpenACC 'declare' testing
... to complement commit ddf852dac2
"OpenACC 2.7: front-end support for readonly modifier".

	gcc/testsuite/
	* c-c++-common/goacc/readonly-1.c: Add basic OpenACC 'declare'
	testing.
	* gfortran.dg/goacc/readonly-1.f90: Likewise.
2024-03-14 15:43:06 +01:00
Thomas Schwinge
473c6123ff Minor fixes for OpenACC/Fortran 'self' clause for compute constructs
... to fix up recent commit 3a3596389c
"OpenACC 2.7: Implement self clause for compute constructs".

	gcc/fortran/
	* dump-parse-tree.cc (show_omp_clauses): Handle 'self_expr'.
	* openmp.cc (gfc_free_omp_clauses): Likewise.
	* trans-openmp.cc (gfc_split_omp_clauses): Don't handle 'self_expr'.
2024-03-14 15:41:57 +01:00
Thomas Schwinge
25242ed8eb Fix 'char' initialization, copy, check in 'libgomp.oacc-fortran/acc-memcpy.f90'
Our dear friend '-Wuninitialized' reported:

    [...]/libgomp.oacc-fortran/acc-memcpy.f90:18:27:

       18 |     char(j) = int (j, int8)
          |                           ^
    Warning: ‘j’ may be used uninitialized [-Wmaybe-uninitialized]
    [...]/libgomp.oacc-fortran/acc-memcpy.f90:14:20:

       14 |   integer(int8) :: j
          |                    ^
    note: ‘j’ was declared here

..., but actually there were other issues.

	libgomp/
	* testsuite/libgomp.oacc-fortran/acc-memcpy.f90: Fix 'char'
	initialization, copy, check.
2024-03-14 15:41:33 +01:00
Jakub Jelinek
9349aefa1d aarch64: Fix TImode __sync_*_compare_and_exchange expansion with LSE [PR114310]
The following testcase ICEs with LSE atomics.
The problem is that the @atomic_compare_and_swap<mode> expander uses
aarch64_reg_or_zero predicate for the desired operand, which is fine,
given that for most of the modes and even for TImode in some cases
it can handle zero immediate just fine, but the TImode
@aarch64_compare_and_swap<mode>_lse just uses register_operand for
that operand instead, again intentionally so, because the casp,
caspa, caspl and caspal instructions need to use a pair of consecutive
registers for the operand and xzr is just one register and we can't
just store zero into the link register to emulate pair of zeros.

So, the following patch fixes that by forcing the newval operand into
a register for the TImode LSE case.

2024-03-14  Jakub Jelinek  <jakub@redhat.com>

	PR target/114310
	* config/aarch64/aarch64.cc (aarch64_expand_compare_and_swap): For
	TImode force newval into a register.

	* gcc.dg/pr114310.c: New test.
2024-03-14 14:09:20 +01:00
Juergen Christ
075104eef6 s390: fix htm-builtins test cases
Transactional and non-transactional stores to the same cache line cause
transactions to abort on newer generations.  Add sufficient padding to make
sure another cache line is used.

Tested on s390.

gcc/testsuite/ChangeLog:

	* gcc.target/s390/htm-builtins-1.c: Fix.
	* gcc.target/s390/htm-builtins-2.c: Fix.

Signed-off-by: Juergen Christ <jchrist@linux.ibm.com>
2024-03-14 14:06:56 +01:00
Jonathan Wakely
e6836bbbd7 libstdc++: Correct notes about std::call_once in manual [PR66146]
The bug with exceptions thrown during a std::call_once call affects all
targets, so fix the docs that say it only affects non-Linux targets.

libstdc++-v3/ChangeLog:

	PR libstdc++/66146
	* doc/xml/manual/status_cxx2011.xml: Remove mention of Linux in
	note about std::call_once.
	* doc/xml/manual/status_cxx2014.xml: Likewise.
	* doc/xml/manual/status_cxx2017.xml: Likewise.
	* doc/html/manual/status.html: Regenerate.
2024-03-14 11:54:32 +00:00
Jonathan Wakely
2a556dbec2 libstdc++: Update C++23 status in the manual
libstdc++-v3/ChangeLog:

	* doc/xml/manual/status_cxx2023.xml: Update C++23 status table.
	* doc/html/manual/status.html: Regenerate.
	* include/bits/version.def: Fix typo in comment.
2024-03-14 11:54:32 +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
Gaius Mulley
b7f70cfdb6 PR modula2/114333 set type comparison against a cardinal should cause an error
The type checker M2Check.mod needs extending to detect if a set, array or
record is in either operand at the end of the cascaded test list.

gcc/m2/ChangeLog:

	PR modula2/114333
	* gm2-compiler/M2Check.mod (checkUnbounded): New procedure
	function.
	(checkArrayTypeEquivalence): Extend checking to cover unbounded
	arrays, arrays and constants.
	(IsTyped): Simplified the expression and corrected a test for
	IsConstructor.
	(checkTypeKindViolation): New procedure function.
	(doCheckPair): Call checkTypeKindViolation.
	* gm2-compiler/M2GenGCC.mod (CodeStatement): Remove parameters
	to CodeEqu and CodeNotEqu.
	(PerformCodeIfEqu): New procedure.
	(CodeIfEqu): Rewrite.
	(PerformCodeIfNotEqu): New procedure.
	(CodeIfNotEqu): Rewrite.
	* gm2-compiler/M2Quads.mod (BuildRelOpFromBoolean): Correct
	comment.

gcc/testsuite/ChangeLog:

	PR modula2/114333
	* gm2/cse/pass/testcse54.mod: New test.
	* gm2/iso/run/pass/array9.mod: New test.
	* gm2/iso/run/pass/strcons3.mod: New test.
	* gm2/iso/run/pass/strcons4.mod: New test.
	* gm2/pim/fail/badset1.mod: New test.
	* gm2/pim/fail/badset2.mod: New test.
	* gm2/pim/fail/badset3.mod: New test.
	* gm2/pim/fail/badset4.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2024-03-14 11:23:42 +00:00
Chung-Lin Tang
ddf852dac2 OpenACC 2.7: front-end support for readonly modifier
This patch implements the front-end support for the 'readonly' modifier for the
OpenACC 'copyin' clause and 'cache' directive.

This currently only includes front-end parsing for C/C++/Fortran and setting of
new bits OMP_CLAUSE_MAP_READONLY, OMP_CLAUSE__CACHE__READONLY. Further linking
of these bits to points-to analysis and/or utilization of read-only memory in
accelerator target are for later patches.

gcc/c/ChangeLog:

	* c-parser.cc (c_parser_oacc_data_clause): Add parsing support for
	'readonly' modifier, set OMP_CLAUSE_MAP_READONLY if readonly modifier
	found, update comments.
	(c_parser_oacc_cache): Add parsing support for 'readonly' modifier,
	set OMP_CLAUSE__CACHE__READONLY if readonly modifier found, update
	comments.

gcc/cp/ChangeLog:

	* parser.cc (cp_parser_oacc_data_clause): Add parsing support for
	'readonly' modifier, set OMP_CLAUSE_MAP_READONLY if readonly modifier
	found, update comments.
	(cp_parser_oacc_cache): Add parsing support for 'readonly' modifier,
	set OMP_CLAUSE__CACHE__READONLY if readonly modifier found, update
	comments.

gcc/fortran/ChangeLog:

	* dump-parse-tree.cc (show_omp_namelist): Print "readonly," for
	OMP_LIST_MAP and OMP_LIST_CACHE if n->u.map.readonly is set.
	Adjust 'n->u.map_op' to 'n->u.map.op'.
	* gfortran.h (typedef struct gfc_omp_namelist): Adjust map_op as
	'ENUM_BITFIELD (gfc_omp_map_op) op:8', add 'bool readonly' field,
	change to named struct field 'map'.
	* openmp.cc (gfc_match_omp_map_clause): Adjust 'n->u.map_op' to
	'n->u.map.op'.
	(gfc_match_omp_clause_reduction): Likewise.
	(gfc_match_omp_clauses): Add readonly modifier parsing for OpenACC
	copyin clause, set 'n->u.map.op' and 'n->u.map.readonly' for parsed
	clause. Adjust 'n->u.map_op' to 'n->u.map.op'.
	(gfc_match_oacc_declare): Adjust 'n->u.map_op' to 'n->u.map.op'.
	(gfc_match_oacc_cache): Add readonly modifier parsing for OpenACC
	cache directive.
	(resolve_omp_clauses): Adjust 'n->u.map_op' to 'n->u.map.op'.
	* trans-decl.cc (add_clause): Adjust 'n->u.map_op' to 'n->u.map.op'.
	(finish_oacc_declare): Likewise.
	* trans-openmp.cc (gfc_trans_omp_clauses): Set OMP_CLAUSE_MAP_READONLY,
	OMP_CLAUSE__CACHE__READONLY to 1 when readonly is set. Adjust
	'n->u.map_op' to 'n->u.map.op'.
	(gfc_add_clause_implicitly): Adjust 'n->u.map_op' to 'n->u.map.op'.

gcc/ChangeLog:

	* tree.h (OMP_CLAUSE_MAP_READONLY): New macro.
	(OMP_CLAUSE__CACHE__READONLY): New macro.
	* tree-core.h (struct GTY(()) tree_base): Adjust comments for new
	uses of readonly_flag bit in OMP_CLAUSE_MAP_READONLY and
	OMP_CLAUSE__CACHE__READONLY.
	* tree-pretty-print.cc (dump_omp_clause): Add support for printing
	OMP_CLAUSE_MAP_READONLY and OMP_CLAUSE__CACHE__READONLY.

gcc/testsuite/ChangeLog:

	* c-c++-common/goacc/readonly-1.c: New test.
	* gfortran.dg/goacc/readonly-1.f90: New test.
2024-03-14 10:39:52 +00:00
Andreas Krebbel
90a7da6952 IBM Z: Fix -munaligned-symbols
With this fix we make sure that only symbols with a natural alignment
smaller than 2 are considered misaligned with
-munaligned-symbols. Background is that -munaligned-symbols is only
supposed to affect symbols whose natural alignment wouldn't be enough
to fulfill our ABI requirement of having all symbols at even
addresses. Because only these are the cases where we differ from other
architectures.

gcc/ChangeLog:

	* config/s390/s390.cc (s390_encode_section_info): Adjust the check
	for misaligned symbols.
	* config/s390/s390.opt: Improve documentation.

gcc/testsuite/ChangeLog:

	* gcc.target/s390/aligned-1.c: Add weak and void variables
	incorporating the cases from unaligned-2.c.
	* gcc.target/s390/unaligned-1.c: Likewise.
	* gcc.target/s390/unaligned-2.c: Removed.
2024-03-14 10:51:57 +01:00
Jakub Jelinek
8f6e0814b4 gimple-iterator: Some gsi_safe_insert_*before fixes
When trying to use the gsi_safe_insert*before APIs in bitint lowering,
I've discovered 3 issues and the following patch addresses those:

1) both split_block and split_edge update CDI_DOMINATORS if they are
   available, but because edge_before_returns_twice_call first splits
   and then adds an extra EDGE_ABNORMAL edge and then removes another
   one, the immediate dominators of both the new bb and the bb with
   returns_twice call need to change
2) the new EDGE_ABNORMAL edge had uninitialized probability; this patch
   copies the probability from the edge that is going to be removed
   and similarly copies other flags (EDGE_EXECUTABLE, EDGE_DFS_BACK,
   EDGE_IRREDUCIBLE_LOOP etc.)
3) if edge_before_returns_twice_call splits a block, then the bb with
   returns_twice call changes, so the gimple_stmt_iterator for it is
   no longer accurate, it points to the right statement, but gsi_bb
   and gsi_seq are no longer correct; the patch updates it

2024-03-14  Jakub Jelinek  <jakub@redhat.com>

	* gimple-iterator.cc (edge_before_returns_twice_call): Copy all
	flags and probability from ad_edge to e edge.  If CDI_DOMINATORS
	are computed, recompute immediate dominator of other_edge->src
	and other_edge->dest.
	(gsi_safe_insert_before, gsi_safe_insert_seq_before): Update *iter
	for the returns_twice call case to the gsi_for_stmt (stmt) to deal
	with update it for bb splitting.
2024-03-14 09:57:13 +01:00
liuhongt
618e34d56c i386[stv]: Handle REG_EH_REGION note
When we split
(insn 37 36 38 10 (set (reg:DI 104 [ _18 ])
        (mem:DI (reg/f:SI 98 [ CallNative_nclosure.0_1 ]) [6 MEM[(struct SQRefCounted *)CallNative_nclosure.0_1]._uiRef+0 S8 A32])) "test.C":22:42 84 {*movdi_internal}
     (expr_list:REG_EH_REGION (const_int -11 [0xfffffffffffffff5])

into

(insn 104 36 37 10 (set (subreg:V2DI (reg:DI 124) 0)
        (vec_concat:V2DI (mem:DI (reg/f:SI 98 [ CallNative_nclosure.0_1 ]) [6 MEM[(struct SQRefCounted *)CallNative_nclosure.0_1]._uiRef+0 S8 A32])
            (const_int 0 [0]))) "test.C":22:42 -1
        (nil)))
(insn 37 104 105 10 (set (subreg:V2DI (reg:DI 104 [ _18 ]) 0)
        (subreg:V2DI (reg:DI 124) 0)) "test.C":22:42 2024 {movv2di_internal}
     (expr_list:REG_EH_REGION (const_int -11 [0xfffffffffffffff5])
        (nil)))

we must copy the REG_EH_REGION note to the first insn and split the block
after the newly added insn.  The REG_EH_REGION on the second insn will be
removed later since it no longer traps.

gcc/ChangeLog:

	* config/i386/i386-features.cc
	(general_scalar_chain::convert_op): Handle REG_EH_REGION note.
	(convert_scalars_to_vector): Ditto.
	* config/i386/i386-features.h (class scalar_chain): New
	memeber control_flow_insns.

gcc/testsuite/ChangeLog:

	* g++.target/i386/pr111822.C: New test.
2024-03-14 15:55:15 +08:00
GCC Administrator
746b71e26b Daily bump. 2024-03-14 00:18:12 +00:00
Jonathan Wakely
a8c7c3a409 libstdc++: Move test error_category to global scope
A recent GDB change causes this test to fail due to missing RTTI for the
custom_cast type. This is presumably because the custom_cat type was
defined as a local class, so has no linkage. Moving it to local scope
seems to fix the test regressions, and probably makes the test more
realistic as a local class with no linkage isn't practical to use as an
error category that almost certainly needs to be referred to in other
scopes.

libstdc++-v3/ChangeLog:

	* testsuite/libstdc++-prettyprinters/cxx11.cc: Move custom_cat
	to namespace scope.
2024-03-13 21:25:14 +00:00
Jonathan Wakely
45a3ee8a40 libstdc++: Improve documentation on debugging with libstdc++
libstdc++-v3/ChangeLog:

	* doc/xml/manual/debug.xml: Improve docs on debug builds and
	using ASan. Mention _GLIBCXX_ASSERTIONS. Reorder sections to put
	the most relevant ones first.
	* doc/xml/manual/using.xml: Add comma.
	* doc/html/*: Regenerate.
2024-03-13 21:25:14 +00:00
Jonathan Wakely
d6490157b3 libstdc++: Document that _GLIBCXX_CONCEPT_CHECKS might be removed in future
The macro-based concept checks are unmaintained and do not support C++11
or later, so reject valid code. If nobody plans to update them we should
consider removing them. Alternatively, we could ignore the macro for
C++11 and later, so they have no effect and don't reject valid code.

libstdc++-v3/ChangeLog:

	* doc/xml/manual/debug.xml: Document that concept checking might
	be removed in future.
	* doc/xml/manual/extensions.xml: Likewise.
2024-03-13 21:25:13 +00:00
Harald Anlauf
11caf47b59 Fortran: fix IS_CONTIGUOUS for polymorphic dummy arguments [PR114001]
gcc/fortran/ChangeLog:

	PR fortran/114001
	* expr.cc (gfc_is_simply_contiguous): Adjust logic so that CLASS
	symbols are also handled.

gcc/testsuite/ChangeLog:

	PR fortran/114001
	* gfortran.dg/is_contiguous_4.f90: New test.
2024-03-13 18:41:20 +01:00
Jakub Jelinek
74bca21db3 store-merging: Match bswap64 on 32-bit targets with bswapsi2 [PR114319]
gimple-ssa-store-merging.cc tests bswap_optab in 3 different places,
in 2 of them it has special exception for double-word bswap using pair
of word-mode bswap optabs, but in the last one it doesn't.

The following patch changes even the last spot.
We don't handle 128-bit bswaps in the passes at all, because currently we
just use uint64_t to represent the byte reshuffling (we'd need to use
offset_int or something like that instead) and we don't have
__builtin_bswap128 nor type-generic __builtin_bswap, so there is nothing
for 64-bit targets there.

2024-03-13  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/114319
	* gimple-ssa-store-merging.cc
	(imm_store_chain_info::try_coalesce_bswap): For 32-bit targets
	allow matching __builtin_bswap64 if there is bswapsi2 optab.

	* gcc.target/i386/pr114319.c: New test.
2024-03-13 15:35:41 +01:00
Torbjörn SVENSSON
5a44e14eb4 testsuite: target test for short_enums
On arm-none-eabi, the test case fails with below warning on GCC13
.../null-deref-pr108251-smp_fetch_ssl_fc_has_early-O2.c:63:65: warning: converting a packed 'enum obj_type' pointer (alignment 1) to a 'struct connection' pointer (alignment 4) may result in an unaligned pointer value [-Waddress-of-packed-member]

Add a dg-bogus to ensure that the warning is not reintroduced.

gcc/testsuite/ChangeLog:

	* c-c++-common/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early-O2.c:
	Added dg-bogus with target on offending line for short_enums.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
2024-03-13 15:16:44 +01:00
Stefan Schulze Frielinghaus
4d049fadc2 s390: Fix TARGET_SECONDARY_RELOAD for non-SYMBOL_REFs
RTX X need not necessarily be a SYMBOL_REF and may e.g. be an
UNSPEC_GOTENT for which SYMBOL_FLAG_NOTALIGN2_P fails.

gcc/ChangeLog:

	* config/s390/s390.cc (s390_secondary_reload): Guard
	SYMBOL_FLAG_NOTALIGN2_P.
2024-03-13 11:07:03 +01:00
Stefan Schulze Frielinghaus
a63fb786f8 s390: Fix tests rosbg_si_srl and rxsbg_si_srl
Starting with r14-2047-gd0e891406b16dc two SI mode tests are optimized
into DI mode.  Thus, the scan-assembler directives fail.  For example
RTL expression

(ior:SI (subreg:SI (lshiftrt:DI (reg:DI 69)
            (const_int 2 [0x2])) 4)
    (subreg:SI (reg:DI 68) 4))

is optimized into

(ior:DI (lshiftrt:DI (reg:DI 69)
        (const_int 2 [0x2]))
    (reg:DI 68))

Fixed by moving operands into memory in order to enforce SI mode
computation.

Furthermore, in r9-6056-g290dfd9bc7bea2 the starting bit position of the
scan-assembler directive for rosbg was incorrectly set to 32 which
actually should be 32+SHIFT_AMOUNT, i.e., in this particular case 34.

gcc/testsuite/ChangeLog:

	* gcc.target/s390/md/rXsbg_mode_sXl.c: Fix tests rosbg_si_srl
	and rxsbg_si_srl.
2024-03-13 11:05:08 +01:00
Stefan Schulze Frielinghaus
9f2b16ce1e s390: Streamline vector builtins with LLVM
Similar as to s390_lcbb, s390_vll, s390_vstl, et al. make use of a
signed vector type for vlbb.  Furthermore, a const void pointer seems
more common and an integer for the mask.

For s390_vfi(s,d)b make use of integers for masks, too.

Use unsigned integers for all s390_vlbr/vstbr variants.

Make use of type UV16QI for the length operand of s390_vstrs(,z)(h,f).

Following the Principles of Operation, change from signed to unsigned
type for s390_va(c,cc,ccc)q and s390_vs(,c,bc)biq and s390_vmslg.

Make use of scalar type UINT128 instead of UV16QI for s390_vgfm(,a)g,
and s390_vsumq(f,g).

gcc/ChangeLog:

	* config/s390/s390-builtin-types.def: Update to reflect latest
	changes.
	* config/s390/s390-builtins.def: Streamline vector builtins with
	LLVM.
2024-03-13 11:03:02 +01:00
Stefan Schulze Frielinghaus
b59f0c9c5a s390: Deprecate some vector builtins
According to IBM Open XL C/C++ for z/OS version 1.1 builtins

- vec_permi
- vec_ctd
- vec_ctsl
- vec_ctul
- vec_ld2f
- vec_st2f

are deprecated.  Also deprecate helper builtins vec_ctd_s64 and
vec_ctd_u64.

Furthermore, the overloads of vec_insert which make use of a bool vector
are deprecated, too.

gcc/ChangeLog:

	* config/s390/s390-builtins.def (vec_permi): Deprecate.
	(vec_ctd): Deprecate.
	(vec_ctd_s64): Deprecate.
	(vec_ctd_u64): Deprecate.
	(vec_ctsl): Deprecate.
	(vec_ctul): Deprecate.
	(vec_ld2f): Deprecate.
	(vec_st2f): Deprecate.
	(vec_insert): Deprecate overloads with bool vectors.
2024-03-13 10:59:02 +01:00
Jakub Jelinek
0613b12dd7 bitint: Fix up lowering of bitfield loads/stores [PR114313]
The following testcase ICEs, because for large/huge _BitInt bitfield
loads/stores we use the DECL_BIT_FIELD_REPRESENTATIVE as the underlying
"var" and indexes into it can be larger than the precision of the
bitfield might normally allow.

The following patch fixes that by passing NULL_TREE type in that case
to limb_access, so that we always return m_limb_type type and don't
do the extra assertions, after all, the callers expect that too.
I had to add the first hunk to avoid ICE, it was using type in one place
even when it was NULL.  But TYPE_SIZE (TREE_TYPE (var)) seems like the
right size to use anyway because the code uses VIEW_CONVERT_EXPR on it.

2024-03-13  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/114313
	* gimple-lower-bitint.cc (bitint_large_huge::limb_access): Use
	TYPE_SIZE of TREE_TYPE (var) rather than TYPE_SIZE of type.
	(bitint_large_huge::handle_load): Pass NULL_TREE rather than
	rhs_type to limb_access for the bitfield load cases.
	(bitint_large_huge::lower_mergeable_stmt): Pass NULL_TREE rather than
	lhs_type to limb_access if nlhs is non-NULL.

	* gcc.dg/torture/bitint-62.c: New test.
2024-03-13 10:19:04 +01:00
Tobias Burnus
c5037fcee2 OpenMP/Fortran: Fix defaultmap(none) issue with dummy procedures [PR114283]
Dummy procedures look similar to variables but aren't - neither in Fortran
nor in OpenMP. As the middle end sees PARM_DECLs, mark them as predetermined
firstprivate for mapping (as already done in gfc_omp_predetermined_sharing).

This does not address the isses related to procedure pointers, which are
still discussed on spec level [see PR].

	PR fortran/114283

gcc/fortran/ChangeLog:

	* trans-openmp.cc (gfc_omp_predetermined_mapping): Map dummy
	procedures as firstprivate.

libgomp/ChangeLog:

	* testsuite/libgomp.fortran/declare-target-indirect-4.f90: New test.
2024-03-13 09:35:28 +01:00
Jakub Jelinek
6586359e8e asan: Fix ICE during instrumentation of returns_twice calls [PR112709]
The following patch on top of the previously posted ubsan/gimple-iterator
one handles asan the same.  While the case of returning by hidden reference
is handled differently because of the first recently posted asan patch,
this deals with instrumentation of the aggregates returned in registers
case as well as instrumentation of loads from aggregate memory in the
function arguments of returns_twice calls.

2024-03-13  Jakub Jelinek  <jakub@redhat.com>

	PR sanitizer/112709
	* asan.cc (maybe_create_ssa_name, maybe_cast_to_ptrmode,
	build_check_stmt, maybe_instrument_call, asan_expand_mark_ifn): Use
	gsi_safe_insert_before instead of gsi_insert_before.

	* gcc.dg/asan/pr112709-2.c: New test.
2024-03-13 09:19:05 +01:00
Jakub Jelinek
364c684c47 gimple-iterator, ubsan: Fix ICE during instrumentation of returns_twice calls [PR112709]
ubsan, asan (both PR112709) and _BitInt lowering (PR113466) want to
insert some instrumentation or adjustment statements before some statement.
This unfortunately creates invalid IL if inserting before a returns_twice
call, because we require that such calls are the first statement in a basic
block and that we have an edge from the .ABNORMAL_DISPATCHER block to
the block containing the returns_twice call (in addition to other edge(s)).

The following patch adds helper functions for such insertions and uses it
for now in ubsan (I'll post a follow up which uses it in asan and will
work later on the _BitInt lowering PR).

In particular, if the bb with returns_twice call at the start has just
2 edges, one EDGE_ABNORMAL from .ABNORMAL_DISPATCHER and another
(non-EDGE_ABNORMAL/EDGE_EH) from some other bb, it just inserts the
statement or sequence on that other edge.
If the bb has more predecessor edges or the one not from
.ABNORMAL_DISPATCHER is e.g. an EH edge (this latter case likely shouldn't
happen, one would need labels or something like that), the patch splits the
block with returns_twice call such that there is just one edge next to
.ABNORMAL_DISPATCHER edge and adjusts PHIs as needed to make it happen.
The functions also replace uses of PHIs from the returns_twice bb with
the corresponding PHI arguments, because otherwise it would be invalid IL.

E.g. in ubsan/pr112709-2.c (qux) we have before the ubsan pass
  <bb 10> :
  # .MEM_5(ab) = PHI <.MEM_4(9), .MEM_25(ab)(11)>
  # _7(ab) = PHI <_20(9), _8(ab)(11)>
  # .MEM_21(ab) = VDEF <.MEM_5(ab)>
  _22 = bar (*_7(ab));
where bar is returns_twice call and bb 11 has .ABNORMAL_DISPATCHER call,
this patch instruments it like:
  <bb 9> :
  # .MEM_4 = PHI <.MEM_17(ab)(4), .MEM_10(D)(5), .MEM_14(ab)(8)>
  # DEBUG BEGIN_STMT
  # VUSE <.MEM_4>
  _20 = p;
  # .MEM_27 = VDEF <.MEM_4>
  .UBSAN_NULL (_20, 0B, 0);
  # VUSE <.MEM_27>
  _2 = __builtin_dynamic_object_size (_20, 0);
  # .MEM_28 = VDEF <.MEM_27>
  .UBSAN_OBJECT_SIZE (_20, 1024, _2, 0);

  <bb 10> :
  # .MEM_5(ab) = PHI <.MEM_28(9), .MEM_25(ab)(11)>
  # _7(ab) = PHI <_20(9), _8(ab)(11)>
  # .MEM_21(ab) = VDEF <.MEM_5(ab)>
  _22 = bar (*_7(ab));
The edge from .ABNORMAL_DISPATCHER is there just to represent the
returning for 2nd and later times, the instrumentation can't be
done at that point as there is no code executed during that point.
The ubsan/pr112709-1.c testcase includes non-virtual PHIs to cover
the handling of those as well.

2024-03-13  Jakub Jelinek  <jakub@redhat.com>

	PR sanitizer/112709
	* gimple-iterator.h (gsi_safe_insert_before,
	gsi_safe_insert_seq_before): Declare.
	* gimple-iterator.cc: Include gimplify.h.
	(edge_before_returns_twice_call, adjust_before_returns_twice_call,
	gsi_safe_insert_before, gsi_safe_insert_seq_before): New functions.
	* ubsan.cc (instrument_mem_ref, instrument_pointer_overflow,
	instrument_nonnull_arg, instrument_nonnull_return): Use
	gsi_safe_insert_before instead of gsi_insert_before.
	(maybe_instrument_pointer_overflow): Use force_gimple_operand,
	gimple_seq_add_seq_without_update and gsi_safe_insert_seq_before
	instead of force_gimple_operand_gsi.
	(instrument_object_size): Likewise.  Use gsi_safe_insert_before
	instead of gsi_insert_before.

	* gcc.dg/ubsan/pr112709-1.c: New test.
	* gcc.dg/ubsan/pr112709-2.c: New test.
2024-03-13 09:16:45 +01:00
GCC Administrator
f6d9426b5b Daily bump. 2024-03-13 00:17:12 +00:00
Harald Anlauf
81ee1298b4 Fortran: handle procedure pointer component in DT array [PR110826]
gcc/fortran/ChangeLog:

	PR fortran/110826
	* array.cc (gfc_array_dimen_size): When walking the ref chain of an
	array and the ultimate component is a procedure pointer, do not try
	to figure out its dimension even if it is a array-valued function.

gcc/testsuite/ChangeLog:

	PR fortran/110826
	* gfortran.dg/proc_ptr_comp_53.f90: New test.
2024-03-12 19:09:26 +01:00
Tobias Burnus
ef79c64cb5 libgomp/libgomp.texi: Fix @node order in @menu
While texinfo 7.0.3 does not warn, an older texinfo did complain about:
libgomp.texi:1964: warning: node next `omp_target_memcpy' in menu
`omp_target_memcpy_rect' and in sectioning `omp_target_memcpy_async' differ

libgomp/

	* libgomp.texi (Device Memory Routines): Swap item order to match
	the order of the '@node's of the '@subsection's.
2024-03-12 15:42:50 +01:00
Richard Biener
73dac51b32 tree-optimization/114121 - chrec_fold_{plus,multiply} and recursion
The following addresses endless recursion in the
chrec_fold_{plus,multiply} functions when handling sign-conversions.
We only need to apply tricks when we'd fail (there's a chrec in the
converted operand) and we need to make sure to not turn the other
operand into something worse (for the chrec-vs-chrec case).

	PR tree-optimization/114121
	* tree-chrec.cc (chrec_fold_plus_1): Guard recursion with
	converted operand properly.
	(chrec_fold_multiply): Likewise.  Handle missed recursion.

	* gcc.dg/torture/pr114312.c: New testcase.
2024-03-12 15:16:05 +01:00
Nathaniel Shead
4aa87b8560 c++: Support target-specific nodes when streaming modules [PR111224]
Some targets make use of POLY_INT_CSTs and other custom builtin types,
which currently violate some assumptions when streaming. This patch adds
support for them, such as types like Aarch64 __fp16, PowerPC __ibm128,
and vector types thereof.

This patch doesn't provide "full" support of AArch64 SVE, however, since
for that we would need to support 'target' nodes (tracked in PR108080).

Adding the new builtin types means that on Aarch64 we now have 217
global trees created on initialisation (up from 191), so this patch also
slightly bumps the initial size of the fixed_trees allocation to 250.

	PR c++/98645
	PR c++/98688
	PR c++/111224

gcc/cp/ChangeLog:

	* module.cc (enum tree_tag): Add new tag for builtin types.
	(trees_out::start): POLY_INT_CSTs can be emitted.
	(trees_in::start): Likewise.
	(trees_out::core_vals): Stream POLY_INT_CSTs.
	(trees_in::core_vals): Likewise.
	(trees_out::type_node): Handle vectors with multiple coeffs.
	(trees_in::tree_node): Likewise.
	(init_modules): Register target-specific builtin types. Bump
	initial capacity slightly.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/target-aarch64-1_a.C: New test.
	* g++.dg/modules/target-aarch64-1_b.C: New test.
	* g++.dg/modules/target-powerpc-1_a.C: New test.
	* g++.dg/modules/target-powerpc-1_b.C: New test.
	* g++.dg/modules/target-powerpc-2_a.C: New test.
	* g++.dg/modules/target-powerpc-2_b.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Patrick Palka <ppalka@redhat.com>
2024-03-13 00:33:40 +11:00
Jakub Jelinek
ad860cc27b asan: Instrument <retval> stores in callees rather than callers [PR112709]
asan currently instruments since PR69276 r6-6758 fix calls which store
the return value into memory on the caller side, before the call it
verifies the memory is writable.
Now PR112709 where we ICE on trying to instrument such calls made me
think about whether that is what we want to do.

There are 3 different cases.

One is when a function returns an aggregate which is passed e.g. in
registers, say like struct S { int a[4]; }; returning on x86_64.
That would be ideally instrumented in between the actual call and
storing of the aggregate into memory, but asan currently mostly
works as a GIMPLE pass and arranging for the instrumentation to happen
at that spot would be really hard.  We could diagnose after the call
but generally asan attempts to diagnose stuff before something is
overwritten rather than after, or keep the current behavior (that is
what this patch does, which has the disadvantage that it can complain
about UB even for functions which never return and so never actually store,
and doesn't check whether the memory wasn't e.g. poisoned during the call)
or could e.g. instrument both before and after the call (that would have
the disadvantage the current state has but at least would check post-factum
the store again afterwards).

Another case is when a function returns an aggregate through a hidden
reference, struct T { int a[128]; }; on x86_64 or even the above struct S
on ia32 as example.  In the actual program such stores happen when storing
something to <retval> or its parts in the callee, because <retval> there
expands to *hidden_retval.  So, IMHO we should instrument those in the
callee rather than caller, that is where the writes are and we can do that
easily.  This is what the patch below does.

And the last case is for builtins/internal functions.  Usually those don't
return aggregates, but in case they'd do and can be expanded inline, it is
better to instrument them in the caller (as before) rather than not
instrumenting the return stores at all.

I had to tweak the expected output on the PR69276 testcase, because
with the patch it keeps previous behavior on x86_64 (structure returned
in registers, stored in the caller, so reported as UB in A::A()),
while on i686 it changed the behavior and is reported as UB in the
vnull::operator vec which stores the structure, A::A() is then a frame
above it in the backtrace.

2024-03-12  Jakub Jelinek  <jakub@redhat.com>

	PR sanitizer/112709
	* asan.cc (has_stmt_been_instrumented_p): Don't instrument call
	stores on the caller side unless it is a call to a builtin or
	internal function or function doesn't return by hidden reference.
	(maybe_instrument_call): Likewise.
	(instrument_derefs): Instrument stores to RESULT_DECL if
	returning by hidden reference.

	* gcc.dg/asan/pr112709-1.c: New test.
	* g++.dg/asan/pr69276.C: Adjust expected output for some targets.
2024-03-12 11:34:50 +01:00