]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
8 months agoAddress UNRESOLVED for 'g++.dg/tree-ssa/empty-loop.C'
Thomas Schwinge [Thu, 28 Nov 2024 13:31:17 +0000 (14:31 +0100)] 
Address UNRESOLVED for 'g++.dg/tree-ssa/empty-loop.C'

As of commit 1046c32de4956c3d706a2ff8683582fd21b8f360 "optimize basic_string",
we've got:

    PASS: g++.dg/tree-ssa/empty-loop.C  -std=gnu++17 (test for excess errors)
    [-PASS:-]{+XFAIL:+} g++.dg/tree-ssa/empty-loop.C  -std=gnu++17  scan-tree-dump-not cddce2 "if"
    {+UNRESOLVED: g++.dg/tree-ssa/empty-loop.C  -std=gnu++17  scan-tree-dump-not cddce3 "if"+}
    [Etc.]

gcc/testsuite/
* g++.dg/tree-ssa/empty-loop.C: Address UNRESOLVED.

8 months agodocs: Fix up __sync_* documentation [PR117642]
Jakub Jelinek [Thu, 28 Nov 2024 13:31:44 +0000 (14:31 +0100)] 
docs: Fix up __sync_* documentation [PR117642]

The PR14311 commit which added support for __sync_* builtins documented that
there is a warning if a particular operation cannot be implemented.
But that commit nor anything later on implemented such warning, it was
always silent generation of the mentioned calls (which can in most cases
result in linker errors of course because those functions aren't implemented
anywhere, in libatomic or elsewhere in code shipped in gcc).

So, the following patch just adjust the documentation to match the
implementation.

2024-11-28  Jakub Jelinek  <jakub@redhat.com>

PR target/117642
* doc/extend.texi: Remove documentation of warning for unimplemented
__sync_* operations, such warning has never been implemented.

8 months agoranger: Handle nonnull_if_nonzero attribute [PR117023]
Jakub Jelinek [Thu, 28 Nov 2024 10:50:49 +0000 (11:50 +0100)] 
ranger: Handle nonnull_if_nonzero attribute [PR117023]

On top of the
https://gcc.gnu.org/pipermail/gcc-patches/2024-November/668554.html
patch which introduces the nonnull_if_nonzero attribute (because
C2Y is allowing NULL arguments on various calls like memcpy, memset,
strncpy etc. as long as the count is 0) the following patch adds just
limited handling of the attribute in the ranger, in particular infers
nonnull for the pointer argument referenced in first argument of the
attribute if the second argument is a non-zero INTEGER_CST
(integer_nonzerop).

Ideally (as the FIXME says) I'd like to query arg2 range and check if
it doesn't contain zero, but am not sure such queries are possible from
gimple_infer_range (and if it is possible whether one can just query
the currently recorded range for it or if one can call something that
will try to compute the range by walking the def stmts etc.).

Could you handle as a follow-up the range querying if it is possible?

As for useful testcase, with the patch I'm going to post next
e.g. gcc.dg/tree-ssa/pr78154.c if the calls use d as destination (not dn)
and count that will have a range which doesn't include 0 and isn't constant.

2024-11-28  Jakub Jelinek  <jakub@redhat.com>

PR c/117023
* gimple-range-infer.cc (gimple_infer_range::gimple_infer_range):
Handle also nonnull_if_nonzero attributes.

8 months agoAdd support for nonnull_if_nonzero attribute [PR117023]
Jakub Jelinek [Thu, 28 Nov 2024 10:48:33 +0000 (11:48 +0100)] 
Add support for nonnull_if_nonzero attribute [PR117023]

As mentioned in an earlier thread, C2Y voted in a change which made
various library APIs callable with NULL arguments in certain cases,
e.g.
memcpy (NULL, NULL, 0);
is now valid, although
memcpy (NULL, NULL, 1);
remains invalid.  This affects various APIs, including several of
GCC builtins; plus on the C library side those APIs are often declared
with nonnull attribute(s) as well.

Florian suggested using the access attribute for this, but our docs
explicitly say that access attribute doesn't imply nonnull and it doesn't
cover e.g. the qsort case where the comparison function pointer may be
also NULL if nmemb is 0, but must be non-zero otherwise.
As this case affects 21 APIs in C standard and I think is going to affect
various wrappers around those in various packages as well, I think it
is a common thing that should have its own attribute, because we should
still warn when people use
qsort (NULL, 1, 1, NULL);
etc., and similarly want to have -fsanitize=null instrumentation for those.

So, the following patch introduces nonnull_if_nonzero attribute (or would
you prefer cond_nonnull or some other name?), which has always 2 arguments,
argument index of a pointer argument (like one argument nonnull) and
argument index of an associated integral argument.  If that argument is
non-zero, it is UB to pass NULL to the pointer argument, if that argument
is zero, it is valid.  And changes various spots which already handled the
nonnull attribute to handle this one as well, with sometimes using the
ranger (or for -fsanitize=nonnull explicitly checking the associated
argument value, so instead of if (!ptr) __ubsan_... (...); it will
now do if (!ptr && sz) __ubsan_... (...);).
I've so far omitted changing gimple_infer_range (am not 100% sure how I can
use the ranger inside of the ranger) and changing the analyzer to handle it.
And I haven't changed builtins.def etc. to make use of that attribute
instead of nonnull where appropriate.

I'd then follow with the builtins.def changes (and eventually glibc
etc. would need to be adjusted too).

2024-11-28  Jakub Jelinek  <jakub@redhat.com>

PR c/117023
gcc/
* gimple.h (infer_nonnull_range_by_attribute): Add a tree *
argument defaulted to NULL.
* gimple.cc (infer_nonnull_range_by_attribute): Add op2 argument.
Handle also nonnull_if_nonzero attributes.
* tree.cc (get_nonnull_args): Fix comment typo.
* builtins.cc (validate_arglist): Handle nonnull_if_nonzero attribute.
* tree-ssa-ccp.cc (pass_post_ipa_warn::execute): Handle
nonnull_if_nonzero attributes.
* ubsan.cc (instrument_nonnull_arg): Adjust
infer_nonnull_range_by_attribute caller.  If it returned true and
filed in non-NULL arg2, check that arg2 is non-zero as another
condition next to checking that arg is zero.
* doc/extend.texi (nonnull_if_nonzero): Document new attribute.
gcc/c-family/
* c-attribs.cc (handle_nonnull_if_nonzero_attribute): New
function.
(c_common_gnu_attributes): Add nonnull_if_nonzero attribute.
(handle_nonnull_attribute): Fix comment typo.
* c-common.cc (struct nonnull_arg_ctx): Add other member.
(check_function_nonnull): Also check nonnull_if_nonzero attributes.
(check_nonnull_arg): Use different warning wording if pctx->other
is non-zero.
(check_function_arguments): Initialize ctx.other.
gcc/testsuite/
* gcc.dg/nonnull-8.c: New test.
* gcc.dg/nonnull-9.c: New test.
* gcc.dg/nonnull-10.c: New test.
* c-c++-common/ubsan/nonnull-6.c: New test.
* c-c++-common/ubsan/nonnull-7.c: New test.

8 months agors6000: Add PowerPC inline asm redzone clobber support
Jakub Jelinek [Thu, 28 Nov 2024 10:45:00 +0000 (11:45 +0100)] 
rs6000: Add PowerPC inline asm redzone clobber support

The following patch on top of the
https://gcc.gnu.org/pipermail/gcc-patches/2024-November/667949.html
patch adds rs6000 part of the support (the only other target I'm aware of
which clearly has red zone as well).

2024-11-28  Jakub Jelinek  <jakub@redhat.com>

* config/rs6000/rs6000.h (struct machine_function): Add
asm_redzone_clobber_seen member.
* config/rs6000/rs6000-logue.cc (rs6000_stack_info): Force
info->push_p if cfun->machine->asm_redzone_clobber_seen.
* config/rs6000/rs6000.cc (TARGET_REDZONE_CLOBBER): Redefine.
(rs6000_redzone_clobber): New function.

* gcc.target/powerpc/asm-redzone-1.c: New test.

8 months agoinline-asm, i386: Add "redzone" clobber support
Jakub Jelinek [Thu, 28 Nov 2024 10:42:11 +0000 (11:42 +0100)] 
inline-asm, i386: Add "redzone" clobber support

The following patch adds a "redzone" clobber (recognized everywhere,
even on on targets which don't do anything with it),
with which one can mark the rare case where inline asm pushes
something on the stack or uses call instruction without taking
red zone into account (i.e. addq $-128, %rsp; and addq $128, %rsp
around that).

2024-11-28  Jakub Jelinek  <jakub@redhat.com>

gcc/
* target.def (redzone_clobber): New target hook.
* varasm.cc (decode_reg_name_and_count): Return -5 for
"redzone".
* cfgexpand.cc (expand_asm_stmt): Handle redzone clobber.
* config/i386/i386.h (struct machine_function): Add
asm_redzone_clobber_seen member.
* config/i386/i386.cc (ix86_compute_frame_layout): Don't
use red zone if cfun->machine->asm_redzone_clobber_seen.
(ix86_redzone_clobber): New function.
(TARGET_REDZONE_CLOBBER): Redefine.
* doc/extend.texi (Clobbers and Scratch Registers): Document
the "redzone" clobber.
* doc/tm.texi.in: Add @hook TARGET_REDZONE_CLOBBER.
* doc/tm.texi: Regenerate.
gcc/testsuite/
* gcc.dg/asm-redzone-1.c: New test.
* gcc.target/i386/asm-redzone-1.c: New test.

8 months agoc++: Small initial fixes for zeroing of padding bits [PR117256]
Jakub Jelinek [Thu, 28 Nov 2024 10:30:32 +0000 (11:30 +0100)] 
c++: Small initial fixes for zeroing of padding bits [PR117256]

https://eel.is/c++draft/dcl.init#general-6
says that even padding bits are supposed to be zeroed during
zero-initialization.
The following patch on top of the
https://gcc.gnu.org/pipermail/gcc-patches/2024-October/665565.html
patch attempts to implement that, though only for the easy
cases so far, in particular marks the CONSTRUCTOR created during
zero-initialization (or zero-initialization done during the
value-initialization) as having padding bits cleared and for
constexpr evaluation attempts to preserve that bit on a new CONSTRUCTOR
created for CONSTRUCTOR_ZERO_PADDING_BITS lhs.

I think we need far more than that, but am not sure where exactly
to implement that.
In particular, I think __builtin_bitcast should take it into account
during constant evaluation, if the padding bits in something are guaranteed
to be zero, then I'd think std::bitcast out of it and testing those
bits in there should be well defined.
But if we do that, the flag needs to be maintained precisely, not just
conservatively, so e.g. any place where some object is copied into another
one (except bitcast?) which would be element-wise copy, the bit should
be cleared (or preserved from the earlier state?  I'd hope
element-wise copying invalidates even the padding bits, but then what
about just stores into some members, do those invalidate the padding bits
in the rest of the object?).  But if it is an elided copy, it shouldn't.
And am not really sure what happens e.g. with non-automatic constexpr
variables.  If it is constructed by something that doesn't guarantee
the zeroing of the padding bits (so similarly constructed constexpr automatic
variable would have undefined state of the padding bits), are those padding
bits well defined because it isn't automatic variable?

Anyway, I hope the following patch is at least a small step in the right
direction.

2024-11-28  Jakub Jelinek  <jakub@redhat.com>

PR c++/78620
PR c++/117256
* init.cc (build_zero_init_1): Set CONSTRUCTOR_ZERO_PADDING_BITS.
(build_value_init_noctor): Likewise.
* constexpr.cc (cxx_eval_store_expression): Propagate
CONSTRUCTOR_ZERO_PADDING_BITS flag.

8 months agoexpr, c: Don't clear whole unions [PR116416]
Jakub Jelinek [Thu, 28 Nov 2024 10:18:07 +0000 (11:18 +0100)] 
expr, c: Don't clear whole unions [PR116416]

As discussed earlier, we currently clear padding bits even when we
don't have to and that causes pessimization of emitted code,
e.g. for
union U { int a; long b[64]; };
void bar (union U *);
void
foo (void)
{
  union U u = { 0 };
  bar (&u);
}
we need to clear just u.a, not the whole union, but on the other side
in cases where the standard requires padding bits to be zeroed, like for
C23 {} initializers of aggregates with padding bits, or for C++11 zero
initialization we don't do that.

This patch
a) moves some of the stuff into complete_ctor_at_level_p (but not
   all the *p_complete = 0; case, for that it would need to change
   so that it passes around the ctor rather than just its type) and
   changes the handling of unions
b) introduces a new option, so that users can either get the new
   behavior (only what is guaranteed by the standards, the default),
   or previous behavior (union padding zero initialization, no such
   guarantees in structures) or also a guarantee in structures
c) introduces a new CONSTRUCTOR flag which says that the padding bits
   (if any) should be zero initialized (and sets it for now in the C
   FE for C23 {} initializers).

Am not sure the CONSTRUCTOR_ZERO_PADDING_BITS flag is really needed
for C23, if there is just empty initializer, I think we already mark
it as incomplete if there are any missing initializers.  Maybe with
some designated initializer games, say
void foo () {
  struct S { char a; long long b; };
  struct T { struct S c; } t = { .c = {}, .c.a = 1, .c.b = 2 };
...
}
Is this supposed to initialize padding bits in C23 and then the .c.a = 1
and .c.b = 2 stores preserve those padding bits, so is that supposed
to be different from struct T t2 = { .c = { 1, 2 } };
?  What about just struct T t3 = { .c.a = 1, .c.b = 2 }; ?

And I haven't touched the C++ FE for the flag, because I'm afraid I'm lost
on where exactly is zero-initialization done (vs. other types of
initialization) and where is e.g. zero-initialization of a temporary then
(member-wise) copied.
Say
struct S { char a; long long b; };
struct T { constexpr T (int a, int b) : c () { c.a = a; c.b = b; } S c; };
void bar (T *);

