aboutsummaryrefslogtreecommitdiff
path: root/gcc
AgeCommit message (Collapse)AuthorFilesLines
2022-10-08Fortran: error recovery for invalid types in array constructors [PR107000]Harald Anlauf3-6/+76
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>
2022-10-08Merge branch 'master' into devel/sphinxMartin Liska289-1447/+10847
2022-10-07c++: track whether we expect a TARGET_EXPR to be elidedJason Merrill12-62/+138
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.
2022-10-08Daily bump.GCC Administrator8-1/+279
2022-10-07c++: fixes for derived-to-base reference binding [PR107085]Marek Polacek7-12/+60
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.
2022-10-07Set discriminators for call stmts on the same line within the same basic block.Eugene Rozenfeld1-0/+32
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.
2022-10-07Use array_at_struct_end_p in __builtin_object_size [PR101836]Qing Zhao9-9/+487
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.
2022-10-07Add a new option -fstrict-flex-arrays[=n] and new attribute strict_flex_arrayQing Zhao14-28/+350
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.
2022-10-07Specialize paths to version.h in _vxworks-versions.hOlivier Hainque1-5/+14
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.
2022-10-07analyzer: extract bits from integer constants [PR105783]David Malcolm3-1/+94
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>
2022-10-07c++ modules: ICE with bitfield in class templatePatrick Palka2-1/+13
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.
2022-10-07c++: catch parm initialization tweakJason Merrill1-11/+12
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.
2022-10-07IPA: support -flto + -flive-patching=inline-cloneMartin Liska3-4/+13
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.
2022-10-07c++ modules: static var in inline function [PR104433]Patrick Palka3-0/+20
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.
2022-10-07gimplify: prevent some C++ temporary elisionJason Merrill2-7/+33
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.
2022-10-07tree-optimization/107153 - autopar SSA update issueRichard Biener3-2/+22
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.
2022-10-07gcc: Fix comment typoJonathan Wakely1-1/+1
gcc/ChangeLog: * value-range.cc (irange::irange_contains_p): Fix comment typo.
2022-10-07Reduce DF computation at -O0Eric Botcazou1-4/+9
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.
2022-10-07Convert nonzero mask back to tree.Aldy Hernandez2-27/+77
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.
2022-10-07fix clang warningsMartin Liska4-20/+20
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.
2022-10-07remove dead variablesMartin Liska2-5/+3
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.
2022-10-07Fix comment typosJakub Jelinek5-5/+5
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.
2022-10-07c++: Improve handling of foreigner namespace attributesJakub Jelinek7-27/+123
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.
2022-10-07Downgrade DWARF_VERSION_DEFAULT to 3 for VxWorks >= 7Olivier Hainque1-1/+1
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.
2022-10-07Introduce DWARF_VERSION_DEFAULT and redefine for VxWorksOlivier Hainque6-13/+25
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.
2022-10-07undef offsetof before defining it in stddef.hOlivier Hainque1-0/+1
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.
2022-10-06compiler: better arg type checking for selected builtinsThan McIntosh2-2/+7
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
2022-10-07Daily bump.GCC Administrator9-1/+444
2022-10-06c++: fix broken conversion in coroutinesJason Merrill2-1/+5
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.
2022-10-06[PR107170] Avoid copying incompatible types in legacy VRP.Aldy Hernandez2-11/+21
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.
2022-10-06analyzer: fix another ICE in PR 107158David Malcolm2-28/+114
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>
2022-10-06analyzer: fixes to call_summary_replay::dump_to_ppDavid Malcolm1-2/+8
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>
2022-10-06openmp: Map holds clause to IFN_ASSUME for FortranTobias Burnus3-1/+132
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.
2022-10-06c: C2x typeofJoseph Myers13-23/+406
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.
2022-10-06c++: remove optimize_specialization_lookup_pPatrick Palka4-118/+59
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.
2022-10-06Fix wrong code generated by unroll-and-jam passEric Botcazou2-2/+45
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.
2022-10-06Minor cleanup in DF codeEric Botcazou1-10/+14
No functional changes. gcc/ * df-scan.cc (df_ref_create_structure): Minor cleanup.
2022-10-06middle-end/107115 - avoid bogus redundant store removal during RTL expansionRichard Biener2-1/+40
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.
2022-10-06aarch64: Remove redundant zero-extends with LDARKyrylo Tkachov2-0/+44
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.
2022-10-06aarch64: Add test for LDAR generation from __atomic_load_nKyrylo Tkachov1-0/+66
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.
2022-10-06aarch64: update Ampere-1 core definitionPhilipp Tomsich1-1/+1
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>
2022-10-06aarch64: fix off-by-one in reading cpuinfoPhilipp Tomsich3-2/+25
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>
2022-10-06tree-optimization/107107 - tail-merging VN wrong-codeRichard Biener2-14/+28
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.
2022-10-06ada: Implementation of support for storage models in gigiEric Botcazou7-61/+605
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.
2022-10-06ada: Minor potential bug in sem_ch6.adbSteve Baird1-1/+1
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.
2022-10-06ada: Reject conditional goto in lock-free protected subprogramsPiotr Trojanek1-1/+1
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.
2022-10-06ada: Cleanup related to lock-free protected subprogramsPiotr Trojanek3-11/+9
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.
2022-10-06ada: hardened conditionals: exemplify codegen changesAlexandre Oliva2-4/+94
gcc/ada/ * doc/gnat_rm/security_hardening_features.rst: Add examples of codegen changes in hardened conditionals. * gnat_rm.texi: Regenerate.
2022-10-06ada: hardened booleans: exemplify codegen changesAlexandre Oliva2-7/+48
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.
2022-10-06ada: stack scrubbing: exemplify codegen changesAlexandre Oliva2-2/+103
gcc/ada/ * doc/gnat_rm/security_hardening_features.rst: Add examples of codegen changes in stack scrubbing. * gnat_rm.texi: Regenerate.