]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
20 months agoc++: P2280R4, Using unknown refs in constant expr [PR106650]
Marek Polacek [Fri, 17 Nov 2023 19:48:44 +0000 (14:48 -0500)] 
c++: P2280R4, Using unknown refs in constant expr [PR106650]

This patch is an attempt to implement (part of?) P2280, Using unknown
pointers and references in constant expressions.  (Note that R4 seems to
only allow References to unknown/Accesses via this, but not Pointers to
unknown.)

This patch works to the extent that the test case added in [expr.const]
works as expected, as well as the test in
<https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2280r4.html#the-this-pointer>

Most importantly, the proposal makes this compile:

  template <typename T, size_t N>
  constexpr auto array_size(T (&)[N]) -> size_t {
      return N;
  }

  void check(int const (&param)[3]) {
      constexpr auto s = array_size(param);
      static_assert (s == 3);
  }

and I think it would be a pity not to have it in GCC 14.

What still doesn't work is the test in $3.2:

  struct A2 { constexpr int f() { return 0; } };
  struct B2 : virtual A2 {};
  void f2(B2 &b) { constexpr int k = b.f(); }

where we say
error: '* & b' is not a constant expression

This will be fixed in the future.

PR c++/106650

gcc/cp/ChangeLog:

* constexpr.cc (cxx_eval_constant_expression) <case PARM_DECL>: Allow
reference to unknown/this as per P2280.
<case VAR_DECL>: Allow reference to unknown as per P2280.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/constexpr-array-ptr6.C: Remove dg-error.
* g++.dg/cpp0x/constexpr-ref12.C: Likewise.
* g++.dg/cpp0x/constexpr-ref2.C: Adjust dg-error.
* g++.dg/cpp0x/noexcept34.C: Remove dg-error.
* g++.dg/cpp1y/lambda-generic-const10.C: Likewise.
* g++.dg/cpp0x/constexpr-ref13.C: New test.
* g++.dg/cpp1z/constexpr-ref1.C: New test.
* g++.dg/cpp1z/constexpr-ref2.C: New test.
* g++.dg/cpp2a/constexpr-ref1.C: New test.

20 months agolibbacktrace: call GetModuleFileNameA on Windows
Ian Lance Taylor [Wed, 29 Nov 2023 22:01:49 +0000 (14:01 -0800)] 
libbacktrace: call GetModuleFileNameA on Windows

Patch from Björn Schäpers.

* fileline.c: Include <windows.h> if available.
(windows_get_executable_path): New static function.
(fileline_initialize): Call windows_get_executable_path.
* configure.ac: Checked for windows.h
* configure: Regenerate.
* config.h.in: Regenerate.

20 months agoc++: fix testcase [PR112765]
Patrick Palka [Wed, 29 Nov 2023 21:47:12 +0000 (16:47 -0500)] 
c++: fix testcase [PR112765]

PR c++/112765

gcc/testsuite/ChangeLog:

* g++.dg/warn/Wparentheses-33.C: Compile with -Wparentheses.

20 months agoc++: bogus -Wparentheses warning [PR112765]
Patrick Palka [Wed, 29 Nov 2023 21:42:39 +0000 (16:42 -0500)] 
c++: bogus -Wparentheses warning [PR112765]

We need to consistently look through implicit INDIRECT_REF when
setting/checking for -Wparentheses warning suppression.  In passing
use the recently introduced STRIP_REFERENCE_REF helper some more.

PR c++/112765

gcc/cp/ChangeLog:

* pt.cc (tsubst_expr) <case MODOP_EXPR>: Look through implicit
INDIRECT_REF when propagating -Wparentheses warning suppression.
* semantics.cc (maybe_warn_unparenthesized_assignment): Replace
REFERENCE_REF_P handling with STRIP_REFERENCE_REF.
(finish_parenthesized_expr): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Wparentheses-33.C: New test.

20 months agobpf: change ASM_COMMENT_START to '#'
David Faust [Wed, 29 Nov 2023 17:36:02 +0000 (09:36 -0800)] 
bpf: change ASM_COMMENT_START to '#'

The BPF "pseudo-C" assembly dialect uses semi-colon (;) to separate
statements, not to begin line comments. The GNU assembler was recently
changed accordingly:

  https://sourceware.org/pipermail/binutils/2023-November/130867.html