void
foo ()
{
  T t (1, 2);
  bar (&t);
}
Is the c () value-initialization of t.c followed by c.a and c.b updates
which preserve the zero initialized padding bits?  Or is there some
copy construction involved which does member-wise copying and makes the
padding bits undefined?
Looking at (older) clang++ with -O2, it initializes also the padding bits
when c () is used and doesn't with c {}.
For GCC, note that there is that optimization from Alex to zero padding bits
for optimization purposes for small aggregates, so either one needs to look
at -O0 -fdump-tree-gimple dumps, or use larger structures which aren't
optimized that way.

2024-11-28  Jakub Jelinek  <jakub@redhat.com>

PR c++/116416
gcc/
* flag-types.h (enum zero_init_padding_bits_kind): New type.
* tree.h (CONSTRUCTOR_ZERO_PADDING_BITS): Define.
* common.opt (fzero-init-padding-bits=): New option.
* expr.cc (categorize_ctor_elements_1): Handle
CONSTRUCTOR_ZERO_PADDING_BITS or
flag_zero_init_padding_bits == ZERO_INIT_PADDING_BITS_ALL.  Fix
up *p_complete = -1; setting for unions.
(complete_ctor_at_level_p): Handle unions differently for
flag_zero_init_padding_bits == ZERO_INIT_PADDING_BITS_STANDARD.
* gimple-fold.cc (type_has_padding_at_level_p): Fix up UNION_TYPE
handling, return also true for UNION_TYPE with no FIELD_DECLs
and non-zero size, handle QUAL_UNION_TYPE like UNION_TYPE.
* doc/invoke.texi (-fzero-init-padding-bits=@var{value}): Document.
gcc/c/
* c-parser.cc (c_parser_braced_init): Set CONSTRUCTOR_ZERO_PADDING_BITS
for flag_isoc23 empty initializers.
* c-typeck.cc (constructor_zero_padding_bits): New variable.
(struct constructor_stack): Add zero_padding_bits member.
(really_start_incremental_init): Save and clear
constructor_zero_padding_bits.
(push_init_level): Save constructor_zero_padding_bits.  Or into it
CONSTRUCTOR_ZERO_PADDING_BITS from previous value if implicit.
(pop_init_level): Set CONSTRUCTOR_ZERO_PADDING_BITS if
constructor_zero_padding_bits and restore
constructor_zero_padding_bits.
gcc/testsuite/
* gcc.dg/plugin/infoleak-1.c (test_union_2b, test_union_4b): Expect
diagnostics.
* gcc.dg/c23-empty-init-5.c: New test.
* gcc.dg/gnu11-empty-init-1.c: New test.
* gcc.dg/gnu11-empty-init-2.c: New test.
* gcc.dg/gnu11-empty-init-3.c: New test.
* gcc.dg/gnu11-empty-init-4.c: New test.

8 months agomiddle-end: rework vectorizable_store to iterate over single index [PR117557]
Tamar Christina [Thu, 28 Nov 2024 10:23:14 +0000 (10:23 +0000)] 
middle-end: rework vectorizable_store to iterate over single index [PR117557]

The testcase

#include <stdint.h>
#include <string.h>

#define N 8
#define L 8

void f(const uint8_t * restrict seq1,
       const uint8_t *idx, uint8_t *seq_out) {
  for (int i = 0; i < L; ++i) {
    uint8_t h = idx[i];
    memcpy((void *)&seq_out[i * N], (const void *)&seq1[h * N / 2], N / 2);
  }
}

compiled at -O3 -mcpu=neoverse-n1+sve

miscompiles to:

    ld1w    z31.s, p3/z, [x23, z29.s, sxtw]
    ld1w    z29.s, p7/z, [x23, z30.s, sxtw]
    st1w    z29.s, p7, [x24, z12.s, sxtw]
    st1w    z31.s, p7, [x24, z12.s, sxtw]

rather than

    ld1w    z31.s, p3/z, [x23, z29.s, sxtw]
    ld1w    z29.s, p7/z, [x23, z30.s, sxtw]
    st1w    z29.s, p7, [x24, z12.s, sxtw]
    addvl   x3, x24, #2
    st1w    z31.s, p3, [x3, z12.s, sxtw]

Where two things go wrong, the wrong mask is used and the address pointers to
the stores are wrong.

This issue is happening because the codegen loop in vectorizable_store is a
nested loop where in the outer loop we iterate over ncopies and in the inner
loop we loop over vec_num.

For SLP ncopies == 1 and vec_num == SLP_NUM_STMS, but the loop mask is
determined by only the outerloop index and the pointer address is only updated
in the outer loop.

As such for SLP we always use the same predicate and the same memory location.
This patch flattens the two loops and instead iterates over ncopies * vec_num
and simplified the indexing.

This does not fully fix the gcc_r miscompile error in SPECCPU 2017 as the error
moves somewhere else.  I will look at that next but fixes some other libraries
that also started failing.

gcc/ChangeLog:

PR tree-optimization/117557
* tree-vect-stmts.cc (vectorizable_store): Flatten the ncopies and
vec_num loops.

gcc/testsuite/ChangeLog:

PR tree-optimization/117557
* gcc.target/aarch64/pr117557.c: New test.

8 months agolibstdc++: Include <sys/cdefs.h> in os_defines.h for FreeBSD [PR117210]
Jonathan Wakely [Wed, 27 Nov 2024 14:10:34 +0000 (14:10 +0000)] 
libstdc++: Include <sys/cdefs.h> in os_defines.h for FreeBSD [PR117210]

This is needed so that __LONG_LONG_SUPPORTED is defined before we depend
on it.

libstdc++-v3/ChangeLog:

PR libstdc++/117210
* config/os/bsd/dragonfly/os_defines.h: Include <sys/cdefs.h>.
* config/os/bsd/freebsd/os_defines.h: Likewise.

8 months agogimple-fold: Avoid ICEs with bogus declarations like const attribute no snprintf...
Jakub Jelinek [Thu, 28 Nov 2024 09:51:16 +0000 (10:51 +0100)] 
gimple-fold: Avoid ICEs with bogus declarations like const attribute no snprintf [PR117358]

When one puts incorrect const or pure attributes on declarations of various
C APIs which have corresponding builtins (vs. what they actually do), we can
get tons of ICEs in gimple-fold.cc.

The following patch fixes it by giving up gimple_fold_builtin_* folding
if the functions don't have gimple_vdef (or for pure functions like
bcmp/strchr/strstr gimple_vuse) when in SSA form (during gimplification
they will surely have both of those NULL even when declared correctly,
yet it is highly desirable to fold them).

Or shall I replace
!gimple_vdef (stmt) && gimple_in_ssa_p (cfun)
tests with
(gimple_call_flags (stmt) & (ECF_CONST | ECF_PURE | ECF_NOVOPS)) != 0
and
!gimple_vuse (stmt) && gimple_in_ssa_p (cfun)
with
(gimple_call_flags (stmt) & (ECF_CONST | ECF_NOVOPS)) != 0
?

2024-11-28  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/117358
* gimple-fold.cc (gimple_fold_builtin_memory_op): Punt if stmt has no
vdef in ssa form.
(gimple_fold_builtin_bcmp): Punt if stmt has no vuse in ssa form.
(gimple_fold_builtin_bcopy): Punt if stmt has no vdef in ssa form.
(gimple_fold_builtin_bzero): Likewise.
(gimple_fold_builtin_memset): Likewise.  Use return false instead of
return NULL_TREE.
(gimple_fold_builtin_strcpy): Punt if stmt has no vdef in ssa form.
(gimple_fold_builtin_strncpy): Likewise.
(gimple_fold_builtin_strchr): Punt if stmt has no vuse in ssa form.
(gimple_fold_builtin_strstr): Likewise.
(gimple_fold_builtin_strcat): Punt if stmt has no vdef in ssa form.
(gimple_fold_builtin_strcat_chk): Likewise.
(gimple_fold_builtin_strncat): Likewise.
(gimple_fold_builtin_strncat_chk): Likewise.
(gimple_fold_builtin_string_compare): Likewise.
(gimple_fold_builtin_fputs): Likewise.
(gimple_fold_builtin_memory_chk): Likewise.
(gimple_fold_builtin_stxcpy_chk): Likewise.
(gimple_fold_builtin_stxncpy_chk): Likewise.
(gimple_fold_builtin_stpcpy): Likewise.
(gimple_fold_builtin_snprintf_chk): Likewise.
(gimple_fold_builtin_sprintf_chk): Likewise.
(gimple_fold_builtin_sprintf): Likewise.
(gimple_fold_builtin_snprintf): Likewise.
(gimple_fold_builtin_fprintf): Likewise.
(gimple_fold_builtin_printf): Likewise.
(gimple_fold_builtin_realloc): Likewise.

* gcc.c-torture/compile/pr117358.c: New test.

8 months agobuiltins: Handle BITINT_TYPE in __builtin_iseqsig folding [PR117802]
Jakub Jelinek [Thu, 28 Nov 2024 09:23:47 +0000 (10:23 +0100)] 
builtins: Handle BITINT_TYPE in __builtin_iseqsig folding [PR117802]

In check_builtin_function_arguments in the _BitInt patchset I've changed
INTEGER_TYPE tests to INTEGER_TYPE or BITINT_TYPE, but haven't done the
same in fold_builtin_iseqsig, which now ICEs because of that.

The following patch fixes that.

BTW, that TYPE_PRECISION (type0) >= TYPE_PRECISION (type1) test
for REAL_TYPE vs. REAL_TYPE looks pretty random and dangerous, I think
it would be useful to handle this builtin also in the C and C++ FEs,
if both arguments have REAL_TYPE, use the FE specific routine to decide
which types to use and error if a comparison between types would be
erroneous (e.g. complain about _Decimal* vs. float/double/long
double/_Float*, pick up the preferred type, complain about
__ibm128 vs. _Float128 in C++, etc.).
But the FEs can just promote one argument to the other in that case
and keep fold_builtin_iseqsig as is for say Fortran and other FEs.

2024-11-28  Jakub Jelinek  <jakub@redhat.com>

PR c/117802
* builtins.cc (fold_builtin_iseqsig): Handle BITINT_TYPE like
INTEGER_TYPE.

* gcc.dg/builtin-iseqsig-1.c: New test.
* gcc.dg/bitint-118.c: New test.

8 months agoc: Fix gimplification ICE for shifts with invalid redeclarations
Joseph Myers [Thu, 28 Nov 2024 02:41:35 +0000 (02:41 +0000)] 
c: Fix gimplification ICE for shifts with invalid redeclarations

As reported in bug 117757, there is a C gimplification ICE for shifts
involving a variable that was incompatibly redeclared (and thus had
its type changed to error_mark_node).  Fix this with an appropriate
error_operand_p check.

Note that this is not the same issue as any of the other bugs reported
for ICEs later in the gimplifier dealing with such erroneous
redeclarations (it is, however, the same as the *second* ICE reported
in bug 115644 - the test in comment#1 for that bug, not the one in the
original bug report).

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

PR c/117757

gcc/c-family/
* c-gimplify.cc (c_gimplify_expr): Check for error_operand_p
before calling TYPE_MAIN_VARIANT for shifts.

gcc/testsuite/
* gcc.dg/pr117757-1.c: New test.

8 months agoanalyzer,timevar: avoid naked "new" in JSON-handling
David Malcolm [Thu, 28 Nov 2024 00:21:16 +0000 (19:21 -0500)] 
analyzer,timevar: avoid naked "new" in JSON-handling

Now that <memory> is always included, use std::unique_ptr in a few more
places to avoid naked "new".

No functional change intended.

gcc/analyzer/ChangeLog:
* engine.cc (strongly_connected_components::to_json): Avoid naked
"new".
* infinite-loop.cc (infinite_loop::to_json): Convert return type
to unique_ptr.  Avoid naked "new".
* sm-signal.cc (signal_delivery_edge_info_t::to_json): Delete
unused function.
* supergraph.cc (supernode::to_json): Avoid naked "new".

gcc/ChangeLog:
* timevar.cc: Include "make-unique.h".
(timer::named_items::make_json): Convert return type to unique_ptr.
Avoid naked "new".
(make_json_for_timevar_time_def): Likewise.
(timer::timevar_def::make_json): Likewise.
(timer::make_json): Likewise.
* timevar.h (timer::make_json): Likewise.
(timer::timevar_def::make_json): Likewise.
* tree-diagnostic-client-data-hooks.cc: Update for above changes.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
8 months agoc-family: offer suggestions for missing command-line options [PR82892]
David Malcolm [Thu, 28 Nov 2024 00:21:15 +0000 (19:21 -0500)] 
c-family: offer suggestions for missing command-line options [PR82892]

Some builtin macros are only defined when certain command-line options
are provided.  Update the error messages for them so that we suggest
the pertinent option ('-fopenacc' for '_OPENACC', and '-fopenmp' for
'_OPENMP')

gcc/c-family/ChangeLog:
PR c/82892
* c-common.h (get_option_for_builtin_define): New decl.
* c-cppbuiltin.cc (get_option_for_builtin_define): New.
* known-headers.cc: Include "opts.h".
(suggest_missing_option::suggest_missing_option): New.
(suggest_missing_option::~suggest_missing_option): New.
* known-headers.h (class suggest_missing_option): New.

gcc/c/ChangeLog:
PR c/82892
* c-decl.cc (lookup_name_fuzzy): Provide hints for missing
command-line options.

gcc/cp/ChangeLog:
PR c/82892
* name-lookup.cc (suggest_alternatives_for_1): Provide hints for
missing command-line options.

gcc/testsuite/ChangeLog:
PR c/82892
* c-c++-common/spellcheck-missing-option.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
8 months agoC/C++: add fix-it hints for missing '&' and '*' (v5) [PR87850]
David Malcolm [Thu, 28 Nov 2024 00:21:15 +0000 (19:21 -0500)] 
C/C++: add fix-it hints for missing '&' and '*' (v5) [PR87850]

