Marek Polacek [Thu, 29 Sep 2022 21:49:32 +0000 (17:49 -0400)]
c-family: ICE with [[gnu::nocf_check]] [PR106937]
When getting the name of an attribute, we ought to use
get_attribute_name, which handles both [[]] and __attribute__(())
forms. Failure to do so may result in an ICE, like here.
pp_c_attributes_display wasn't able to print the [[]] form of
attributes, so this patch teaches it to.
When printing a pointer to function with a standard attribute, the attribute
should be printed after the parameter-list. With this patch we print:
aka 'void (*)(int) [[gnu::nocf_check]]'
or, in C++ with noexcept:
aka 'void (*)(int) noexcept [[gnu::nocf_check]]'
pp_c_attributes has been unused since its introduction in r56273 so
this patch removes it.
PR c++/106937
gcc/c-family/ChangeLog:
* c-pretty-print.cc (pp_c_specifier_qualifier_list): Print only GNU
attributes here.
(c_pretty_printer::direct_abstract_declarator): Print the standard [[]]
attributes here.
(pp_c_attributes): Remove.
(pp_c_attributes_display): Print the [[]] form if appropriate. Use
get_attribute_name. Don't print a trailing space when printing the
[[]] form.
* c-pretty-print.h (pp_c_attributes): Remove.
gcc/cp/ChangeLog:
* error.cc: Include "attribs.h".
(dump_type_prefix): Print only GNU attributes here.
(dump_type_suffix): Print standard attributes here.
gcc/testsuite/ChangeLog:
* c-c++-common/pointer-to-fn1.c: New test.
Andrea Corallo [Tue, 27 Sep 2022 14:20:28 +0000 (16:20 +0200)]
Don't ICE running selftests if errors were raised [PR99723]
Hi all
this is to address PR 99723.
In the PR GCC crashes as the initialization of common trees is not
performed as no compilation is happening, this is because we raise an
error earlier while processing the arch flags.
This patch changes the code to execute selftests only if no errors
where raised before.
Bootstrapped on aarch64, okay for trunk?
Best Regards
Andrea
2022-09-27 Andrea Corallo <andrea.corallo@arm.com>
PR other/99723
* toplev.cc (toplev::main): Don't run self tests in case of
previous error.
Kito Cheng [Fri, 7 Oct 2022 08:55:14 +0000 (16:55 +0800)]
RISC-V: Add riscv_vector.h wrapper in testsuite to prevent pull in stdint.h from C library
For RISC-V linux/glibc toolchain will got header file not found when including
stdint.h if multilib is not enabled, it because some header file will
try to include gnu/stubs-<ABI-NAME>.h from the system, however it only
generated when multilib enabled.
In order to prevent that, we introduce a wrapper for riscv_vector.h,
include stdint-gcc.h rather than the default stdint.h.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/rvv/base/riscv_vector.h: New.
Reported-by: Christoph Müllner <christoph.muellner@vrull.eu>
Tested-by: Christoph Müllner <christoph.muellner@vrull.eu>
Reviewed-by: Ju-Zhe Zhong <juzhe.zhong@rivai.ai>
Kito Cheng [Fri, 7 Oct 2022 08:54:05 +0000 (16:54 +0800)]
RISC-V: Adjust testcase for rvv/base/user-1.c
The -march option check isn't precise enough, -march=rv*v* also mach any
zve extensions.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/rvv/base/user-1.c: Add dg-options and drop
dg-skip-if.
Reported-by: Christoph Müllner <christoph.muellner@vrull.eu>
Tested-by: Christoph Müllner <christoph.muellner@vrull.eu>
Reviewed-by: Ju-Zhe Zhong <juzhe.zhong@rivai.ai>
Kito Cheng [Mon, 10 Oct 2022 13:05:50 +0000 (21:05 +0800)]
RISC-V: Add newline to the end of file [NFC]
gcc/ChangeLog:
* config/riscv/riscv-c.cc: Add newline to the end of file.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/rvv/base/pragma-1.c: Add newline to the end of file.
* gcc.target/riscv/rvv/base/pragma-2.c: Ditto.
* gcc.target/riscv/rvv/base/pragma-3.c: Ditto.
* gcc.target/riscv/rvv/base/user-1.c: Ditto.
* gcc.target/riscv/rvv/base/user-2.c: Ditto.
* gcc.target/riscv/rvv/base/user-3.c: Ditto.
* gcc.target/riscv/rvv/base/user-4.c: Ditto.
* gcc.target/riscv/rvv/base/user-5.c: Ditto.
* gcc.target/riscv/rvv/base/user-6.c: Ditto.
* gcc.target/riscv/rvv/base/vread_csr.c: Ditto.
* gcc.target/riscv/rvv/base/vwrite_csr.c: Ditto.
Aldy Hernandez [Mon, 10 Oct 2022 11:46:32 +0000 (13:46 +0200)]
Make range-op-float entries public.
gcc/ChangeLog:
* range-op-float.cc (class foperator_identity): Make members public.
(class foperator_equal): Same.
(class foperator_not_equal): Same.
(class foperator_lt): Same.
(class foperator_le): Same.
(class foperator_gt): Same.
(class foperator_ge): Same.
(class foperator_unordered): Same.
(class foperator_ordered): Same.
Aldy Hernandez [Mon, 10 Oct 2022 11:43:16 +0000 (13:43 +0200)]
Add frange::maybe_isnan (bool sign).
It is useful to know if there's the possiblity of a NAN with a given
sign. This is to complement maybe_isnan(void) which returns TRUE for a
NAN of any sign.
A follow-up patch implementing ABS will make use of this.
gcc/ChangeLog:
* value-range.h (frange::maybe_isnan): New.
Aldy Hernandez [Mon, 10 Oct 2022 09:15:43 +0000 (11:15 +0200)]
The true side of x != x should set NAN.
gcc/ChangeLog:
* range-op-float.cc (foperator_not_equal::op1_range): Set NAN on
TRUE side for x != x.
Aldy Hernandez [Mon, 10 Oct 2022 09:01:48 +0000 (11:01 +0200)]
x UNORD x should set NAN on the TRUE side (and !NAN on the FALSE side).
gcc/ChangeLog:
* range-op-float.cc (foperator_unordered::op1_range): Set NAN when
operands are equal and result is TRUE.
Aldy Hernandez [Mon, 10 Oct 2022 11:43:56 +0000 (13:43 +0200)]
Return non-legacy ranges in range.h.
int_range<1> is a legacy range (think anti ranges, legacy VRP, etc).
There is a penalty for converting anything built with <1> to
non-legacy. Since most of the uses of these functions are now ranger,
we can save a miniscule amount of time by converting them to
non-legacy.
gcc/ChangeLog:
* range.h (range_true): Return int_range<2>.
(range_false): Same.
(range_true_and_false): Same.
Jonathan Wakely [Fri, 7 Oct 2022 11:18:57 +0000 (12:18 +0100)]
libstdc++: std::make_signed_t<cv bool> should be ill-formed
Currently we only reject std::make_signed_t<bool> but not cv bool.
Similarly for std::make_unsigned_t<cv bool>.
As well as making those ill-formed, this adds a requires-clause to the
make_signed and make_unsigned primary templates. This makes
non-integral, non-enum cases fail immediately with a clear error, rather
than giving an error about __make_signed_selector<T, false, false> being
incomplete.
libstdc++-v3/ChangeLog:
* include/std/type_traits (make_signed, make_unsigned): Add
specializations for cv bool. Add requires-clause for C++20 to
improve diagnostics for non-integral, non-enum cases.
* testsuite/20_util/make_signed/requirements/typedefs_neg.cc:
Check cv bool.
* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc:
Likewise.
* testsuite/24_iterators/range_access/range_access_cpp20_neg.cc:
Adjust expected errors for C++20 and later.
* testsuite/lib/prune.exp: Prune "in requirements [with ...]"
lines from diagnostics.
Jakub Jelinek [Mon, 10 Oct 2022 10:04:56 +0000 (12:04 +0200)]
Require fgraphite effective target for pr107153.c test [PR107153]
The test uses -floop-parallelize-all which emits a sorry when graphite
isn't configured in.
2022-10-10 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/107153
* gcc.dg/autopar/pr107153.c: Require fgraphite effective target.
Aldy Hernandez [Wed, 5 Oct 2022 18:23:15 +0000 (20:23 +0200)]
Add op1_range for __builtin_signbit.
This is the op1_range range-op entry for __builtin_signbit. It allows
us to wind back through a call to signbit.
For example, on the true side of if (__builtin_signbit(x_5) != 0) we
can crop down the range of x_5 to:
[frange] float [-Inf, -0.0 (-0x0.0p+0)] -NAN
Similarly on the false side, we can crop to:
[frange] float [0.0 (0x0.0p+0), +Inf] +NAN
Tested on x86-64 Linux.
gcc/ChangeLog:
* gimple-range-op.cc: Add op1_range entry for __builtin_signbit.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/vrp-float-signbit-3.c: New test.
liuhongt [Sun, 9 Oct 2022 07:30:10 +0000 (15:30 +0800)]
Fix unrecognizable insn of cvtss2si.
Adjust lrintmn2 operand preidcates according to real instructions.
gcc/ChangeLog:
PR target/107185
* config/i386/i386.md (lrint<MODEF:mode><SWI48:mode>2): Swap
predicate of operands[0] and operands[1].
gcc/testsuite/ChangeLog:
* gcc.target/i386/pr107185.c: New test.
Jakub Jelinek [Mon, 10 Oct 2022 07:34:35 +0000 (09:34 +0200)]
openmp, fortran: Fix up IFN_ASSUME call
Like in other spots in trans-openmp.cc that create a TARGET_EXPR, the
slot has to be created with create_tmp_var_raw, because gfc_create_var
adds the var to BLOCK_VARS and that ICEs during expansion because
gimple_add_tmp_var_fn has:
gcc_assert (!DECL_CHAIN (tmp) && !DECL_SEEN_IN_BIND_EXPR_P (tmp));
assertion. Also, both C/C++ ensure the argument to IFN_ASSUME has
boolean_type_node, it is easier if Fortran does that too.
2022-10-10 Jakub Jelinek <jakub@redhat.com>
* trans-openmp.cc (gfc_trans_omp_assume): Use create_tmp_var_raw
instead of gfc_create_var for TARGET_EXPR slot creation. Create it
with boolean_type_node and convert.
Claudiu Zissulescu [Mon, 10 Oct 2022 07:27:12 +0000 (10:27 +0300)]
arc: Remove obsolete mRcq and mRcw options.
gcc/
* common/config/arc/arc-common.cc (arc_option_optimization_table):
Remove Rcq and Rcw options.
* config/arc/arc.opt (mRcq): Ignore option, preserve it for
backwards compatibility.
(mRcw): Likewise.
* doc/invoke.texi (mRcw, mRcq): Update document.
Signed-off-by: Claudiu Zissulescu <claziss@gmail.com>
Claudiu Zissulescu [Mon, 10 Oct 2022 07:27:12 +0000 (10:27 +0300)]
arc: Remove Rcq constraint.
gcc/
* config/arc/arc.cc (arc_check_short_reg_p): New function.
(arc_address_cost): Replace satisfies_constraint_Rcq with the
above new function.
(arc_output_addsi): Likewise.
(split_addsi): Likewise.
(split_subsi): Likewise.
* config/arc/arc.md (movqi_insn): Remove Rcq constraint.
(movhi_insn): Likewise.
(movsi_insn): Likewise.
(tst_movb): Likewise.
(tst): Likewise.
(tst_bitfield): Likewise.
(abssi2): Likewise.
(addsi3_mixed): Likewise.
(mulhisi3_reg): Likewise.
(umulhisi3_reg): Likewise.
(mulsi_600): Likewise.
(mul64): Likewise.
(subsi3_insn): Likewise.
(bicsi3_insn): Likewise.
(xorsi3): Likewise.
(negsi2): Likewise.
(one_cmplsi2): Likewise.
(lshrsi3_insn): Likewise.
(cmpsi_cc_insn_mixed): Likewise.
(cmpsi_cc_zn_insn): Likewise.
(btst): Likewise.
(cmpsi_cc_z_insn): Likewise.
(cmpsi_cc_c_insn): Likewise.
(indirect_jump): Likewise.
(casesi_jump): Likewise.
(call_i): Likewise.
(call_value_i): Likewise.
(bbit): Likewise.
(abssf2): Likewise.
(ashlsi2_cnt1): Likewise.
(lshrsi3_cnt1): Likewise.
(ashrsi3_cnt1): Likewise.
* config/arc/constraints.md (Rcq): Remove.
Signed-off-by: Claudiu Zissulescu <claziss@gmail.com>
Claudiu Zissulescu [Mon, 10 Oct 2022 07:27:12 +0000 (10:27 +0300)]
arc: Remove Rcw constraint
gcc/Changelog:
* config/arc/arc.md (smaxsi3): Remove Rcw.
(sminsi3): Likewise.
(addsi3_mixed): Likewise.
(add_f_2): Likewise.
(subsi3_insn): Likewise.
(sub_f): Likewise.
(sub_n): Likewise.
(bset): Likewise.
(bxor): Likewise.
(bclr): Likewise.
(bset_insn): Likewise.
(bxor_insn): Likewise.
(bclr_insn): Likewise.
(bmsk_insn): Likewise.
(bicsi3_insn): Likewise.
(xorsi3): Likewise.
(negsi2): Likewise.
(lshrsi3_insn): Likewise.
(abssf2): Likewise.
(negsf2): Likewise.
* config/arc/constraints.md(Rcw): Remove it.
Signed-off-by: Claudiu Zissulescu <claziss@gmail.com>
Claudiu Zissulescu [Mon, 10 Oct 2022 07:27:12 +0000 (10:27 +0300)]
arc: Remove Rcr constraint
gcc/ChangeLog:
* config/arc/arc.md(mulsi3_700): Remove Rcr.
(mulsi3_highpart): Likewise.
(umulsi3_highpart_i): Likewise.
(umulsi3_highpart_int): Likewise.
(macd): Likewise.
(macdu): Likewise.
* config/arc/constraints.md (Rcr): Remove it.
gcc/testsuite/ChangeLog:
* gcc.target/arc/tmac-2.c: Update test.
Signed-off-by: Claudiu Zissulescu <claziss@gmail.com>
Claudiu Zissulescu [Mon, 10 Oct 2022 07:27:12 +0000 (10:27 +0300)]
arc: Use negative enter pattern instruction's offsets
The enter pattern instruction contains the necessary information for
the dwarf machinery to generate the appropriate dwarf code. This
patch is fixing the register offsets related to CFA, and adds a test.
gcc/
* config/arc/arc.cc (arc_save_callee_enter): Use negative offsets.
gcc/testsuite
* gcc.target/arc/enter-dw2-1.c: New file.
Signed-off-by: Claudiu Zissulescu <claziss@gmail.com>
LIU Hao [Fri, 27 May 2022 15:12:48 +0000 (23:12 +0800)]
libgfortran: Use `__gthread_t` instead of `pthread_t`
It used to cause errors if a thread model other than `posix` was selected,
which looks like a leftover from
a79878585a1c5e32bafbc6d1e73f91fd6e4293bf.
libgfortran/
* io/async.h (struct async_unit): Use `__gthread_t` instead
of `pthread_t`.
Signed-off-by: LIU Hao <lh_mouse@126.com>
Signed-off-by: Jonathan Yong <10walls@gmail.com>
GCC Administrator [Mon, 10 Oct 2022 00:16:29 +0000 (00:16 +0000)]
Daily bump.
Dimitar Dimitrov [Sun, 18 Sep 2022 13:27:18 +0000 (16:27 +0300)]
pru: Add cbranchdi4 pattern
Manually expanding into 32-bit comparisons is much more efficient than
the default expansion into word-size comparisons. Note that word for PRU
is 8-bit.
PR target/106562
gcc/ChangeLog:
* config/pru/pru-protos.h (pru_noteq_condition): New
function declaration.
* config/pru/pru.cc (pru_noteq_condition): New function.
* config/pru/pru.md (cbranchdi4): Define new pattern.
gcc/testsuite/ChangeLog:
* gcc.target/pru/pr106562-1.c: New test.
* gcc.target/pru/pr106562-2.c: New test.
* gcc.target/pru/pr106562-3.c: New test.
* gcc.target/pru/pr106562-4.c: New test.
Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
Dimitar Dimitrov [Thu, 22 Sep 2022 20:08:43 +0000 (23:08 +0300)]
pru: Optimize DI shifts
If the number of shift positions is a constant, then the DI shift
operation is expanded to a sequence of 2 to 4 machine instructions.
That is more efficient than the default action to call libgcc.
gcc/ChangeLog:
* config/pru/pru.md (lshrdi3): New expand pattern.
(ashldi3): Ditto.
gcc/testsuite/ChangeLog:
* gcc.target/pru/ashiftdi-1.c: New test.
* gcc.target/pru/lshiftrtdi-1.c: New test.
Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
YunQiang Su [Tue, 2 Aug 2022 10:57:18 +0000 (10:57 +0000)]
MIPS: improve -march=native arch detection
If we cannot get info from options and cpuinfo, we try to get from:
1. getauxval(AT_BASE_PLATFORM), introduced since Linux 5.7
2. _MIPS_ARCH from host compiler.
mnan=2008 option is also used if __mips_nan2008__ is used.
This can fix the wrong loader usage on r5/r6 platform with
-march=native.
gcc/ChangeLog:
* config.gcc: set with_arch to default_mips_arch if no defined.
* config/mips/driver-native.cc (host_detect_local_cpu):
try getauxval(AT_BASE_PLATFORM) and _MIPS_ARCH, too.
pass -mnan=2008 if __mips_nan2008__ is defined.
* config.in: define HAVE_SYS_AUXV_H and HAVE_GETAUXVAL.
* configure.ac: detect sys/auxv.h and getauxval.
* configure: regenerated.
GCC Administrator [Sun, 9 Oct 2022 00:17:55 +0000 (00:17 +0000)]
Daily bump.
Harald Anlauf [Tue, 4 Oct 2022 21:04:06 +0000 (23:04 +0200)]
Fortran: error recovery for invalid types in array constructors [PR107000]
gcc/fortran/ChangeLog:
PR fortran/107000
* arith.cc (gfc_arith_error): Define error message for
ARITH_INVALID_TYPE.
(reduce_unary): Catch arithmetic expressions with invalid type.
(reduce_binary_ac): Likewise.
(reduce_binary_ca): Likewise.
(reduce_binary_aa): Likewise.
(eval_intrinsic): Likewise.
(gfc_real2complex): Source expression must be of type REAL.
* gfortran.h (enum arith): Add ARITH_INVALID_TYPE.
gcc/testsuite/ChangeLog:
PR fortran/107000
* gfortran.dg/pr107000.f90: New test.
Co-authored-by: Mikael Morin <mikael@gcc.gnu.org>
Jason Merrill [Sat, 17 Sep 2022 10:04:05 +0000 (12:04 +0200)]
c++: track whether we expect a TARGET_EXPR to be elided
A discussion at Cauldron made me think that with the formalization of copy
elision in C++17, we should be able to determine before optimization which
TARGET_EXPRs will become temporaries and which are initializers. This patch
implements that: we set TARGET_EXPR_ELIDING_P if it's used as an
initializer, and later check that we were right.
There's an exception in the cp_gimplify_expr check to allow extra
temporaries of non-addressable type: this is used by
gimplify_init_ctor_preeval to materialize subobjects of a CONSTRUCTOR on the
rhs of a MODIFY_EXPR rather than materializing the whole object. If the
type isn't addressable, there's no way for a program to tell the difference,
so this is a valid optimization.
I considered changing replace_placeholders_for_class_temp_r to check
TARGET_EXPR_ELIDING_P instead of potential_prvalue_result_of, but decided
that would be wrong: if we have an eliding TARGET_EXPR inside a non-eliding
one, we would miss replacing its placeholders.
gcc/cp/ChangeLog:
* cp-tree.h (TARGET_EXPR_ELIDING_P): New.
(unsafe_copy_elision_p, set_target_expr_eliding)
(cp_build_init_expr): Declare.
* call.cc (unsafe_copy_elision_p): No longer static.
(build_over_call, build_special_member_call)
(build_new_method_call): Use cp_build_init_expr.
* coroutines.cc (expand_one_await_expression)
(build_actor_fn, flatten_await_stmt, handle_nested_conditionals)
(await_statement_walker, morph_fn_to_coro): Use cp_build_init_expr.
* cp-gimplify.cc (cp_gimplify_init_expr)
(cp_gimplify_expr): Check TARGET_EXPR_ELIDING_P.
(cp_fold_r): Propagate it.
(cp_fold): Use cp_build_init_expr.
* decl.cc (check_initializer): Use cp_build_init_expr.
* except.cc (build_throw): Use cp_build_init_expr.
* init.cc (get_nsdmi): Call set_target_expr_eliding.
(perform_member_init, expand_default_init, expand_aggr_init_1)
(build_new_1, build_vec_init): Use cp_build_init_expr.
* method.cc (do_build_copy_constructor): Use cp_build_init_expr.
* semantics.cc (simplify_aggr_init_expr, finalize_nrv_r)
(finish_omp_reduction_clause): Use cp_build_init_expr.
* tree.cc (build_target_expr): Call set_target_expr_eliding.
(bot_manip): Copy TARGET_EXPR_ELIDING_P.
* typeck.cc (cp_build_modify_expr): Call set_target_expr_eliding.
(check_return_expr): Use cp_build_modify_expr.
* typeck2.cc (split_nonconstant_init_1)
(split_nonconstant_init): Use cp_build_init_expr.
(massage_init_elt): Call set_target_expr_eliding.
(process_init_constructor_record): Clear TARGET_EXPR_ELIDING_P on
unsafe copy elision.
(set_target_expr_eliding, cp_build_init_expr): New.
GCC Administrator [Sat, 8 Oct 2022 00:17:29 +0000 (00:17 +0000)]
Daily bump.
Marek Polacek [Wed, 5 Oct 2022 19:51:30 +0000 (15:51 -0400)]
c++: fixes for derived-to-base reference binding [PR107085]
This PR reports that
struct Base {};
struct Derived : Base {};
static_assert(__reference_constructs_from_temporary(Base const&, Derived));
doesn't pass, which it should: it's just like
const Base& b(Derived{});
where we bind 'b' to the Base subobject of a temporary object of type
Derived. The ck_base conversion didn't have ->need_temporary_p set because
we didn't need to create a temporary object just for the base, but the whole
object is a temporary so we're still binding to a temporary. Since the
Base subobject is an xvalue, a new function is introduced.
PR c++/107085
gcc/cp/ChangeLog:
* call.cc (conv_binds_ref_to_temporary): New.
(ref_conv_binds_directly): Rename to...
(ref_conv_binds_to_temporary): ...this. Use
conv_binds_ref_to_temporary.
* cp-tree.h (ref_conv_binds_directly): Rename to...
(ref_conv_binds_to_temporary): ...this.
* method.cc (ref_xes_from_temporary): Use ref_conv_binds_to_temporary.
* parser.cc (warn_for_range_copy): Likewise.
gcc/testsuite/ChangeLog:
* g++.dg/ext/reference_constructs_from_temporary1.C: Adjust expected
result.
* g++.dg/ext/reference_converts_from_temporary1.C: Likewise.
* g++.dg/cpp0x/elision4.C: New test.
Eugene Rozenfeld [Thu, 21 Apr 2022 23:43:24 +0000 (16:43 -0700)]
Set discriminators for call stmts on the same line within the same basic block.
Call statements are possible split points of a basic block so they may end up
in different basic blocks by the time pass_ipa_auto_profile executes.
This change will also simplify call site lookups since now location with discriminator
will uniquely identify the call site (no callee function name is needed).
This change is based on commit
1e6c4a7a8fb8e20545bb9f9032d3854f3f794c18
by Dehao Chen in vendors/google/heads/gcc-4_8.
Tested on x86_64-pc-linux-gnu.
gcc/ChangeLog:
* tree-cfg.cc (assign_discriminators): Set discriminators for call stmts
on the same line within the same basic block.
Qing Zhao [Fri, 7 Oct 2022 14:59:01 +0000 (14:59 +0000)]
Use array_at_struct_end_p in __builtin_object_size [PR101836]
Use array_at_struct_end_p to determine whether the trailing array
of a structure is flexible array member in __builtin_object_size.
gcc/ChangeLog:
PR tree-optimization/101836
* tree-object-size.cc (addr_object_size): Use array_at_struct_end_p
to determine a flexible array member reference.
gcc/testsuite/ChangeLog:
PR tree-optimization/101836
* gcc.dg/pr101836.c: New test.
* gcc.dg/pr101836_1.c: New test.
* gcc.dg/pr101836_2.c: New test.
* gcc.dg/pr101836_3.c: New test.
* gcc.dg/pr101836_4.c: New test.
* gcc.dg/pr101836_5.c: New test.
* gcc.dg/strict-flex-array-2.c: New test.
* gcc.dg/strict-flex-array-3.c: New test.
Qing Zhao [Fri, 7 Oct 2022 14:58:20 +0000 (14:58 +0000)]
Add a new option -fstrict-flex-arrays[=n] and new attribute strict_flex_array
Add the following new option -fstrict-flex-arrays[=n] and a corresponding
attribute strict_flex_array to GCC:
'-fstrict-flex-arrays'
Control when to treat the trailing array of a structure as a flexible array
member for the purpose of accessing the elements of such an array.
The positive form is equivalent to '-fstrict-flex-arrays=3', which is the
strictest. A trailing array is treated as a flexible array member only when
it declared as a flexible array member per C99 standard onwards.
The negative form is equivalent to '-fstrict-flex-arrays=0', which is the
least strict. All trailing arrays of structures are treated as flexible
array members.
'-fstrict-flex-arrays=LEVEL'
Control when to treat the trailing array of a structure as a flexible array
member for the purpose of accessing the elements of such an array. The value
of LEVEL controls the level of strictness
The possible values of LEVEL are the same as for the
'strict_flex_array' attribute (*note Variable Attributes::).
You can control this behavior for a specific trailing array field
of a structure by using the variable attribute 'strict_flex_array'
attribute (*note Variable Attributes::).
'strict_flex_array (LEVEL)'
The 'strict_flex_array' attribute should be attached to the trailing
array field of a structure. It controls when to treat the trailing array
field of a structure as a flexible array member for the purposes of accessing
the elements of such an array. LEVEL must be an integer betwen 0 to 3.
LEVEL=0 is the least strict level, all trailing arrays of
structures are treated as flexible array members. LEVEL=3 is the
strictest level, only when the trailing array is declared as a
flexible array member per C99 standard onwards ('[]'), it is
treated as a flexible array member.
There are two more levels in between 0 and 3, which are provided to
support older codes that use GCC zero-length array extension
('[0]') or one-element array as flexible array members('[1]'): When
LEVEL is 1, the trailing array is treated as a flexible array member
when it is declared as either '[]', '[0]', or '[1]'; When
LEVEL is 2, the trailing array is treated as a flexible array member
when it is declared as either '[]', or '[0]'.
This attribute can be used with or without the
'-fstrict-flex-arrays'. When both the attribute and the option
present at the same time, the level of the strictness for the
specific trailing array field is determined by the attribute.
gcc/c-family/ChangeLog:
* c-attribs.cc (handle_strict_flex_array_attribute): New function.
(c_common_attribute_table): New item for strict_flex_array.
* c.opt: (fstrict-flex-arrays): New option.
(fstrict-flex-arrays=): New option.
gcc/c/ChangeLog:
* c-decl.cc (flexible_array_member_type_p): New function.
(one_element_array_type_p): Likewise.
(zero_length_array_type_p): Likewise.
(add_flexible_array_elts_to_size): Call new utility
routine flexible_array_member_type_p.
(is_flexible_array_member_p): New function.
(finish_struct): Set the new DECL_NOT_FLEXARRAY flag.
gcc/cp/ChangeLog:
* module.cc (trees_out::core_bools): Stream out new bit
decl_not_flexarray.
(trees_in::core_bools): Stream in new bit decl_not_flexarray.
gcc/ChangeLog:
* doc/extend.texi: Document strict_flex_array attribute.
* doc/invoke.texi: Document -fstrict-flex-arrays[=n] option.
* print-tree.cc (print_node): Print new bit decl_not_flexarray.
* tree-core.h (struct tree_decl_common): New bit field
decl_not_flexarray.
* tree-streamer-in.cc (unpack_ts_decl_common_value_fields): Stream
in new bit decl_not_flexarray.
* tree-streamer-out.cc (pack_ts_decl_common_value_fields): Stream
out new bit decl_not_flexarray.
* tree.cc (array_at_struct_end_p): Update it with the new bit field
decl_not_flexarray.
* tree.h (DECL_NOT_FLEXARRAY): New flag.
gcc/testsuite/ChangeLog:
* g++.dg/strict-flex-array-1.C: New test.
* gcc.dg/strict-flex-array-1.c: New test.
Olivier Hainque [Fri, 7 Oct 2022 10:12:26 +0000 (10:12 +0000)]
Specialize paths to version.h in _vxworks-versions.h
The _vxworks-versions.h runtime file helps us control
the compilation of some library components depending on
the OS version extracted out of a system header.
The system header name is "version.h", and gcc has a
"version.h" file of its own.
gcc's version.h is now generated and the current
instance instead of the OS one, resulting in build failures
from
#if !defined(_WRS_VXWORKS_MAJOR)
#error "_WRS_VXWORKS_MAJOR undefined"
#endif
This change introduces a twist in the way
_vxworks-versions.h #includes version.h, using a relative
path with components that will match in the OS include
dirs only.
The actual relative path is conditioned on _VSB_CONFIG_FILE
to accommodate a change in the include dirs organisation between
VxWorks 6 and 7.
2022-10-07 Olivier Hainque <hainque@adacore.com>
gcc/
* config/vxworks/_vxworks-versions.h: Use OS specific
paths in #include of version.h.
David Malcolm [Fri, 7 Oct 2022 16:41:59 +0000 (12:41 -0400)]
analyzer: extract bits from integer constants [PR105783]
Fix a false positive from -Wanalyzer-null-dereference due to -fanalyzer
failing to grok the value of a particular boolean field initialized to a
constant.
gcc/analyzer/ChangeLog:
PR analyzer/105783
* region-model.cc (selftest::get_bit): New function.
(selftest::test_bits_within_svalue_folding): New.
(selfftest::analyzer_region_model_cc_tests): Call it.
* svalue.cc (constant_svalue::maybe_fold_bits_within): Handle the
case of extracting a single bit.
gcc/testsuite/ChangeLog:
PR analyzer/105783
* gcc.dg/analyzer/pr105783.c: New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Nathan Sidwell [Fri, 30 Sep 2022 19:11:42 +0000 (12:11 -0700)]
libiberty: Demangle variadic template lambdas
Now we have templated lambdas, we can have variadic template lambdas,
and this leads to lambda signatures containing parameter packs. But
just like 'auto' inside such a signature, we don't have a containing
template, and thus fail. The fix is to check is_lambda_arg, just as
for a template parameter. This allows us to demangle g++'s manglings
of such lambdas.
It's not a totally accurate demangling, because we don't mangle the
template head (that's a separate issue), but it is better than failing
to demangle.
Due to the way we print subexprs, we add an unnecessary parens around
the argument of the pack. That's an orthogonal problem, for which the
solution is to have better knowledge of operator precedence.
libiberty/
* cp-demangle.c (d_print_comp_inner): Allow parameter packs
in a lambda signature.
* testsuite/demangle-expected: Add tests.
Patrick Palka [Fri, 7 Oct 2022 16:01:58 +0000 (12:01 -0400)]
c++ modules: ICE with bitfield in class template
According to grokbitfield, DECL_BIT_FIELD_REPRESENTATIVE contains the
width of the bitfield until we layout the class type (after which it'll
contain a decl). Thus for a bitfield in a class template it'll always
be the width, and this patch makes us avoid ICEing from mark_class_def
in this case.
gcc/cp/ChangeLog:
* module.cc (trees_out::mark_class_def): Guard against
DECL_BIT_FIELD_REPRESENTATIVE not being a decl.
gcc/testsuite/ChangeLog:
* g++.dg/modules/bfield-3.H: New test.
Jason Merrill [Fri, 7 Oct 2022 01:10:52 +0000 (21:10 -0400)]
c++: catch parm initialization tweak
We want to push the INIT_EXPR inside the CLEANUP_POINT_EXPR for the same
reason we want to push it into the MUST_NOT_THROW_EXPR: any cleanups follow
the initialization.
gcc/cp/ChangeLog:
* init.cc (expand_default_init): Also push the INIT_EXPR inside a
CLEANUP_POINT_EXPR.
Martin Liska [Wed, 5 Oct 2022 09:15:36 +0000 (11:15 +0200)]
IPA: support -flto + -flive-patching=inline-clone
There's no fundamental reason why -flive-patching=inline-clone can't
coexist with -flto. Yes, one can theoretically have many more clone
function that includes a live patch. It is pretty much the same
as in-module inlining.
gcc/ChangeLog:
* opts.cc (finish_options): Print sorry message only
for -flive-patching=inline-only-static.
gcc/testsuite/ChangeLog:
* gcc.dg/live-patching-2.c: Update scanned pattern.
* gcc.dg/live-patching-5.c: New test.
Patrick Palka [Fri, 7 Oct 2022 13:32:45 +0000 (09:32 -0400)]
c++ modules: static var in inline function [PR104433]
The below testcase fails to link with the error
undefined reference to `f()::y'
ultimately because during stream out for the static VAR_DECL y we
override DECL_EXTERNAL to true, which later during IPA confuses
symbol_table::remove_unreachable_nodes into thinking it's safe
to not emit the symbol.
The streaming code here already avoids overriding DECL_EXTERNAL for
inline vars and functions, so it seems natural to extend this to
static vars from an inline function.
PR c++/104433
gcc/cp/ChangeLog:
* module.cc (trees_out::core_bools): Don't override
DECL_EXTERNAL to true for static variables from an inline
function.
gcc/testsuite/ChangeLog:
* g++.dg/modules/static-2_a.H: New test.
* g++.dg/modules/static-2_b.C: New test.
Jason Merrill [Wed, 5 Oct 2022 15:50:59 +0000 (11:50 -0400)]
gimplify: prevent some C++ temporary elision
In this testcase, we were optimizing away the temporary for f(), but
C++17 and above are clear that there is a temporary, and because its
destructor has visible side-effects we can't optimize it away under the
as-if rule. So disable this optimization for TREE_ADDRESSABLE type.
I moved the declaration of volatile_p after the call to
gimple_fold_indirect_ref_rhs to minimize indentation changes; I don't see
any way the value of that flag could be affected by the call.
gcc/ChangeLog:
* gimplify.cc (gimplify_modify_expr_rhs): Don't optimize
x = *(A*)&<expr> to x = <expr> for a TREE_ADDRESSABLE type.
gcc/testsuite/ChangeLog:
* g++.dg/init/elide9.C: New test.
Richard Biener [Fri, 7 Oct 2022 08:28:56 +0000 (10:28 +0200)]
tree-optimization/107153 - autopar SSA update issue
autopar performs insertion of stores, eventually requiring a
virtual loop PHI and assorted LC PHI adjustments which we intend
to do once after the pass finishes. But we also perform intermediate
update_ssa after loop duplication which can lose this fact. The
following forces renaming of the virtual operand before the final
SSA update to fix that. It also removes the explicit update_ssa
call from the gimple_duplicate_sese_tail utility as has been done
for all other such utilities and instead performs the SSA update
from autopar.
PR tree-optimization/107153
* tree-cfg.cc (gimple_duplicate_sese_tail): Do not update
SSA form here.
* tree-parloops.cc (gen_parallel_loop): Update SSA form
after to-exit-first transform, no PHI insertion is necessary.
(pass_parallelize_loops::execute): Force re-write of the
virtual operand SSA web.
* gcc.dg/autopar/pr107153.c: New testcase.
Jonathan Wakely [Thu, 6 Oct 2022 17:41:22 +0000 (18:41 +0100)]
libstdc++: Add --disable-libstdcxx-hosted as an alias for hosted-libstdcxx
Most libstdc++ configure args are of the form --enable-libstdcxx-xxx but
the option to build freestanding is --disable-hosted-libstdcxx. If you
accidentally type --disable-libstdcxx-hosted then it will be ignored.
This adds --disable-libstdcxx-hosted as an alias for the existing arg,
so it works whichever way you say it. If both args are used explicitly
and their values do not agree, configure fails with an error.
libstdc++-v3/ChangeLog:
* acinclude.m4 (GLIBCXX_ENABLE_HOSTED): Add libstdcxx-hosted
enable arg as an alias for hosted-libstdcxx enable arg.
* configure: Regenerate.
Jonathan Wakely [Thu, 6 Oct 2022 13:34:49 +0000 (14:34 +0100)]
libstdc++: Shuffle header dependencies of <functional>
The <new> header is needed by std::function to use placement new, so
include it in <bits/std_function.h> instead of in <functional>.
libstdc++-v3/ChangeLog:
* include/bits/std_function.h: Include <new> but do not include
<bits/stl_function.h>.
* include/std/functional: Do not include <new>.
Jonathan Wakely [Fri, 7 Oct 2022 11:20:36 +0000 (12:20 +0100)]
gcc: Fix comment typo
gcc/ChangeLog:
* value-range.cc (irange::irange_contains_p): Fix comment typo.
Jonathan Wakely [Wed, 5 Oct 2022 10:54:36 +0000 (11:54 +0100)]
libstdc++: Use bold style for DR titles in the manual
This matches how the issues are styled in the LWG issues list, and also
allows us to use italics for "cv" (e.g. in issue 2487).
libstdc++-v3/ChangeLog:
* doc/xml/manual/intro.xml: Add role="bold" attribute to
emphasis elements for issue titles.
* doc/html/manual/bugs.html: Regenerate.
Eric Botcazou [Fri, 7 Oct 2022 10:14:30 +0000 (12:14 +0200)]
Reduce DF computation at -O0
Even at -O0 there may be a fair amount of DF computation performed when
compiling large units and part of it appears to be useless.
gcc/
* function.cc (thread_prologue_and_epilogue_insns): Update only
entry and exit blocks when not optimizing. Remove dead statement.
Aldy Hernandez [Fri, 7 Oct 2022 07:57:32 +0000 (09:57 +0200)]
Convert nonzero mask back to tree.
Having nonzero masks always set had a performance penalty of 10% in
VRP, so mask==NULL is a shortcut to all bits set.
gcc/ChangeLog:
* value-range.cc (irange::irange_set): Convert nonzero mask to
tree.
(irange::irange_set_anti_range): Same.
(irange::set): Same.
(irange::verify_range): Same.
(irange::contains_p): Same.
(irange::invert): Same.
(irange::set_range_from_nonzero_bits): Same.
(irange::set_nonzero_bits): Same.
(mask_to_wi): Same.
(irange::intersect_nonzero_bits): Same.
(irange::union_nonzero_bits): Same.
* value-range.h (irange::varying_compatible_p): Same.
(gt_ggc_mx): Same.
(gt_pch_nx): Same.
(irange::set_undefined): Same.
(irange::set_varying): Same.
Martin Liska [Fri, 7 Oct 2022 09:35:32 +0000 (11:35 +0200)]
contrib: remove extra fetch from git_update_version
Remove extra fetch call that didn't help with the issue
we had (missing object).
contrib/ChangeLog:
* gcc-changelog/git_update_version.py: Remove extra fetch.
Martin Liska [Fri, 7 Oct 2022 08:34:39 +0000 (10:34 +0200)]
libdecnumber: remove unused variable
Fixes:
libdecnumber/dpd/decimal64.c:617:8: warning: variable 'n' set but not used [-Wunused-but-set-variable]
libdecnumber/ChangeLog:
* dpd/decimal64.c (decDigitsToDPD): Remove unused variable.
Martin Liska [Fri, 7 Oct 2022 08:22:24 +0000 (10:22 +0200)]
fix clang warnings
Fixes:
gcc/c-family/name-hint.h:109:66: warning: unqualified call to 'std::move' [-Wunqualified-std-cast-call]
gcc/config/i386/i386-expand.cc:1351:9: warning: argument 'operands' of type 'rtx[3]' (aka 'rtx_def *[3]') with mismatched bound [-Warray-parameter]
gcc/config/i386/i386.cc:15635:8: warning: argument 'operands' of type 'rtx[2]' (aka 'rtx_def *[2]') with mismatched bound [-Warray-parameter]
gcc/cp/module.cc:17482:51: warning: argument 'counts' of type 'unsigned int[8]' with mismatched bound [-Warray-parameter]
gcc/cp/module.cc:17508:37: warning: argument 'counts' of type 'unsigned int[8]' with mismatched bound [-Warray-parameter]
gcc/cp/name-lookup.cc:6385:16: warning: unqualified call to 'std::move' [-Wunqualified-std-cast-call]
gcc/c-family/ChangeLog:
* name-hint.h: Use std::move.
gcc/ChangeLog:
* config/i386/i386-protos.h (ix86_binary_operator_ok): Add array
size to function parameter.
(ix86_unary_operator_ok): Likewise.
gcc/cp/ChangeLog:
* module.cc (enum module_state_counts): Use array size.
* name-lookup.cc (class namespace_limit_reached): Likewise.
(class module_state): Move up in the file.
Martin Liska [Fri, 7 Oct 2022 08:10:30 +0000 (10:10 +0200)]
remove dead variables
Remove unused variables that are modified but not used.
gcc/ChangeLog:
* auto-profile.cc (get_inline_stack): Remove unused variable.
gcc/objc/ChangeLog:
* objc-gnu-runtime-abi-01.cc (generate_static_references):
Remove unused variable.
Jakub Jelinek [Fri, 7 Oct 2022 07:08:46 +0000 (09:08 +0200)]
Fix comment typos
When looking at tree-inline.cc I've noticed a comment typo and grepped
for similar typos elsewhere.
2022-10-07 Jakub Jelinek <jakub@redhat.com>
* ipa-prop.h (ipa_constant_data): Fix comment typo.
* value-range.cc (irange::irange_contains_p): Likewise.
* value-relation.cc (dom_oracle::set_one_relation): Likewise.
* gimple-predicate-analysis.cc (predicate::simplify_4): Likewise.
* tree-inline.cc (remap_ssa_name): Likewise.
Jakub Jelinek [Fri, 7 Oct 2022 07:01:04 +0000 (09:01 +0200)]
c++: Improve handling of foreigner namespace attributes
In some cases we want to look up or remove both standard
attributes and attributes from gnu namespace but not others.
This patch arranges for ATTR_NS of "" to stand for ATTR_NS
NULL or "gnu", so that we don't need 2 separate calls, and
introduces is_attribute_namespace_p function which allows
testing the namespace of an attribute similar way.
The patch also uses the new lookup_attribute overload and extra
tests to avoid emitting weird warnings on foreign namespace attributes
which we should just ignore (perhaps with a warning), but shouldn't
imply any meaning to them just because they have a name matching some
standard or gnu attribute name.
2022-10-07 Jakub Jelinek <jakub@redhat.com>
gcc/
* attribs.h (is_attribute_namespace_p): New inline function.
(lookup_attribute): Document meaning of ATTR_NS equal to "".
* attribs.cc (remove_attribute): Use is_attribute_namespace_p.
(private_lookup_attribute): For ATTR_NS "" match either standard
attribute or "gnu" namespace one.
gcc/c-family/
* c-common.cc (attribute_fallthrough_p): Lookup fallthrough attribute
only in gnu namespace or as standard attribute, treat fallthrough
attributes in other namespaces like any other unknown attribute.
gcc/cp/
* parser.cc (cp_parser_check_std_attribute): Only do checks if
attribute is a standard attribute or in gnu namespace and only
lookup other attributes in those namespaces.
* cp-gimplify.cc (lookup_hotness_attribute): Adjust function comment.
Only return true for standard attribute or gnu namespace attribute.
(remove_hotness_attribute): Only remove hotness attributes when
they are standard or in gnu namespace, implement it in a single
loop rather than former 4 now 8 remove_attribute calls.
gcc/testsuite/
* g++.dg/cpp1z/fallthrough2.C: New test.
* g++.dg/cpp2a/attr-likely7.C: New test.
Jakub Jelinek [Fri, 7 Oct 2022 06:59:05 +0000 (08:59 +0200)]
fixincludes: Deal also with the _Float128x cases [PR107059]
On Wed, Sep 28, 2022 at 08:19:43PM +0200, Jakub Jelinek via Gcc-patches wrote:
> Another case are the following 3 snippets:
> # if !__GNUC_PREREQ (7, 0) || defined __cplusplus
> # error "_Float128X supported but no constant suffix"
> # else
> # define __f128x(x) x##f128x
> # endif
> ...
> # if !__GNUC_PREREQ (7, 0) || defined __cplusplus
> # error "_Float128X supported but no complex type"
> # else
> # define __CFLOAT128X _Complex _Float128x
> # endif
> ...
> # if !__GNUC_PREREQ (7, 0) || defined __cplusplus
> # error "_Float128x supported but no type"
> # endif
> but as no target has _Float128x right now and don't see it
> coming soon, it isn't a big deal (on the glibc side it is of
> course ok to adjust those).
This incremental patch deals handles the above 3 cases, so we
fixinclude what glibc itself changed too.
2022-10-07 Jakub Jelinek <jakub@redhat.com>
PR bootstrap/107059
* inclhack.def (glibc_cxx_floatn_5): New.
* fixincl.x: Regenerated.
* tests/base/bits/floatn.h: Regenerated.
Jakub Jelinek [Fri, 7 Oct 2022 06:56:04 +0000 (08:56 +0200)]
fixincludes: Fix up powerpc floatn.h tweaks [PR107059]
On Wed, Sep 28, 2022 at 12:23:31AM +0000, Joseph Myers wrote:
> In general the changes match those made by fixincludes, though I think
> the ones in sysdeps/powerpc/bits/floatn.h, where the header tests
> __LDBL_MANT_DIG__ == 113 or uses #elif, wouldn't match the existing
> fixincludes patterns.
You're right, missed that.
The header has:
/* Defined to a complex binary128 type if __HAVE_FLOAT128 is 1. */
# if __HAVE_FLOAT128
# if __LDBL_MANT_DIG__ == 113 && defined __cplusplus
typedef long double _Float128;
# define __CFLOAT128 _Complex long double
# elif !__GNUC_PREREQ (7, 0) || defined __cplusplus
/* The type _Float128 exist for powerpc only since GCC 7.0. */
typedef __float128 _Float128;
/* Add a typedef for older GCC and C++ compilers which don't natively support
_Complex _Float128. */
typedef _Complex float __cfloat128 __attribute__ ((__mode__ (__KC__)));
# define __CFLOAT128 __cfloat128
# else
# define __CFLOAT128 _Complex _Float128
# endif
# endif
and my current rules don't do anything about that.
The following patch fixes that.
I've run additionally
MACRO_LIST=`pwd`/../gcc/macro_list TARGET_MACHINE=x86_64-pc-linux-gnu \
../fixincludes/fixinc.sh /tmp/include-fixed \
`echo /usr/src/libc | sed -e :a -e 's,[^/]*/\.\.\/,,' -e ta`
in the builddir/fixincludes directory where /usr/src/libc is latest glibc
trunk checkout and seems the remaining defined __cplusplus cases in the floatn.h
and floatn-common.h headers are ok or acceptable.
The remaining cases are:
#if __GNUC_PREREQ (7, 0) && !defined __cplusplus
# define __HAVE_FLOATN_NOT_TYPEDEF 1
#else
# define __HAVE_FLOATN_NOT_TYPEDEF 0
#endif
which is IMHO ok because this is only used in tgmath.h or tgmath-like math.h
stuff which is C only, as C++ doesn't have _Generic.
Another case are the following 3 snippets:
# if !__GNUC_PREREQ (7, 0) || defined __cplusplus
# error "_Float128X supported but no constant suffix"
# else
# define __f128x(x) x##f128x
# endif
...
# if !__GNUC_PREREQ (7, 0) || defined __cplusplus
# error "_Float128X supported but no complex type"
# else
# define __CFLOAT128X _Complex _Float128x
# endif
...
# if !__GNUC_PREREQ (7, 0) || defined __cplusplus
# error "_Float128x supported but no type"
# endif
but as no target has _Float128x right now and don't see it
coming soon, it isn't a big deal (on the glibc side it is of
course ok to adjust those).
OT, besides floatn.h and floatn-common.h headers, the only
one remaining in /tmp/include-fixed is sysdeps/arm/unwind.h, perhaps
-#if defined(linux) || defined(__NetBSD__)
+#if defined(__linux__) || defined(__NetBSD__)
should be done in that header (and libgcc/config/arm/unwind-arm.h
too).
2022-10-07 Jakub Jelinek <jakub@redhat.com>
PR bootstrap/107059
* inclhack.def (glibc_cxx_floatn_2): Handle #elif the same as #if.
(glibc_cxx_floatn_4): New.
* fixincl.x: Regenerated.
* tests/base/bits/floatn.h: Regenerated.
Olivier Hainque [Thu, 3 Mar 2022 16:58:51 +0000 (16:58 +0000)]
Downgrade DWARF_VERSION_DEFAULT to 3 for VxWorks >= 7
Using 4 as the DWARF_VERSION_DEFAULT value for VxWorks observably
still hangs recent system debuggers on tbreak for some contructs,
and downgrading to 3 improves the situation.
2022-03-06 Olivier Hainque <hainque@adacore.com>
gcc/
* config/vxworks.h (DWARF_VERSION_DEFAULT): Adjust from
4 to 3 for VxWorks >= 7.
Olivier Hainque [Mon, 26 Sep 2022 16:05:48 +0000 (16:05 +0000)]
Introduce DWARF_VERSION_DEFAULT and redefine for VxWorks
This change introduces a target overridable macro to replace
the hardcoded value used to initialize dwarf_version from common.opt.
The main advantage compared to special code in a target
override_options hook is that redefinitions by target config files
are visible by both the compiler proper and by the driver, which
might refer to dwarf_version in ASM_DEBUG_SPECs and friends.
This is useful at least on VxWorks, where we usually need to
default to dwarf 4 or even 2 to accommodate non-gdb debuggers
provided by the environment, including for assembly sources
used in libgcc for some ports (witnessed with lse.S on aarch64).
2022-02-28 Olivier Hainque <hainque@adacore.com>
gcc/
* defaults.h (DWARF_DEFAULT_VERSION): Define if not
defined already.
* common.opt (gdwarf-): Use it.
* doc/tm.texi.in (DWARF_DEFAULT_VERSION): Document.
* doc/tm.texi: Update accordingly.
* config/vxworks.h (DWARF_DEFAULT_VERSION): Redefine.
* config/vxworks.cc: Remove code setting dwarf_version, now
handled by the DWARF_DEFAULT_VERSION redefinition.
Olivier Hainque [Fri, 28 Jan 2022 16:34:50 +0000 (16:34 +0000)]
undef offsetof before defining it in stddef.h
This prevents redefinition warnings by -Wsystem-headers on
OSses where system headers happen to provide a definition of
their own, such as VxWorks.
2022-02-15 Olivier Hainque <hainque@adacore.com>
gcc/
* ginclude/stddef.h: #undef offsetof before #define.
Than McIntosh [Thu, 6 Oct 2022 19:58:59 +0000 (15:58 -0400)]
compiler: better arg type checking for selected builtins
Tighten up the argument type checking for Builtin_call_expression to
catch erroneous cases such as
panic(panic("bad")))
where an argument void type is being passed to panic/alignof/sizeof.
Fixes golang/go#56071.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/439815
GCC Administrator [Fri, 7 Oct 2022 00:17:52 +0000 (00:17 +0000)]
Daily bump.
Jakub Jelinek [Thu, 6 Oct 2022 22:16:11 +0000 (00:16 +0200)]
libgcc, arc: Fix build
Missed one spot in the r13-3108-g146e45914032 change (my sed script
didn't expect nested []s).
2022-10-07 Jakub Jelinek <jakub@redhat.com>
* config/arc/linux-unwind.h (arc_fallback_frame_state): Use
fs->regs.how[X] instead of fs->regs.reg[X].how.
Jason Merrill [Fri, 30 Sep 2022 14:04:22 +0000 (10:04 -0400)]
c++: fix broken conversion in coroutines
You can't use CONVERT_EXPR to convert between two class types.
VIEW_CONVERT_EXPR takes liberties with the C++ type system, but is probably
safe in this context. Let's also only use it when the type isn't already
what we want.
gcc/cp/ChangeLog:
* coroutines.cc (expand_one_await_expression): Change conversion
to VIEW_CONVERT_EXPR.
* cp-gimplify.cc (cp_genericize_r) [CONVERT_EXPR]: Add assert.
Aldy Hernandez [Thu, 6 Oct 2022 17:11:08 +0000 (19:11 +0200)]
[PR107170] Avoid copying incompatible types in legacy VRP.
Legacy VRP is calling ranger deep inside the bowels, and then trying to
copy an incompatible type. My previous patch in this area assumed that
the only possibility out of vr_values::get_value_range for an
unsupported type was VARYING, but UNDEFINED can also be returned.
PR tree-optimization/107170
gcc/ChangeLog:
* vr-values.cc (vr_values::range_of_expr): Do not die on
unsupported types.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/pr107170.c: New test.
David Malcolm [Thu, 6 Oct 2022 19:46:49 +0000 (15:46 -0400)]
analyzer: fix another ICE in PR 107158
I overreduced PR analyzer/107158 in r13-3096-gef878564140cbc, and there
was another ICE in the original reproducer, which this patch fixes.
gcc/analyzer/ChangeLog:
PR analyzer/107158
* store.cc (store::replay_call_summary_cluster): Eliminate
special-casing of RK_HEAP_ALLOCATED in favor of sharing code with
RK_DECL, avoiding an ICE due to attempting to bind a
compound_svalue into a binding_cluster when an svalue in the
summary cluster converts to a compound_svalue in the caller.
gcc/testsuite/ChangeLog:
PR analyzer/107158
* gcc.dg/analyzer/call-summaries-pr107158-2.c: New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
David Malcolm [Thu, 6 Oct 2022 19:46:20 +0000 (15:46 -0400)]
analyzer: fixes to call_summary_replay::dump_to_pp
gcc/analyzer/ChangeLog:
* call-summary.cc (call_summary_replay::dump_to_pp): Bulletproof
against NULL caller regions/svalues.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Tobias Burnus [Thu, 6 Oct 2022 16:42:32 +0000 (18:42 +0200)]
openmp: Map holds clause to IFN_ASSUME for Fortran
Same as r13-3107-g847f5addc4d07a2f3b95f5daa50ab4a64dfd957d did for C/C++.
Convert '!$omp assume holds(cond)' to IFN_ASSUME (cond).
gcc/fortran/
* trans-openmp.cc (gfc_trans_omp_assume): New.
(gfc_trans_omp_directive): Call it.
gcc/testsuite/
* gfortran.dg/gomp/assume-3.f90: New test.
* gfortran.dg/gomp/assume-4.f90: New test.
Joseph Myers [Thu, 6 Oct 2022 14:26:21 +0000 (14:26 +0000)]
c: C2x typeof
C2x adds typeof as a standard feature. In general this follows
existing GNU C semantics very closely, but there are various ways in
which the implementation involves more than simply enabling the
keyword for C2x:
* As well as typeof, there is a typeof_unqual variant, which removes
all qualifiers and _Atomic from the resulting type (whereas typeof
preserves qualifiers and _Atomic on qualified or atomic (lvalue or
type name) operands).
* The typeof keyword is disabled by -fno-asm, so enabling it for C2x
needs to be implemented in a way that preserves the disabling by
-fno-asm for older standard versions (which having -fno-asm having
no effect on it in C2x mode). This is done via adding a new D_EXT11
mask (which is also where the C++ front-end change comes from, to
handle D_EXT11 appropriately there for -fno-asm and
-fno-gnu-keywords).
* GNU typeof treats the noreturn property of a function (as specified
in standard C with _Noreturn or [[noreturn]]) as being part of the
type of a pointer to function, but it is not part of the type in
standard terms. Thus a special case is needed in the typeof
implementation, just like in the _Generic implementation, to avoid
treating it as a type for standard typeof. It seems plausible this
is being used when copying the type of one object to another using
typeof, so the existing semantics are preserved for __typeof__, and
for typeof in pre-C2x modes, while typeof for C2x or later has the
standard semantics.
* It turns out that, even after Martin Uecker's changes in this area,
there were still cases where rvalues could wrongly have a qualified
or atomic type in GCC. This applied to ++ and -- increment and
decrement expressions, and also to calls to functions returning an
atomic type. (For the latter, the working draft doesn't actually
explicitly exclude the function call expression having an atomic
type, but given all the changes that have gone into C17 and C2x to
avoid rvalues ever having qualified types, and given that
lvalue-to-rvalue conversion removes both qualifiers and _Atomic, it
seems unlikely that this (or casts, where GCC already removes
_Atomic) is actually intended as a route to allow an
_Atomic-qualified rvalue; I've noted this to raise as an NB comment
on the CD ballot.)
Bootstrapped with no regressions for x86_64-pc-linux-gnu. OK to
commit (C+
gcc/
* doc/invoke.texi (-fno-asm): Update description of effects on
typeof keyword.
gcc/c-family/
* c-common.cc (c_common_reswords): Mark typeof as D_EXT11. Add
typeof_unqual.
* c-common.h (enum rid): Add RID_TYPEOF_UNQUAL.
(D_EXT11): New macro. Values of subsequent macros updated.
gcc/c/
* c-parser.cc (c_parse_init): Add D_EXT11 to mask if flag_no_asm
and not C2x.
(c_keyword_starts_typename, c_token_starts_declspecs)
(c_parser_declspecs, c_parser_objc_selector): Handle
RID_TYPEOF_UNQUAL.
(c_parser_typeof_specifier): Handle RID_TYPEOF_UNQUAL.
Distinguish typeof for C2x from __typeof__ for all standard
versions and typeof before C2x.
* c-typeck.cc (build_function_call_vec): Use unqualified version
of non-void return type.
(build_unary_op): Use unqualified type for increment and
decrement.
gcc/cp/
* lex.cc (init_reswords): Handle D_EXT11.
gcc/testsuite/
* gcc.dg/c11-typeof-1.c, gcc.dg/c2x-typeof-1.c,
gcc.dg/c2x-typeof-2.c, gcc.dg/c2x-typeof-3.c,
gcc.dg/gnu11-typeof-1.c, gcc.dg/gnu11-typeof-2.c,
gcc.dg/gnu2x-typeof-1.c: New tests.
Patrick Palka [Thu, 6 Oct 2022 14:04:52 +0000 (10:04 -0400)]
c++: remove optimize_specialization_lookup_p
Roughly speaking, optimize_specialization_lookup_p returns true for a
non-template member function of a class template, e.g.
template<class T> struct A { int f(); };
The idea behind the optimization guarded by this predicate is that if
we want to look up the specialization A<T>::f [with T=int], then we can
just do a name lookup for f in A<int> and avoid having to add a
spec_entry for f in the decl_specializations table.
But the benefit of this optimization seems questionable because in
order to do the name lookup we first need to look up A<T> [with T=int]
in the type_specializations table, which is as expensive as the
decl_specializations lookup we're avoiding. And according to some
experiments (using stdc++.h, range-v3 and libstdc++ tests) the compiler
is slightly (<1%) _faster_ if we disable this optimization.
Additionally, this optimization means we won't record an explicit
specialization in decl_specializations for such a template either, which
is an unfortunate inconsistency that apparently breaks the below modules
testcase.
So since this optimization doesn't improve performance, and complicates
the explicit specialization story which causes issues with modules, this
patch proposes to remove it.
gcc/cp/ChangeLog:
* pt.cc (optimize_specialization_lookup_p): Remove.
(retrieve_specialization): Assume the above returns false
and simplify accordingly.
(register_specialization): Likewise.
gcc/testsuite/ChangeLog:
* g++.dg/modules/indirect-3_b.C: Expect that the entity
foo::TPL<0>::frob is tagged as a specialization instead
of as a declaration.
* g++.dg/modules/tpl-spec-8_a.H: New test.
* g++.dg/modules/tpl-spec-8_b.C: New test.
Eric Botcazou [Thu, 6 Oct 2022 13:13:50 +0000 (15:13 +0200)]
Fix wrong code generated by unroll-and-jam pass
There is a loophole in the unroll-and-jam pass that can quickly result in
wrong code generation. The code reads:
if (!compute_data_dependences_for_loop (outer, true, &loop_nest,
&datarefs, &dependences))
{
if (dump_file && (dump_flags & TDF_DETAILS))
fprintf (dump_file, "Cannot analyze data dependencies\n");
free_data_refs (datarefs);
free_dependence_relations (dependences);
continue;
}
but compute_data_dependences_for_loop may return true even if the analysis
is reported as failing by compute_affine_dependence for a dependence pair:
(compute_affine_dependence
ref_a: data[_14], stmt_a: data[_14] = i_59;
ref_b: data[_14], stmt_b: data[_14] = i_59;
Data ref a:
Data ref b:
affine dependence test not usable: access function not affine or constant.
) -> dependence analysis failed
Note that this is a self-dependence pair and the code for them reads:
/* Nothing interesting for the self dependencies. */
if (dra == drb)
continue;
This means that the pass may reorder "complex" accesses to the same memory
location in successive iterations, which is OK for reads but not for writes.
gcc/
* gimple-loop-jam.cc (tree_loop_unroll_and_jam): Bail out for a self
dependency that is a write-after-write if the access function is not
affine or constant.
gcc/testsuite/
* gcc.c-torture/execute/
20221006-1.c: New test.
Eric Botcazou [Thu, 6 Oct 2022 13:12:53 +0000 (15:12 +0200)]
Minor cleanup in DF code
No functional changes.
gcc/
* df-scan.cc (df_ref_create_structure): Minor cleanup.
Richard Biener [Thu, 6 Oct 2022 09:48:03 +0000 (11:48 +0200)]
middle-end/107115 - avoid bogus redundant store removal during RTL expansion
The following preserves the (premature) redundant store removal
done in store_expr by appropriately guarding it with
mems_same_for_tbaa_p. The testcase added needs scheduling disabled
for now since there's a similar bug there still present.
PR middle-end/107115
* expr.cc (store_expr): Check mems_same_for_tbaa_p before
eliding a seemingly redundant store.
* gcc.dg/torture/pr107115.c: New testcase.
Kyrylo Tkachov [Thu, 6 Oct 2022 11:09:28 +0000 (12:09 +0100)]
aarch64: Remove redundant zero-extends with LDAR
Like other loads in AArch64, the LDARB,LDARH,LDAR instructions clear out the top part of their
destination register and we can thus avoid having to explicitly zero-extend it.
We were missing a combine pattern that this patch adds.
For one of the examples in the testcase we generated:
load_uint8_t_ext_uint16_t:
adrp x0, .LANCHOR0
add x0, x0, :lo12:.LANCHOR0
ldarb w0, [x0]
and w0, w0, 255
ret
but now generate:
load_uint8_t_ext_uint16_t:
adrp x0, .LANCHOR0
add x0, x0, :lo12:.LANCHOR0
ldarb w0, [x0]
ret
Bootstrapped and tested on aarch64-none-linux-gnu.
gcc/ChangeLog:
* config/aarch64/atomics.md (*atomic_load<ALLX:mode>_zext<SD_HSDI:mode>):
New pattern.
gcc/testsuite/ChangeLog:
* gcc.target/aarch64/ldar_2.c: New test.
Kyrylo Tkachov [Thu, 6 Oct 2022 11:08:40 +0000 (12:08 +0100)]
aarch64: Add test for LDAR generation from __atomic_load_n
I'd like a test to check the generation of LDAR for atomic_load_n.
No new functionality added.
gcc/testsuite/ChangeLog:
* gcc.target/aarch64/ldar_1.c: New test.
Philipp Tomsich [Sun, 7 Aug 2022 22:30:52 +0000 (00:30 +0200)]
aarch64: update Ampere-1 core definition
This brings the extensions detected by -mcpu=native on Ampere-1 systems
in sync with the defaults generated for -mcpu=ampere1.
Note that some early kernel versions on Ampere1 may misreport the
presence of PAUTH and PREDRES (i.e., -mcpu=native will add 'nopauth'
and 'nopredres').
gcc/ChangeLog:
* config/aarch64/aarch64-cores.def (AARCH64_CORE): Update
Ampere-1 core entry.
Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
Philipp Tomsich [Mon, 3 Oct 2022 19:59:50 +0000 (21:59 +0200)]
aarch64: fix off-by-one in reading cpuinfo
Fixes:
341573406b39
Don't subtract one from the result of strnlen() when trying to point
to the first character after the current string. This issue would
cause individual characters (where the 128 byte buffers are stitched
together) to be lost.
gcc/ChangeLog:
* config/aarch64/driver-aarch64.cc (readline): Fix off-by-one.
gcc/testsuite/ChangeLog:
* gcc.target/aarch64/cpunative/info_18: New test.
* gcc.target/aarch64/cpunative/native_cpu_18.c: New test.
Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
Richard Biener [Thu, 6 Oct 2022 09:20:16 +0000 (11:20 +0200)]
tree-optimization/107107 - tail-merging VN wrong-code
The following fixes an unintended(?) side-effect of the special
MODIFY_EXPR expression entries we add for tail-merging during VN.
We shouldn't value-number the virtual operand differently here.
PR tree-optimization/107107
* tree-ssa-sccvn.cc (visit_reference_op_store): Do not
affect value-numbering when doing the tail merging
MODIFY_EXPR lookup.
* gcc.dg/pr107107.c: New testcase.
Eric Botcazou [Fri, 23 Sep 2022 10:18:22 +0000 (12:18 +0200)]
ada: Implementation of support for storage models in gigi
It is based on a new LOAD_EXPR node in GENERIC that is later turned into
a bona-fide temporary during gimplification.
gcc/ada/
* gcc-interface/ada-tree.def (LOAD_EXPR): New expression code.
* gcc-interface/gigi.h (build_storage_model_load): Declare.
(build_storage_model_store): Likewise.
(instantiate_load_in_expr): Likewise.
(INSTANTIATE_LOAD_IN_EXPR): New macro.
(instantiate_load_in_array_ref): Declare.
* gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Record_Type>: Set a
fake discriminant number on the fields of the template type.
(gnat_to_gnu_field): Use integer for DECL_DISCRIMINANT_NUMBER.
* gcc-interface/misc.cc (gnat_init_ts): Mark LOAD_EXPR as typed.
* gcc-interface/trans.cc (fold_constant_decl_in_expr) <ARRAY_REF>:
Also preserve the 4th operand.
(Attribute_to_gnu): Deal with LOAD_EXPR of unconstrained array type.
<Attr_Size>: Call INSTANTIATE_LOAD_IN_EXPR for a storage model.
<Attr_Length>: Likewise.
<Attr_Bit_Position>: Likewise.
(get_storage_model): New function.
(get_storage_model_access): Likewise.
(storage_model_access_required_p): Likewise.
(Call_to_gnu): Add GNAT_STORAGE_MODEL parameter and deal with it.
Also deal with actual parameters that have a storage model.
(gnat_to_gnu) <N_Object_Declaratio>: Adjust call to Call_to_gnu.
<N_Explicit_Dereference>: Deal with a storage model access.
<N_Indexed_Component>: Likewise.
<N_Slice>: Likewise.
<N_Selected_Component>: Likewise.
<N_Assignment_Statement>: Adjust call to Call_to_gnu. Deal with a
storage model access either on the LHS, on the RHS or on both.
<N_Function_Cal>: Adjust call to Call_to_gnu.
<N_Free_Statement>: Deal with a pool that is a storage model.
Replace test for UNCONSTRAINED_ARRAY_REF with test on the type.
(gnat_gimplify_expr) <CALL_EXPR>: Tidy up.
<LOAD_EXPR>: New case.
<UNCONSTRAINED_ARRAY_REF>: Move down.
* gcc-interface/utils.cc (maybe_unconstrained_array): Deal with a
LOAD_EXPR by recursing on its first operand.
* gcc-interface/utils2.cc (build_allocator): Deal with a pool that
is a storage model.
(build_storage_model_copy): New function.
(build_storage_model_load): Likewise.
(build_storage_model_store): Likewise.
(instantiate_load_in_expr): Likewise.
(instantiate_load_in_array_ref): Likewise.
(gnat_rewrite_reference) <ARRAY_REF>: Also preserve the 4th operand.
(get_inner_constant_reference) <ARRAY_REF>: Remove useless test.
(gnat_invariant_expr) <ARRAY_REF>: Rewrite test.
Steve Baird [Fri, 30 Sep 2022 18:14:20 +0000 (11:14 -0700)]
ada: Minor potential bug in sem_ch6.adb
In sem_ch6.adb, the procedure Analyze_Procedure_Call is preceded with a
comment:
-- WARNING: This routine manages Ghost regions. Return statements must be
-- replaced by gotos that jump to the end of the routine and restore the
-- Ghost mode.
Correct a violation of this comment. This is a one-line change.
gcc/ada/
* sem_ch6.adb
(Analyze_Procedure_Call): Replace "return;" with "goto Leave;", as
per comment preceding body of Analyze_Procedure_Call.
Piotr Trojanek [Mon, 3 Oct 2022 14:49:19 +0000 (16:49 +0200)]
ada: Reject conditional goto in lock-free protected subprograms
In lock-free protected subprograms we don't allow goto statements;
likewise, we now reject conditional goto statements.
This fix only affects semantic checking mode with switch -gnatc.
In ordinary compilation we already rejected conditional goto after
it was expanded into ordinary goto.
gcc/ada/
* sem_ch9.adb (Allows_Lock_Free_Implementation): Reject
conditional goto statements.
Piotr Trojanek [Mon, 3 Oct 2022 14:45:49 +0000 (16:45 +0200)]
ada: Cleanup related to lock-free protected subprograms
Cleanup code and documentation; semantics is unaffected.
gcc/ada/
* doc/gnat_rm/implementation_defined_pragmas.rst
(Lock_Free): Remove inconsistent periods that end item
descriptions.
* sem_ch9.adb
(Allows_Lock_Free_Implementation): Remove unnecessary guard
against an empty list of parameters; replace low-level entity kind
membership test with a high-level query; refill error message.
* gnat_rm.texi: Regenerate.
Alexandre Oliva [Thu, 8 Sep 2022 02:49:58 +0000 (23:49 -0300)]
ada: hardened conditionals: exemplify codegen changes
gcc/ada/
* doc/gnat_rm/security_hardening_features.rst: Add examples of
codegen changes in hardened conditionals.
* gnat_rm.texi: Regenerate.
Alexandre Oliva [Thu, 8 Sep 2022 03:15:19 +0000 (00:15 -0300)]
ada: hardened booleans: exemplify codegen changes
Show the sort of code that is to be expected from using hardened
booleans in Ada code. Mention that C traps instead of raising
exceptions.
gcc/ada/
* doc/gnat_rm/security_hardening_features.rst: Add examples of
codegen changes in hardened booleans. Mention that C traps where
Ada raises exceptions.
* gnat_rm.texi: Regenerate.
Alexandre Oliva [Thu, 8 Sep 2022 03:33:15 +0000 (00:33 -0300)]
ada: stack scrubbing: exemplify codegen changes
gcc/ada/
* doc/gnat_rm/security_hardening_features.rst: Add examples of
codegen changes in stack scrubbing.
* gnat_rm.texi: Regenerate.
Piotr Trojanek [Fri, 30 Sep 2022 14:56:37 +0000 (16:56 +0200)]
ada: Fix inserting of validity checks in lock-free protected subprograms
Validity checks for statements in a lock-free implementation of
protected subprogram were wrongly inserted in front of the original
statements. This happened because the lock-free implementation was
created as a shallow copy, where only the protected body statements were
copied while its children still had the Parent pointing to the original
statements.
gcc/ada/
* exp_ch9.adb (Build_Lock_Free_Protected_Subprogram_Body): Replace
shallow copy of protected statements with a deep copy.
Marc Poulhiès [Thu, 28 Jul 2022 13:57:46 +0000 (15:57 +0200)]
ada: Add C declarations for Storage Model support
Add needed C declarations for Storage Model support in gigi.
gcc/ada/
* fe.h (Has_Storage_Model_Type_Aspect)
(Has_Designated_Storage_Model_Aspect, Storage_Model_Object)
(Storage_Model_Copy_From, Storage_Model_Copy_To): Add
declarations.
* sem_util.ads: Add WARNING markers for functions for which a new
C declaration has been added in fe.h
Steve Baird [Wed, 28 Sep 2022 17:32:00 +0000 (10:32 -0700)]
ada: Incorrect inferences drawn from if/elsif/while conditions with -gnatVo
Within the first (respectively, second) statement list of this if statement
declare
X : constant Integer := ... ;
begin
if X > 0 then
...;
else
...;
end if;
end;
we can safely assume that X is greater (respectively, not greater) than 0.
Fix a bug that incorrectly computed the region in which such assumptions
can be made to include the condition of the if-statement. This bug usually
had no effect because semantic analysis/simplification of the condition was
already complete before the code containing the bug was executed.
Unfortunately, this is not true in some cases involving -gnatVo validity
checking. In these cases, the bug could result in incorrect simplification
of the condition at compile time. This, in turn, could lead to incorrect
unconditional execution of one arm of the if-statement at run time. Similar
errors appear to be possible for the conditions of an elsif or a while loop;
the fix addresses these cases as well, although corresponding problems with
these constructs have not been demonstrated.
gcc/ada/
* exp_util.adb
(Get_Current_Value_Condition): Treat references occurring within
the condition of an if statement, an elsif, or a while loop in the
same way as references that occur before the start of that
enclosing construct.
Gary Dismukes [Wed, 28 Sep 2022 17:22:26 +0000 (13:22 -0400)]
ada: Accessibility error incorrectly flagged on call within Pre'Class expression
The compiler was wrongly reporting an error on a function call within
a Pre'Class expression when a formal of the aspect's subprogram was
passed to an aliased formal. This occurred due to the call appearing
with the return statement of the wrapper function created for the
precondition, but the accessibility error check should only be done
for return statements that appear in the source program.
gcc/ada/
* sem_ch4.adb (Analyze_Call): Add test of Comes_From_Source on the
enclosing subprogram's Entity_Id for determining whether to
perform the compile-time accessibility check on actuals passed to
aliased formals in a function call occurring within a return
statement. That test excludes cases where the call occurs within
the return statement of a Pre'Class wrapper function.
Bob Duff [Wed, 28 Sep 2022 15:24:49 +0000 (11:24 -0400)]
ada: Clean up slice-of-component optimization
In the recursive case of Volatile_Or_Independent = False for array
types, fall through into later checks, so for example we check
the type of the prefix of a slice. The pattern here is "return True
in certain cases, otherwise fall through into the final 'return False'".
Remove check for "Ndim = 1"; if Slices is True, then the number of
dimensions is necessarily 1, because Ada doesn't have multi-dimensional
slices.
gcc/ada/
* exp_ch5.adb
(Expand_Assign_Array_Loop_Or_Bitfield): Minor cleanups.
Yannick Moy [Fri, 23 Sep 2022 15:14:52 +0000 (17:14 +0200)]
ada: Do not issue compiler warnings in GNATprove mode
Use of pragma Warning with a string literal to set warning
switches, should not impact GNATprove which is not subject
to these switches.
gcc/ada/
* sem_prag.adb (Analyze_Pragma): Ignore one variant of pragma
Warnings in GNATprove mode.
Bob Duff [Tue, 27 Sep 2022 16:10:21 +0000 (12:10 -0400)]
ada: Disable slice-of-component optimization in some cases
This patch disables the Fast_Copy_Bitfield optimization in certain rare
cases that currently do not work (crash in gigi). We could improve
Expand_Assign_Array_Bitfield_Fast to handle these cases properly, but
that change is delicate, so for now, we simply disable the optimization.
gcc/ada/
* exp_ch5.adb
(Expand_Assign_Array_Loop_Or_Bitfield): Disable the
Fast_Copy_Bitfield optimization in certain cases.
Piotr Trojanek [Mon, 26 Sep 2022 10:51:41 +0000 (12:51 +0200)]
ada: Fix spurious warning on unreferenced refinement constituents
Listing an object as a state refinement constituent shouldn't be
considered to be a reference, at least from the point of view of the
machinery for detecting objects that are never referenced or written
without being referenced.
This patch fixes a spurious warning that rarely occurred in practice but
was annoyingly emitted for minimal reproducers for issues related to
state abstractions.
Note: there are other pragmas that should be similarly recognized (e.g.
Depends, Global and their refined variants), but recognizing them
efficiently probably requires a dedicated utility routine (i.e. to avoid
traversal of the parent chain for every kind of pragma).
gcc/ada/
* sem_prag.adb
(Sig_Pragma): Change flag for pragma Refined_State to mean "not
significant"; this is primarily for documentation, because the
exact value of the flag is not really taken into account for
Refined_State.
(Is_Non_Significant_Pragma_Reference): Add special handling for
pragma Refined_State.
Martin Liska [Thu, 6 Oct 2022 09:14:48 +0000 (11:14 +0200)]
git_update_version: add robust logging
contrib/ChangeLog:
* gcc-changelog/git_update_version.py: Use logging module
and provide robust debugging output.
Claudiu Zissulescu [Thu, 6 Oct 2022 08:36:31 +0000 (11:36 +0300)]
arc: Remove max-page-size and common-page-size forced setting
Max page size is defined in the ARC's BFD file, and the common page
size is also set by the appropriate binutils macros. Remove them from
LINK_SPEC.
2022-10-06 Claudiu Zissulescu <claziss@synopsys.com>
* config/arc/linux.h (LINK_SPEC): Remove max-page-size and
common-pave-size.
Signed-off-by: Claudiu Zissulescu <claziss@gmail.com>
Jakub Jelinek [Thu, 6 Oct 2022 09:04:52 +0000 (11:04 +0200)]
libgcc: Decrease size of _Unwind_FrameState and even more size of cleared area in uw_frame_state_for
The following patch implements something that has Florian found as
low hanging fruit in our unwinder and has been discussed in the
https://gcc.gnu.org/wiki/cauldron2022#cauldron2022talks.inprocess_unwinding_bof
talk.
_Unwind_FrameState type seems to be (unlike the pre-GCC 3 frame_state
which has been part of ABI) private to unwind-dw2.c + unwind.inc it
includes, it is always defined on the stack of some entrypoints, initialized
by static uw_frame_state_for and the address of it is also passed to other
static functions or the static inlines handling machine dependent unwinding,
but it isn't fortunately passed to any callbacks or public functions, so I
think we can safely change it any time we want.
Florian mentioned that the structure is large even on x86_64, 384 bytes
there, starts with 328 bytes long element with frame_state_reg_info type
which then starts with an array with __LIBGCC_DWARF_FRAME_REGISTERS__ + 1
elements, each of them is 16 bytes long, on x86_64
__LIBGCC_DWARF_FRAME_REGISTERS__ is just 17 but even that is big, on say
riscv __LIBGCC_DWARF_FRAME_REGISTERS__ is I think 128, on powerpc 111,
on sh 153 etc. And, we memset to zero the whole fs variable with the
_Unwind_FrameState type at the start of the unwinding.
The reason why each element is 16 byte (on 64-bit arches) is that it
contains some pointer or pointer sized integer and then an enum (with just
7 different enumerators) + padding.
The following patch decreases it by moving the enum into a separate
array and using just one byte for each register in that second array.
We could compress it even more, say 4 bits per register, but I don't
want to uglify the code for it too much and make the accesses slower.
Furthermore, the clearing of the object can clear only thos how array
and members after it, because REG_UNSAVED enumerator (0) doesn't actually
need any pointer or pointer sized integer, it is just the other kinds
that need to have there something.
By doing this, on x86_64 the above numbers change to _Unwind_FrameState
type being now 264 bytes long, frame_state_reg_info 208 bytes and we
don't clear the first 144 bytes of the object, so the memset is 120 bytes,
so ~ 31% of the old clearing size. On riscv 64-bit assuming it has same
structure layout rules for the few types used there that would be
~ 2160 bytes of _Unwind_FrameState type before and ~ 1264 bytes after,
with the memset previously ~ 2160 bytes and after ~ 232 bytes after.
We've also talked about possibly adding a number of initially initialized
regs and initializing the rest lazily, but at least for x86_64 with
18 elements in the array that doesn't seem to be worth it anymore,
especially because return address column is 16 there and that is usually the
first thing to be touched. It might theory help with lots of registers if
they are usually untouched, but would uglify and complicate any stores to
how by having to check there for the not initialized yet cases and lazy
initialization, and similarly for all reads of how to do there if below
last initialized one, use how, otherwise imply REG_UNSAVED.
The disadvantage of the patch is that touching reg[x].loc and how[x]
now means 2 cachelines rather than one as before, and I admit beyond
bootstrap/regtest I haven't benchmarked it in any way.
2022-10-06 Jakub Jelinek <jakub@redhat.com>
* unwind-dw2.h (REG_UNSAVED, REG_SAVED_OFFSET, REG_SAVED_REG,
REG_SAVED_EXP, REG_SAVED_VAL_OFFSET, REG_SAVED_VAL_EXP,
REG_UNDEFINED): New anonymous enum, moved from inside of
struct frame_state_reg_info.
(struct frame_state_reg_info): Remove reg[].how element and the
anonymous enum there. Add how element.
* unwind-dw2.c: Include stddef.h.
(uw_frame_state_for): Don't clear first
offsetof (_Unwind_FrameState, regs.how[0]) bytes of *fs.
(execute_cfa_program, __frame_state_for, uw_update_context_1,
uw_update_context): Use fs->regs.how[X] instead of fs->regs.reg[X].how
or fs.regs.how[X] instead of fs.regs.reg[X].how.
* config/sh/linux-unwind.h (sh_fallback_frame_state): Likewise.
* config/bfin/linux-unwind.h (bfin_fallback_frame_state): Likewise.
* config/pa/linux-unwind.h (pa32_fallback_frame_state): Likewise.
* config/pa/hpux-unwind.h (UPDATE_FS_FOR_SAR, UPDATE_FS_FOR_GR,
UPDATE_FS_FOR_FR, UPDATE_FS_FOR_PC, pa_fallback_frame_state):
Likewise.
* config/alpha/vms-unwind.h (alpha_vms_fallback_frame_state):
Likewise.
* config/alpha/linux-unwind.h (alpha_fallback_frame_state): Likewise.
* config/arc/linux-unwind.h (arc_fallback_frame_state,
arc_frob_update_context): Likewise.
* config/riscv/linux-unwind.h (riscv_fallback_frame_state): Likewise.
* config/nios2/linux-unwind.h (NIOS2_REG): Likewise.
* config/nds32/linux-unwind.h (NDS32_PUT_FS_REG): Likewise.
* config/s390/tpf-unwind.h (s390_fallback_frame_state): Likewise.
* config/s390/linux-unwind.h (s390_fallback_frame_state): Likewise.
* config/sparc/sol2-unwind.h (sparc64_frob_update_context,
MD_FALLBACK_FRAME_STATE_FOR): Likewise.
* config/sparc/linux-unwind.h (sparc64_fallback_frame_state,
sparc64_frob_update_context, sparc_fallback_frame_state): Likewise.
* config/i386/sol2-unwind.h (x86_64_fallback_frame_state,
x86_fallback_frame_state): Likewise.
* config/i386/w32-unwind.h (i386_w32_fallback_frame_state): Likewise.
* config/i386/linux-unwind.h (x86_64_fallback_frame_state,
x86_fallback_frame_state): Likewise.
* config/i386/freebsd-unwind.h (x86_64_freebsd_fallback_frame_state):
Likewise.
* config/i386/dragonfly-unwind.h
(x86_64_dragonfly_fallback_frame_state): Likewise.
* config/i386/gnu-unwind.h (x86_gnu_fallback_frame_state): Likewise.
* config/csky/linux-unwind.h (csky_fallback_frame_state): Likewise.
* config/aarch64/linux-unwind.h (aarch64_fallback_frame_state):
Likewise.
* config/aarch64/freebsd-unwind.h
(aarch64_freebsd_fallback_frame_state): Likewise.
* config/aarch64/aarch64-unwind.h (aarch64_frob_update_context):
Likewise.
* config/or1k/linux-unwind.h (or1k_fallback_frame_state): Likewise.
* config/mips/linux-unwind.h (mips_fallback_frame_state): Likewise.
* config/loongarch/linux-unwind.h (loongarch_fallback_frame_state):
Likewise.
* config/m68k/linux-unwind.h (m68k_fallback_frame_state): Likewise.
* config/xtensa/linux-unwind.h (xtensa_fallback_frame_state):
Likewise.
* config/rs6000/darwin-fallback.c (set_offset): Likewise.
* config/rs6000/aix-unwind.h (MD_FROB_UPDATE_CONTEXT): Likewise.
* config/rs6000/linux-unwind.h (ppc_fallback_frame_state): Likewise.
* config/rs6000/freebsd-unwind.h (frob_update_context): Likewise.
Jakub Jelinek [Thu, 6 Oct 2022 08:39:41 +0000 (10:39 +0200)]
openmp: Map holds clause to IFN_ASSUME for C/C++
Now that [[assume (cond)]] support is in, this simple patch makes
#pragma omp assume holds(cond)
use it.
2022-10-06 Jakub Jelinek <jakub@redhat.com>
* c-parser.cc (c_parser_omp_assumption_clauses): Emit IFN_ASSUME
call for holds clause on assume construct.
* parser.cc (cp_parser_omp_assumption_clauses): Emit IFN_ASSUME
call for holds clause on assume construct.
* c-c++-common/gomp/assume-4.c: New test.
Jakub Jelinek [Thu, 6 Oct 2022 06:56:48 +0000 (08:56 +0200)]
c++, c: Implement C++23 P1774R8 - Portable assumptions [PR106654]
The following patch implements C++23 P1774R8 - Portable assumptions
paper, by introducing support for [[assume (cond)]]; attribute for C++.
In addition to that the patch adds [[gnu::assume (cond)]]; and
__attribute__((assume (cond))); support to both C and C++.
As described in C++23, the attribute argument is conditional-expression
rather than the usual assignment-expression for attribute arguments,
the condition is contextually converted to bool (for C truthvalue conversion
is done on it) and is never evaluated at runtime.
For C++ constant expression evaluation, I only check the simplest conditions
for undefined behavior, because otherwise I'd need to undo changes to
*ctx->global which happened during the evaluation (but I believe the spec
allows that and we can further improve later).
The patch uses a new internal function, .ASSUME, to hold the condition
in the FEs. At gimplification time, if the condition is simple/without
side-effects, it is gimplified as if (cond) ; else __builtin_unreachable ();
and otherwise for now dropped on the floor. The intent is to incrementally
outline the conditions into separate artificial functions and use
.ASSUME further to tell the ranger and perhaps other optimization passes
about the assumptions, as detailed in the PR.
When implementing it, I found that assume entry hasn't been added to
https://eel.is/c++draft/cpp.cond#6
Jonathan said he'll file a NB comment about it, this patch assumes it
has been added into the table as 202207L when the paper has been voted in.
With the attributes for both C/C++, I'd say we don't need to add
__builtin_assume with similar purpose, especially when __builtin_assume
in LLVM is just weird. It is strange for side-effects in function call's
argument not to be evaluated, and LLVM in that case (annoyingly) warns
and ignores the side-effects (but doesn't do then anything with it),
if there are no side-effects, it will work like our
if (!cond) __builtin_unreachable ();
2022-10-06 Jakub Jelinek <jakub@redhat.com>
PR c++/106654
gcc/
* internal-fn.def (ASSUME): New internal function.
* internal-fn.h (expand_ASSUME): Declare.
* internal-fn.cc (expand_ASSUME): Define.
* gimplify.cc (gimplify_call_expr): Gimplify IFN_ASSUME.
* fold-const.h (simple_condition_p): Declare.
* fold-const.cc (simple_operand_p_2): Rename to ...
(simple_condition_p): ... this. Remove forward declaration.
No longer static. Adjust function comment and fix a typo in it.
Adjust recursive call.
(simple_operand_p): Adjust function comment.
(fold_truth_andor): Adjust simple_operand_p_2 callers to call
simple_condition_p.
* doc/extend.texi: Document assume attribute. Move fallthrough
attribute example to its section.
gcc/c-family/
* c-attribs.cc (handle_assume_attribute): New function.
(c_common_attribute_table): Add entry for assume attribute.
* c-lex.cc (c_common_has_attribute): Handle
__have_cpp_attribute (assume).
gcc/c/
* c-parser.cc (handle_assume_attribute): New function.
(c_parser_declaration_or_fndef): Handle assume attribute.
(c_parser_attribute_arguments): Add assume_attr argument,
if true, parse first argument as conditional expression.
(c_parser_gnu_attribute, c_parser_std_attribute): Adjust
c_parser_attribute_arguments callers.
(c_parser_statement_after_labels) <case RID_ATTRIBUTE>: Handle
assume attribute.
gcc/cp/
* cp-tree.h (process_stmt_assume_attribute): Implement C++23
P1774R8 - Portable assumptions. Declare.
(diagnose_failing_condition): Declare.
(find_failing_clause): Likewise.
* parser.cc (assume_attr): New enumerator.
(cp_parser_parenthesized_expression_list): Handle assume_attr.
Remove identifier variable, for id_attr push the identifier into
expression_list right away instead of inserting it before all the
others at the end.
(cp_parser_conditional_expression): New function.
(cp_parser_constant_expression): Use it.
(cp_parser_statement): Handle assume attribute.
(cp_parser_expression_statement): Likewise.
(cp_parser_gnu_attribute_list): Use assume_attr for assume
attribute.
(cp_parser_std_attribute): Likewise. Handle standard assume
attribute like gnu::assume.
* cp-gimplify.cc (process_stmt_assume_attribute): New function.
* constexpr.cc: Include fold-const.h.
(find_failing_clause_r, find_failing_clause): New functions,
moved from semantics.cc with ctx argument added and if non-NULL,
call cxx_eval_constant_expression rather than fold_non_dependent_expr.
(cxx_eval_internal_function): Handle IFN_ASSUME.
(potential_constant_expression_1): Likewise.
* pt.cc (tsubst_copy_and_build): Likewise.
* semantics.cc (diagnose_failing_condition): New function.
(find_failing_clause_r, find_failing_clause): Moved to constexpr.cc.
(finish_static_assert): Use it. Add auto_diagnostic_group.
gcc/testsuite/
* gcc.dg/attr-assume-1.c: New test.
* gcc.dg/attr-assume-2.c: New test.
* gcc.dg/attr-assume-3.c: New test.
* g++.dg/cpp2a/feat-cxx2a.C: Add colon to C++20 features
comment, add C++20 attributes comment and move C++20
new features after the attributes before them.
* g++.dg/cpp23/feat-cxx2b.C: Likewise. Test
__has_cpp_attribute(assume).
* g++.dg/cpp23/attr-assume1.C: New test.
* g++.dg/cpp23/attr-assume2.C: New test.
* g++.dg/cpp23/attr-assume3.C: New test.
* g++.dg/cpp23/attr-assume4.C: New test.
Stefan Schulze Frielinghaus [Thu, 6 Oct 2022 06:43:53 +0000 (08:43 +0200)]
cselib: Skip BImode while keeping track of subvalue relations [PR107088]
For BImode get_narrowest_mode evaluates to QImode but BImode < QImode.
Thus FOR_EACH_MODE_UNTIL never reaches BImode and iterates until OImode
for which no wider mode exists so we end up with VOIDmode and fail.
Fixed by adding a size guard so we effectively skip BImode.
gcc/ChangeLog:
PR rtl-optimization/107088
* cselib.cc (new_cselib_val): Skip BImode while keeping track of
subvalue relations.
Aldy Hernandez [Wed, 5 Oct 2022 18:22:38 +0000 (20:22 +0200)]
Setting explicit NANs sets UNDEFINED for -ffinite-math-only.
We recently agreed that setting a range of NAN should instead set
UNDEFINED for -ffinite-math-only. This patch makes that change to
frange::set_nan() directly. Also, calling frange::update_nan() will now
be a nop for !HONOR_NANS.
Doing this in the setters simplifies everywhere we set NANs, as it keeps
us from introducing NANs by mistake.
gcc/ChangeLog:
* value-range.cc (frange::set): Call set_nan unconditionally.
(range_tests_nan): Adjust tests.
(range_tests_signed_zeros): Same.
(range_tests_floats): Same.
* value-range.h (frange::update_nan): Guard with HONOR_NANS.
(frange::set_nan): Set undefined if !HONOR_NANS.
Aldy Hernandez [Wed, 5 Oct 2022 18:21:26 +0000 (20:21 +0200)]
Do not check finite_operands_p twice in range-ops-float.
The uses of finite_operands_p removed are guarded by a call to
finite_operands_p already.
gcc/ChangeLog:
* range-op-float.cc (foperator_lt::fold_range): Remove extra check
to finite_operands_p.
(foperator_le::fold_range): Same.
(foperator_gt::fold_range): Same.
(foperator_ge::fold_range): Same.