This patch adapts the BPF backend in GCC accordingly, to use a hash (#)
instead of semi-colon (;) for ASM_COMMENT_START. This is supported
already in clang.

gcc/
* config/bpf/bpf.h (ASM_COMMENT_START): Change from ';' to '#'.

gcc/testsuite/
* gcc.target/bpf/core-builtin-enumvalue-opt.c: Change dg-final
scans to not assume a specific comment character.
* gcc.target/bpf/core-builtin-enumvalue.c: Likewise.
* gcc.target/bpf/core-builtin-type-based.c: Likewise.
* gcc.target/bpf/core-builtin-type-id.c: Likewise.

20 months agors6000: Fix up c-c++-common/builtin-classify-type-1.c failure [PR112725]
Jakub Jelinek [Wed, 29 Nov 2023 18:19:07 +0000 (19:19 +0100)] 
rs6000: Fix up c-c++-common/builtin-classify-type-1.c failure [PR112725]

The rs6000 backend (and s390 one as well) diagnoses passing vector types
to unprototyped functions, which breaks the builtin-classify-type-1.c test.
The builtin isn't really unprototyped, it is just type-generic and accepting
vector types is just fine there, all it does is categorize the vector type.
The following patch makes sure we don't diagnose it for this builtin.

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

PR target/112725
* config/rs6000/rs6000.cc (invalid_arg_for_unprototyped_fn): Return
NULL for __builtin_classify_type calls with vector arguments.

20 months agoCheck operands before invoking fold_range.
Andrew MacLeod [Tue, 28 Nov 2023 18:02:35 +0000 (13:02 -0500)] 
Check operands before invoking fold_range.

Call check_operands_p before fold_range to make sure it is a valid operation.

PR tree-optimization/111922
gcc/
* ipa-cp.cc (ipa_vr_operation_and_type_effects): Check the
operands are valid before calling fold_range.

gcc/testsuite/
* gcc.dg/pr111922.c: New.

20 months agoAdd operand_check_p to range-ops.
Andrew MacLeod [Tue, 28 Nov 2023 14:39:30 +0000 (09:39 -0500)] 
Add operand_check_p to range-ops.

Add an optional method to verify operands are compatible, and check
the operands before all range operations.

* range-op-mixed.h (operator_equal::operand_check_p): New.
(operator_not_equal::operand_check_p): New.
(operator_lt::operand_check_p): New.
(operator_le::operand_check_p): New.
(operator_gt::operand_check_p): New.
(operator_ge::operand_check_p): New.
(operator_plus::operand_check_p): New.
(operator_abs::operand_check_p): New.
(operator_minus::operand_check_p): New.
(operator_negate::operand_check_p): New.
(operator_mult::operand_check_p): New.
(operator_bitwise_not::operand_check_p): New.
(operator_bitwise_xor::operand_check_p): New.
(operator_bitwise_and::operand_check_p): New.
(operator_bitwise_or::operand_check_p): New.
(operator_min::operand_check_p): New.
(operator_max::operand_check_p): New.
* range-op.cc (range_op_handler::fold_range): Check operand
parameter types.
(range_op_handler::op1_range): Ditto.
(range_op_handler::op2_range): Ditto.
(range_op_handler::operand_check_p): New.
(range_operator::operand_check_p): New.
(operator_lshift::operand_check_p): New.
(operator_rshift::operand_check_p): New.
(operator_logical_and::operand_check_p): New.
(operator_logical_or::operand_check_p): New.
(operator_logical_not::operand_check_p): New.
* range-op.h (range_operator::operand_check_p): New.
(range_op_handler::operand_check_p): New.

20 months agotree-sra: Avoid returns of references to SRA candidates
Martin Jambor [Wed, 29 Nov 2023 15:24:33 +0000 (16:24 +0100)] 
tree-sra: Avoid returns of references to SRA candidates

The enhancement to address PR 109849 contained an importsnt thinko,
and that any reference that is passed to a function and does not
escape, must also not happen to be aliased by the return value of the
function.  This has quickly transpired as bugs PR 112711 and PR
112721.

Just as IPA-modref does a good enough job to allow us to rely on the
escaped set of variables, it sems to be doing well also on updating
EAF_NOT_RETURNED_DIRECTLY call argument flag which happens to address
exactly the situation we need to avoid.  Of course, if a call
statement ignores any returned value, we also do not need to check the
flag.

Hopefully this does not pessimize things too much, I have verified
that the PR 109849 testcae remains quick and so should also the
benchmark it is derived from.

gcc/ChangeLog:

2023-11-27  Martin Jambor  <mjambor@suse.cz>

PR tree-optimization/112711
PR tree-optimization/112721
* tree-sra.cc (build_access_from_call_arg): New parameter
CAN_BE_RETURNED, disqualify any candidate passed by reference if it is
true.  Adjust leading comment.
(scan_function): Pass appropriate value to CAN_BE_RETURNED of
build_access_from_call_arg.

gcc/testsuite/ChangeLog:

2023-11-29  Martin Jambor  <mjambor@suse.cz>

PR tree-optimization/112711
PR tree-optimization/112721
* g++.dg/tree-ssa/pr112711.C: New test.
* gcc.dg/tree-ssa/pr112721.c: Likewise.

20 months agoIn 'libgomp.c/target-simd-clone-{1,2,3}.c', restrict 'scan-offload-ipa-dump's to...
Thomas Schwinge [Tue, 21 Nov 2023 19:20:21 +0000 (20:20 +0100)] 
In 'libgomp.c/target-simd-clone-{1,2,3}.c', restrict 'scan-offload-ipa-dump's to 'only_for_offload_target amdgcn-amdhsa'

This gets rid of UNRESOLVEDs if nvptx offloading compilation is enabled in
addition to GCN:

     PASS: libgomp.c/target-simd-clone-1.c (test for excess errors)
     PASS: libgomp.c/target-simd-clone-1.c scan-amdgcn-amdhsa-offload-ipa-dump simdclone "Generated local clone _ZGV.*N.*_addit"
    -UNRESOLVED: libgomp.c/target-simd-clone-1.c scan-nvptx-none-offload-ipa-dump simdclone "Generated local clone _ZGV.*N.*_addit"
     PASS: libgomp.c/target-simd-clone-1.c scan-amdgcn-amdhsa-offload-ipa-dump simdclone "Generated local clone _ZGV.*M.*_addit"
    -UNRESOLVED: libgomp.c/target-simd-clone-1.c scan-nvptx-none-offload-ipa-dump simdclone "Generated local clone _ZGV.*M.*_addit"
     PASS: libgomp.c/target-simd-clone-2.c (test for excess errors)
     PASS: libgomp.c/target-simd-clone-2.c scan-amdgcn-amdhsa-offload-ipa-dump-not simdclone "Generated .* clone"
    -UNRESOLVED: libgomp.c/target-simd-clone-2.c scan-nvptx-none-offload-ipa-dump-not simdclone "Generated .* clone"
     PASS: libgomp.c/target-simd-clone-3.c (test for excess errors)
     PASS: libgomp.c/target-simd-clone-3.c scan-amdgcn-amdhsa-offload-ipa-dump simdclone "device doesn't match"
    -UNRESOLVED: libgomp.c/target-simd-clone-3.c scan-nvptx-none-offload-ipa-dump simdclone "device doesn't match"
     PASS: libgomp.c/target-simd-clone-3.c scan-amdgcn-amdhsa-offload-ipa-dump-not simdclone "Generated .* clone"
    -UNRESOLVED: libgomp.c/target-simd-clone-3.c scan-nvptx-none-offload-ipa-dump-not simdclone "Generated .* clone"

Minor fix-up for commit 309e2d95e3b930c6f15c8a5346b913158404c76d
'OpenMP: Generate SIMD clones for functions with "declare target"'.

libgomp/
* testsuite/libgomp.c/target-simd-clone-1.c: Restrict
'scan-offload-ipa-dump's to
'only_for_offload_target amdgcn-amdhsa'.
* testsuite/libgomp.c/target-simd-clone-2.c: Likewise.
* testsuite/libgomp.c/target-simd-clone-3.c: Likewise.

20 months agotestsuite: Add 'only_for_offload_target' wrapper for 'scan-offload-tree-dump' etc.
Thomas Schwinge [Tue, 21 Nov 2023 16:31:37 +0000 (17:31 +0100)] 
testsuite: Add 'only_for_offload_target' wrapper for 'scan-offload-tree-dump' etc.

This allows restricting scans to one specific offload target only.

gcc/
* doc/sourcebuild.texi (Final Actions): Document
'only_for_offload_target' wrapper.
gcc/testsuite/
* lib/scanoffload.exp (only_for_offload_target): New 'proc'.

20 months agotestsuite, i386: Only check for cfi directives if supported [PR112729]
Rainer Orth [Wed, 29 Nov 2023 13:52:04 +0000 (14:52 +0100)] 
testsuite, i386: Only check for cfi directives if supported [PR112729]

gcc.target/i386/apx-interrupt-1.c and two more tests FAIL on Solaris/x86
with the native assembler.  Like Darwin as, it doesn't support cfi
directives.  Instead of adding more and more targets in every affected
test, this patch introduces a cfi effective-target keyword to check for
the prerequisite.

Tested on i386-pc-solaris2.11 (as and gas), x86_64-pc-linux-gnu, and
x86_64-apple-darwin23.1.0.

2023-11-24  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

gcc/testsuite:
PR testsuite/112729
* lib/target-supports.exp (check_effective_target_cfi): New proc.
* gcc.target/i386/apx-interrupt-1.c: Require cfi instead of
skipping on *-*-darwin*.
* gcc.target/i386/apx-push2pop2_force_drap-1.c: Likewise.
* gcc.target/i386/apx-push2pop2-1.c: Likewise.

gcc:
PR testsuite/112729
* doc/sourcebuild.texi (Effective-Target Keywords, Environment
attributes): Document cfi.

20 months agoFix 'g++.dg/cpp26/static_assert1.C' for '-fno-exceptions' configurations
Thomas Schwinge [Tue, 28 Nov 2023 16:52:34 +0000 (17:52 +0100)] 
Fix 'g++.dg/cpp26/static_assert1.C' for '-fno-exceptions' configurations

This test case, added in recent commit 6ce952188ab39e303e4f63e474b5cba83b5b12fd
"c++: Implement C++26 P2741R3 - user-generated static_assert messages [PR110348]",
expectedly runs into 'UNSUPPORTED: [...]: exception handling disabled', but
along the way also FAILs a few tests:

    UNSUPPORTED: g++.dg/cpp26/static_assert1.C  -std=gnu++98
    PASS: g++.dg/cpp26/static_assert1.C  -std=gnu++11  (test for warnings, line 6)
    [...]
    PASS: g++.dg/cpp26/static_assert1.C  -std=gnu++11  (test for warnings, line 51)
    FAIL: g++.dg/cpp26/static_assert1.C  -std=gnu++11  (test for errors, line 52)
    PASS: g++.dg/cpp26/static_assert1.C  -std=gnu++11  (test for warnings, line 56)
    PASS: g++.dg/cpp26/static_assert1.C  -std=gnu++11  (test for warnings, line 57)
    FAIL: g++.dg/cpp26/static_assert1.C  -std=gnu++11  at line 58 (test for errors, line 57)
    PASS: g++.dg/cpp26/static_assert1.C  -std=gnu++11  (test for warnings, line 59)
    [...]
    PASS: g++.dg/cpp26/static_assert1.C  -std=gnu++11  at line 308 (test for errors, line 307)
    UNSUPPORTED: g++.dg/cpp26/static_assert1.C  -std=gnu++11: exception handling disabled
    PASS: g++.dg/cpp26/static_assert1.C  -std=gnu++14  (test for warnings, line 6)
    [...]
    PASS: g++.dg/cpp26/static_assert1.C  -std=gnu++14  (test for warnings, line 51)
    FAIL: g++.dg/cpp26/static_assert1.C  -std=gnu++14  (test for errors, line 52)
    PASS: g++.dg/cpp26/static_assert1.C  -std=gnu++14  (test for warnings, line 56)
    PASS: g++.dg/cpp26/static_assert1.C  -std=gnu++14  (test for warnings, line 57)
    FAIL: g++.dg/cpp26/static_assert1.C  -std=gnu++14  at line 58 (test for errors, line 57)
    PASS: g++.dg/cpp26/static_assert1.C  -std=gnu++14  (test for warnings, line 59)
    [...]
    PASS: g++.dg/cpp26/static_assert1.C  -std=gnu++14  at line 257 (test for errors, line 256)
    FAIL: g++.dg/cpp26/static_assert1.C  -std=gnu++14  (test for errors, line 261)
    PASS: g++.dg/cpp26/static_assert1.C  -std=gnu++14  (test for warnings, line 262)
    [...]
    PASS: g++.dg/cpp26/static_assert1.C  -std=gnu++14  at line 308 (test for errors, line 307)
    UNSUPPORTED: g++.dg/cpp26/static_assert1.C  -std=gnu++14: exception handling disabled
    PASS: g++.dg/cpp26/static_assert1.C  -std=gnu++20  (test for warnings, line 6)
    [...]
    PASS: g++.dg/cpp26/static_assert1.C  -std=gnu++20  (test for warnings, line 51)
    FAIL: g++.dg/cpp26/static_assert1.C  -std=gnu++20  (test for errors, line 52)
    PASS: g++.dg/cpp26/static_assert1.C  -std=gnu++20  (test for warnings, line 56)
    PASS: g++.dg/cpp26/static_assert1.C  -std=gnu++20  (test for warnings, line 57)
    FAIL: g++.dg/cpp26/static_assert1.C  -std=gnu++20  at line 58 (test for errors, line 57)
    PASS: g++.dg/cpp26/static_assert1.C  -std=gnu++20  (test for warnings, line 59)
    [...]
    PASS: g++.dg/cpp26/static_assert1.C  -std=gnu++20  at line 257 (test for errors, line 256)
    FAIL: g++.dg/cpp26/static_assert1.C  -std=gnu++20  (test for errors, line 261)
    PASS: g++.dg/cpp26/static_assert1.C  -std=gnu++20  (test for warnings, line 262)
    [...]
    PASS: g++.dg/cpp26/static_assert1.C  -std=gnu++20  at line 308 (test for errors, line 307)
    UNSUPPORTED: g++.dg/cpp26/static_assert1.C  -std=gnu++20: exception handling disabled

Use an explicit '-fexceptions' to turn this front end test case all-PASS.

gcc/testsuite/
* g++.dg/cpp26/static_assert1.C: Fix for '-fno-exceptions'
configurations.

20 months agoFix '23_containers/span/at.cc' for '-fno-exceptions' configurations
Thomas Schwinge [Tue, 28 Nov 2023 16:30:13 +0000 (17:30 +0100)] 
Fix '23_containers/span/at.cc' for '-fno-exceptions' configurations

Added in recent commit 1fa85dcf656e2f2c7e483c9ed3c2680bf7db6858
"libstdc++: Add std::span::at for C++26 (P2821R5)", the test case already
does use '#if __cpp_exceptions', but failed to correspondingly guard the
'dg-warning' directives, resulting in:

    FAIL: 23_containers/span/at.cc  -std=gnu++26  (test for warnings, line 15)
    FAIL: 23_containers/span/at.cc  -std=gnu++26  (test for warnings, line 26)
    PASS: 23_containers/span/at.cc  -std=gnu++26 (test for excess errors)
    PASS: 23_containers/span/at.cc  -std=gnu++26 execution test

libstdc++-v3/
* testsuite/23_containers/span/at.cc: Fix for '-fno-exceptions'
configurations.

20 months agoAdjust 'g++.dg/ext/has-feature.C' for default-'-fno-exceptions', '-fno-rtti' configur...
Thomas Schwinge [Tue, 28 Nov 2023 14:57:09 +0000 (15:57 +0100)] 
Adjust 'g++.dg/ext/has-feature.C' for default-'-fno-exceptions', '-fno-rtti' configurations

..., where you currently get:

    FAIL: g++.dg/ext/has-feature.C  -std=gnu++98 (test for excess errors)
    [...]

Minor fix-up for recent commit 06280a906cb3dc80cf5e07cf3335b758848d488d
"c-family: Implement __has_feature and __has_extension [PR60512]".

gcc/testsuite/
* g++.dg/ext/has-feature.C: Adjust for default-'-fno-exceptions',
'-fno-rtti' configurations.

20 months agomiddle-end/110237 - wrong MEM_ATTRs for partial loads/stores
Richard Biener [Wed, 21 Jun 2023 07:31:30 +0000 (09:31 +0200)] 
middle-end/110237 - wrong MEM_ATTRs for partial loads/stores

The following addresses a miscompilation by RTL scheduling related
to the representation of masked stores.  For that we have

(insn 38 35 39 3 (set (mem:V16SI (plus:DI (reg:DI 40 r12 [orig:90 _22 ] [90])
                (const:DI (plus:DI (symbol_ref:DI ("b") [flags 0x2]  <var_decl 0x7ffff6e28d80 b>)
                        (const_int -4 [0xfffffffffffffffc])))) [1 MEM <vector(16) int> [(int *)vectp_b.12_28]+0 S64 A32])
        (vec_merge:V16SI (reg:V16SI 20 xmm0 [118])
            (mem:V16SI (plus:DI (reg:DI 40 r12 [orig:90 _22 ] [90])
                    (const:DI (plus:DI (symbol_ref:DI ("b") [flags 0x2]  <var_decl 0x7ffff6e28d80 b>)
                            (const_int -4 [0xfffffffffffffffc])))) [1 MEM <vector(16) int> [(int *)vectp_b.12_28]+0 S64 A32])

and specifically the memory attributes

  [1 MEM <vector(16) int> [(int *)vectp_b.12_28]+0 S64 A32]

are problematic.  They tell us the instruction stores and reads a full
vector which it if course does not.  There isn't any good MEM_EXPR
we can use here (we lack a way to just specify a pointer and restrict
info for example), and since the MEMs have a vector mode it's
difficult in general as passes do not need to look at the memory
attributes at all.

The easiest way to avoid running into the alias analysis problem is
to scrap the MEM_EXPR when we expand the internal functions for
partial loads/stores.  That avoids the disambiguation we run into
which is realizing that we store to an object of less size as
the size of the mode we appear to store.

After the patch we see just

  [1  S64 A32]

so we preserve the alias set, the alignment and the size (the size
is redundant if the MEM insn't BLKmode).  That's still not good
in case the RTL alias oracle would implement the same
disambiguation but it fends off the gimple one.

This fixes gcc.dg/torture/pr58955-2.c when built with AVX512
and --param=vect-partial-vector-usage=1.

PR middle-end/110237
* internal-fn.cc (expand_partial_load_optab_fn): Clear
MEM_EXPR and MEM_OFFSET.
(expand_partial_store_optab_fn): Likewise.

20 months agofold-const: Fix up multiple_of_p [PR112733]
Jakub Jelinek [Wed, 29 Nov 2023 11:26:50 +0000 (12:26 +0100)] 
fold-const: Fix up multiple_of_p [PR112733]

We ICE on the following testcase when wi::multiple_of_p is called on
widest_int 1 and -128 with UNSIGNED.  I still need to work on the
actual wide-int.cc issue, the latest patch attached to the PR regressed
bitint-{38,39}.c, so will need to debug that, but there is a clear bug
on the fold-const.cc side as well - widest_int is a signed representation
by definition, using UNSIGNED with it certainly doesn't match what was
intended, because -128 as the second operand effectively means unsigned
131072 bit 0xfffff............ffff80 integer, not the signed char -128
that appeared in the source.

In the INTEGER_CST case a few lines above this we already use
    case INTEGER_CST:
      if (TREE_CODE (bottom) != INTEGER_CST || integer_zerop (bottom))
        return false;
      return wi::multiple_of_p (wi::to_widest (top), wi::to_widest (bottom),
                                SIGNED);
so I think using SIGNED with widest_int is best there (compared to the
other choices in the PR).

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

PR middle-end/112733
* fold-const.cc (multiple_of_p): Pass SIGNED rather than
UNSIGNED for wi::multiple_of_p on widest_int arguments.

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

20 months agotestsuite, x86: Handle a broken assembler
Iain Sandoe [Sun, 29 Oct 2023 07:19:53 +0000 (07:19 +0000)] 
testsuite, x86: Handle a broken assembler

Earlier assembler support for complex fp16 on x86_64 Darwin is broken.
This adds an additional test to the existing target-supports that fails
for the broken assemblers but works for the newer, fixed, ones.

gcc/testsuite/ChangeLog:

* lib/target-supports.exp: Test an asm line that fails on broken
Darwin assembler versions.

20 months agotestsuite: Adjust g++.dg/opt/devirt2.C on SPARC
Rainer Orth [Wed, 29 Nov 2023 09:54:22 +0000 (10:54 +0100)] 
testsuite: Adjust g++.dg/opt/devirt2.C on SPARC

Since 20231124, g++.dg/opt/devirt2.C began to FAIL on 32 and 64-bit
Solaris/SPARC:

FAIL: g++.dg/opt/devirt2.C  -std=gnu++14  scan-assembler-times (jmp|call)[^\\n]*xyzzy 4
FAIL: g++.dg/opt/devirt2.C  -std=gnu++17  scan-assembler-times (jmp|call)[^\\n]*xyzzy 4
FAIL: g++.dg/opt/devirt2.C  -std=gnu++20  scan-assembler-times (jmp|call)[^\\n]*xyzzy 4
FAIL: g++.dg/opt/devirt2.C  -std=gnu++98  scan-assembler-times (jmp|call)[^\\n]*xyzzy 4

This is no doubt due to

commit ba0869323e1d45b1328b4cb723cb139a2e2146c3
Author: Maciej W. Rozycki <macro@embecosm.com>
Date:   Thu Nov 23 16:13:59 2023 +0000

    testsuite: Fix subexpressions with `scan-assembler-times'

which fixes exactly the double-counting the test relied on/worked around
on sparc.  Fixed by adjusting the count.

Tested on sparc-sun-solaris2.11.

2023-11-28  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

gcc/testsuite:
* g++.dg/opt/devirt2.C: Adjust scan-assembler-count on sparc for
removal of -inline from regexp.  Update comment.

20 months agoRISC-V: Support highpart register overlap for vwcvt
Juzhe-Zhong [Wed, 29 Nov 2023 08:34:10 +0000 (16:34 +0800)] 
RISC-V: Support highpart register overlap for vwcvt

Since Richard supports register filters recently, we are able to support highpart register
overlap for widening RVV instructions.

This patch support it for vwcvt intrinsics.

I leverage real application user codes for vwcvt:
https://github.com/riscv/riscv-v-spec/issues/929
https://godbolt.org/z/xoeGnzd8q

This is the real application codes that using LMUL = 8 with unrolling to gain optimal
performance for specific libraury.

You can see in the codegen, GCC has optimal codegen for such since we supported register
lowpart overlap for narrowing instructions (dest EEW < source EEW).

Now, we start to support highpart register overlap from this patch for widening instructions (dest EEW > source EEW).

Leverage this intrinsic codes above but for vwcvt:

https://godbolt.org/z/1TMPE5Wfr

size_t
foo (char const *buf, size_t len)
{
  size_t sum = 0;
  size_t vl = __riscv_vsetvlmax_e8m8 ();
  size_t step = vl * 4;
  const char *it = buf, *end = buf + len;
  for (; it + step <= end;)
    {
      vint8m4_t v0 = __riscv_vle8_v_i8m4 ((void *) it, vl);
      it += vl;
      vint8m4_t v1 = __riscv_vle8_v_i8m4 ((void *) it, vl);
      it += vl;
      vint8m4_t v2 = __riscv_vle8_v_i8m4 ((void *) it, vl);
      it += vl;
      vint8m4_t v3 = __riscv_vle8_v_i8m4 ((void *) it, vl);
      it += vl;

      asm volatile("nop" ::: "memory");
      vint16m8_t vw0 = __riscv_vwcvt_x_x_v_i16m8 (v0, vl);
      vint16m8_t vw1 = __riscv_vwcvt_x_x_v_i16m8 (v1, vl);
      vint16m8_t vw2 = __riscv_vwcvt_x_x_v_i16m8 (v2, vl);
      vint16m8_t vw3 = __riscv_vwcvt_x_x_v_i16m8 (v3, vl);

      asm volatile("nop" ::: "memory");
      size_t sum0 = __riscv_vmv_x_s_i16m8_i16 (vw0);
      size_t sum1 = __riscv_vmv_x_s_i16m8_i16 (vw1);
      size_t sum2 = __riscv_vmv_x_s_i16m8_i16 (vw2);
      size_t sum3 = __riscv_vmv_x_s_i16m8_i16 (vw3);

      sum += sumation (sum0, sum1, sum2, sum3);
    }
  return sum;
}

Before this patch:

...
csrr    t0,vlenb
...
        vwcvt.x.x.v     v16,v8
        vwcvt.x.x.v     v8,v28
        vs8r.v  v16,0(sp)               ---> spill
        vwcvt.x.x.v     v16,v24
        vwcvt.x.x.v     v24,v4
        nop
        vsetvli zero,zero,e16,m8,ta,ma
        vmv.x.s a2,v16
        vl8re16.v       v16,0(sp)      --->  reload
...
csrr    t0,vlenb
...

You can see heavy spill && reload inside the loop body.

After this patch:

...
vwcvt.x.x.v v8,v12
vwcvt.x.x.v v16,v20
vwcvt.x.x.v v24,v28
vwcvt.x.x.v v0,v4
...

Optimal codegen after this patch.

Tested on zvl128b no regression.

I am gonna to test zve64d/zvl256b/zvl512b/zvl1024b.

Ok for trunk if no regression on the testing above ?

Co-authored-by: kito-cheng <kito.cheng@sifive.com>
Co-authored-by: kito-cheng <kito.cheng@gmail.com>
PR target/112431

gcc/ChangeLog:

* config/riscv/constraints.md (TARGET_VECTOR ? V_REGS : NO_REGS): New register filters.
* config/riscv/riscv.md (no,W21,W42,W84,W41,W81,W82): Ditto.
(no,yes): Ditto.
* config/riscv/vector.md: Support highpart register overlap for vwcvt.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/pr112431-1.c: New test.
* gcc.target/riscv/rvv/base/pr112431-2.c: New test.
* gcc.target/riscv/rvv/base/pr112431-3.c: New test.

20 months agotestsuite: Handle double-quoted LTO section names [PR112728]
Rainer Orth [Wed, 29 Nov 2023 09:29:50 +0000 (10:29 +0100)] 
testsuite: Handle double-quoted LTO section names [PR112728]

The gcc.dg/scantest-lto.c test FAILs on Solaris/SPARC with the native as:

FAIL: gcc.dg/scantest-lto.c scan-assembler-not ascii
FAIL: gcc.dg/scantest-lto.c scan-assembler-times ascii 0

It requires double-quoting the section name which scanasm.exp doesn't
allow for.

This patch fixes that.

Tested on sparc-sun-solaris2.11 (as and gas) and i386-pc-solaris2.11 (as
and gas).

2023-11-23  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

gcc/testsuite:
PR testsuite/112728
* lib/scanasm.exp (dg-scan): Allow for double-quoted LTO section names.
(scan-assembler-times): Likewise.
(scan-assembler-dem-not): Likewise.

20 months agoRISC-V: Add explicit braces to eliminate warning.
xuli [Wed, 29 Nov 2023 08:38:00 +0000 (08:38 +0000)] 
RISC-V: Add explicit braces to eliminate  warning.

../.././gcc/gcc/config/riscv/riscv.cc: In function ‘void riscv_option_override()’:
../.././gcc/gcc/config/riscv/riscv.cc:8673:6: warning: suggest explicit braces to avoid ambiguous ‘else’ [-Wdangling-else]
   if (TARGET_RVE)
      ^

gcc/ChangeLog:

* config/riscv/riscv.cc (riscv_option_override): Eliminate warning.

20 months agotestsuite: move gcc.c-torture/compile/libcall-2.c to gcc.target/i386/libcall-1.c
Jose E. Marchesi [Wed, 29 Nov 2023 08:16:48 +0000 (09:16 +0100)] 
testsuite: move gcc.c-torture/compile/libcall-2.c to gcc.target/i386/libcall-1.c

This patch relocates a test that is really x86 specific, and changes
it to use check_effective_target_int128.

gcc/testsuite/ChangeLog

* gcc.c-torture/compile/libcall-2.c: Remove.
* gcc.target/i386/libcall-1.c: Moved from
gcc.c-torture/compile/libcall-2.c and adapted to use
effective-target for int128_t.

20 months agoc++: Fix a compile time memory leak in finish_static_assert
Jakub Jelinek [Wed, 29 Nov 2023 08:19:02 +0000 (09:19 +0100)] 
c++: Fix a compile time memory leak in finish_static_assert

On Tue, Nov 28, 2023 at 11:31:48AM -0500, Jason Merrill wrote:
> Jonathan pointed out elsewhere that this gets leaked if error return
> prevents us from getting to the XDELETEVEC.

As there is a single error return in which it can leak, I've just added
a XDELETEVEC (buf); statement to that path rather than introducing some
RAII solution.

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

* semantics.cc (finish_static_assert): Free buf on error return.

20 months agofold-mem-offsets: Fix powerpc64le-linux profiledbootstrap [PR111601]
Jakub Jelinek [Wed, 29 Nov 2023 08:14:03 +0000 (09:14 +0100)] 
fold-mem-offsets: Fix powerpc64le-linux profiledbootstrap [PR111601]

The introduction of the fold-mem-offsets pass breaks profiledbootstrap
on powerpc64le-linux.
From what I can see, the pass works one basic block at a time and
will punt on any non-DEBUG_INSN uses outside of the current block
(I believe because of the
          /* This use affects instructions outside of CAN_FOLD_INSNS.  */
          if (!bitmap_bit_p (&can_fold_insns, INSN_UID (use)))
            return 0;
test and can_fold_insns only set in do_analysis (when processing insns in
current bb, cleared at the end) or results of get_single_def_in_bb
(which are checked to be in the same bb).
But, while get_single_def_in_bb checks for
  if (DF_INSN_LUID (def) > DF_INSN_LUID (insn))
    return NULL;
The basic block in the PR in question has:
...
(insn 212 210 215 25 (set (mem/f:DI (reg/v/f:DI 10 10 [orig:152 last_viable ] [152]) [2 *last_viable_336+0 S8 A64])
        (reg/f:DI 9 9 [orig:155 _342 ] [155])) "pr111601.ii":50:17 683 {*movdi_internal64}
     (expr_list:REG_DEAD (reg/v/f:DI 10 10 [orig:152 last_viable ] [152])
        (nil)))
(insn 215 212 484 25 (set (reg:DI 5 5 [226])
        (const_int 0 [0])) "pr111601.ii":52:12 683 {*movdi_internal64}
     (expr_list:REG_EQUIV (const_int 0 [0])
        (nil)))
(insn 484 215 218 25 (set (reg/v/f:DI 10 10 [orig:152 last_viable ] [152])
        (reg/f:DI 9 9 [orig:155 _342 ] [155])) "pr111601.ii":52:12 683 {*movdi_internal64}
     (nil))
...
(insn 564 214 216 25 (set (reg/v/f:DI 10 10 [orig:152 last_viable ] [152])
        (plus:DI (reg/v/f:DI 10 10 [orig:152 last_viable ] [152])
            (const_int 96 [0x60]))) "pr111601.ii":52:12 66 {*adddi3}
     (nil))
(insn 216 564 219 25 (set (mem/f:DI (reg/v/f:DI 10 10 [orig:152 last_viable ] [152]) [2 _343->next+0 S8 A64])
        (reg:DI 5 5 [226])) "pr111601.ii":52:12 683 {*movdi_internal64}
     (expr_list:REG_DEAD (reg:DI 5 5 [226])
        (nil)))
...
and when asking for all uses of %r10 from def 564, it will see uses
in 216 and 212; the former is after the += 96 addition and gets changed
to load from %r10+96 with the addition being dropped, but there is
the other store which is a use across the backedge and when reached
from other edges certainly doesn't have the + 96 addition anywhere,
so the pass doesn't actually change that location.

This patch adds checks from get_single_def_in_bb to get_uses as well,
in particular check that the (regular non-debug) use only appears in the
same basic block as the definition and that it doesn't appear before it (i.e.
use across backedge).

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

PR bootstrap/111601
* fold-mem-offsets.cc (get_uses): Ignore DEBUG_INSN uses.  Otherwise,
punt if use is in a different basic block from INSN or appears before
INSN in the same basic block.  Formatting fixes.
(get_single_def_in_bb): Formatting fixes.
(fold_offsets_1, pass_fold_mem_offsets::execute): Comment formatting
fixes.

* g++.dg/opt/pr111601.C: New test.

20 months agoLoongArch: Use LSX for scalar FP rounding with explicit rounding mode
Xi Ruoyao [Sun, 19 Nov 2023 19:51:56 +0000 (03:51 +0800)] 
LoongArch: Use LSX for scalar FP rounding with explicit rounding mode

In LoongArch FP base ISA there is only the frint.{s/d} instruction which
reads the global rounding mode.  Utilize LSX for explicit rounding mode
even if the operand is scalar.  It seems wasting the CPU power, but
still much faster than calling the library function.

gcc/ChangeLog:

* config/loongarch/simd.md (LSX_SCALAR_FRINT): New int iterator.
(VLSX_FOR_FMODE): New mode attribute.
(<simd_for_scalar_frint_pattern><mode>2): New expander,
expanding to vreplvei.{w/d} + frint{rp/rz/rm/rne}.{s.d}.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/vect-frint-scalar.c: New test.
* gcc.target/loongarch/vect-frint-scalar-no-inexact.c: New test.

20 months agoLoongArch: Remove lrint_allow_inexact
Xi Ruoyao [Sun, 19 Nov 2023 17:34:26 +0000 (01:34 +0800)] 
LoongArch: Remove lrint_allow_inexact

No functional change, just a cleanup.

gcc/ChangeLog:

* config/loongarch/loongarch.md (lrint_allow_inexact): Remove.
(<lrint_pattern><ANYF:mode><ANYFI:mode>2): Check if <LRINT>
== UNSPEC_FTINT instead of <lrint_allow_inexact>.

20 months agoLoongArch: Use standard pattern name and RTX code for LSX/LASX rotate shift
Xi Ruoyao [Sun, 19 Nov 2023 09:28:06 +0000 (17:28 +0800)] 
LoongArch: Use standard pattern name and RTX code for LSX/LASX rotate shift

Remove unnecessary UNSPECs and make the [x]vrotr[i] instructions useful
with GNU vectors and auto vectorization.

gcc/ChangeLog:

* config/loongarch/lsx.md (bitimm): Move to ...
(UNSPEC_LSX_VROTR): Remove.
(lsx_vrotr_<lsxfmt>): Remove.
(lsx_vrotri_<lsxfmt>): Remove.
* config/loongarch/lasx.md (UNSPEC_LASX_XVROTR): Remove.
(lsx_vrotr_<lsxfmt>): Remove.
(lsx_vrotri_<lsxfmt>): Remove.
* config/loongarch/simd.md (bitimm): ... here.  Expand it to
cover LASX modes.
(vrotr<mode>3): New define_insn.
(vrotri<mode>3): New define_insn.
* config/loongarch/loongarch-builtins.cc:
(CODE_FOR_lsx_vrotr_b): Use standard pattern name.
(CODE_FOR_lsx_vrotr_h): Likewise.
(CODE_FOR_lsx_vrotr_w): Likewise.
(CODE_FOR_lsx_vrotr_d): Likewise.
(CODE_FOR_lasx_xvrotr_b): Likewise.
(CODE_FOR_lasx_xvrotr_h): Likewise.
(CODE_FOR_lasx_xvrotr_w): Likewise.
(CODE_FOR_lasx_xvrotr_d): Likewise.
(CODE_FOR_lsx_vrotri_b): Define to standard pattern name.
(CODE_FOR_lsx_vrotri_h): Likewise.
(CODE_FOR_lsx_vrotri_w): Likewise.
(CODE_FOR_lsx_vrotri_d): Likewise.
(CODE_FOR_lasx_xvrotri_b): Likewise.
(CODE_FOR_lasx_xvrotri_h): Likewise.
(CODE_FOR_lasx_xvrotri_w): Likewise.
(CODE_FOR_lasx_xvrotri_d): Likewise.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/vect-rotr.c: New test.

20 months agoLoongArch: Use standard pattern name and RTX code for LSX/LASX muh instructions
Xi Ruoyao [Sun, 19 Nov 2023 08:28:59 +0000 (16:28 +0800)] 
LoongArch: Use standard pattern name and RTX code for LSX/LASX muh instructions

Removes unnecessary UNSPECs and make the muh instructions useful with
GNU vectors or auto vectorization.

gcc/ChangeLog:

* config/loongarch/simd.md (muh): New code attribute mapping
any_extend to smul_highpart or umul_highpart.
(<su>mul<mode>3_highpart): New define_insn.
* config/loongarch/lsx.md (UNSPEC_LSX_VMUH_S): Remove.
(UNSPEC_LSX_VMUH_U): Remove.
(lsx_vmuh_s_<lsxfmt>): Remove.
(lsx_vmuh_u_<lsxfmt>): Remove.
* config/loongarch/lasx.md (UNSPEC_LASX_XVMUH_S): Remove.
(UNSPEC_LASX_XVMUH_U): Remove.
(lasx_xvmuh_s_<lasxfmt>): Remove.
(lasx_xvmuh_u_<lasxfmt>): Remove.
* config/loongarch/loongarch-builtins.cc (CODE_FOR_lsx_vmuh_b):
Redefine to standard pattern name.
(CODE_FOR_lsx_vmuh_h): Likewise.
(CODE_FOR_lsx_vmuh_w): Likewise.
(CODE_FOR_lsx_vmuh_d): Likewise.
(CODE_FOR_lsx_vmuh_bu): Likewise.
(CODE_FOR_lsx_vmuh_hu): Likewise.
(CODE_FOR_lsx_vmuh_wu): Likewise.
(CODE_FOR_lsx_vmuh_du): Likewise.
(CODE_FOR_lasx_xvmuh_b): Likewise.
(CODE_FOR_lasx_xvmuh_h): Likewise.
(CODE_FOR_lasx_xvmuh_w): Likewise.
(CODE_FOR_lasx_xvmuh_d): Likewise.
(CODE_FOR_lasx_xvmuh_bu): Likewise.
(CODE_FOR_lasx_xvmuh_hu): Likewise.
(CODE_FOR_lasx_xvmuh_wu): Likewise.
(CODE_FOR_lasx_xvmuh_du): Likewise.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/vect-muh.c: New test.

20 months agoLoongArch: Fix usage of LSX and LASX frint/ftint instructions [PR112578]
Xi Ruoyao [Fri, 17 Nov 2023 20:48:20 +0000 (04:48 +0800)] 
LoongArch: Fix usage of LSX and LASX frint/ftint instructions [PR112578]

The usage LSX and LASX frint/ftint instructions had some problems:

1. These instructions raises FE_INEXACT, which is not allowed with
   -fno-fp-int-builtin-inexact for most C2x section F.10.6 functions
   (the only exceptions are rint, lrint, and llrint).
2. The "frint" instruction without explicit rounding mode is used for
   roundM2, this is incorrect because roundM2 is defined "rounding
   operand 1 to the *nearest* integer, rounding away from zero in the
   event of a tie".  We actually don't have such an instruction.  Our
   frintrne instruction is roundevenM2 (unfortunately, this is not
   documented).
3. These define_insn's are written in a way not so easy to hack.

So I removed these instructions and created a "simd.md" file, then added
them and the corresponding expanders there.  The advantage of the
simd.md file is we don't need to duplicate the RTL template twice (in
lsx.md and lasx.md).

gcc/ChangeLog:

PR target/112578
* config/loongarch/lsx.md (UNSPEC_LSX_VFTINT_S,
UNSPEC_LSX_VFTINTRNE, UNSPEC_LSX_VFTINTRP,
UNSPEC_LSX_VFTINTRM, UNSPEC_LSX_VFRINTRNE_S,
UNSPEC_LSX_VFRINTRNE_D, UNSPEC_LSX_VFRINTRZ_S,
UNSPEC_LSX_VFRINTRZ_D, UNSPEC_LSX_VFRINTRP_S,
UNSPEC_LSX_VFRINTRP_D, UNSPEC_LSX_VFRINTRM_S,
UNSPEC_LSX_VFRINTRM_D): Remove.
(ILSX, FLSX): Move into ...
(VIMODE): Move into ...
(FRINT_S, FRINT_D): Remove.
(frint_pattern_s, frint_pattern_d, frint_suffix): Remove.
(lsx_vfrint_<flsxfmt>, lsx_vftint_s_<ilsxfmt>_<flsxfmt>,
lsx_vftintrne_w_s, lsx_vftintrne_l_d, lsx_vftintrp_w_s,
lsx_vftintrp_l_d, lsx_vftintrm_w_s, lsx_vftintrm_l_d,
lsx_vfrintrne_s, lsx_vfrintrne_d, lsx_vfrintrz_s,
lsx_vfrintrz_d, lsx_vfrintrp_s, lsx_vfrintrp_d,
lsx_vfrintrm_s, lsx_vfrintrm_d,
<FRINT_S:frint_pattern_s>v4sf2,
<FRINT_D:frint_pattern_d>v2df2, round<mode>2,
fix_trunc<mode>2): Remove.
* config/loongarch/lasx.md: Likewise.
* config/loongarch/simd.md: New file.
(ILSX, ILASX, FLSX, FLASX, VIMODE): ... here.
(IVEC, FVEC): New mode iterators.
(VIMODE): ... here.  Extend it to work for all LSX/LASX vector
modes.
(x, wu, simd_isa, WVEC, vimode, simdfmt, simdifmt_for_f,
elebits): New mode attributes.
(UNSPEC_SIMD_FRINTRP, UNSPEC_SIMD_FRINTRZ, UNSPEC_SIMD_FRINT,
UNSPEC_SIMD_FRINTRM, UNSPEC_SIMD_FRINTRNE): New unspecs.
(SIMD_FRINT): New int iterator.
(simd_frint_rounding, simd_frint_pattern): New int attributes.
(<simd_isa>_<x>vfrint<simd_frint_rounding>_<simdfmt>): New
define_insn template for frint instructions.
(<simd_isa>_<x>vftint<simd_frint_rounding>_<simdifmt_for_f>_<simdfmt>):
Likewise, but for ftint instructions.
(<simd_frint_pattern><mode>2): New define_expand with
flag_fp_int_builtin_inexact checked.
(l<simd_frint_pattern><mode><vimode>2): Likewise.
(ftrunc<mode>2): New define_expand.  It does not require
flag_fp_int_builtin_inexact.
(fix_trunc<mode><vimode>2): New define_insn_and_split.  It does
not require flag_fp_int_builtin_inexact.
(include): Add lsx.md and lasx.md.
* config/loongarch/loongarch.md (include): Include simd.md,
instead of including lsx.md and lasx.md directly.
* config/loongarch/loongarch-builtins.cc
(CODE_FOR_lsx_vftint_w_s, CODE_FOR_lsx_vftint_l_d,
CODE_FOR_lasx_xvftint_w_s, CODE_FOR_lasx_xvftint_l_d):
Remove.

gcc/testsuite/ChangeLog:

PR target/112578
* gcc.target/loongarch/vect-frint.c: New test.
* gcc.target/loongarch/vect-frint-no-inexact.c: New test.
* gcc.target/loongarch/vect-ftint.c: New test.
* gcc.target/loongarch/vect-ftint-no-inexact.c: New test.

20 months agoIntroduce hardbool attribute for C
Alexandre Oliva [Wed, 29 Nov 2023 07:00:45 +0000 (04:00 -0300)] 
Introduce hardbool attribute for C

This patch introduces hardened booleans in C.  The hardbool attribute,
when attached to an integral type, turns it into an enumerate type
with boolean semantics, using the named or implied constants as
representations for false and true.

Expressions of such types decay to _Bool, trapping if the value is
neither true nor false, and _Bool can convert implicitly back to them.
Other conversions go through _Bool first.

for  gcc/c-family/ChangeLog

* c-attribs.cc (c_common_attribute_table): Add hardbool.
(handle_hardbool_attribute): New.
(type_valid_for_vector_size): Reject hardbool.
* c-common.cc (convert_and_check): Skip warnings for convert
and check for hardbool.
(c_hardbool_type_attr_1): New.
* c-common.h (c_hardbool_type_attr): New.

for  gcc/c/ChangeLog

* c-typeck.cc (convert_lvalue_to_rvalue): Decay hardbools.
* c-convert.cc (convert): Convert to hardbool through
truthvalue.
* c-decl.cc (check_bitfield_type_and_width): Skip enumeral
truncation warnings for hardbool.
(finish_struct): Propagate hardbool attribute to bitfield
types.
(digest_init): Convert to hardbool.

for  gcc/ChangeLog

* doc/extend.texi (hardbool): New type attribute.
* doc/invoke.texi (-ftrivial-auto-var-init): Document
representation vs values.

for  gcc/testsuite/ChangeLog

* gcc.dg/hardbool-err.c: New.
* gcc.dg/hardbool-trap.c: New.
* gcc.dg/torture/hardbool.c: New.
* gcc.dg/torture/hardbool-s.c: New.
* gcc.dg/torture/hardbool-us.c: New.
* gcc.dg/torture/hardbool-i.c: New.
* gcc.dg/torture/hardbool-ul.c: New.
* gcc.dg/torture/hardbool-ll.c: New.
* gcc.dg/torture/hardbool-5a.c: New.
* gcc.dg/torture/hardbool-s-5a.c: New.
* gcc.dg/torture/hardbool-us-5a.c: New.
* gcc.dg/torture/hardbool-i-5a.c: New.
* gcc.dg/torture/hardbool-ul-5a.c: New.
* gcc.dg/torture/hardbool-ll-5a.c: New.

20 months agocall maybe_return_this in build_clone
Alexandre Oliva [Wed, 29 Nov 2023 07:00:35 +0000 (04:00 -0300)] 
call maybe_return_this in build_clone

__dt_base doesn't get its body from a maybe_return_this caller, it's
rather cloned with the full body within build_clone, and then it's
left alone, without going through finish_function_body or
build_delete_destructor_body, that call maybe_return_this.

Now, this is correct as far as the generated code is concerned, since
the cloned body of a cdtor that returns this is also a cdtor body that
returns this.  The problem is that the decl for THIS is also cloned,
and it doesn't get the warning suppression introduced by
maybe_return_this, so Wuse-after-free3.C fails with an excess warning
at the closing brace of the dtor body.

I've split out the warning suppression from maybe_return_this, and
arranged to call that bit from the relevant build_clone case.
Unfortunately, because the warning is silenced for all uses of the
THIS decl, rather than only for the ABI-mandated return stmt, this
also silences the very warning that the testcase checks for.

I'm not revamping the warning suppression approach to overcome this,
so I'm xfailing the expected warning on ARM EABI, hoping that's the
only target with cdtor_return_this, and leaving it at that.

for  gcc/cp/ChangeLog

* decl.cc (maybe_prepare_return_this): Split out of...
(maybe_return_this): ... this.
* cp-tree.h (maybe_prepare_return_this): Declare.
* class.cc (build_clone): Call it.

for  gcc/testsuite/ChangeLog

* g++.dg/warn/Wuse-after-free3.C: xfail on arm_eabi.

20 months agoc++: for contracts, cdtors never return this
Alexandre Oliva [Wed, 29 Nov 2023 07:00:28 +0000 (04:00 -0300)] 
c++: for contracts, cdtors never return this

When targetm.cxx.cdtor_return_this() holds, cdtors have a
non-VOID_TYPE_P result, but IMHO this ABI implementation detail
shouldn't leak to the abstract language conceptual framework, in which
cdtors don't have return values.  For contracts, specifically those
that establish postconditions on results, such a leakage is present,
and the present patch puts an end to it: with it, cdtors get an error
for result postconditions regardless of the ABI.  This fixes
g++.dg/contracts/contracts-ctor-dtor2.C on arm-eabi.

for  gcc/cp/ChangeLog

* contracts.cc (check_postcondition_result): Cope with
cdtor_return_this.

20 months agoIntroduce -finline-stringops
Alexandre Oliva [Wed, 29 Nov 2023 07:00:24 +0000 (04:00 -0300)] 
Introduce -finline-stringops

try_store_by_multiple_pieces was added not long ago, enabling
variable-sized memset to be expanded inline when the worst-case
in-range constant length would, using conditional blocks with powers
of two to cover all possibilities of length and alignment.

This patch introduces -finline-stringops[=fn] to request expansions to
start with a loop, so as to still take advantage of known alignment
even with long lengths, but without necessarily adding store blocks
for every power of two.

This makes it possible for the supported stringops (memset, memcpy,
memmove, memset) to be expanded, even if storing a single byte per
iteration.  Surely efficient implementations can run faster, with a
pre-loop to increase alignment, but that would likely be excessive for
inline expansions.

Still, in some cases, such as in freestanding environments, users
prefer to inline such stringops, especially those that the compiler
may introduce itself, even if the expansion is not as performant as a
highly optimized C library implementation could be, to avoid
depending on a C runtime library.

for  gcc/ChangeLog

* expr.cc (emit_block_move_hints): Take ctz of len.  Obey
-finline-stringops.  Use oriented or sized loop.
(emit_block_move): Take ctz of len, and pass it on.
(emit_block_move_via_sized_loop): New.
(emit_block_move_via_oriented_loop): New.
(emit_block_move_via_loop): Take incr.  Move an incr-sized
block per iteration.
(emit_block_cmp_via_cmpmem): Take ctz of len.  Obey
-finline-stringops.
(emit_block_cmp_via_loop): New.
* expr.h (emit_block_move): Add ctz of len defaulting to zero.
(emit_block_move_hints): Likewise.
(emit_block_cmp_hints): Likewise.
* builtins.cc (expand_builtin_memory_copy_args): Pass ctz of
len to emit_block_move_hints.
(try_store_by_multiple_pieces): Support starting with a loop.
(expand_builtin_memcmp): Pass ctz of len to
emit_block_cmp_hints.
(expand_builtin): Allow inline expansion of memset, memcpy,
memmove and memcmp if requested.
* common.opt (finline-stringops): New.
(ilsop_fn): New enum.
* flag-types.h (enum ilsop_fn): New.
* doc/invoke.texi (-finline-stringops): Add.

for  gcc/testsuite/ChangeLog

* gcc.dg/torture/inline-mem-cmp-1.c: New.
* gcc.dg/torture/inline-mem-cpy-1.c: New.
* gcc.dg/torture/inline-mem-cpy-cmp-1.c: New.
* gcc.dg/torture/inline-mem-move-1.c: New.
* gcc.dg/torture/inline-mem-set-1.c: New.

20 months agoRISC-V: Bugfix for ICE in block move when zve32f
Pan Li [Wed, 29 Nov 2023 06:31:30 +0000 (14:31 +0800)] 
RISC-V: Bugfix for ICE in block move when zve32f

The exact_div requires the exactly multiple of the divider.
Unfortunately, the condition will be broken when zve32f in
some cases. For example,

potential_ew is 8
BYTES_PER_RISCV_VECTOR * lmul1 is [4, 4]

This patch would like to ensure the precondition of exact_div
when get_vec_mode.

PR target/112743

gcc/ChangeLog:

* config/riscv/riscv-string.cc (expand_block_move): Add
precondition check for exact_div.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/pr112743-1.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
20 months agotestsuite: fix gcc.c-torture/compile/libcall-2.c in -m32
Jose E. Marchesi [Wed, 29 Nov 2023 06:44:59 +0000 (07:44 +0100)] 
testsuite: fix gcc.c-torture/compile/libcall-2.c in -m32

This test relies on having __int128 in x86_64 targets, which is only
available in -m64.

gcc/testsuite/ChangeLog

* gcc.c-torture/compile/libcall-2.c: Skip test in -m32.

20 months ago[i386] Fix push2pop2 test fail on non-linux target [PR112729]
Hongyu Wang [Tue, 28 Nov 2023 03:24:01 +0000 (11:24 +0800)] 
[i386] Fix push2pop2 test fail on non-linux target [PR112729]

On linux x86-64, -fomit-frame-pointer was by default enabled so the
push2pop2 tests cfi scans are based on it. On other target with
-fno-omit-frame-pointer the cfi scan will be wrong as the frame pointer
is pushed at first. Add -fomit-frame-pointer to these tests that related
to cfi scan.

gcc/testsuite/ChangeLog:

PR target/112729
* gcc.target/i386/apx-interrupt-1.c: Add -fomit-frame-pointer.
* gcc.target/i386/apx-push2pop2-1.c: Likewise.
* gcc.target/i386/apx-push2pop2_force_drap-1.c: Likewise.

20 months agoDaily bump.
GCC Administrator [Wed, 29 Nov 2023 00:17:27 +0000 (00:17 +0000)] 
Daily bump.

20 months agoc++: prvalue array decay [PR94264]
Jason Merrill [Tue, 28 Nov 2023 18:54:47 +0000 (13:54 -0500)] 
c++: prvalue array decay [PR94264]

My change for PR53220 made array to pointer decay for prvalue arrays
ill-formed to catch well-defined C code that produces a dangling pointer in
C++ due to the shorter lifetime of compound literals.  This wasn't really
correct, but wasn't a problem until C++17 added prvalue arrays, at which
point it started rejecting valid C++ code.

I wanted to make sure that we still diagnose the problematic code;
-Wdangling-pointer covers the array-lit.c case, but I needed to extend
-Wreturn-local-addr to handle the return case.

PR c++/94264
PR c++/53220

gcc/c/ChangeLog:

* c-typeck.cc (array_to_pointer_conversion): Adjust -Wc++-compat
diagnostic.

gcc/cp/ChangeLog:

* call.cc (convert_like_internal): Remove obsolete comment.
* typeck.cc (decay_conversion): Allow array prvalue.
(maybe_warn_about_returning_address_of_local): Check
for returning pointer to temporary.

gcc/testsuite/ChangeLog:

* c-c++-common/array-lit.c: Adjust.
* g++.dg/cpp1z/array-prvalue1.C: New test.
* g++.dg/ext/complit17.C: New test.

20 months agoARC: Consistent use of whitespace in assembler templates.
Roger Sayle [Tue, 28 Nov 2023 18:34:56 +0000 (18:34 +0000)] 
ARC: Consistent use of whitespace in assembler templates.

This minor clean-up patch tweaks arc.md to use whitespace consistently
in output templates, always using a TAB between the mnemonic and its
operands, and avoiding spaces after commas betweem operands.  There
should be no functional changes with this patch, though several test
cases' scan-assembler need to be updated to use \\s+ instead of testing
for a TAB or a space explicitly.

2023-11-28  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
* config/arc/arc.md: Make output template whitespace consistent.

gcc/testsuite/ChangeLog
* gcc.target/arc/jli-1.c: Update dg-final whitespace.
* gcc.target/arc/jli-2.c: Likewise.
* gcc.target/arc/naked-1.c: Likewise.
* gcc.target/arc/naked-2.c: Likewise.
* gcc.target/arc/tmac-1.c: Likewise.
* gcc.target/arc/tmac-2.c: Likewise.

20 months agovarasm.cc: refer to assemble_external_libcall only ifdef ASM_OUTPUT_EXTERNAL
Jose E. Marchesi [Tue, 28 Nov 2023 18:21:32 +0000 (19:21 +0100)] 
varasm.cc: refer to assemble_external_libcall only ifdef ASM_OUTPUT_EXTERNAL

This fixes boostrap in targets where ASM_OUTPUT_EXTERNAL is not
defined.

gcc/ChangeLog

* varasm.cc (assemble_external_libcall): Refer in assert only ifdef
ASM_OUTPUT_EXTERNAL.

20 months agoMATCH: Fix invalid signed boolean type usage
Andrew Pinski [Tue, 28 Nov 2023 00:41:25 +0000 (16:41 -0800)] 
MATCH: Fix invalid signed boolean type usage

This fixes the incorrect assumption that was done in r14-3721-ge6bcf839894783,
that being able to doing the negative after the conversion would be a valid thing
but really it is not valid for boolean types.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

PR tree-optimization/112738
* match.pd (`(nop_convert)-(convert)a`): Reject
when the outer type is boolean.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
20 months agoc++: Fix up __has_extension (cxx_init_captures)
Jakub Jelinek [Tue, 28 Nov 2023 17:25:14 +0000 (18:25 +0100)] 
c++: Fix up __has_extension (cxx_init_captures)

On Mon, Nov 27, 2023 at 10:58:04AM +0000, Alex Coplan wrote:
> Many thanks both for the reviews, this is now pushed (with Jason's
> above changes implemented) as g:06280a906cb3dc80cf5e07cf3335b758848d488d.

The new test FAILs everywhere with GXX_TESTSUITE_STDS=98,11,14,17,20,2b
I'm normally using for testing.
FAIL: g++.dg/ext/has-feature.C  -std=gnu++11 (test for excess errors)
Excess errors:
/home/jakub/src/gcc/gcc/testsuite/g++.dg/ext/has-feature.C:185:2: error: #error

This is on
 #if __has_extension (cxx_init_captures) != CXX11
 #error
 #endif
Comparing the values with clang++ on godbolt and with what is actually
implemented:
void foo () { auto a = [b = 3]() { return b; }; }
both clang++ and GCC implement init captures as extension already in C++11
(and obviously not in C++98 because lambdas aren't implemented there),
unless -pedantic-errors/-Werror=pedantic, so I think we should change
the FE to match the test rather than the other way around.

Making __has_extension return __has_feature for -pedantic-errors and not
for -Werror=pedantic is just weird, but as that is what clang++ implements
and this is for compatibility with it, I can live with it (but perhaps
we should mention it in the documentation).  Note, the warnings/errors
can be changed using pragmas inside of the source, so whether one can
use an extension or not depends on where in the code it is (__extension__
to the rescue if it can be specified around it).
I wonder if the has-feature.C test shouldn't be #included in other 2 tests,
one where -pedantic-errors would be in dg-options and through some macro
tell the file that __has_extension will behave like __has_feature, and
another with -Werror=pedantic to document that the option doesn't change
it.

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

* cp-objcp-common.cc (cp_feature_table): Evaluate
__has_extension (cxx_init_captures) to 1 even for -std=c++11.

20 months agoFix PR ada/111909 On Darwin, determine filesystem case sensitivity at runtime
Simon Wright [Tue, 28 Nov 2023 13:56:36 +0000 (14:56 +0100)] 
Fix PR ada/111909 On Darwin, determine filesystem case sensitivity at runtime

In gcc/ada/adaint.c(__gnat_get_file_names_case_sensitive), the current
assumption for __APPLE__ is that file names are case-insensitive
unless __arm__ or __arm64__ are defined, in which case file names are
declared case-sensitive.

The associated comment is
  "By default, we suppose filesystems aren't case sensitive on
  Windows and Darwin (but they are on arm-darwin)."

This means that on aarch64-apple-darwin, file names are treated as
case-sensitive, which is not the default case.

The true default position is that macOS file systems are
case-insensitive, iOS file systems are case-sensitive.

Apple provide a header file <TargetConditionals.h> which permits a
compile-time check for the compiler target (e.g. OSX vs IOS); if
TARGET_OS_IOS is defined as 1, this is a build for iOS.

2023-11-22  Simon Wright  <simon@pushface.org>

gcc/ada/

PR ada/111909
* adaint.c
(__gnat_get_file_names_case_sensitive): Split out the __APPLE__
check and remove the checks for __arm__, __arm64__. For Apple,
file names are by default case-insensitive unless TARGET_OS_IOS is
set.

Signed-off-by: Simon Wright <simon@pushface.org>
20 months agomiddle-end/112741 - ICE with gimple FE and later regimplification
Richard Biener [Tue, 28 Nov 2023 11:49:35 +0000 (12:49 +0100)] 
middle-end/112741 - ICE with gimple FE and later regimplification

The GIMPLE frontend, when bypassing gimplification, doesn't set
DECL_SEEN_IN_BIND_EXPR_P given there are no such things in GIMPLE.
But it probably should set the flag anyway to avoid later ICEs
when regimplifying.

PR middle-end/112741
gcc/c/
* gimple-parser.cc (c_parser_parse_gimple_body): Also
set DECL_SEEN_IN_BIND_EXPR_Pfor locals.

gcc/testsuite/
* gcc.dg/ubsan/pr112741.c: New testcase.

20 months agomiddle-end/112732 - stray TYPE_ALIAS_SET in type variant
Richard Biener [Tue, 28 Nov 2023 11:36:21 +0000 (12:36 +0100)] 
middle-end/112732 - stray TYPE_ALIAS_SET in type variant

The following fixes a stray TYPE_ALIAS_SET in a type variant built
by build_opaque_vector_type which is diagnosed by type checking
enabled with -flto.

PR middle-end/112732
* tree.cc (build_opaque_vector_type): Reset TYPE_ALIAS_SET
of the newly built type.

20 months agoi386: Improve cmpstrnqi_1 insn pattern [PR112494]
Uros Bizjak [Tue, 28 Nov 2023 15:56:29 +0000 (16:56 +0100)] 
i386: Improve cmpstrnqi_1 insn pattern [PR112494]

REPZ CMPSB instruction does not update FLAGS register when %ecx register
equals zero.  Improve cmpstrnqi_1 insn pattern to set FLAGS_REG to its
previous value instead of (const_int 0) when operand 2 equals zero.

PR target/112494

gcc/ChangeLog:

* config/i386/i386.md (cmpstrnqi_1): Set FLAGS_REG to its previous
value when operand 2 equals zero.
(*cmpstrnqi_1): Ditto.
(*cmpstrnqi_1 peephole2): Ditto.

20 months agoRevert "This patch enables errors when external calls are created."
Cupertino Miranda [Tue, 28 Nov 2023 15:44:53 +0000 (15:44 +0000)] 
Revert "This patch enables errors when external calls are created."

Reverted commit was breaking the BPF build, because libgcc emits
libcalls to __builtin_abort.

This reverts commit faf5b148588bd7fbb60ec669aefa704044037cdc.

20 months agoFortran: fix reallocation on assignment of polymorphic variables [PR110415]
Andrew Jenner [Tue, 28 Nov 2023 15:27:05 +0000 (15:27 +0000)] 
Fortran: fix reallocation on assignment of polymorphic variables [PR110415]

This patch fixes two bugs related to polymorphic class assignment in the
Fortran front-end. One (described in PR110415) is an issue with the malloc
and realloc calls using the size from the old vptr rather than the new one.
The other is caused by the return value from the realloc call being ignored.
Testcases are added for these issues.

2023-11-28  Andrew Jenner  <andrew@codesourcery.com>

gcc/fortran/
PR fortran/110415
* trans-expr.cc (trans_class_vptr_len_assignment): Add
from_vptrp parameter. Populate it. Don't check for DECL_P
when deciding whether to create temporary.
(trans_class_pointer_fcn, gfc_trans_pointer_assignment): Add
NULL argument to trans_class_vptr_len_assignment calls.
(trans_class_assignment): Get rhs_vptr from
trans_class_vptr_len_assignment and use it for determining size
for allocation/reallocation. Use return value from realloc.

gcc/testsuite/
PR fortran/110415
* gfortran.dg/pr110415.f90: New test.
* gfortran.dg/asan/pr110415-2.f90: New test.
* gfortran.dg/asan/pr110415-3.f90: New test.

Co-Authored-By: Tobias Burnus <tobias@codesourcery.com>
20 months agoEmit funcall external declarations only if actually used.
Jose E. Marchesi [Fri, 24 Nov 2023 05:30:28 +0000 (06:30 +0100)] 
Emit funcall external declarations only if actually used.

There are many places in GCC where alternative local sequences are
tried in order to determine what is the cheapest or best alternative
to use in the current target.  When any of these sequences involve a
libcall, the current implementation of emit_library_call_value_1
introduce a side-effect consisting on emitting an external declaration
for the funcall (such as __divdi3) which is thus emitted even if the
sequence that does the libcall is not retained.

This is problematic in targets such as BPF, because the kernel loader
chokes on the spurious symbol __divdi3 and makes the resulting BPF
object unloadable.  Note that BPF objects are not linked before being
loaded.

This patch changes asssemble_external_libcall to defer emitting
declarations of external libcall symbols, by saving the call tree
nodes in a temporary list pending_libcall_symbols and letting
process_pending_assembly_externals to emit them only if they have been
referenced.  Solution suggested and sketched by Richard Sandiford.

Regtested in x86_64-linux-gnu.
Tested with host x86_64-linux-gnu with target bpf-unknown-none.

gcc/ChangeLog

PR target/109253
* varasm.cc (pending_libcall_symbols): New variable.
(process_pending_assemble_externals): Process
pending_libcall_symbols.
(assemble_external_libcall): Defer emitting external libcall
symbols to process_pending_assemble_externals.

gcc/testsuite/ChangeLog

PR target/109253
* gcc.target/bpf/divmod-libcall-1.c: New test.
* gcc.target/bpf/divmod-libcall-2.c: Likewise.
* gcc.c-torture/compile/libcall-2.c: Likewise.

20 months agolibsanitizer: Update LOCAL_PATCHES
Rainer Orth [Tue, 28 Nov 2023 14:00:31 +0000 (15:00 +0100)] 
libsanitizer: Update LOCAL_PATCHES

2023-11-28  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

libsanitizer:
* LOCAL_PATCHES: Update.

20 months agolibsanitizer: Only use assembler symbol assignment if supported [PR112563]
Rainer Orth [Tue, 28 Nov 2023 13:55:52 +0000 (14:55 +0100)] 
libsanitizer: Only use assembler symbol assignment if supported [PR112563]

This patch only enables symbol assignment if the configure test determined
it's supported.

Bootstrapped without regressions on sparc-sun-solaris2.11 (as and gas) and
i386-pc-solaris2.11 (as and gas).

2023-11-23  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

libsanitizer:
PR sanitizer/112563
* sanitizer_common/sanitizer_redefine_builtins.h: Check
HAVE_AS_SYM_ASSIGN.

20 months agolibsanitizer: Check assembler support for symbol assignment [PR112563]
Rainer Orth [Tue, 28 Nov 2023 13:54:34 +0000 (14:54 +0100)] 
libsanitizer: Check assembler support for symbol assignment [PR112563]

The recent libsanitizer import broke the build on Solaris/SPARC with the
native as:

/usr/ccs/bin/as: ".libs/sanitizer_errno.s", line 4247: error: symbol
"__sanitizer_internal_memset" is used but not defined
/usr/ccs/bin/as: ".libs/sanitizer_errno.s", line 4247: error: symbol
"__sanitizer_internal_memcpy" is used but not defined
/usr/ccs/bin/as: ".libs/sanitizer_errno.s", line 4247: error: symbol
"__sanitizer_internal_memmove" is used but not defined

Since none of the alternatives considered in the PR worked out, this
patch checks if the assembler does support symbol assignment, disabling
the code otherwise.  This returns the code to the way it was up to LLVM 16.

Bootstrapped without regressions on sparc-sun-solaris2.11 (as and gas) and
i386-pc-solaris2.11 (as and gas).

2023-11-23  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

libsanitizer:
PR sanitizer/112563
* configure.ac (libsanitizer_cv_as_sym_assign): Check for
assembler symbol assignment support.
* configure: Regenerate.
* asan/Makefile.am (DEFS): Add @AS_SYM_ASSIGN_DEFS@.
* Makefile.in, asan/Makefile.in, hwasan/Makefile.in,
interception/Makefile.in, libbacktrace/Makefile.in,
lsan/Makefile.in, sanitizer_common/Makefile.in, tsan/Makefile.in,
ubsan/Makefile.in: Regenerate.

20 months agoFixed problem with BTF defining smaller enums.
Cupertino Miranda [Fri, 10 Nov 2023 14:02:30 +0000 (14:02 +0000)] 
Fixed problem with BTF defining smaller enums.

This patch fixes a BTF, which would become invalid when having
smaller then 4 byte definitions of enums.
For example, when using the __attribute__((mode(byte))) in the enum
definition.

Two problems were identified:
 - it would incorrectly create an entry for enum64 when the size of the
   enum was different then 4.
 - it would allocate less then 4 bytes for the value entry in BTF, in
   case the type was smaller.

BTF generated was validated against clang.

gcc/ChangeLog:
* btfout.cc (btf_calc_num_vbytes): Fixed logic for enum64.
(btf_asm_enum_const): Corrected logic for enum64 and smaller
than 4 bytes values.

gcc/testsuite/ChangeLog:
* gcc.dg/debug/btf/btf-enum-small.c: Added test.

20 months agoThis patch enables errors when external calls are created.
Cupertino Miranda [Thu, 23 Nov 2023 22:28:01 +0000 (22:28 +0000)] 
This patch enables errors when external calls are created.

When architectural limitations or usage of builtins implies the compiler
to create function calls to external libraries that implement the
functionality, GCC will now report an error claiming that this function
calls are not compatible with eBPF target.
Examples of those are the usage of __builtin_memmove and a sign division
in BPF ISA v3 or below that will require to call __divdi3.
This is currently an eBPF limitation which does not support linking of
object files but rather "raw" non linked ones. Those object files are
loaded and relocated by libbpf and the kernel.

gcc/ChangeLog:
* config/bpf/bpf.cc (bpf_output_call): Report error in case the
function call is for a builtin.
(bpf_external_libcall): Added target hook to detect and report
error when other external calls that are not builtins.

gcc/testsuite/ChangeLog:
* gcc.target/bpf/atomic-cmpxchg-2.c: Adapted.
* gcc.target/bpf/atomic-fetch-op-3.c: Adapted.
* gcc.target/bpf/atomic-op-3.c: Adapted.
* gcc.target/bpf/atomic-xchg-2.c: Adapted.
* gcc.target/bpf/diag-sdiv.c: Adapted.
* gcc.target/bpf/diag-smod.c: Adapted.

20 months agotestsuite: Fix gcc.dg/pr111409.c on Solaris/SPARC with as
Rainer Orth [Tue, 28 Nov 2023 12:51:47 +0000 (13:51 +0100)] 
testsuite: Fix gcc.dg/pr111409.c on Solaris/SPARC with as

gcc.dg/pr111409.c FAILs on Solaris/SPARC with the native as:

FAIL: gcc.dg/pr111409.c scan-assembler-times .section\\\\s+.debug_macro 1

Unlike most other ELF targets, that assembler requires the section name to
be double-quoted.  This patch allows for that.  It also expects \t to
separate .section directive and name like other similar tests, and escapes
literal dots.

Tested on sparc-sun-solaris2.11 (as and gas) and i386-pc-solaris2.11 (as
and gas).

2023-11-23  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

gcc/testsuite:
* gcc.dg/pr111409.c: Allow for " before .debug_macro.
Quote literals dots.

20 months agobpf: Forces __buildin_memcmp not to generate a call upto 1024 bytes.
Cupertino Miranda [Fri, 10 Nov 2023 16:42:13 +0000 (16:42 +0000)] 
bpf: Forces __buildin_memcmp not to generate a call upto 1024 bytes.

This patch forces __builtin_memcmp calls upto data sizes of 1024 to
become inline in caller.
This is a requirement by BPF and it mimics the default behaviour of the
clang BPF implementation.

gcc/ChangeLog:
* config/bpf/bpf.cc (bpf_use_by_pieces_infrastructure_p): Added
function to bypass default behaviour.
* config/bpf/bpf.h (COMPARE_MAX_PIECES): Defined to 1024 bytes.

20 months agolibstdc++: Include <stdint.h> in <bits/atomic_wait.h>
Jonathan Wakely [Sun, 26 Nov 2023 21:31:05 +0000 (21:31 +0000)] 
libstdc++: Include <stdint.h> in <bits/atomic_wait.h>

This is needed in order to compile it as a header-unit, which might be
desired because it's included by both <atomic> and <semaphore>.

libstdc++-v3/ChangeLog:

* include/bits/atomic_wait.h: Include <stdint.h>.

20 months agolibstdc++: Fix typo in comment
Jonathan Wakely [Mon, 27 Nov 2023 19:08:31 +0000 (19:08 +0000)] 
libstdc++: Fix typo in comment

libstdc++-v3/ChangeLog:

* include/bits/stl_uninitialized.h: Fix typo in comment.

20 months agobpf: Corrected condition in core_mark_as_access_index.
Cupertino Miranda [Thu, 9 Nov 2023 18:54:29 +0000 (18:54 +0000)] 
bpf: Corrected condition in core_mark_as_access_index.

gcc/ChangeLog:
* config/bpf/core-builtins.cc (core_mark_as_access_index):
Corrected check.

20 months agobpf: Delayed the removal of the parser enum plugin handler.
Cupertino Miranda [Wed, 8 Nov 2023 18:23:22 +0000 (18:23 +0000)] 
bpf: Delayed the removal of the parser enum plugin handler.

The parser plugin handler that is responsible for collecting enum values
information was being removed way too early.
bpf_resolve_overloaded_core_builtin is called by the parser.
It was moved to the function execute_lower_bpf_core.

gcc/ChangeLog:
* config/bpf/core-builtins.cc
(bpf_resolve_overloaded_core_builtin): Removed call.
(execute_lower_bpf_core): Added all to remove_parser_plugin.

20 months agolibiberty: Use x86 HW optimized sha1
Jakub Jelinek [Tue, 28 Nov 2023 12:14:05 +0000 (13:14 +0100)] 
libiberty: Use x86 HW optimized sha1

Nick has approved this patch (+ small ld change to use it for --build-id=),
so I'm commiting it to GCC as master as well.

If anyone from ARM would be willing to implement it similarly with
vsha1{cq,mq,pq,h,su0q,su1q}_u32 intrinsics, it could be a useful linker
speedup on those hosts as well, the intent in sha1.c was that
sha1_hw_process_bytes, sha1_hw_process_block functions
would be defined whenever
defined (HAVE_X86_SHA1_HW_SUPPORT) || defined (HAVE_WHATEVERELSE_SHA1_HW_SUPPORT)
but the body of sha1_hw_process_block and sha1_choose_process_bytes
would then have #elif defined (HAVE_WHATEVERELSE_SHA1_HW_SUPPORT) for
the other arch support, similarly for any target attributes on
sha1_hw_process_block if needed.

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

include/
* sha1.h (sha1_process_bytes_fn): New typedef.
(sha1_choose_process_bytes): Declare.
libiberty/
* configure.ac (HAVE_X86_SHA1_HW_SUPPORT): New check.
* sha1.c: If HAVE_X86_SHA1_HW_SUPPORT is defined, include x86intrin.h
and cpuid.h.
(sha1_hw_process_bytes, sha1_hw_process_block,
sha1_choose_process_bytes): New functions.
* config.in: Regenerated.
* configure: Regenerated.

20 months agoRISC-V: Disallow poly (1,1) VLA SLP interleave vectorization
Juzhe-Zhong [Tue, 28 Nov 2023 08:00:33 +0000 (16:00 +0800)] 
RISC-V: Disallow poly (1,1) VLA SLP interleave vectorization

This patch fixes all following ICE in zve64d:

FAIL: gcc.dg/vect/pr71259.c -flto -ffat-lto-objects (internal compiler error: in SET_TYPE_VECTOR_SUBPARTS, at tree.h:4248)
FAIL: gcc.dg/vect/pr71259.c -flto -ffat-lto-objects (test for excess errors)
FAIL: gcc.dg/vect/vect-alias-check-14.c (internal compiler error: in SET_TYPE_VECTOR_SUBPARTS, at tree.h:4248)
FAIL: gcc.dg/vect/vect-alias-check-14.c (test for excess errors)
FAIL: gcc.dg/vect/vect-alias-check-14.c -flto -ffat-lto-objects (internal compiler error: in SET_TYPE_VECTOR_SUBPARTS, at tree.h:4248)
FAIL: gcc.dg/vect/vect-alias-check-14.c -flto -ffat-lto-objects (test for excess errors)
FAIL: gcc.dg/vect/vect-alias-check-9.c (internal compiler error: in SET_TYPE_VECTOR_SUBPARTS, at tree.h:4248)
FAIL: gcc.dg/vect/vect-alias-check-9.c (test for excess errors)
FAIL: gcc.dg/vect/vect-alias-check-9.c -flto -ffat-lto-objects (internal compiler error: in SET_TYPE_VECTOR_SUBPARTS, at tree.h:4248)
FAIL: gcc.dg/vect/vect-alias-check-9.c -flto -ffat-lto-objects (test for excess errors)
FAIL: gcc.dg/vect/vect-cond-arith-6.c (internal compiler error: in SET_TYPE_VECTOR_SUBPARTS, at tree.h:4248)
FAIL: gcc.dg/vect/vect-cond-arith-6.c (test for excess errors)
FAIL: gcc.dg/vect/vect-cond-arith-6.c -flto -ffat-lto-objects (internal compiler error: in SET_TYPE_VECTOR_SUBPARTS, at tree.h:4248)
FAIL: gcc.dg/vect/vect-cond-arith-6.c -flto -ffat-lto-objects (test for excess errors)
FAIL: gcc.dg/vect/vect-gather-5.c (internal compiler error: in SET_TYPE_VECTOR_SUBPARTS, at tree.h:4248)
FAIL: gcc.dg/vect/vect-gather-5.c (test for excess errors)
FAIL: gcc.dg/vect/vect-gather-5.c -flto -ffat-lto-objects (internal compiler error: in SET_TYPE_VECTOR_SUBPARTS, at tree.h:4248)
FAIL: gcc.dg/vect/vect-gather-5.c -flto -ffat-lto-objects (test for excess errors)

poly size (1, 1) vectors can not be allowed to interleave VLA SLP since interleave VLA SLP suppose VF at least hold 2 elements,
whereas, poly size (1,1) may possible only have 1 element.

PR target/112694

gcc/ChangeLog:

* config/riscv/riscv-v.cc (expand_vec_perm_const): Disallow poly size (1, 1) VLA SLP.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/pr112694-2.c: New test.
* gcc.target/riscv/rvv/autovec/pr112694-3.c: New test.

20 months agoada: Fix wrong size value output with -gnatR -gnatc
Eric Botcazou [Thu, 16 Nov 2023 09:29:23 +0000 (10:29 +0100)] 
ada: Fix wrong size value output with -gnatR -gnatc

This happens when a parameter is involved in the computation.

gcc/ada/

* gcc-interface/decl.cc (annotate_value): Apply the same processing
for parameters as for variables.

20 months agoada: Add comment for assertion
Marc Poulhiès [Mon, 6 Nov 2023 10:16:40 +0000 (11:16 +0100)] 
ada: Add comment for assertion

Add possible cause for a failed assertion.

gcc/ada/

* gcc-interface/utils2.cc (build_simple_component_ref): Add
comment on assertion.

20 months agoada: Error compiling reduction expression with overloaded reducer subprogram
Steve Baird [Tue, 14 Nov 2023 20:06:36 +0000 (12:06 -0800)] 
ada: Error compiling reduction expression with overloaded reducer subprogram

In some cases involving a reduction expression with an overloaded reducer
subprogram, the accumulator type is not determined correctly. This can lead
to spurious compile-time errors.

gcc/ada/

* exp_attr.adb (Expand_N_Attribute_Reference): In the case of a
Reduce attribute reference, fix bugs in initializing Accum_Typ.
The previous version was incorrect in the case where E1 refers to
the first of multiple possible overload resolution candidates and
that candidate does not turn out to be the right one. The previous
version also had code to compute Accum_Typ via a different method
if the initial computation turned out to yield a universal numeric
type. Delete that initial computation and use the second method in
all cases.

20 months agoada: Errors on instance of Multiway_Trees with discriminated type
Gary Dismukes [Wed, 15 Nov 2023 23:57:47 +0000 (23:57 +0000)] 
ada: Errors on instance of Multiway_Trees with discriminated type

The compiler may report various type conflicts on an instantiation
of the generic package Ada.Containers.Multiway_Trees with an actual
for Element_Type that is a nonprivate actual type with discriminants
that has a discriminant-dependent component of a private type (such
as a Bounded_Vector type). The type errors occur on an aggregate
of the implementation type Tree_Node_Type within the body of
Multiway_Trees, where the aggregate has a box-defaulted association
for the Element component. (Such type errors could of course arise
in other cases of generic instantiations that follow a similar type
model.)

In the case where the discriminant-dependent component type has a
default-initialization procedure (init proc), the compiler was handling
box associations for such components by expanding the topmost box
association into subaggregates that themselves have box associations,
and didn't properly account for discriminant-dependent subcomponents of
private types. This could be fixed internally in Propagate_Discriminants,
but it seems that the entire machinery for dealing with such subcomponent
associations is unnecessary, and the topmost component association can
be handled directly as a default-initialized box association.

gcc/ada/

* sem_aggr.adb (Add_Discriminant_Values): Remove this procedure.
(Propagate_Discriminants): Remove this procedure.
(Resolve_Record_Aggregate): Remove code (the Capture_Discriminants
block statement) related to propagating discriminants and
generating initializations for subcomponents of a
discriminant-dependent box-defaulted subcomponent of a nonprivate
record type with discriminants, and handle all top-level
components that have a non-null base init proc directly, by
calling Add_Association with "Is_Box_Present => True". Also,
combine that elsif clause with the immediately preceding elsif
clause, since they now both contain the same statement (calls to
Add_Association with the same actuals).

20 months agoada: False alarms from -gnatw.t with generic functions
Bob Duff [Thu, 16 Nov 2023 21:45:13 +0000 (16:45 -0500)] 
ada: False alarms from -gnatw.t with generic functions

Disable the warnings generated by -gnatw.t on instances.
Otherwise, we get false positives.

gcc/ada/

* sem_util.adb (Check_Result_And_Post_State): Disable this when
we're in an instance. Misc cleanup.

20 months agoada: Further cleanup in finalization machinery
Eric Botcazou [Thu, 9 Nov 2023 14:00:56 +0000 (15:00 +0100)] 
ada: Further cleanup in finalization machinery

When transient scopes are being materialized, they can give rise to a block
created around the construct being wrapped or not, depending on the kind of
construct.  In both cases finalization actions for the transient objects of
the scope are generated the same way, with normal finalization done manually
immediately after the construct and exceptional finalization deferred to the
enclosing scope by means of a hooking mechanism.

Now when the block is generated, it becomes this enclosing scope, so the
normal finalization that comes with it would also be done immediately after
the construct, even without normal finalization generated manually.

Therefore this change gets rid of the manual finalization as well as of the
hooking in the cases where the block is generated, leading to a significant
streamlining of the expanded code in these cases.  This requires fixing a
small inaccuracy of the Within_Case_Or_If_Expression predicate, which must
only be concerned with the dependent expressions, since those are the only
ones to be treated specially by the finalization machinery.

It also contains a small cleanup for the description of the transient scope
management present at the beginning of the exp_ch7.adb file.

gcc/ada/

* exp_ch7.ads (Expand_Cleanup_Actions): Move declaration to the
Finalization Management section.
* exp_ch7.adb (Transient Scope Management): Move description down to
after that of the general finalization and make a few changes.
(Insert_Actions_In_Scope_Around): Call Process_Transients_In_Scope
only if cleanups are being handled.
(Process_Transients_In_Scope): Remove redundant test on Clean.
* exp_util.ads (Within_Case_Or_If_Expression): Adjust description.
* exp_util.adb (Within_Case_Or_If_Expression): Only return true if
within the dependent expressions of the conditional expressions.

20 months agoada: Fix incorrect quoting in documentation
Eric Botcazou [Thu, 16 Nov 2023 07:26:33 +0000 (08:26 +0100)] 
ada: Fix incorrect quoting in documentation

gcc/ada/

* doc/gnat_rm/the_implementation_of_standard_i_o.rst: Fix a couple
occurrences of incorrect quoting.
* gnat_rm.texi: Regenerate.

20 months agoada: Fix premature finalization for nested return within extended one
Eric Botcazou [Wed, 8 Nov 2023 22:29:01 +0000 (23:29 +0100)] 
ada: Fix premature finalization for nested return within extended one

The return object is incorrectly finalized when the nested return is taken,
because the special flag attached to the return object is not updated.

gcc/ada/

* exp_ch6.adb (Build_Flag_For_Function): New function made up of the
code building the special flag for return object present...
(Expand_N_Extended_Return_Statement): ...in there.  Replace the code
with a call to Build_Flag_For_Function.  Add assertion for the flag.
(Expand_Non_Function_Return): For a nested return, if the return
object needs finalization actions, update the special flag.

20 months agoada: Add new predicate Is_Address_Compatible_Type
Sebastian Poeplau [Tue, 7 Nov 2023 12:28:25 +0000 (13:28 +0100)] 
ada: Add new predicate Is_Address_Compatible_Type

When emitting code for architectures with tagged pointers, it is useful
to be able to recognize values representing addresses because they
require special handling. This commits adds the predicate
Is_Address_Compatible_Type, which differs from the node attribute
Is_Descendant_Of_Address by also taking Standard_Address into account.

gcc/ada/

* einfo-utils.ads, einfo-utils.adb (Is_Address_Compatible_Type):
New function.

20 months agoada: Type error on container aggregate with loop_parameter_specification
Gary Dismukes [Tue, 7 Nov 2023 22:16:31 +0000 (22:16 +0000)] 
ada: Type error on container aggregate with loop_parameter_specification

The compiler incorrectly reported a type error on a container aggregate
for a Vector type with a loop_parameter_specification specifying a
nonstatic upper bound, complaining that it expected the Vector index
type, but instead found type Count_Type. The expansion of the aggregate
was incorrectly passing a size temporary of type Count_Type to the
function associated with the New_Indexed part of the container type's
Aggregate aspect (New_Vector in the case of Vectors), which has two
formals of the container index type. The fix is to convert the size
temporary to the expected index type.

gcc/ada/

* exp_aggr.adb (Expand_Container_Aggregate): Apply a conversion to the
size temp object passed as the second actual parameter on the call to
the New_Indexed_Subp function, to convert it to the index type of the
container type (taken from the first formal parameter of the function).

20 months agoada: Fix internal error on declare expression in expression function
Eric Botcazou [Mon, 6 Nov 2023 22:34:20 +0000 (23:34 +0100)] 
ada: Fix internal error on declare expression in expression function

When the expression function is not a completion, its (return) expression
does not cause freezing so analyzing the declare expression in this context
must not freeze the type of the object.

The change also contains another fix, which makes it so that the compiler
does not evaluate a nonstatic representation attribute of a scalar subtype
in the same context if the subtype is not already frozen.

gcc/ada/

* sem_attr.adb (Eval_Attribute): Do not proceed in a spec expression
for nonstatic representation attributes of a scalar subtype when the
subtype is not frozen.
* sem_ch3.adb (Analyze_Object_Declaration): Do not freeze the type
of the object in a spec expression.

20 months agoada: Handle unchecked conversion in bound
Richard Kenner [Fri, 3 Nov 2023 22:04:59 +0000 (18:04 -0400)] 
ada: Handle unchecked conversion in bound

Look through both unchecked and normal conversions when seeing if any
part of a bound is uplevel.

gcc/ada/

* exp_unst.adb (Note_Uplevel_Bound): Treat
N_Unchecked_Type_Conversion like N_Type_Conversion.

20 months agoada: Remove dependency on System.Val_Bool in System.Img_Bool
Yannick Moy [Fri, 3 Nov 2023 13:49:30 +0000 (14:49 +0100)] 
ada: Remove dependency on System.Val_Bool in System.Img_Bool

In order to facilitate the certification of System.Img_Bool, remove
its dependency on unit System.Val_Bool. Modify the definition of
ghost function Is_Boolean_Image_Ghost to take the expected boolean
value and move it to System.Val_Spec.

gcc/ada/

* libgnat/s-imgboo.adb: Remove with_clause now in spec file.
* libgnat/s-imgboo.ads: Remove dependency on System.Val_Bool.
(Image_Boolean): Replace call to Value_Boolean by passing value V
to updated ghost function Is_Boolean_Image_Ghost.
* libgnat/s-valboo.ads (Is_Boolean_Image_Ghost): Move to other
unit.
(Value_Boolean.): Update precondition.
* libgnat/s-valspe.ads (Is_Boolean_Image_Ghost): Move here. Add
new parameter for expected boolean value.

20 months agoada: Fix predicate failure that occurred in a test case
Tucker Taft [Sat, 4 Nov 2023 13:53:28 +0000 (13:53 +0000)] 
ada: Fix predicate failure that occurred in a test case

The CodePeer test case illustrating a problem where a "high"
precondition failure was expected, died in the GNAT FE on
input_reading.adb.  The problem was in Check_SCIL, where
it didn't properly handle a discriminant_specification.

gcc/ada/

* sem_scil.adb: Handle discriminant specification.

20 months agotestsuite: Fix up pr111754.c test
Jakub Jelinek [Tue, 28 Nov 2023 09:16:47 +0000 (10:16 +0100)] 
testsuite: Fix up pr111754.c test

On Tue, Nov 28, 2023 at 03:56:47PM +0800, juzhe.zhong@rivai.ai wrote:
> Hi, there is a regression in RISC-V caused by this patch:
>
> FAIL: gcc.dg/vect/pr111754.c -flto -ffat-lto-objects  scan-tree-dump optimized "return { 0.0, 9.0e\\+0, 0.0, 0.0 }"
> FAIL: gcc.dg/vect/pr111754.c scan-tree-dump optimized "return { 0.0, 9.0e\\+0, 0.0, 0.0 }"
>
> I have checked the dump is :
> F foo (F a, F b)
> {
>   <bb 2> [local count: 1073741824]:
>   <retval> = { 0.0, 9.0e+0, 0.0, 0.0 };
>   return <retval>;
>
> }
>
> The dump IR seems reasonable to me.
> I wonder whether we should walk around in RISC-V backend to generate the same IR as ARM SVE ?
> Or we should adjust the test ?

Note, the test also FAILs on i686-linux (but not e.g. on x86_64-linux):
/home/jakub/src/gcc/obj67/gcc/xgcc -B/home/jakub/src/gcc/obj67/gcc/ /home/jakub/src/gcc/gcc/testsuite/gcc.dg/vect/pr111754.c -fdiagnostics-plain-output -O2 -fdump-tree-optimized -S
+-o pr111754.s
/home/jakub/src/gcc/gcc/testsuite/gcc.dg/vect/pr111754.c: In function 'foo':
/home/jakub/src/gcc/gcc/testsuite/gcc.dg/vect/pr111754.c:7:1: warning: SSE vector return without SSE enabled changes the ABI [-Wpsabi]
/home/jakub/src/gcc/gcc/testsuite/gcc.dg/vect/pr111754.c:6:3: note: the ABI for passing parameters with 16-byte alignment has changed in GCC 4.6
/home/jakub/src/gcc/gcc/testsuite/gcc.dg/vect/pr111754.c:6:3: warning: SSE vector argument without SSE enabled changes the ABI [-Wpsabi]
FAIL: gcc.dg/vect/pr111754.c (test for excess errors)
Excess errors:
/home/jakub/src/gcc/gcc/testsuite/gcc.dg/vect/pr111754.c:7:1: warning: SSE vector return without SSE enabled changes the ABI [-Wpsabi]
/home/jakub/src/gcc/gcc/testsuite/gcc.dg/vect/pr111754.c:6:3: warning: SSE vector argument without SSE enabled changes the ABI [-Wpsabi]

PASS: gcc.dg/vect/pr111754.c scan-tree-dump-not optimized "VEC_PERM_EXPR"
FAIL: gcc.dg/vect/pr111754.c scan-tree-dump optimized "return { 0.0, 9.0e\\+0, 0.0, 0.0 }"

So, I think it is wrong to specify
/* { dg-options "-O2 -fdump-tree-optimized" } */
in the test, should be dg-additional-options instead, so that it gets
the implied vector compilation options e.g. for i686-linux (-msse2 in that
case at least), question is if -Wno-psabi should be added as well or not,
and certainly the scan-tree-dump needs to be guarded by appropriate
vect_* effective target (but dunno which, one which asserts support for
V4SFmode and returning it).
Alternatively, perhaps don't check optimized dump but some earlier one
before generic vector lowering, then hopefully it could match on all
targets?  Maybe with the <retval> = ... vs. return ... variants.

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

PR middle-end/111754
* gcc.dg/vect/pr111754.c: Use dg-additional-options rather than
dg-options, add -Wno-psabi and use -fdump-tree-forwprop1 rather than
-fdump-tree-optimized.  Scan forwprop1 dump rather than optimized and
scan for either direct return or setting of <retval> to the vector.

20 months agomatch.pd: Fix parity (X) ^ parity (Y) simplification [PR112719]
Jakub Jelinek [Tue, 28 Nov 2023 09:15:52 +0000 (10:15 +0100)] 
match.pd: Fix parity (X) ^ parity (Y) simplification [PR112719]

When looking around, I've noticed we have a similar simplification
for parity (with ^ rather than +).  Note, unlike the popcount one,
this one doesn't check for INTEGRAL_TYPE_P (type) (which rules out
vector simplification), so I've used the old handling for types_match and
otherwise do it only for scalar argument types and handle different
precision in there.

The testcase ICEs without the previous patch on the first function,
but strangely not on the second which tests parity.  The reason
is that in this case there is no wi::bit_and test like for popcount
and for BITINT_TYPEs build_call_internal actually refuses to create it
and thus the whole simplification fails.  While
.{CLZ,CTZ,CLRSB,FFS,POPCOUNT,PARITY} ifns are direct optab ifns for
normal integer and vector types (and thus it is desirable to punt if
there is no supported optab for them), they have this large/huge _BitInt
extension before bitint lowering, so the patch also adjusts
build_call_internal to allow that case.

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

PR tree-optimization/112719
* match.pd (parity(X)^parity(Y) -> parity(X^Y)): Handle case of
mismatched types.
* gimple-match-exports.cc (build_call_internal): Add special-case for
bit query ifns on large/huge BITINT_TYPE before bitint lowering.

* gcc.dg/bitint-43.c: New test.

20 months agomatch.pd: Fix popcount (X) + popcount (Y) simplification [PR112719]
Jakub Jelinek [Tue, 28 Nov 2023 09:14:55 +0000 (10:14 +0100)] 
match.pd: Fix popcount (X) + popcount (Y) simplification [PR112719]

Since my PR112566 r14-5557 changes the following testcase ICEs, because
.POPCOUNT (x) + .POPCOUNT (y) has a simplification attempted even when
x and y have incompatible types (different precisions).
Note, with _BitInt it can ICE already starting with r14-5435 and
I think as a latent problem it exists for years, because IFN_POPCOUNT
calls inherently can have different argument types and return type
is always the same.
The following patch fixes it by using widest_int during the analysis
(which is where it was ICEing) and if it is optimizable, casting to
the wider type so that bit_ior has matching argument types.

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

PR tree-optimization/112719
* match.pd (popcount (X) + popcount (Y) -> POPCOUNT (X | Y)): Deal
with argument types with different precisions.

20 months agoanalyzer: install header files for use by plugins [PR109077]
David Malcolm [Tue, 28 Nov 2023 08:20:02 +0000 (03:20 -0500)] 
analyzer: install header files for use by plugins [PR109077]

PLUGIN_ANALYZER_INIT was added in r11-5583-g66dde7bc64b75d, but we
haven't been installing the analyzer's headers files.

Fixed thusly.

gcc/ChangeLog:
PR analyzer/109077
* Makefile.in (PLUGIN_HEADERS): Add analyzer headers.
(install-plugin): Keep the directory structure for files in
"analyzer".

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
20 months agolibcpp: Fix unsigned promotion for unevaluated divide by zero [PR112701]
Lewis Hyatt [Mon, 27 Nov 2023 17:08:41 +0000 (12:08 -0500)] 
libcpp: Fix unsigned promotion for unevaluated divide by zero [PR112701]

When libcpp encounters a divide by zero while processing a constant
expression "x/y", it returns "x" as a fallback. The value of the fallback is
not normally important, since an error will be generated anyway, but if the
expression appears in an unevaluated context, such as "0 ? 0/0u : -1", then
there will be no error, and the fallback value will be meaningful to the
extent that it may cause promotion from signed to unsigned of an operand
encountered later. As the PR notes, libcpp does not do the unsigned
promotion correctly in this case; fix it by making the fallback return value
unsigned as necessary.

libcpp/ChangeLog:

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

gcc/testsuite/ChangeLog:

PR preprocessor/112701
* gcc.dg/cpp/expr.c: Add additional tests to cover divide by 0 in an
unevaluated context, where the unsignedness still matters.

20 months agoRISC-V: Fix VSETVL PASS regression
Juzhe-Zhong [Mon, 27 Nov 2023 13:24:12 +0000 (21:24 +0800)] 
RISC-V: Fix VSETVL PASS regression

This patch is regression fix patch, not an optimization patch.
Since trunk GCC generates redundant vsetvl than GCC-13.

This is the case:

bb 2:
  def a2 (vsetvl a2, zero)
bb 3:
  use a2
bb 4:
  use a2 (vle)

before this patch:

bb 2:
vsetvl a2 zero
bb 3:
vsetvl zero, zero ----> should be eliminated.
bb 4:
vle.v

The root cause is we didn't set bb 3 as transparent since the incorrect codes.
bb 3 didn't modify "a2" just use it, the VSETVL status from bb 2 can be available to bb 3 and bb 4:

bb 2 -> bb 3 -> bb4.

Another regression fix is anticipation calculation:

bb 4:
use a5 (sub)
use a5 (vle)

The vle VSETVL status should be considered as anticipated as long as both sub and vle a5 def are coming from same def.

Tested on zvl128b no regression.

I am going to test on zvl256/zvl512/zvl1024

PR target/112713

gcc/ChangeLog:

* config/riscv/riscv-vsetvl.cc (pre_vsetvl::compute_lcm_local_properties): Fix regression.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/vsetvl/pr112713-1.c: New test.
* gcc.target/riscv/rvv/vsetvl/pr112713-2.c: New test.

20 months agodiagnostics: don't print annotation lines when there's no column info
David Malcolm [Tue, 28 Nov 2023 01:09:35 +0000 (20:09 -0500)] 
diagnostics: don't print annotation lines when there's no column info

gcc/ChangeLog:
* diagnostic-show-locus.cc (layout::maybe_add_location_range):
Don't print annotation lines for ranges when there's no column
info.
(selftest::test_one_liner_no_column): New.
(selftest::test_diagnostic_show_locus_one_liner): Call it.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
20 months agodiagnostics: add diagnostic_context::get_location_text
David Malcolm [Tue, 28 Nov 2023 01:09:35 +0000 (20:09 -0500)] 
diagnostics: add diagnostic_context::get_location_text

No functional change intended.

gcc/ChangeLog:
* diagnostic.cc (diagnostic_get_location_text): Convert to...
(diagnostic_context::get_location_text): ...this, and convert
return type from char * to label_text.
(diagnostic_build_prefix): Update for above change.
(default_diagnostic_start_span_fn): Likewise.
(selftest::assert_location_text): Likewise.
* diagnostic.h (diagnostic_context::get_location_text): New decl.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
20 months agoDaily bump.
GCC Administrator [Tue, 28 Nov 2023 00:17:28 +0000 (00:17 +0000)] 
Daily bump.

20 months agoaarch64: Improve cost of `a ? {-,}1 : b`
Andrew Pinski [Sun, 26 Nov 2023 23:25:51 +0000 (23:25 +0000)] 
aarch64: Improve cost of `a ? {-,}1 : b`

While looking into PR 112454, I found the cost for
`(if_then_else (cmp) (const_int 1) (reg))` was being recorded as 8
(or `COSTS_N_INSNS (2)`) but it should have been 4 (or `COSTS_N_INSNS (1)`).
This improves the cost by not adding the cost of `(const_int 1)` to
the total cost.

It does not does not fully fix PR 112454 as that requires other changes to forwprop
the `(const_int 1)` earlier than combine. Though we do fix the loop case where the
constant was only used once.

Bootstrapped and tested on aarch64-linux-gnu with no regressions.

gcc/ChangeLog:

* config/aarch64/aarch64.cc (aarch64_if_then_else_costs):
Handle csinv/csinc case of 1/-1.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/csinc-3.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
20 months agoFix time-profiler-3.c after r14-5628-g53ba8d669550d3
Andrew Pinski [Mon, 27 Nov 2023 18:08:33 +0000 (10:08 -0800)] 
Fix time-profiler-3.c after r14-5628-g53ba8d669550d3

This testcase started to fail after r14-5628-g53ba8d669550d3 because
IPA-VRP can now start to figure out the functions return a constant
value and there was nothing that profiling needed to profile any more.
This disables IPA-VRP for this testcase to be able to profile again.

Bootrapped/tested on x86_64-linux-gnu with no regressions.

gcc/testsuite/ChangeLog:

PR testsuite/112689
* gcc.dg/tree-prof/time-profiler-3.c: Add -fno-ipa-vrp.

20 months agoarm: libgcc: tweak warning from __sync_synchronize
Richard Earnshaw [Mon, 27 Nov 2023 17:59:39 +0000 (17:59 +0000)] 
arm: libgcc: tweak warning from __sync_synchronize

My previous patch to add an implementation of __sync_syncrhonize with
a warning trips a testsuite failure in fortran (and possibly other
languages as well) as the framework expects no blank lines in the
output, but this warning was generating one.  So remove the newline
from the end of the message and rely on the one added by the linker
instead.

Since we're there, remove the trailing period from the message as
well, since the convention seems to be not to have one.

libgcc/

* config/arm/lib1funcs.S (__sync_synchronize): Adjust warning message.

20 months agoPR111754: Rework encoding of result for VEC_PERM_EXPR with constant input vectors.
Prathamesh Kulkarni [Mon, 27 Nov 2023 17:10:49 +0000 (22:40 +0530)] 
PR111754: Rework encoding of result for VEC_PERM_EXPR with constant input vectors.

gcc/ChangeLog:
PR middle-end/111754
* fold-const.cc (fold_vec_perm_cst): Set result's encoding to sel's
encoding, and set res_nelts_per_pattern to 2 if sel contains stepped
sequence but input vectors do not.
(test_nunits_min_2): New test Case 8.
(test_nunits_min_4): New tests Case 8 and Case 9.

gcc/testsuite/ChangeLog:
PR middle-end/111754
* gcc.target/aarch64/sve/slp_3.c: Adjust code-gen.
* gcc.target/aarch64/sve/slp_4.c: Likewise.
* gcc.dg/vect/pr111754.c: New test.

Co-authored-by: Richard Sandiford <richard.sandiford@arm.com>
20 months agoaarch64: Disable branch-protection for pcs tests
Szabolcs Nagy [Fri, 2 Jun 2023 12:06:21 +0000 (13:06 +0100)] 
aarch64: Disable branch-protection for pcs tests

The tests manipulate the return address in abitest-2.h and thus not
compatible with -mbranch-protection=pac-ret+leaf or
-mbranch-protection=gcs.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/aapcs64/func-ret-1.c: Disable branch-protection.
* gcc.target/aarch64/aapcs64/func-ret-2.c: Likewise.
* gcc.target/aarch64/aapcs64/func-ret-3.c: Likewise.
* gcc.target/aarch64/aapcs64/func-ret-4.c: Likewise.
* gcc.target/aarch64/aapcs64/func-ret-64x1_1.c: Likewise.

20 months agoaarch64: Add eh_return compile tests
Szabolcs Nagy [Fri, 2 Jun 2023 13:17:02 +0000 (14:17 +0100)] 
aarch64: Add eh_return compile tests

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/eh_return-2.c: New test.
* gcc.target/aarch64/eh_return-3.c: New test.

20 months agoaarch64: Do not force a stack frame for EH returns
Szabolcs Nagy [Tue, 9 May 2023 10:07:05 +0000 (11:07 +0100)] 
aarch64: Do not force a stack frame for EH returns

EH returns no longer rely on clobbering the return address on the stack
so forcing a stack frame is not necessary.

This does not actually change the code gen for the unwinder since there
are calls before the EH return.

gcc/ChangeLog:

* config/aarch64/aarch64.cc (aarch64_needs_frame_chain): Do not
force frame chain for eh_return.

20 months agoaarch64: Use br instead of ret for eh_return
Szabolcs Nagy [Wed, 26 Apr 2023 13:28:32 +0000 (14:28 +0100)] 
aarch64: Use br instead of ret for eh_return

The expected way to handle eh_return is to pass the stack adjustment
offset and landing pad address via

  EH_RETURN_STACKADJ_RTX
  EH_RETURN_HANDLER_RTX

to the epilogue that is shared between normal return paths and the
eh_return paths.  EH_RETURN_HANDLER_RTX is the stack slot of the
return address that is overwritten with the landing pad in the
eh_return case and EH_RETURN_STACKADJ_RTX is a register added to sp
right before return and it is set to 0 in the normal return case.

The issue with this design is that eh_return and normal return may
require different return sequence but there is no way to distinguish
the two cases in the epilogue (the stack adjustment may be 0 in the
eh_return case too).

The reason eh_return and normal return requires different return
sequence is that control flow integrity hardening may need to treat
eh_return as a forward-edge transfer (it is not returning to the
previous stack frame) and normal return as a backward-edge one.
In case of AArch64 forward-edge is protected by BTI and requires br
instruction and backward-edge is protected by PAUTH or GCS and
requires ret (or authenticated ret) instruction.

This patch resolves the issue by introducing EH_RETURN_TAKEN_RTX that
is a flag set to 1 in the eh_return path and 0 in normal return paths.
Branching on the EH_RETURN_TAKEN_RTX flag, the right return sequence
can be used in the epilogue.

The handler could be passed the old way via clobbering the return
address, but since now the eh_return case can be distinguished, the
handler can be in a different register than x30 and no stack frame
is needed for eh_return.

This patch fixes a return to anywhere gadget in the unwinder with
existing standard branch protection as well as makes EH return
compatible with the Guarded Control Stack (GCS) extension.

Some tests are adjusted because eh_return no longer prevents pac-ret
in the normal return path.

gcc/ChangeLog:

* config/aarch64/aarch64-protos.h (aarch64_eh_return_handler_rtx):
Remove.
* config/aarch64/aarch64.cc (aarch64_return_address_signing_enabled):
Sign return address even in functions with eh_return.
(aarch64_expand_epilogue): Conditionally return with br or ret.
(aarch64_eh_return_handler_rtx): Remove.
* config/aarch64/aarch64.h (EH_RETURN_TAKEN_RTX): Define.
(EH_RETURN_STACKADJ_RTX): Change to R5.
(EH_RETURN_HANDLER_RTX): Change to R6.
* df-scan.cc: Handle EH_RETURN_TAKEN_RTX.
* doc/tm.texi: Regenerate.
* doc/tm.texi.in: Document EH_RETURN_TAKEN_RTX.
* except.cc (expand_eh_return): Handle EH_RETURN_TAKEN_RTX.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/return_address_sign_1.c: Move func4 to ...
* gcc.target/aarch64/return_address_sign_2.c: ... here and fix the
scan asm check.
* gcc.target/aarch64/return_address_sign_b_1.c: Move func4 to ...
* gcc.target/aarch64/return_address_sign_b_2.c: ... here and fix the
scan asm check.

20 months agoGCN: Remove 'last_arg' spec function
Thomas Schwinge [Wed, 22 Nov 2023 14:39:50 +0000 (15:39 +0100)] 
GCN: Remove 'last_arg' spec function

The LLVM 13.0.1 assembler ('llvm-mc') indeed still does complain in presence of
multiple '-mcpu=[...]' options:

    as: for the --mcpu option: may only occur zero or one times!

However, as of
"GCN: Tag '-march=[...]', '-mtune=[...]' as 'Negative' of themselves [PR112669]",
the GCC-side special handling is no longer necessary.

gcc/
* config.gcc <amdgcn-*-amdhsa> (extra_gcc_objs): Don't set.
* config/gcn/driver-gcn.cc: Remove.
* config/gcn/gcn-hsa.h (ASM_SPEC, EXTRA_SPEC_FUNCTIONS): Remove
'last_arg' spec function.
* config/gcn/t-gcn-hsa (driver-gcn.o): Remove.

20 months agoGCN: Tag '-march=[...]', '-mtune=[...]' as 'Negative' of themselves [PR112669]
Thomas Schwinge [Wed, 22 Nov 2023 16:35:23 +0000 (17:35 +0100)] 
GCN: Tag '-march=[...]', '-mtune=[...]' as 'Negative' of themselves [PR112669]

Certain other command-line flags are mutually exclusive (random example: GCN
'-march=gfx906', '-march=gfx908').  If they're not appropriately marked up,
this does disturb the multilib selection machinery, for example:

    $ build-gcc-offload-amdgcn-amdhsa/gcc/xgcc -print-multi-directory -march=gfx906
    gfx906
    $ build-gcc-offload-amdgcn-amdhsa/gcc/xgcc -print-multi-directory -march=gfx908
    gfx908
    $ build-gcc-offload-amdgcn-amdhsa/gcc/xgcc -print-multi-directory -march=gfx906 -march=gfx908
    .

In the last invocation, '-march=gfx900 -march=gfx906', for example, in
'gcc/gcc.cc:set_multilib_dir' we see both flags -- which there doesn't exist a
matching multilib for, therefore we "fail" to the default ('.').  Tagges as
'Negative', only the last flag survives, and we, for example, get the expected:

    $ build-gcc-offload-amdgcn-amdhsa/gcc/xgcc -print-multi-directory -march=gfx906 -march=gfx908
    gfx908

I quickly found that the same also applies to GCN's '-mtune=[...]', but I've
not otherwise reviewed the GCN options.

PR target/112669
gcc/
* config/gcn/gcn.opt (march=, mtune=): Tag as 'Negative' of
themselves.

20 months agohurd: Ad default-pie and static-pie support
Samuel Thibault [Sat, 6 May 2023 11:55:44 +0000 (13:55 +0200)] 
hurd: Ad default-pie and static-pie support

This fixes the Hurd spec in the default-pie case, and adds static-pie
support.

gcc/ChangeLog:

* config/i386/gnu.h: Use PIE_SPEC, add static-pie case.
* config/i386/gnu64.h: Use PIE_SPEC, add static-pie case.

20 months agohurd: Add multilib paths for gnu-x86_64
Samuel Thibault [Sat, 6 May 2023 11:50:36 +0000 (13:50 +0200)] 
hurd: Add multilib paths for gnu-x86_64

We need the multilib paths in gcc to find e.g. glibc crt files on
Debian.  This is essentially based on t-linux64 version.

gcc/ChangeLog:

* config/i386/t-gnu64: New file.
* config.gcc [x86_64-*-gnu*]: Add i386/t-gnu64 to
tmake_file.

20 months agoaarch64: Remove redundant zeroing/merging in SVE intrinsics [PR106326]
Richard Sandiford [Mon, 27 Nov 2023 14:44:02 +0000 (14:44 +0000)] 
aarch64: Remove redundant zeroing/merging in SVE intrinsics [PR106326]

Many predicated SVE intrinsics provide three forms of predication:
zeroing, merging, and any/dont-care.  All three are equivalent when
the predicate is all-true, so this patch drops the zeroing and
merging in that case.

gcc/
PR target/106326
* config/aarch64/aarch64-sve-builtins.h (is_ptrue): Declare.
* config/aarch64/aarch64-sve-builtins.cc (is_ptrue): New function.
(gimple_folder::redirect_pred_x): Likewise.
(gimple_folder::fold): Use it.

gcc/testsuite/
PR target/106326
* gcc.target/aarch64/sve/acle/general/pr106326_1.c: New test.

20 months agoaarch64: Move and generalise vect_all_same
Richard Sandiford [Mon, 27 Nov 2023 14:44:02 +0000 (14:44 +0000)] 
aarch64: Move and generalise vect_all_same

The fix for PR106329 needs a way of testing for a ptrue of a particular
element size.  We already had such a function for svlast, so this patch
moves it to common code and generalises it to work with all kinds of
vectors.

gcc/
* config/aarch64/aarch64-sve-builtins.h (vector_cst_all_same): Declare.
* config/aarch64/aarch64-sve-builtins.cc (vector_cst_all_same): New
function, a generalized replacement of...
* config/aarch64/aarch64-sve-builtins-base.cc
(svlast_impl::vect_all_same): ...this.
(svlast_impl::fold): Update accordingly.