This patch adds a note with a fix-it hint to various
pointer-vs-non-pointer diagnostics, suggesting the addition of
a leading '&' or '*'.

For example, note the ampersand fix-it hint in the following:

demo.c: In function 'int main()':
demo.c:5:22: error: invalid conversion from 'pthread_key_t' {aka 'unsigned int'}
   to 'pthread_key_t*' {aka 'unsigned int*'} [-fpermissive]
    5 |   pthread_key_create(key, NULL);
      |                      ^~~
      |                      |
      |                      pthread_key_t {aka unsigned int}
demo.c:5:22: note: possible fix: take the address with '&'
    5 |   pthread_key_create(key, NULL);
      |                      ^~~
      |                      &
In file included from demo.c:1:
/usr/include/pthread.h:1122:47: note:   initializing argument 1 of
   'int pthread_key_create(pthread_key_t*, void (*)(void*))'
 1122 | extern int pthread_key_create (pthread_key_t *__key,
      |                                ~~~~~~~~~~~~~~~^~~~~

gcc/c-family/ChangeLog:
PR c++/87850
* c-common.cc: Include "gcc-rich-location.h".
(maybe_emit_indirection_note): New function.
* c-common.h (maybe_emit_indirection_note): New decl.
(compatible_types_for_indirection_note_p): New decl.

gcc/c/ChangeLog:
PR c++/87850
* c-typeck.cc (compatible_types_for_indirection_note_p): New
function.
(convert_for_assignment): Call maybe_emit_indirection_note for
pointer vs non-pointer diagnostics.

gcc/cp/ChangeLog:
PR c++/87850
* call.cc (convert_like_real): Call maybe_emit_indirection_note
for "invalid conversion" diagnostic.
* typeck.cc (compatible_types_for_indirection_note_p): New
function.

gcc/testsuite/ChangeLog:
PR c++/87850
* c-c++-common/indirection-fixits.c: New test.
* g++.dg/template/error60.C: Add fix-it hint to expected output.
* g++.dg/template/error60a.C: Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
8 months agodiagnostics: replace %<%s%> with %qs [PR104896]
David Malcolm [Thu, 28 Nov 2024 00:21:15 +0000 (19:21 -0500)] 
diagnostics: replace %<%s%> with %qs [PR104896]

No functional change intended.

gcc/analyzer/ChangeLog:
PR c/104896
* sm-malloc.cc: Replace "%<%s%>" with "%qs" in message wording.

gcc/c-family/ChangeLog:
PR c/104896
* c-lex.cc (c_common_lex_availability_macro): Replace "%<%s%>"
with "%qs" in message wording.
* c-opts.cc (c_common_handle_option): Likewise.
* c-warn.cc (warn_parm_array_mismatch): Likewise.

gcc/ChangeLog:
PR c/104896
* common/config/ia64/ia64-common.cc (ia64_handle_option): Replace
"%<%s%>" with "%qs" in message wording.
* common/config/rs6000/rs6000-common.cc (rs6000_handle_option):
Likewise.
* config/aarch64/aarch64.cc (aarch64_validate_sls_mitigation):
Likewise.
(aarch64_override_options): Likewise.
(aarch64_process_target_attr): Likewise.
* config/arm/aarch-common.cc (aarch_validate_mbranch_protection):
Likewise.
* config/pru/pru.cc (pru_insert_attributes): Likewise.
* config/riscv/riscv-target-attr.cc
(riscv_target_attr_parser::parse_arch): Likewise.
* omp-general.cc (oacc_verify_routine_clauses): Likewise.
* tree-ssa-uninit.cc (maybe_warn_read_write_only): Likewise.
(maybe_warn_pass_by_reference): Likewise.

gcc/cp/ChangeLog:
PR c/104896
* cvt.cc (maybe_warn_nodiscard): Replace "%<%s%>" with "%qs" in
message wording.

gcc/fortran/ChangeLog:
PR c/104896
* resolve.cc (resolve_operator): Replace "%<%s%>" with "%qs" in
message wording.

gcc/go/ChangeLog:
PR c/104896
* gofrontend/embed.cc (Gogo::initializer_for_embeds): Replace
"%<%s%>" with "%qs" in message wording.
* gofrontend/expressions.cc
(Selector_expression::lower_method_expression): Likewise.
* gofrontend/gogo.cc (Gogo::set_package_name): Likewise.
(Named_object::export_named_object): Likewise.
* gofrontend/parse.cc (Parse::struct_type): Likewise.
(Parse::parameter_list): Likewise.

gcc/rust/ChangeLog:
PR c/104896
* backend/rust-compile-expr.cc
(CompileExpr::compile_integer_literal): Replace "%<%s%>" with
"%qs" in message wording.
(CompileExpr::compile_float_literal): Likewise.
* backend/rust-compile-intrinsic.cc (Intrinsics::compile):
Likewise.
* backend/rust-tree.cc (maybe_warn_nodiscard): Likewise.
* checks/lints/rust-lint-scan-deadcode.h: Likewise.
* lex/rust-lex.cc (Lexer::parse_partial_unicode_escape): Likewise.
(Lexer::parse_raw_byte_string): Likewise.
* lex/rust-token.cc (Token::get_str): Likewise.
* metadata/rust-export-metadata.cc
(PublicInterface::write_to_path): Likewise.
* parse/rust-parse.cc
(peculiar_fragment_match_compatible_fragment): Likewise.
(peculiar_fragment_match_compatible): Likewise.
* resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path):
Likewise.
* resolve/rust-ast-resolve-toplevel.h: Likewise.
* resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go):
Likewise.
* rust-session-manager.cc (validate_crate_name): Likewise.
(Session::load_extern_crate): Likewise.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Likewise.
(TypeCheckExpr::resolve_fn_trait_call): Likewise.
* typecheck/rust-hir-type-check-implitem.cc
(TypeCheckImplItemWithTrait::visit): Likewise.
* typecheck/rust-hir-type-check-item.cc
(TypeCheckItem::validate_trait_impl_block): Likewise.
* typecheck/rust-hir-type-check-struct.cc
(TypeCheckStructExpr::visit): Likewise.
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit):
Likewise.
* typecheck/rust-tyty.cc (BaseType::bounds_compatible): Likewise.
* typecheck/rust-unify.cc (UnifyRules::emit_abi_mismatch):
Likewise.
* util/rust-attributes.cc (AttributeChecker::visit): Likewise.

libcpp/ChangeLog:
PR c/104896
* pch.cc (cpp_valid_state): Replace "%<%s%>" with "%qs" in message
wording.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
8 months agoDaily bump.
GCC Administrator [Thu, 28 Nov 2024 00:19:41 +0000 (00:19 +0000)] 
Daily bump.

8 months agooptimize basic_string
Jan Hubicka [Wed, 27 Nov 2024 22:52:37 +0000 (23:52 +0100)] 
optimize basic_string

Add __builtin_unreachable conditionls to declare value ranges of
basic_string::length().  FIx max_size() to return actual max size
using logic similar to std::vector. Aviod use of size() in empty()
to save some compile time overhead.

As disucced, max_size() change is technically ABI breaking, but
hopefully this does not really matter in practice.

Change of length() breaks empty-loop testcase where we now optimize the
loop only after inlining, so template is updated to check cddce3 instead
of cddce2. This is PR117764.

With these chages we now optimize out unused strings as tested in
string-1.C

libstdc++-v3/ChangeLog:

* include/bits/basic_string.h (basic_string::size(),
basic_string::length(), basic_string::capacity()): Add
__builtin_unreachable to declare value ranges.
(basic_string::empty()): Implement directly
(basic_string::max_size()): Account correctly the terminating 0
and limits implied by ptrdiff_t.

gcc/testsuite/ChangeLog:

* g++.dg/tree-ssa/empty-loop.C: xfail optimization at cddce2 and check
it happens at cddce3.
* g++.dg/tree-ssa/string-1.C: New test.

8 months agoc: Fix ICE using function name in parameter type in old-style function definition...
Joseph Myers [Wed, 27 Nov 2024 22:27:08 +0000 (22:27 +0000)] 
c: Fix ICE using function name in parameter type in old-style function definition [PR91193]

As reported in bug 91193, if an old-style function definition
redeclares a typedef name as a function, then uses that function name
at the start of the first old-style parameter definition, then the
parser interprets that token as a typedef name (because lookahead
occurred before processing of the function declarator completed), but
when it is looked up in processing that parameter definition, what is
found is the redefinition, resulting in an ICE.

The function name's scope starts at the end of its declarator, so this
is similar to other cases where we call
c_parser_maybe_reclassify_token because lookahead might have
classified a token as being a typedef or not based on information from
the wrong scope; do so in this case as well, so resulting in the
expected parse errors from using something that's no longer a typedef
name as if it were a typedef name, and eliminating the ICE.

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

PR c/91193

gcc/c/
* c-parser.cc (c_parser_maybe_reclassify_token): Define earlier.
(c_parser_declaration_or_fndef): Call
c_parser_maybe_reclassify_token before parsing old-style parameter
definitions.

gcc/testsuite/
* gcc.dg/pr91193-1.c, gcc.dg/pr91193-2.c: New tests.

8 months agolibstdc++: Remove __builtin_expect from consteval assertion
Jonathan Wakely [Wed, 27 Nov 2024 12:28:30 +0000 (12:28 +0000)] 
libstdc++: Remove __builtin_expect from consteval assertion

libstdc++-v3/ChangeLog:

* include/bits/c++config (__glibcxx_assert): Remove useless
__builtin_expect from constexpr-only assertion. Improve
comments.

8 months agolibstdc++: Add cold attribute to assertion failure functions [PR117650]
Jonathan Wakely [Wed, 27 Nov 2024 11:52:40 +0000 (11:52 +0000)] 
libstdc++: Add cold attribute to assertion failure functions [PR117650]

This helps the compiler to split the cold path into a separate clone, so
that the hot path is a smaller function that uses less icache, and the
cold path is only fetched into the icache if actually executed.

libstdc++-v3/ChangeLog:

PR libstdc++/117650
* include/bits/c++config (__glibcxx_assert_fail): Add cold
attribute.
* include/debug/formatter.h (_Error_formatter::_M_error):
Likewise.

8 months agoi386: x86 can use x >> y for x >> 32+y [PR36503]
Uros Bizjak [Wed, 27 Nov 2024 19:45:25 +0000 (20:45 +0100)] 
i386: x86 can use x >> y for x >> 32+y [PR36503]

x86 targets mask 32-bit shifts with a 5-bit mask (and 64-bit with 6-bit mask),
so they can use x >> y instead of x >> 32+y.

The optimization converts:

leal    32(%rsi), %ecx
sall    %cl, %eax

to:
sall    %cl, %eax

PR target/36503

gcc/ChangeLog:

* config/i386/i386.md (*ashl<mode>3_add):
New define_insn_and_split pattern.
(*ashl<mode>3_add_1): Ditto.
(*<insn><mode>3_add): Ditto.
(*<insn><mode>3_add_1): Ditto.
(*ashl<mode>3_sub): Rename from *ashl<mode>3_negcnt.
(*ashl<mode>3_sub_1): Rename from *ashl<mode>3_negcnt_1.
(*<insn><mode>3_sub): Rename from *<insn><mode>3_negcnt.
(*<insn><mode>3_sub_1): Rename from *<insn><mode>3_negcnt_1.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr36503-3.c: New test.
* gcc.target/i386/pr36503-4.c: New test.

8 months agomatch: Improve handling of double convert [PR117776]
Andrew Pinski [Tue, 26 Nov 2024 00:04:21 +0000 (16:04 -0800)] 
match: Improve handling of double convert [PR117776]

For a double conversion, we will simplify it into a conversion
with an and if the outer type and inside precision matches and
the intra precision is smaller and unsigned. We should be able
to extend this to where the outer precision is larger too.
This is a good canonicalization too.

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/117776
gcc/ChangeLog:

* match.pd (nested int casts): Allow for the case
where the final prec is greater than the original
prec.

gcc/testsuite/ChangeLog:

* g++.dg/vect/pr117776.cc: New test.
* gcc.dg/tree-ssa/cast-3.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
8 months agolibstdc++/ranges: make _RangeAdaptorClosure befriend operator|
Patrick Palka [Wed, 27 Nov 2024 16:59:38 +0000 (11:59 -0500)] 
libstdc++/ranges: make _RangeAdaptorClosure befriend operator|

This declares the range adaptor pipe operators a friend of the
_RangeAdaptorClosure base class so that the std module doesn't need to
export them for ADL to find them.

Note that we deliberately don't define these pipe operators as hidden
friends, see r14-3293-g4a6f3676e7dd9e.

libstdc++-v3/ChangeLog:

* include/std/ranges (views::__adaptor::_RangeAdaptorClosure):
Befriend both operator| overloads.
* src/c++23/std.cc.in: Don't export views::__adaptor::operator|.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
8 months agoc: Fix sizeof error recovery [PR117745]
Jakub Jelinek [Wed, 27 Nov 2024 16:29:28 +0000 (17:29 +0100)] 
c: Fix sizeof error recovery [PR117745]

Compilation of the following testcase hangs forever after emitting first
error.  The problem is that in one place we just return error_mark_node
directly rather than going through c_expr_sizeof_expr or c_expr_sizeof_type.
The parsing of the expression could have called record_maybe_used_decl
though, but nothing calls pop_maybe_used which needs to be called after
parsing of every sizeof/typeof, successful or not.
At the end of the toplevel declaration we free the parser_obstack and in
another function record_maybe_used_decl is called again and due to the
missing pop_maybe_unused we end up with a cycle in the chain.

The following patch fixes it by just setting error and goto to the
    sizeof_expr:
      c_inhibit_evaluation_warnings--;
      in_sizeof--;
      mark_exp_read (expr.value);
      if (TREE_CODE (expr.value) == COMPONENT_REF
          && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
        error_at (expr_loc, "%<sizeof%> applied to a bit-field");
      result = c_expr_sizeof_expr (expr_loc, expr);
where c_expr_sizeof_expr will do:
  struct c_expr ret;
  if (expr.value == error_mark_node)
    {
      ret.value = error_mark_node;
      ret.original_code = ERROR_MARK;
      ret.original_type = NULL;
      ret.m_decimal = 0;
      pop_maybe_used (false);
    }
...
  return ret;
which is exactly what the old code did manually except for the missing
pop_maybe_used call.  mark_exp_read does nothing on error_mark_node and
error_mark_node doesn't have COMPONENT_REF tree_code.

2024-11-27  Jakub Jelinek  <jakub@redhat.com>

PR c/117745
* c-parser.cc (c_parser_sizeof_expression): If type_name is NULL,
just expr.set_error () and goto sizeof_expr instead of doing error
recovery manually.

* gcc.dg/pr117745.c: New test.

8 months agoI386: Add more testcases for unsigned SAT_ADD vector pattern
Pan Li [Fri, 22 Nov 2024 03:48:26 +0000 (11:48 +0800)] 
I386: Add more testcases for unsigned SAT_ADD vector pattern

Some forms like below failed to be recognized as a SAT_ADD pattern
for target i386.  It is related to some match pattern
extraction but get fixed after the refactor of the SAT_ADD
pattern.  Thus, add testcases to ensure we won't have similar
issues in the future.

  #define DEF_SAT_ADD(T)   \
  T sat_add_##T (T x, T y) \
  {                        \
    T res;                 \
    res = x + y;           \
    res |= -(T)(res < x);  \
    return res;            \
  }

  #define VEC_DEF_SAT_ADD(T)                       \
  void vec_sat_add(T * restrict a, T * restrict b) \
  {                                                \
    for (int i = 0; i < 8; i++)                    \
      b[i] = sat_add_##T (a[i], b[i]);             \
  }

  DEF_SAT_ADD (uint32_t)
  VEC_DEF_SAT_ADD (uint32_t)

The below test suites are passed for this patch.
make -k check-gcc RUNTESTFLAGS="--target_board=unix\{,-m32\} i386.exp=pr112600-5a-*.c"

PR target/112600

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr112600-5-u16.c: New test.
* gcc.target/i386/pr112600-5-u32.c: New test.
* gcc.target/i386/pr112600-5-u64.c: New test.
* gcc.target/i386/pr112600-5-u8.c: New test.
* gcc.target/i386/pr112600-5.h: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
8 months agoMatch: Refactor the unsigned SAT_ADD match ADD_OVERFLOW pattern [NFC]
Pan Li [Mon, 25 Nov 2024 01:21:24 +0000 (09:21 +0800)] 
Match: Refactor the unsigned SAT_ADD match ADD_OVERFLOW pattern [NFC]

This patch would like to refactor the unsigned SAT_ADD pattern when
leverage the IFN ADD_OVERFLOW, aka:
* Extract type check outside.
* Re-arrange the related match pattern forms together.
* Remove unnecessary helper pattern matches.

The below test suites are passed for this patch.
* The rv64gcv fully regression test.
* The x86 bootstrap test.
* The x86 fully regression test.

gcc/ChangeLog:

* match.pd: Refactor sorts of unsigned SAT_ADD match pattern for
IFN ADD_OVERFLOW.

Signed-off-by: Pan Li <pan2.li@intel.com>
8 months agoc: Do not remove _Atomic from array element type for typeof_unqual [PR117781]
Joseph Myers [Wed, 27 Nov 2024 14:10:37 +0000 (14:10 +0000)] 
c: Do not remove _Atomic from array element type for typeof_unqual [PR117781]

As reported in bug 117781, my fix for bug 112841 broke the case of
typeof_unqual applied to an array of _Atomic elements, which should
not have _Atomic removed since only the element type is atomic, not
the array type.  Fix with logic to ensure that atomic element types
are preserved as such, while other qualifiers (i.e. those that are
semantically rather than only syntactically such in C) are removed.

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

PR c/117781

gcc/c/
* c-parser.cc (c_parser_typeof_specifier): Do not remove _Atomic
from array element type for typeof_unqual.

gcc/testsuite/
* gcc.dg/c23-typeof-5.c: New test.

8 months agobuiltins: Emit __sync_lock_release_{8,16} call as last resort instead of doing nothin...
Jakub Jelinek [Wed, 27 Nov 2024 13:33:16 +0000 (14:33 +0100)] 
builtins: Emit __sync_lock_release_{8,16} call as last resort instead of doing nothing [PR117642]

As the following testcases show, in case of multi-word
__sync_lock_test_and_set where we don't actually support atomics for that
size (__int128 for x86_64 lp64 with -mno-cx16, long long for ia32 with
-march=i{3,4}86), as the last fallback if we don't know anything else
we just emit calls to __sync_lock_test_and_set_{8,16}.  Those aren't defined
in libatomic, but perhaps users could define them themselves.
While __sync_lock_release if it gives up and has no way to emit the atomic
store just does nothing at all, so no clear sign to the users something
went wrong and that the code will not do what they expected.
This regressed when __atomic_* support has been introduced, previously we
would just emit those calls even in this case.

The patch just emits the call as the last fallback.

2024-11-27  Jakub Jelinek  <jakub@redhat.com>

PR target/117642
* builtins.cc (expand_builtin_sync_lock_release): Change return type
from void to rtx, return result of expand_atomic_store.
(expand_builtin) <case BUILT_IN_SYNC_LOCK_RELEASE_16>: If
expand_builtin_sync_lock_release returns NULL, do a break rather
than return const0_rtx.

* gcc.target/i386/pr117642-1.c: New test.
* gcc.target/i386/pr117642-2.c: New test.

8 months agomatch.pd: Avoid introducing UB in the ((X /[ex] C1) +- C2) * (C1 * C3) simplification...
Jakub Jelinek [Wed, 27 Nov 2024 13:32:07 +0000 (14:32 +0100)] 
match.pd: Avoid introducing UB in the ((X /[ex] C1) +- C2) * (C1 * C3) simplification [PR117692]

As the pr117692.c testcase shows, the generalized pattern can introduce
UB when there wasn't any.
The old pattern was I believe correct, it is as if in the new
pattern C3 was always 1 and I don't see how that could have introduced
UB.
But if type is signed and C3 (aka factor) isn't 1 and for + X and C2
could have different sign or for - X and C2 could have the same sign,
when doing the addition/subtraction first the absolute value could
decrease, while if first multiplying by C3 we could invoke UB already
during that multiplication.

The following patch fixes it by going through the casts to utype if
ranger (get_range_pos_neg) detects the sign compared to sign of C2
(INTEGER_CST) could be the same or could be different depending on op
because then the absolute value will not increase.

Other possibility (perhaps as another check if this check doesn't succeed)
would be to test whether X * C3 could actually overflow.
vr-values.cc has check_for_binary_op_overflow (currently not exported)
which I think does what we'd need to check, if it returns true and sets
ovf to false.

2024-11-27  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/117692
* tree.cc (get_range_pos_neg): Adjust function comment, use
non-negative instead of positive.
* match.pd
(((X /[ex] C1) +- C2) * (C1 * C3) -> (X * C3) +- (C1 * C2 * C3)):
Use casts to utype if type is signed, factor isn't 1 and
C1 and C2 could have different sign for + or could have the
same sign for -.

* gcc.dg/tree-ssa/mulexactdiv-5.c: Expect 8 nop_exprs.
* gcc.dg/tree-ssa/pr117692.c: New test.

8 months agolibstdc++: module std fixes
Jason Merrill [Tue, 19 Nov 2024 23:21:00 +0000 (00:21 +0100)] 
libstdc++: module std fixes

Some tests were failing due to the exported using declaration of iter_move
conflicting with friend declarations; the exported using needs to be in the
inline namespace, like the customization point itself, rather than
std::ranges.

Also add a few missing exports.

Some tests failed to find some operators defined in implementation-detail
namespaces; this exports them as well, but as previously discussed it's
probably preferable to make those operators friends so ADL can find them
that way.

libstdc++-v3/ChangeLog:

* src/c++23/std.cc.in: Fix iter_move/swap.  Add fold_left_first, to,
concat, and some operators.

8 months agolibstdc++: Add debug assertions to std::list and std::forward_list
Jonathan Wakely [Fri, 15 Nov 2024 22:03:20 +0000 (22:03 +0000)] 
libstdc++: Add debug assertions to std::list and std::forward_list

While working on fancy pointer support for the linked lists I noticed
they didn't have any debug assertions. This adds the obvious non-empty
assertions to front() and back().

libstdc++-v3/ChangeLog:

* include/bits/forward_list.h (forward_list::front): Add
non-empty assertions.
* include/bits/stl_list.h (list::front, list::back): Add
non-empty assertions.

8 months agolibstdc++: Simplify std::forward_list assignment using 'if constexpr'
Jonathan Wakely [Mon, 25 Nov 2024 21:57:57 +0000 (21:57 +0000)] 
libstdc++: Simplify std::forward_list assignment using 'if constexpr'

Use diagnostic pragmas to allow using `if constexpr` in C++11 mode, so
that we don't need to use tag dispatching.

The unused member functions are preserved for the purposes of explicit
instantiations. The _M_assign function template can be removed, because
member function templates aren't instantiated by explicit instantiations
anyway.

libstdc++-v3/ChangeLog:

* include/bits/forward_list.h (operator=(forward_list&&)): Use
if constexpr instead of dispatching to _M_move_assign.
(assign(InputIterator, InputIterator)): Use if constexpr instead
of dispatching to _M_assign.
(assign(size_type, const T&)): Use if constexpr instead of
dispatching to _M_assign_n.
(_M_move_assign, _M_assign_n): Do not define for versioned
namespace.
(_M_assign): Remove.

8 months agolibstdc++: Simplify std::list assignment using 'if constexpr'
Jonathan Wakely [Mon, 25 Nov 2024 21:57:57 +0000 (21:57 +0000)] 
libstdc++: Simplify std::list assignment using 'if constexpr'

Use diagnostic pragmas to allow using `if constexpr` in C++11 mode, so
that we don't need to use tag dispatching.

The _M_move_assign overloads that were previously used for tag
dispatching are no longer used, but are retained here (at least for the
default config) so that an explicit instantiation will still define
those members. This ensures that old code which expects an explicit
instantiation in some other translation unit will still link. I'm not
sure if that's really needed, we should probably have a policy about
whether we support explicit instantiations where the declaration and
definition use different versions of the headers.

libstdc++-v3/ChangeLog:

* include/bits/stl_list.h (operator=(list&&)): Use if constexpr
instead of dispatching to _M_move_assign.
(_M_move_assign): Do not define for versioned namespace.

8 months agolibstdc++: Fix unsigned wraparound in codecvt::do_length [PR105857]
Jonathan Wakely [Tue, 26 Nov 2024 20:07:33 +0000 (20:07 +0000)] 
libstdc++: Fix unsigned wraparound in codecvt::do_length [PR105857]

When the max argument to std::codecvt<wchar_t, char, mbstate_t>::length
is SIZE_MAX/4+1 or greater the multiplication with sizeof(wchar_t) will
wrap to a small value, and the alloca call will have a buffer that's
smaller than requested. The call to mbsnrtowcs then has a buffer that is
smaller than the value passed as the buffer length. When libstdc++.so is
built with -D_FORTIFY_SOURCE=3 the mismatched buffer and length will get
detected and will abort inside Glibc.

When it doesn't abort, there's no buffer overflow because Glibc's
mbsnrtowcs has the same len * sizeof(wchar_t) calculation to determine
the size of the buffer in bytes, and that will wrap to the same small
number as the alloca argument. So luckily Glibc agrees with the caller
about the real size of the buffer, and won't overflow it.

Even when the max argument isn't large enough to wrap, it can still be
much too large to safely pass to alloca, so we should limit that. We
already have a loop that processes chunks so that we can handle null
characters in the middle of the input. If we limit the alloca buffer to
4kB then we'll just loop each time that buffer is filled.

libstdc++-v3/ChangeLog:

PR libstdc++/105857
* config/locale/dragonfly/codecvt_members.cc (do_length): Limit
size of alloca buffer to 4k.
* config/locale/gnu/codecvt_members.cc (do_length): Likewise.
* testsuite/22_locale/codecvt/length/wchar_t/105857.cc: New
test.

8 months agoifcombine: skip fallback conjunction on noncontiguous blocks
Alexandre Oliva [Wed, 27 Nov 2024 09:27:12 +0000 (06:27 -0300)] 
ifcombine: skip fallback conjunction on noncontiguous blocks

When everything else fails, if enabled by the target or by a
parameter, and when other requirements are satisfied, ifcombine
generates an AND of both conditions.

That may be good for contiguous conditions, but it's unlikely to be an
optimization when the blocks are separate.

Add contiguity to the set of requirements for this fallback
transformation.

for  gcc/ChangeLog

* tree-ssa-ifcombine.cc (ifcombine_ifandif): Avoid fallback
conjunction of noncontiguous conditions.

8 months agoFortran: Fix non_overridable typebound proc problems [PR84674/117768].
Paul Thomas [Wed, 27 Nov 2024 09:20:23 +0000 (09:20 +0000)] 
Fortran: Fix non_overridable typebound proc problems [PR84674/117768].

2024-11-27  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran/ChangeLog

PR fortran/84674
* class.cc (add_proc_comp): If the component points to a tbp
that is abstract, do not return since the new version is more
likely to be usable.
PR fortran/117768
* resolve.cc (resolve_fl_derived): Remove the condition that
rejected a completely empty derived type extension.

gcc/testsuite/ChangeLog

PR fortran/117768
* gfortran.dg/pr117768.f90: New test.

8 months agoc: Introduce -Wfree-labels
Florian Weimer [Wed, 27 Nov 2024 08:32:31 +0000 (09:32 +0100)] 
c: Introduce -Wfree-labels

This is another recent GCC extension whose use is apparently
difficult to spot in code reviews.

The name of the option is due to Jonathan Wakely.  Part of it
could apply to C++ as well (for labels at the end of a compound
statement).

gcc/c-family/

* c-opts.cc (c_common_post_options): Initialize
warn_free_labels.
* c.opt (Wfree-labels): New option.
* c.opt.urls: Regenerate.

gcc/c/

* c-parser.cc (c_parser_compound_statement_nostart): Use
OPT_Wfree_labels for warning about labels on declarations.
(c_parser_compound_statement_nostart): Use OPT_Wfree_labels
for warning about labels at end of compound statements.

gcc/

* doc/invoke.texi: Document -Wfree-labels.

gcc/testsuite/

* gcc.dg/Wfree-labels-1.c: New test.
* gcc.dg/Wfree-labels-2.c: New test.
* gcc.dg/Wfree-labels-3.c: New test.

8 months agoc++: modules and local static
Jason Merrill [Tue, 26 Nov 2024 12:50:49 +0000 (07:50 -0500)] 
c++: modules and local static

Here we weren't emitting the guard variable for 'a'  when we emitted 'afn'
in the importer, because we only treated inline variables as needing that.
Fixed by generalizing to vague_linkage_p.

But we need to specifically exempt vtables, because the rest of the module
code handles them specially and expects them to be DECL_EXTERNAL.

gcc/cp/ChangeLog:

* module.cc (trees_out::core_bools): Check vague_linkage_p.
(has_definition): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/modules/static-3_b.C: New test.
* g++.dg/modules/static-3_a.H: New test.

8 months agoc++: enable -Warray-compare by default
Jason Merrill [Fri, 22 Nov 2024 07:47:56 +0000 (08:47 +0100)] 
c++: enable -Warray-compare by default

Discussion of P2865R5 mentioned that we only enabled this warning with
-Wall; we should handle it like other deprecations.

gcc/c-family/ChangeLog:

* c-opts.cc (c_common_post_options): Enable -Warray-compare
in C++20.

gcc/testsuite/ChangeLog:

* g++.dg/tree-ssa/pr15791-1.C: Add -Wno-array-compare.

8 months agolibcpp: modules and -include again
Jason Merrill [Tue, 26 Nov 2024 21:19:05 +0000 (16:19 -0500)] 
libcpp: modules and -include again

I enabled include translation to header units in r15-1104-ga29f481bbcaf2b,
but it seems that patch wasn't sufficient, as any diagnostics in the main
source file would show up as coming from the header instead.

Fixed by setting buffer->file for leaving the file transition that my
previous patch made us enter.  And don't push a buffer of newlines, in this
case that messes up line numbers instead of aligning them.

libcpp/ChangeLog:

* files.cc (_cpp_stack_file): Handle -include of header unit more
specially.

gcc/testsuite/ChangeLog:

* g++.dg/modules/dashinclude-1_b.C: Add an #error.
* g++.dg/modules/dashinclude-1_a.H: Remove dg-module-do run.

8 months agoPR117350: Keep assembler name for abstract decls for autofdo
Andi Kleen [Thu, 31 Oct 2024 17:26:16 +0000 (10:26 -0700)] 
PR117350: Keep assembler name for abstract decls for autofdo

autofdo looks up inline stacks and tries to match them with the profile
data using their symbol name. Make sure all decls that can be in a inline stack
have a valid assembler name.

This fixes a bootstrap problem with autoprofiledbootstrap and LTO.

2024-10-30  Jason Merrill  <jason@redhat.com>
    Andrew Pinski  <quic_apinski@quicinc.com>
    Andi Kleen  <ak@gcc.gnu.org>
gcc/ChangeLog:

PR bootstrap/117350
* tree.cc (need_assembler_name_p): Keep assembler name
for abstract declarations when autofdo is used.

8 months agoDaily bump.
GCC Administrator [Wed, 27 Nov 2024 00:20:18 +0000 (00:20 +0000)] 
Daily bump.

8 months agolibstdc++: Add -fno-assume-sane-operators-new-delete to test [PR117751]
Jonathan Wakely [Mon, 25 Nov 2024 22:40:43 +0000 (22:40 +0000)] 
libstdc++: Add -fno-assume-sane-operators-new-delete to test [PR117751]

libstdc++-v3/ChangeLog:

PR libstdc++/117751
* testsuite/18_support/50594.cc: Edit dg-options to include the
-fno-assume-sane-operators-new-delete option.

8 months agoFortran: fix minor front-end memleaks
Harald Anlauf [Tue, 26 Nov 2024 19:37:35 +0000 (20:37 +0100)] 
Fortran: fix minor front-end memleaks

gcc/fortran/ChangeLog:

* expr.cc (find_inquiry_ref): Fix memleak introduced by scanning
the reference chain to find and simplify inquiry references.
* symbol.cc (gfc_copy_formal_args_intr): Free formal namespace
when not needed to avoid a front-end memleak.

8 months agoaarch64: Update error message check for __builtin_launder check of sve-sizeless-2.C
Andrew Pinski [Tue, 26 Nov 2024 21:38:15 +0000 (13:38 -0800)] 
aarch64: Update error message check for __builtin_launder check of sve-sizeless-2.C

r15-3614-g9fe57e4879de93 changed the error message for __builtin_launder but this testcase
was not updated for the new format of the error message since it is an aarch64 specific
testcase.

This patch updates the expected error message.

Pushed as obvious after testing to see the testcase now works.

gcc/testsuite/ChangeLog:

* g++.dg/ext/sve-sizeless-2.C: Update the expected error message
for __builtin_launder.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
8 months agoaarch64: Fix fp8_scalar_1.c's stacktest1
Andrew Pinski [Tue, 26 Nov 2024 21:05:00 +0000 (13:05 -0800)] 
aarch64: Fix fp8_scalar_1.c's stacktest1

The function body test was expecting:
umov w0, v0.b[0]
strb w0, [sp, 15]

But the code generation was improved after r15-5375-gbeec291225be to just:
str b0, [sp, 15]

which is correct and better because no longer need to move between SIMD registers
and the GPRs.
This changes the function body test to new better code generation.

Pushed as obvious after a test of the testcase to make sure it now passes.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/fp8_scalar_1.c (stacktest1): Fix for new
improved code generation.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
8 months agoselftest: invoke "diff" when ASSERT_STREQ fails
David Malcolm [Tue, 26 Nov 2024 21:09:37 +0000 (16:09 -0500)] 
selftest: invoke "diff" when ASSERT_STREQ fails

Currently when ASSERT_STREQ or ASSERT_STREQ_AT fail we print
both strings to stderr.  However it can be hard to figure out
the problem (e.g. for 1-character differences in long strings).

Extend the output by writing out the strings to tempfiles and
invoking "diff -up" on them when we have such a selftest failure,
to (I hope) simplify debugging.

gcc/ChangeLog:
* selftest.cc (selftest::print_diff): New function.
(selftest::assert_streq): Call it when we have non-equal
non-null strings.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
8 months agotestsuite: rename plugins from .c to .cc
David Malcolm [Tue, 26 Nov 2024 21:01:35 +0000 (16:01 -0500)] 
testsuite: rename plugins from .c to .cc

In r12-6650-g5c69acb32329d4 we updated our sources from .c to .cc
since for some time GCC has been implemented in C++, not C.

GCC plugins are also implemented in C++, not C, but the plugins
in our testsuite still have .c extensions.

Rename the plugin implementation files in the testsuite from .c to .cc,
for consistency with GCC's implementation files (as opposed to .C,
which is used in C++ parts of the testsuite).

Don't rename the files that the plugins are tested *on*.

gcc/testsuite/ChangeLog:
* g++.dg/plugin/plugin.exp (plugin_test_list): Update for renaming
of all plugin implementation files from .c to .cc.
* g++.dg/plugin/attribute_plugin.c: Rename to...
* g++.dg/plugin/attribute_plugin.cc: ...this.
* g++.dg/plugin/comment_plugin.c: Rename to...
* g++.dg/plugin/comment_plugin.cc: ...this.
* g++.dg/plugin/decl_plugin.c: Rename to...
* g++.dg/plugin/decl_plugin.cc: ...this.
* g++.dg/plugin/def_plugin.c: Rename to...
* g++.dg/plugin/def_plugin.cc: ...this.
* g++.dg/plugin/dumb_plugin.c: Rename to...
* g++.dg/plugin/dumb_plugin.cc: ...this.
* g++.dg/plugin/header_plugin.c: Rename to...
* g++.dg/plugin/header_plugin.cc: ...this.
* g++.dg/plugin/pragma_plugin.c: Rename to...
* g++.dg/plugin/pragma_plugin.cc: ...this.
* g++.dg/plugin/selfassign.c: Rename to...
* g++.dg/plugin/selfassign.cc: ...this.
* g++.dg/plugin/show_template_tree_color_plugin.c: Rename to...
* g++.dg/plugin/show_template_tree_color_plugin.cc: ...this.
* gcc.dg/plugin/plugin.exp (plugin_test_list): Update for renaming
of all plugin implementation files from .c to .cc.
* gcc.dg/plugin/analyzer_cpython_plugin.c: Rename to...
* gcc.dg/plugin/analyzer_cpython_plugin.cc: ...this.
* gcc.dg/plugin/analyzer_gil_plugin.c: Rename to...
* gcc.dg/plugin/analyzer_gil_plugin.cc: ...this.
* gcc.dg/plugin/analyzer_kernel_plugin.c: Rename to...
* gcc.dg/plugin/analyzer_kernel_plugin.cc: ...this.
* gcc.dg/plugin/analyzer_known_fns_plugin.c: Rename to...
* gcc.dg/plugin/analyzer_known_fns_plugin.cc: ...this.
* gcc.dg/plugin/crash_test_plugin.c: Rename to...
* gcc.dg/plugin/crash_test_plugin.cc: ...this.
* gcc.dg/plugin/diagnostic_group_plugin.c: Rename to...
* gcc.dg/plugin/diagnostic_group_plugin.cc: ...this.
* gcc.dg/plugin/diagnostic_plugin_show_trees.c: Rename to...
* gcc.dg/plugin/diagnostic_plugin_show_trees.cc: ...this.
* gcc.dg/plugin/diagnostic_plugin_test_inlining.c: Rename to...
* gcc.dg/plugin/diagnostic_plugin_test_inlining.cc: ...this.
* gcc.dg/plugin/diagnostic_plugin_test_metadata.c: Rename to...
* gcc.dg/plugin/diagnostic_plugin_test_metadata.cc: ...this.
* gcc.dg/plugin/diagnostic_plugin_test_nesting.c: Rename to...
* gcc.dg/plugin/diagnostic_plugin_test_nesting.cc: ...this.
* gcc.dg/plugin/diagnostic_plugin_test_paths.c: Rename to...
* gcc.dg/plugin/diagnostic_plugin_test_paths.cc: ...this.
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c: Rename to...
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc: ...this.
* gcc.dg/plugin/diagnostic_plugin_test_string_literals.c: Rename
* gcc.dg/plugin/diagnostic_plugin_test_string_literals.cc: ..to
this.
* gcc.dg/plugin/diagnostic_plugin_test_text_art.c: Rename to...
* gcc.dg/plugin/diagnostic_plugin_test_text_art.cc: ...this.
* gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.c:
Rename to...
* gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.cc:
...this.
* gcc.dg/plugin/diagnostic_plugin_xhtml_format.c: Rename to...
* gcc.dg/plugin/diagnostic_plugin_xhtml_format.cc: ...this.
* gcc.dg/plugin/dump_plugin.c: Rename to...
* gcc.dg/plugin/dump_plugin.cc: ...this.
* gcc.dg/plugin/expensive_selftests_plugin.c: Rename to...
* gcc.dg/plugin/expensive_selftests_plugin.cc: ...this.
* gcc.dg/plugin/finish_unit_plugin.c: Rename to...
* gcc.dg/plugin/finish_unit_plugin.cc: ...this.
* gcc.dg/plugin/ggcplug.c: Rename to...
* gcc.dg/plugin/ggcplug.cc: ...this.
* gcc.dg/plugin/location_overflow_plugin.c: Rename to...
* gcc.dg/plugin/location_overflow_plugin.cc: ...this.
* gcc.dg/plugin/must_tail_call_plugin.c: Rename to...
* gcc.dg/plugin/must_tail_call_plugin.cc: ...this.
* gcc.dg/plugin/one_time_plugin.c: Rename to...
* gcc.dg/plugin/one_time_plugin.cc: ...this.
* gcc.dg/plugin/poly-int-01_plugin.c: Rename to...
* gcc.dg/plugin/poly-int-01_plugin.cc: ...this.
* gcc.dg/plugin/poly-int-02_plugin.c: Rename to...
* gcc.dg/plugin/poly-int-02_plugin.cc: ...this.
* gcc.dg/plugin/poly-int-03_plugin.c: Rename to...
* gcc.dg/plugin/poly-int-03_plugin.cc: ...this.
* gcc.dg/plugin/poly-int-04_plugin.c: Rename to...
* gcc.dg/plugin/poly-int-04_plugin.cc: ...this.
* gcc.dg/plugin/poly-int-05_plugin.c: Rename to...
* gcc.dg/plugin/poly-int-05_plugin.cc: ...this.
* gcc.dg/plugin/poly-int-06_plugin.c: Rename to...
* gcc.dg/plugin/poly-int-06_plugin.cc: ...this.
* gcc.dg/plugin/poly-int-07_plugin.c: Rename to...
* gcc.dg/plugin/poly-int-07_plugin.cc: ...this.
* gcc.dg/plugin/selfassign.c: Rename to...
* gcc.dg/plugin/selfassign.cc: ...this.
* gcc.dg/plugin/start_unit_plugin.c: Rename to...
* gcc.dg/plugin/start_unit_plugin.cc: ...this.
* gcc.dg/plugin/wide-int_plugin.c: Rename to...
* gcc.dg/plugin/wide-int_plugin.cc: ...this.
* obj-c++.dg/plugin/plugin.exp: Update for renaming of plugin
implementation file from .c to .cc.
* objc.dg/plugin/plugin.exp: Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
8 months agocsky: use quotes when referring to cpus and archs [PR90160]
David Malcolm [Tue, 26 Nov 2024 20:58:25 +0000 (15:58 -0500)] 
csky: use quotes when referring to cpus and archs [PR90160]

gcc/ChangeLog:
PR translation/90160
* config/csky/csky.cc (csky_configure_build_target): Use %qs when
referring to cpu and arch names.
(csky_option_override): Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
8 months ago[PATCH] testsuite:RISC-V:Modify the char string.
yulong [Tue, 26 Nov 2024 17:36:44 +0000 (10:36 -0700)] 
[PATCH] testsuite:RISC-V:Modify the char string.

From: yulong <shiyulong@iscas.ac.cn>

This patch modifies the char string from __riscv_xsfvcp to __riscv_xsfcease.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/predef-sf-2.c: Modify the char string.

8 months agoFortran: passing inquiry ref of complex array to assumed rank dummy [PR117774]
Harald Anlauf [Mon, 25 Nov 2024 21:55:10 +0000 (22:55 +0100)] 
Fortran: passing inquiry ref of complex array to assumed rank dummy [PR117774]

PR fortran/117774

gcc/fortran/ChangeLog:

* trans-expr.cc (gfc_conv_procedure_call): When passing an array
to an assumed-rank dummy, terminate search for array reference of
actual argument before an inquiry reference (e.g. INQUIRY_RE,
INQUIRY_IM) so that bounds update works properly.

gcc/testsuite/ChangeLog:

* gfortran.dg/assumed_rank_25.f90: New test.

8 months agoc: avoid double-negative in warning message [PR94370]
David Malcolm [Tue, 26 Nov 2024 15:39:48 +0000 (10:39 -0500)] 
c: avoid double-negative in warning message [PR94370]

gcc/c/ChangeLog:
PR c/94370
* c-typeck.cc (c_build_functype_attribute_variant): Reword
warning message to avoid double-negative.

gcc/testsuite/ChangeLog:
PR c/94370
* gcc.dg/format/proto.c: Update wording of message.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
8 months agoloop-prefetch: fix wording of warning [PR80760]
David Malcolm [Tue, 26 Nov 2024 15:39:18 +0000 (10:39 -0500)] 
loop-prefetch: fix wording of warning [PR80760]

gcc/ChangeLog:
PR translation/80760
* tree-ssa-loop-prefetch.cc (pass_loop_prefetch::execute): Add
missing colon to not-a-power-of-two param warning.

gcc/testsuite/ChangeLog:
PR translation/80760
* gcc.dg/tree-ssa/pr79803.c: Add ':' to expected warning.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
8 months agoplugin: add missing colon in error message [PR93746]
David Malcolm [Tue, 26 Nov 2024 15:39:12 +0000 (10:39 -0500)] 
plugin: add missing colon in error message [PR93746]

gcc/ChangeLog:
PR plugins/93746
* plugin.cc (try_init_one_plugin): Add missing colon in error
message.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
8 months agogdbhooks: Handle references to vec* in VecPrinter
Alex Coplan [Tue, 26 Nov 2024 15:10:29 +0000 (15:10 +0000)] 
gdbhooks: Handle references to vec* in VecPrinter

vec.h has this method:

  template<typename T, typename A>
  inline T *
  vec_safe_push (vec<T, A, vl_embed> *&v, const T &obj CXX_MEM_STAT_INFO)

where v is a reference to a pointer to vec.  This matches the regex for
VecPrinter, so gdbhooks.py attempts to print it but chokes on the reference.
I see the following:

  #1  0x0000000002b84b7b in vec_safe_push<edge_def*, va_gc> (v=Traceback (most
  recent call last):
    File "$SRC/gcc/gcc/gdbhooks.py", line 486, in to_string
      return '0x%x' % intptr(self.gdbval)
    File "$SRC/gcc/gcc/gdbhooks.py", line 168, in intptr
      return long(gdbval) if sys.version_info.major == 2 else int(gdbval)
  gdb.error: Cannot convert value to long.

This patch makes VecPrinter handle such references by stripping them
(dereferencing) at the top of the relevant functions.

gcc/ChangeLog:

* gdbhooks.py (strip_ref): New. Use it ...
(VecPrinter.to_string): ... here,
(VecPrinter.children): ... and here.

8 months agoRISC-V: Refactor the testcases for RVV gather/scatter
Pan Li [Mon, 25 Nov 2024 03:45:30 +0000 (11:45 +0800)] 
RISC-V: Refactor the testcases for RVV gather/scatter

This patch would like to refactor the testcases of gather/scatter
after sorts of optimization option passing to testcase.  Includes:

* Remove unnecessary optimization options.
* Adjust dg-final by any-opts and/or no-opts if the rtl dump changes
  on different optimization options (like O2, O3).

The below test suites are passed for this patch.
* The rv64gcv fully regression test.

It is test only patch and obvious up to a point, will commit it
directly if no comments in next 48H.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/gather-scatter/gather_load_64-12-zvbb.c:
Adjust the dump check times.
* gcc.target/riscv/rvv/autovec/gather-scatter/strided_load-1.c:
Remove unnecessary option and add target no-opts/any-tops.
* gcc.target/riscv/rvv/autovec/gather-scatter/strided_load-2.c: Ditto.
* gcc.target/riscv/rvv/autovec/gather-scatter/strided_store-1.c: Ditto.
* gcc.target/riscv/rvv/autovec/gather-scatter/strided_store-2.c: Ditto.

Signed-off-by: Pan Li <pan2.li@intel.com>
8 months agoRISC-V: Fix incorrect optimization options passing to gather/scatter
Pan Li [Mon, 25 Nov 2024 03:45:29 +0000 (11:45 +0800)] 
RISC-V: Fix incorrect optimization options passing to gather/scatter

Like the strided load/store, the testcases of vector gather/scatter are
designed to pick up different sorts of optimization options but actually
these option are ignored according to the Execution log of gcc.log.  This patch
would like to make it correct almost the same as what we fixed for
strided load/store.

The below test suites are passed for this patch.
* The rv64gcv fully regression test.

It is test only patch and obvious up to a point, will commit it
directly if no comments in next 48H.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/rvv.exp: Fix the incorrect optimization
options passing to testcases.

Signed-off-by: Pan Li <pan2.li@intel.com>
8 months agoimprove std::deque::_M_reallocate_map
Jan Hubicka [Tue, 26 Nov 2024 12:52:09 +0000 (13:52 +0100)] 
improve std::deque::_M_reallocate_map

Looking into reason why we still do throw_bad_alloc in clang binary I noticed
that quite few calls come from deque::_M_reallocate_map.  This patch adds
unreachable to limit the size of realloc_map.  _M_reallocate_map is called only
if new size is smaller then max_size.  map is an array holding pointers to
entries of fixed size.

Since rellocation is done by doubling the map size, I think the maximal size of
map allocated is max_size / deque_buf_size rounded up times two.  This should
be also safe for overflows since we have extra bit.

map size is always at least 8. Theoretically this computation may be wrong for
very large T, but in that case callers should never reallocate.

On the testcase I get:
jh@shroud:~> ~/trunk-install-new4/bin/g++ -O2 dq.C -c ; size -A dq.o | grep text
.text                                              284      0
.text._ZNSt5dequeIiSaIiEE17_M_reallocate_mapEmb    485      0
.text.unlikely                                      10      0
jh@shroud:~> ~/trunk-install-new5/bin/g++ -O2 dq.C -c ; size -A dq.o | grep text
.text                                              284      0
.text._ZNSt5dequeIiSaIiEE17_M_reallocate_mapEmb    465      0
.text.unlikely                                      10      0

so this saves about 20 bytes of rellocate_map, which I think is worthwhile.
Curiously enough gcc14 does:

jh@shroud:~> g++ -O2 dq.C -c ; size -A dq.o | grep text
.text                 604      0
.text.unlikely         10      0

which is 145 bytes smaller. Obvoius difference is that _M_reallocate_map gets inlined.
Compiling gcc14 preprocessed file with trunk gives:

jh@shroud:~> g++ -O2 dq.C -S ; size -A dq.o | grep text
.text                 762      0
.text.unlikely         10      0

So inlining is due to changes at libstdc++ side, but code size growth is due to
something else.

For clang this reduced number of thris_bad_new_array_length from 121 to 61.

libstdc++-v3/ChangeLog:

* include/bits/deque.tcc (std::deque::_M_reallocate_map): Add
__builtin_unreachable check to declare that maps are not very large.
* include/bits/stl_deque.h (std::deque::size): Add __builtin_unreachable
to check for maximal size of map.

gcc/testsuite/ChangeLog:

* g++.dg/tree-ssa/deque-1.C: New test.
* g++.dg/tree-ssa/deque-2.C: New test.

8 months agoada: Do not use ATTR_ADDR_EXPR for 'Unrestricted_Access
Eric Botcazou [Mon, 11 Nov 2024 10:16:26 +0000 (11:16 +0100)] 
ada: Do not use ATTR_ADDR_EXPR for 'Unrestricted_Access

Unlike for 'Access or 'Unchecked_Access, the Attribute_to_gnu routine passes
ATTR_ADDR_EXPR to build_unary_op for 'Unrestricted_Access, which causes the
processing done in build_unary_op to flatten the reference, in particular to
remove all intermediate (view) conversions, which may be problematic for the
SUBSTITUTE_PLACEHOLDER_IN_EXPR machinery.

gcc/ada/ChangeLog:

* gcc-interface/trans.cc (Attribute_to_gnu) <Attr_Access>: Do not
pass ATTR_ADDR_EXPR to build_unary_op for 'Unrestricted_Access.

8 months agoada: Add minimal support for address clause/aspect on controlled objects
Eric Botcazou [Tue, 12 Nov 2024 18:46:12 +0000 (19:46 +0100)] 
ada: Add minimal support for address clause/aspect on controlled objects

The clause and aspect have been accepted by the compiler for a few years,
but the result is generally an internal compiler error or an incorrect
finalization at run time.

gcc/ada/ChangeLog:

* exp_ch3.adb (Expand_N_Object_Declaration): Do not insert the tag
assignment there if the object has the Address aspect.
* exp_ch7.adb: Add clauses for Aspect package.
(Build_Finalizer.Process_Object_Declaration): Deal with an object
with delayed freezing.
(Insert_Actions_In_Scope_Around): If the target is the declaration
of an object with address clause or aspect, move all the statements
that have been inserted after it into the Initialization_Statements
list of the object.
* freeze.adb (Check_Address_Clause): Do not reassign the tag here,
instead set the appropriate flag on the assignment statement.

8 months agoada: Clean up previous change
Eric Botcazou [Wed, 13 Nov 2024 15:37:32 +0000 (16:37 +0100)] 
ada: Clean up previous change

gcc/ada/ChangeLog:

* sem_res.adb (Valid_Conversion): Do not initialize Opnd_Type before
calling Get_Corresponding_Mutably_Tagged_Type_If_Present.

8 months agoada: Minor adjustments to error message for RM B.1(24)
Eric Botcazou [Wed, 13 Nov 2024 08:42:01 +0000 (09:42 +0100)] 
ada: Minor adjustments to error message for RM B.1(24)

The RM B.1(24) sub-clause says that imported entities cannot be initialized
and it is checked in three contexts, aspect Import, pragma Import and pragma
Import_Object, with slightly different error messages.  Moreover, for the
aspect, the error is given twice because that of the pragma is also given.

In addition, if the initialization expression is an aggregate that is not
static, the error is given only for the aspect and not for the two pragmas.

This change aligns the error messages on that of pragma Import and plugs the
aforementioned loophole for the two pragmas.

gcc/ada/ChangeLog:

* sem_ch13.adb (Analyze_Aspect_Export_Import): Add explicit mention
of the declaration in the error message for the Import.
* sem_prag.adb (Process_Extended_Import_Export_Object_Pragma): Also
test Has_Init_Expression on the declaration node for Import_Object
and use the same wording as that of Import.
(Process_Import_Or_Interface): Also test Has_Init_Expression on the
declaration node for Import.

8 months agoada: Refactor code of Check_Ambiguous_Call and Valid_Conversion
Javier Miranda [Tue, 29 Oct 2024 08:31:28 +0000 (08:31 +0000)] 
ada: Refactor code of Check_Ambiguous_Call and Valid_Conversion

Code cleanup; factorizing code.

gcc/ada/ChangeLog:

* sem_ch2.adb (Check_Ambiguous_Call): Replace code factorized
code by call to the new subprogram Is_Ambiguous_Operand.
* sem_res.ads (Is_Ambiguous_Operand): New subprogram that
factorizes previous code in Check_Ambiguous_Call and
Valid_Conversion.
* sem_res.adb (Is_Ambiguous_Operand): New subprogram.
(Valid_Tagged_Conversion): Replace factorized code by call to
the new subprogram Is_Ambiguous_Operand.
(Report_Error_N): New subprogram.
(Report_Error_NE): New subprogram.
(Report_Interpretation): New subprogram.
(Conversion_Error_N): Removed; replaced by Report_Error_N.
(Conversion_Error_NE): Removed; replaced by Report_Error_NE.
(Valid_Conversion): Update Opnd_Type after the call to
Is_Ambiguous_Operand in the overloaded case.

8 months agoada: Relocate implementation of Write_Error_Summary
Viljar Indus [Tue, 12 Nov 2024 11:11:00 +0000 (13:11 +0200)] 
ada: Relocate implementation of Write_Error_Summary

Reuse the same implementation in Errout and Errutil.

gcc/ada/ChangeLog:

* errout.adb: Remove implmentation of Write_Error_Summary.
* erroutc.adb: Add implemenetation of Write_Error_Summary.
* erroutc.ads: Add spec of Write_Error_Summary.
* errutil.adb: Remove implementation for writing the error summary.

8 months agoada: Relocate implementation of Set_Msg_Insertion_Column
Viljar Indus [Tue, 12 Nov 2024 10:32:05 +0000 (12:32 +0200)] 
ada: Relocate implementation of Set_Msg_Insertion_Column

The implementation was duplicated in errout and errutil. Move
the implementation to erroutc where other similar commonly used
functions are.

gcc/ada/ChangeLog:

* errout.adb: Remove implemntation of Set_Msg_Insertion_Column.
* erroutc.adb: Add implementation of Set_Msg_Insertion_Column.
* erroutc.ads: Add spec of Set_Msg_Insertion_Column.
* errutil.adb: Remove implementation of Set_Msg_Insertion_Column.

8 months agoada: Remove Warn_Runtime_Raise attribute from Error_Msg_Object
Viljar Indus [Mon, 11 Nov 2024 09:01:12 +0000 (11:01 +0200)] 
ada: Remove Warn_Runtime_Raise attribute from Error_Msg_Object

The goal of this attribute is to raise a warning to an error when
the -gnatwE flag is used. This is similar to the existing warnings
as error behavior under the Warn_Err flag so it can be merged.

gcc/ada/ChangeLog:

* errout.adb: Set Warn_Err as true if Is_Runtime_Error was
set in the error message.
* erroutc.adb: Remove instances of Warn_Runtime_Raise.
* erroutc.ads: Likewise.
* errutil.adb: Likewise.

8 months agoada: Refactor checking redundant messages
Viljar Indus [Mon, 11 Nov 2024 08:19:21 +0000 (10:19 +0200)] 
ada: Refactor checking redundant messages

Move common code between errout and errutil into a single function.

gcc/ada/ChangeLog:

* errout.adb: Use Is_Redundant_Error_Message.
* erroutc.adb: Move the common code for checking if a message
can be removed to Is_Redundant_Error_Message.
* erroutc.ads: Add definition of Is_Redundant_Error_Message.
* errutil.adb: Use Is_Redundant_Error_Message.

8 months agoada: Remove Current_Node from Errout
Viljar Indus [Tue, 5 Nov 2024 08:42:55 +0000 (10:42 +0200)] 
ada: Remove Current_Node from Errout

This variable was used for Opt.Include_Subprogram_In_Messages
activated by -gnatdJ. This switch has been removed so this variable
is no longer used.

gcc/ada/ChangeLog:

* errout.ads: Remove Current_Node.
* errout.adb: Remove uses of Current_Node.
* par-ch6.adb: Same as above.
* par-ch7.adb: Same as above.
* par-ch9.adb: Same as above.

8 months agoada: Remove Raise_Exception_On_Error
Viljar Indus [Mon, 4 Nov 2024 12:16:02 +0000 (14:16 +0200)] 
ada: Remove Raise_Exception_On_Error

Raise_Exception_On_Error is never modified so it can be removed.

gcc/ada/ChangeLog:

* err_vars.ads: Remove Raise_Exception_On_Error and
Error_Msg_Exception.
* errout.ads: Same as above.
* errout.adb: Remove uses of Raise_Exception_On_Error and
Error_Msg_Exception.
* errutil.adb: Same as above.

8 months agoada: Store error message kind as an enum
Viljar Indus [Thu, 31 Oct 2024 13:50:46 +0000 (15:50 +0200)] 
ada: Store error message kind as an enum

Simplify the storage for the kind of error message under a single
enumerator. This replaces the existing attributes with the following
enumeration values.
* Is_Warning_Msg => Warning
* Is_Style_Msg => Style
* Is_Info_Msg => Info
* Is_Check_Msg => Low_Check, Medium_Check, High_Check
* Is_Serious_Error => Error, if the attribute was false then
  Non_Serious_Error.

gcc/ada/ChangeLog:

* diagnostics-converter.adb: Use new enum values instead
of the old attributes.
* diagnostics-switch_repository.adb: Same as above.
* diagnostics-utils.adb: Same as above.
* diagnostics.adb: Same as above.
* diagnostics.ads: Same as above.
* errout.adb: Same as above.
* erroutc.adb: Same as above.
* erroutc.ads: Remove old attriubtes and replace them
with Error_Msg_Kind.
* errutil.adb: Same as others.

8 months agoada: Refactor code for printing the error location
Viljar Indus [Fri, 1 Nov 2024 11:15:21 +0000 (13:15 +0200)] 
ada: Refactor code for printing the error location

gcc/ada/ChangeLog:

* errout.adb: Use Output_Msg_Location
* erroutc.adb: add common implementation for printing the
error message line.
* erroutc.ads: Add new method Output_Msg_Location
* errutil.adb: use Output_Msg_Location

8 months agoada: Simplify code
Viljar Indus [Mon, 16 Sep 2024 09:14:00 +0000 (12:14 +0300)] 
ada: Simplify code

gcc/ada/ChangeLog:

* diagnostics-converter.adb: Remove uses of Info_Warning type. Use
common constructors to simplify implementation.
* diagnostics-pretty_emitter.adb: Remove Info_Warning type.
* diagnostics-utils.adb: Remove uses of Info_Warning.
* diagnostics.adb: Simplify implementation of Primary_Location.
* diagnostics.ads: Remove Info_Warning type.

8 months agoada: Fix the file documenting the ali format
Jose Ruiz [Tue, 12 Nov 2024 11:22:55 +0000 (12:22 +0100)] 
ada: Fix the file documenting the ali format

gcc/ada/ChangeLog:

* doc/gnat_ugn/the_gnat_compilation_model.rst: The format of
the ali file is documented in lib-writ.ads.
* gnat_ugn.texi: Regenerate.

8 months agoada: Change specifications of Uname subprograms
Ronan Desplanques [Tue, 12 Nov 2024 15:09:13 +0000 (16:09 +0100)] 
ada: Change specifications of Uname subprograms

The old specifications were ambiguous as to whether they expected
actuals to have %s/%b suffixes. The new specifications also increases
modularity across the board.

gcc/ada/ChangeLog:

* uname.ads (Is_Internal_Unit_Name, Is_Predefined_Unit_Name): Change
specifications to take a Unit_Name_Type as input.
(Encoded_Library_Unit_Name): New subprogram.
(Is_Predefined_Unit_Name): New overloaded subprogram.
(Get_External_Unit_Name_String): Make use of new
Encoded_Library_Unit_Name subprogram.
* uname.adb (Is_Internal_Unit_Name, Is_Predefined_Unit_Name): Adapt
bodies to specification changes.
* fname-uf.adb (Get_File_Name): Adapt to Uname interface changes.

8 months agoada: Remove use of global name buffer
Ronan Desplanques [Tue, 12 Nov 2024 12:35:17 +0000 (13:35 +0100)] 
ada: Remove use of global name buffer

Before this patch, the body of Fname.UF.Get_File_Name did a lot of
juggling with the global name buffer, which made it hard to understand.
This patch makes the body use local buffers instead.

gcc/ada/ChangeLog:

* fname-uf.adb (Get_File_Name): Use local name buffers.

8 months agoada: Clean up utility function
Ronan Desplanques [Tue, 12 Nov 2024 08:31:35 +0000 (09:31 +0100)] 
ada: Clean up utility function

This patch makes Sem_Util.Get_Library_Unit_Name use Uname more idiomatically.

gcc/ada/ChangeLog:

* sem_util.adb (Get_Library_Unit_Name): Improve use of Uname.

8 months agoada: Fix latent issue exposed by recent change in aggregate expansion
Eric Botcazou [Mon, 11 Nov 2024 23:18:00 +0000 (00:18 +0100)] 
ada: Fix latent issue exposed by recent change in aggregate expansion

The tag is not assigned when a compile-time known aggregate initializes an
object declared with an address clause/aspect.

gcc/ada/ChangeLog:

* freeze.adb: Remove clauses for Exp_Ch3.
(Check_Address_Clause): Always reassign the tag for an object of a
tagged type if there is an initialization expression.

8 months agoFortran: Partial reversion of r15-5083 [PR117763]
Paul Thomas [Tue, 26 Nov 2024 08:58:21 +0000 (08:58 +0000)] 
Fortran: Partial reversion of r15-5083 [PR117763]

2024-11-26  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
PR fortran/117763
* trans-array.cc (gfc_get_array_span): Guard against derefences
of 'expr'. Clean up some typos. Use 'gfc_get_vptr_from_expr'
for clarity and apply a functional reversion of last section
that deals with class dummies.

gcc/testsuite/
PR fortran/117763
* gfortran.dg/pr117763.f90: New test.

8 months agoRISC-V: avlprop: Do not propagate VL from slidedown.
Robin Dapp [Mon, 25 Nov 2024 11:40:53 +0000 (12:40 +0100)] 
RISC-V: avlprop: Do not propagate VL from slidedown.

In the following situation (found in the
rvv/autovec/vls-vlmax/shuffle-slide.c test which is not yet pushed)

vsetivli zero,4,e8,mf4,ta,ma
vle8.v v2,0(a1) # (1)
vle8.v v1,0(a2) # (2)
vsetivli zero,2,e8,mf4,tu,ma
vslidedown.vi v1,v2,2
vsetivli zero,4,e8,mf4,ta,ma
vse8.v v1,0(a2)

we wrongly "propagate" VL=2 from vslidedown into the load.

Although we check whether the "target" instruction has a merge operand
the check only handles cases where the merge operand itself is
loaded, like (2) in the snippet above.  For (1) we load the non-merged
operand, assume propagation is valid and continue despite (2).

This patch just re-uses avl_can_be_propagated_p in order to disable
slides altogether in such situations.

gcc/ChangeLog:

* config/riscv/riscv-avlprop.cc (pass_avlprop::get_vlmax_ta_preferred_avl):
Check whether the use insn is valid for propagation.

8 months agobuiltins: Fix up DFP ICEs on __builtin_fpclassify [PR102674]
Jakub Jelinek [Tue, 26 Nov 2024 08:46:51 +0000 (09:46 +0100)] 
builtins: Fix up DFP ICEs on __builtin_fpclassify [PR102674]

This patch is similar to the one I've just posted, __builtin_fpclassify also
needs to print decimal float minimum differently and use real_from_string3.
Plus I've done some formatting fixes.

2024-11-26  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/102674
* builtins.cc (fold_builtin_fpclassify): Use real_from_string3 rather
than real_from_string.  Use "1E%d" format string rather than "0x1p%d"
for decimal float minimum.  Formatting fixes.

* gcc.dg/dfp/pr102674.c: New test.

8 months agobuiltins: Fix up DFP ICEs on __builtin_is{inf,finite,normal} [PR43374]
Jakub Jelinek [Tue, 26 Nov 2024 08:45:21 +0000 (09:45 +0100)] 
builtins: Fix up DFP ICEs on __builtin_is{inf,finite,normal} [PR43374]

__builtin_is{inf,finite,normal} builtins ICE on _Decimal{32,64,128,64x}
operands unless those operands are constant.

The problem is that we fold the builtins to comparisons with the largest
finite number, but
a) get_max_float was only handling binary floats
b) real_from_string again assumes binary float
and so we were ICEing in the build_real called after the two calls.

This patch adds decimal handling into get_max_float (well, moves it
from c-cppbuiltin.cc which was printing those for __DEC{32,64,128}_MAX__
macros) and uses real_from_string3 (perhaps it is time to rename it
to just real_from_string now that we can use function overloading)
so that it handles both binary and decimal floats.

2024-11-26  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/43374
gcc/
* real.cc (get_max_float): Handle decimal float.
* builtins.cc (fold_builtin_interclass_mathfn): Use
real_from_string3 rather than real_from_string.  Use
"1E%d" format string rather than "0x1p%d" for decimal
float minimum.
gcc/c-family/
* c-cppbuiltin.cc (builtin_define_decimal_float_constants): Use
get_max_float.
gcc/testsuite/
* gcc.dg/dfp/pr43374.c: New test.

8 months agoaffine: Remove unused variable rem from wide_int_constant_multiple_p
Andrew Pinski [Tue, 26 Nov 2024 08:37:33 +0000 (00:37 -0800)] 
affine: Remove unused variable rem from wide_int_constant_multiple_p

This might fix the current bootstrap failure on aarch64, I only tested it
on x86_64. But the rem variable is unused and the for poly_widest_int, there
could be loop if NUM_POLY_INT_COEFFS is 2 or more. In the case of aarch64,
NUM_POLY_INT_COEFFS is 2.
Note the reason why there is warning for the unused variable is due to the deconstructor.

Pushed as obvious after a build for x86_64-linux-gnu.

gcc/ChangeLog:

* tree-affine.cc (wide_int_constant_multiple_p): Remove unused rem variable.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
8 months agolibstdc++: Add conditional noexcept to range access functions
Jonathan Wakely [Mon, 25 Nov 2024 21:22:12 +0000 (21:22 +0000)] 
libstdc++: Add conditional noexcept to range access functions

As an extension, this adds conditional noexcept to std::begin, std::end,
and std::ssize.

libstdc++-v3/ChangeLog:

* include/bits/range_access.h (begin, end, ssize): Add
conditional noexcept.
* testsuite/18_support/initializer_list/range_access.cc: Check
results and noexcept-specifier for std::begin and std::end.
* testsuite/24_iterators/headers/iterator/range_access_c++11.cc:
Check for conditional noexcept on std::begin and std::end.
* testsuite/24_iterators/headers/iterator/range_access_c++14.cc:
Likewise.
* testsuite/24_iterators/headers/iterator/range_access_c++17.cc:
Likewise.
* testsuite/24_iterators/range_access/range_access.cc: Check
conditional noexcept is correct.
* testsuite/24_iterators/range_access/range_access_cpp17.cc:
Check std::size, std::empty and std::data.
* testsuite/24_iterators/range_access/range_access_cpp20.cc:
Check conditional noexcept on std::ssize.

8 months agolibstdc++: Improve Doxygen comments in <forward_list>
Jonathan Wakely [Mon, 25 Nov 2024 16:21:01 +0000 (16:21 +0000)] 
libstdc++: Improve Doxygen comments in <forward_list>

Use Markdown backticks to format comments, instead of Doxygen @c and @a
commands.

libstdc++-v3/ChangeLog:

* include/bits/forward_list.h: Use Markdown in Doxygen comments.

8 months agolibstdc++: Move std::error_category symbol to separate file [PR117630]
Jonathan Wakely [Sun, 17 Nov 2024 20:46:07 +0000 (20:46 +0000)] 
libstdc++: Move std::error_category symbol to separate file [PR117630]

As described in PR 117630 the cow-stdexcept.cc file pulls in symbols
from system_error.cc, which are not actually needed there. Moving the
definition of error_category::_M_message to a separate file should solve
it.

libstdc++-v3/ChangeLog:

PR libstdc++/117630
* src/c++11/Makefile.am: Add new file.
* src/c++11/Makefile.in: Regnerate.
* src/c++11/cow-stdexcept.cc (error_category::_M_message): Move
member function definition to ...
* src/c++11/cow-system_error.cc: New file.

8 months agoOptimize 128-bit vector permutation with pand, pandn and por.
Cui, Lili [Tue, 26 Nov 2024 07:10:23 +0000 (15:10 +0800)] 
Optimize 128-bit vector permutation with pand, pandn and por.

This patch introduces a new subroutine in ix86_expand_vec_perm_const_1.
On x86, use mixed constant permutation for V8HImode and V16QImode when
SSE2 is supported. This patch handles certain vector shuffle operations
more efficiently using pand, pandn, and por. This change is intended to
improve assembly code generation for configurations that support SSE2.

gcc/ChangeLog:

PR target/116675
* config/i386/i386-expand.cc (expand_vec_perm_pand_pandn_por):
New subroutine.
(ix86_expand_vec_perm_const_1): Call expand_vec_perm_pand_pandn_por.

gcc/testsuite/ChangeLog:

PR target/116675
* gcc.target/i386/pr116675.c: New test.

8 months agoi386/testsuite: Correct AVX10.2 FP8 test mask usage
Haochen Jiang [Fri, 22 Nov 2024 07:57:47 +0000 (15:57 +0800)] 
i386/testsuite: Correct AVX10.2 FP8 test mask usage

Under FP8, we should not use AVX512F_LEN_HALF to get the mask size since
it will get 16 instead of 8 and drop into wrong if condition. Correct
the usage for vcvtneph2[b,h]f8[,s] runtime test.

gcc/testsuite/ChangeLog:

* gcc.target/i386/avx10_2-512-vcvtneph2bf8-2.c: Correct 128bit
mask usage.
* gcc.target/i386/avx10_2-512-vcvtneph2bf8s-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtneph2hf8-2.c: Ditto.
* gcc.target/i386/avx10_2-512-vcvtneph2hf8s-2.c: Ditto.

8 months agoc: Fix ICEs from invalid atomic compound assignment [PR98195, PR117755]
Joseph Myers [Tue, 26 Nov 2024 03:25:44 +0000 (03:25 +0000)] 
c: Fix ICEs from invalid atomic compound assignment [PR98195, PR117755]

As reported in bug 98195, there are ICEs from an _Atomic compound
assignment with an incomplete type on the RHS, arising from an invalid
temporary being created with such a type.  As reported in bug 117755,
there are also (different) ICEs in cases with complete types where the
binary operation itself is invalid, when inside a nested function,
arising from a temporary being created for the RHS, but then not used
because the binary operation returns error_mark_node, resulting in the
temporary not appearing in a TARGET_EXPR, never getting its
DECL_CONTEXT set by the gimplifier and eventually resulting in an ICE
in nested function processing (trying to find a function context for
the temporary) as a result.

Fix the first ICE with an earlier check for a complete type for the
RHS of an assignment so the problematic temporary is never created for
an incomplete type (which changes the error message three existing
tests get for that case; the new message seems as good as the old
one).  Fix the second ICE by ensuring that once a temporary has been
created, it always gets a corresponding TARGET_EXPR even on error.

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

PR c/98195
PR c/117755

gcc/c/
* c-typeck.cc (build_atomic_assign): Always create a TARGET_EXPR
for newval even in case of error from binary operation.
(build_modify_expr): Check early for incomplete type of rhs.

gcc/testsuite/
* gcc.dg/pr98195-1.c, gcc.dg/pr117755-1.c: New tests.
* gcc.dg/noncompile/20020207-1.c, gcc.dg/pr14765-1.c,
objc.dg/method-11.m: Update expected error messages.

8 months agoDaily bump.
GCC Administrator [Tue, 26 Nov 2024 00:19:26 +0000 (00:19 +0000)] 
Daily bump.

8 months agoPR modula2/117777: m2 does not allow single const string in asm volatile
Gaius Mulley [Mon, 25 Nov 2024 22:46:16 +0000 (22:46 +0000)] 
PR modula2/117777: m2 does not allow single const string in asm volatile

gm2 does not allow single const string in ASM VOLATILE.  The bugfix is to
modify AsmOperands in all passes except P3Build.bnf (which is correct).
The remaining passes need to make the term following the ConstExpression
optional.

gcc/m2/ChangeLog:

PR modula2/117777
* gm2-compiler/P0SyntaxCheck.bnf (AsmOperands): Allow term after
ConstExpression to be optional.
* gm2-compiler/P1Build.bnf (AsmOperands): Ditto.
* gm2-compiler/P2Build.bnf (AsmOperands): Ditto.
* gm2-compiler/PCBuild.bnf (AsmOperands): Ditto.
* gm2-compiler/PHBuild.bnf (AsmOperands): Ditto.

gcc/testsuite/ChangeLog:

PR modula2/117777
* gm2/extensions/asm/pass/conststr.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
8 months agobuild: Move sstream include above safe-ctype.h {PR117771]
Andrew Pinski [Mon, 25 Nov 2024 22:03:27 +0000 (14:03 -0800)] 
build: Move sstream include above safe-ctype.h {PR117771]

sstream in some versions of libstdc++ include locale which might not have been
included yet. safe-ctype.h defines the toupper, tolower, etc. as macros so the
c++ header files needed to be included before hand as comment in system.h says:
/* Include C++ standard headers before "safe-ctype.h" to avoid GCC
   poisoning the ctype macros through safe-ctype.h */

I don't understand how it was working before when memory was included after
safe-ctype.h rather than before. But this makes sstream consistent with the
other C++ headers.

Pushed as obvious after a build for riscv64-elf.

gcc/ChangeLog:

PR target/117771
* system.h: Move the include of sstream above safe-ctype.h.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
8 months agosibcall: Check partial != 0 for BLKmode argument
H.J. Lu [Sat, 12 Oct 2024 20:53:14 +0000 (04:53 +0800)] 
sibcall: Check partial != 0 for BLKmode argument

The outgoing stack slot size may be different from the BLKmode argument
size due to parameter alignment.  Check partial != 0 for BLKmode argument
passed on stack.

gcc/

PR middle-end/117098
* calls.cc (store_one_arg): Check partial != 0 for BLKmode argument
passed on stack.

gcc/testsuite/

PR middle-end/117098
* gcc.dg/sibcall-12.c: New test.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
8 months agohppa: Revise TImode aritmetic patterns to support arith11_operands
John David Anglin [Mon, 25 Nov 2024 21:40:29 +0000 (16:40 -0500)] 
hppa: Revise TImode aritmetic patterns to support arith11_operands

2024-11-25  John David Anglin  <danglin@gcc.gnu.org>

gcc/ChangeLog:

PR target/117645
* config/pa/pa.md (addti3): Revise pattern to support
arith11_operands.  Use "R" operand prefix to print least
significant register of TImode register pair.
(addvti3, subti3, subvti3): Likewise.
(negti2, negvti2): Use "R" operand prefix.

8 months ago[PR117105][LRA]: Use unique value reload pseudo for early clobber operand
Vladimir N. Makarov [Mon, 25 Nov 2024 21:09:00 +0000 (16:09 -0500)] 
[PR117105][LRA]: Use unique value reload pseudo for early clobber operand

LRA did not generate insn satisfying insn constraints on the PR
test.  The reason for this is that LRA assigned the same hard reg for
two conflicting reload pseudos.  The two insn reload pseudos are
originated from the same pseudo and LRA tried to optimize as it
assigned the same value for the reload pseudos.  It is an LRA
optimization to minimize reload insns.  The two reload pseudos
conflict as one of them is an early clobber insn operands.  The patch
solves this problem by assigning unique value if the operand is early
clobber one.

gcc/ChangeLog:

PR target/117105
* lra-constraints.cc (get_reload_reg): Create unique value reload
pseudos for early clobbered operands.

gcc/testsuite/ChangeLog:

PR target/117105
* gcc.target/i386/pr117105.c: New test.

8 months agoi386: Generalize x >> 32-y to x >> -y conversion with multiples of 32
Uros Bizjak [Mon, 25 Nov 2024 19:04:38 +0000 (20:04 +0100)] 
i386: Generalize x >> 32-y to x >> -y conversion with multiples of 32

Optimize also cases where immediate value is a multiple of 32 for 32-bit
shifts (or multiple of 64 for 64-bit shifts).

gcc/ChangeLog:

* config/i386/i386.md (*ashl<mode>3_negcnt):
For SImode shifts allow multiples of 32 (or multiples
of 64 for DImode shifts) for immediate operand 3.
(*ashl<mode>3_negcnt_1): Ditto.
(*<insn><mode>3_negcnt): Ditto.
(*<insn><mode>3_negcnt_1): Ditto.

8 months agoRegeernate .opt.urls after nios2 removal
Andrew Pinski [Mon, 25 Nov 2024 18:29:07 +0000 (10:29 -0800)] 
Regeernate .opt.urls after nios2 removal

The index markers changed slightly when nios2 were removed.
This just regenerates the files.

gcc/ChangeLog:

* config/g.opt.urls: Regenerate.
* config/i386/i386.opt.urls: Regenerate.
* config/i386/nto.opt.urls: Regenerate.
* config/nvptx/nvptx.opt.urls: Regenerate.
* config/riscv/riscv.opt.urls: Regenerate.
* config/s390/s390.opt.urls: Regenerate.
* config/sol2.opt.urls: Regenerate.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
8 months agonios2: Remove all support for Nios II target.
Sandra Loosemore [Sat, 23 Nov 2024 23:59:13 +0000 (23:59 +0000)] 
nios2: Remove all support for Nios II target.

nios2 target support in GCC was deprecated in GCC 14 as the
architecture has been EOL'ed by the vendor.  This patch removes the
entire port for GCC 15

There are still references to "nios2" in libffi and libgo.  Since those
libraries are imported into the gcc sources from master copies maintained
by other projects, those will need to be addressed elsewhere.

ChangeLog:
* MAINTAINERS: Remove references to nios2.
* configure.ac: Likewise.
* configure: Regenerated.

config/ChangeLog:
* mt-nios2-elf: Deleted.

contrib/ChangeLog:
* config-list.mk: Remove references to Nios II.

gcc/ChangeLog:
* common/config/nios2/*: Delete entire directory.
* config/nios2/*: Delete entire directory.
* config.gcc: Remove references to nios2.
* configure.ac: Likewise.
* doc/extend.texi: Likewise.
* doc/install.texi: Likewise.
* doc/invoke.texi: Likewise.
* doc/md.texi: Likewise.
* regenerate-opt-urls.py: Likewise.
* config.in: Regenerated.
* configure: Regenerated.

gcc/testsuite/ChangeLog:
* g++.target/nios2/*: Delete entire directory.
* gcc.target/nios2/*: Delete entire directory.
* g++.dg/cpp0x/constexpr-rom.C: Remove refences to nios2.
* g++.old-deja/g++.jason/thunk3.C: Likewise.
* gcc.c-torture/execute/20101011-1.c: Likewise.
* gcc.c-torture/execute/pr47237.c: Likewise.
* gcc.dg/20020312-2.c: Likewise.
* gcc.dg/20021029-1.c: Likewise.
* gcc.dg/debug/btf/btf-datasec-1.c: Likewise.
* gcc.dg/ifcvt-4.c: Likewise.
* gcc.dg/stack-usage-1.c: Likewise.
* gcc.dg/struct-by-value-1.c: Likewise.
* gcc.dg/tree-ssa/reassoc-33.c: Likewise.
* gcc.dg/tree-ssa/reassoc-34.c: Likewise.
* gcc.dg/tree-ssa/reassoc-35.c: Likewise.
* gcc.dg/tree-ssa/reassoc-36.c: Likewise.
* lib/target-supports.exp: Likewise.

libgcc/ChangeLog:
* config/nios2/*: Delete entire directory.
* config.host: Remove refences to nios2.
* unwind-dw2-fde-dip.c: Likewise.

8 months agoFortran: Check IMPURE in BLOCK inside DO CONCURRENT.
Steve Kargl [Mon, 25 Nov 2024 02:26:03 +0000 (18:26 -0800)] 
Fortran: Check IMPURE in BLOCK inside DO CONCURRENT.

PR fortran/117765

gcc/fortran/ChangeLog:

* resolve.cc (check_pure_function): Check the stack to
see if the function is in a nested BLOCK and, if that
block is inside a DO_CONCURRENT, issue an error.

gcc/testsuite/ChangeLog:

* gfortran.dg/impure_fcn_do_concurrent.f90: New test.