aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimplify.c
AgeCommit message (Collapse)AuthorFilesLines
2020-11-25libsanitizer: Add hwasan pass and associated gimple changesMatthew Malcomson1-3/+6
There are four main features to this change: 1) Check pointer tags match address tags. When sanitizing for hwasan we now put HWASAN_CHECK internal functions before memory accesses in the `asan` pass. This checks that a tag in the pointer being used match the tag stored in shadow memory for the memory region being used. These internal functions are expanded into actual checks in the sanopt pass that happens just before expansion into RTL. We use the same mechanism that currently inserts ASAN_CHECK internal functions to insert the new HWASAN_CHECK functions. 2) Instrument known builtin function calls. Handle all builtin functions that we know use memory accesses. This commit uses the machinery added for ASAN to identify builtin functions that access memory. The main differences between the approaches for HWASAN and ASAN are: - libhwasan intercepts much less builtin functions. - Alloca needs to be transformed differently (instead of adding redzones it needs to tag shadow memory and return a tagged pointer). - stack_restore needs to untag the shadow stack between the current position and where it's going. - `noreturn` functions can not be handled by simply unpoisoning the entire shadow stack -- there is no "always valid" tag. (exceptions and things such as longjmp need to be handled in a different way, usually in the runtime). For hardware implemented checking (such as AArch64's memory tagging extension) alloca and stack_restore will need to be handled by hooks in the backend rather than transformation at the gimple level. This will allow architecture specific handling of such stack modifications. 3) Introduce HWASAN block-scope poisoning Here we use exactly the same mechanism as ASAN_MARK to poison/unpoison variables on entry/exit of a block. In order to simply use the exact same machinery we're using the same internal functions until the SANOPT pass. This means that all handling of ASAN_MARK is the same. This has the negative that the naming may be a little confusing, but a positive that handling of the internal function doesn't have to be duplicated for a function that behaves exactly the same but has a different name. gcc/ChangeLog: * asan.c (asan_instrument_reads): New. (asan_instrument_writes): New. (asan_memintrin): New. (handle_builtin_stack_restore): Account for HWASAN. (handle_builtin_alloca): Account for HWASAN. (get_mem_refs_of_builtin_call): Special case strlen for HWASAN. (hwasan_instrument_reads): New. (hwasan_instrument_writes): New. (hwasan_memintrin): New. (report_error_func): Assert not HWASAN. (build_check_stmt): Make HWASAN_CHECK instead of ASAN_CHECK. (instrument_derefs): HWASAN does not tag globals. (instrument_builtin_call): Use new helper functions. (maybe_instrument_call): Don't instrument `noreturn` functions. (initialize_sanitizer_builtins): Add new type. (asan_expand_mark_ifn): Account for HWASAN. (asan_expand_check_ifn): Assert never called by HWASAN. (asan_expand_poison_ifn): Account for HWASAN. (asan_instrument): Branch based on whether using HWASAN or ASAN. (pass_asan::gate): Return true if sanitizing HWASAN. (pass_asan_O0::gate): Return true if sanitizing HWASAN. (hwasan_check_func): New. (hwasan_expand_check_ifn): New. (hwasan_expand_mark_ifn): New. (gate_hwasan): New. * asan.h (hwasan_expand_check_ifn): New decl. (hwasan_expand_mark_ifn): New decl. (gate_hwasan): New decl. (asan_intercepted_p): Always false for hwasan. (asan_sanitize_use_after_scope): Account for HWASAN. * builtin-types.def (BT_FN_PTR_CONST_PTR_UINT8): New. * gimple-fold.c (gimple_build): New overload for building function calls without arguments. (gimple_build_round_up): New. * gimple-fold.h (gimple_build): New decl. (gimple_build): New inline function. (gimple_build_round_up): New decl. (gimple_build_round_up): New inline function. * gimple-pretty-print.c (dump_gimple_call_args): Account for HWASAN. * gimplify.c (asan_poison_variable): Account for HWASAN. (gimplify_function_tree): Remove requirement of SANITIZE_ADDRESS, requiring asan or hwasan is accounted for in `asan_sanitize_use_after_scope`. * internal-fn.c (expand_HWASAN_CHECK): New. (expand_HWASAN_ALLOCA_UNPOISON): New. (expand_HWASAN_CHOOSE_TAG): New. (expand_HWASAN_MARK): New. (expand_HWASAN_SET_TAG): New. * internal-fn.def (HWASAN_ALLOCA_UNPOISON): New. (HWASAN_CHOOSE_TAG): New. (HWASAN_CHECK): New. (HWASAN_MARK): New. (HWASAN_SET_TAG): New. * sanitizer.def (BUILT_IN_HWASAN_LOAD1): New. (BUILT_IN_HWASAN_LOAD2): New. (BUILT_IN_HWASAN_LOAD4): New. (BUILT_IN_HWASAN_LOAD8): New. (BUILT_IN_HWASAN_LOAD16): New. (BUILT_IN_HWASAN_LOADN): New. (BUILT_IN_HWASAN_STORE1): New. (BUILT_IN_HWASAN_STORE2): New. (BUILT_IN_HWASAN_STORE4): New. (BUILT_IN_HWASAN_STORE8): New. (BUILT_IN_HWASAN_STORE16): New. (BUILT_IN_HWASAN_STOREN): New. (BUILT_IN_HWASAN_LOAD1_NOABORT): New. (BUILT_IN_HWASAN_LOAD2_NOABORT): New. (BUILT_IN_HWASAN_LOAD4_NOABORT): New. (BUILT_IN_HWASAN_LOAD8_NOABORT): New. (BUILT_IN_HWASAN_LOAD16_NOABORT): New. (BUILT_IN_HWASAN_LOADN_NOABORT): New. (BUILT_IN_HWASAN_STORE1_NOABORT): New. (BUILT_IN_HWASAN_STORE2_NOABORT): New. (BUILT_IN_HWASAN_STORE4_NOABORT): New. (BUILT_IN_HWASAN_STORE8_NOABORT): New. (BUILT_IN_HWASAN_STORE16_NOABORT): New. (BUILT_IN_HWASAN_STOREN_NOABORT): New. (BUILT_IN_HWASAN_TAG_MISMATCH4): New. (BUILT_IN_HWASAN_HANDLE_LONGJMP): New. (BUILT_IN_HWASAN_TAG_PTR): New. * sanopt.c (sanopt_optimize_walker): Act for hwasan. (pass_sanopt::execute): Act for hwasan. * toplev.c (compile_file): Use `gate_hwasan` function.
2020-11-20c++: Add __builtin_clear_padding builtin - C++20 P0528R3 compiler side [PR88101]Jakub Jelinek1-0/+14
The following patch implements __builtin_clear_padding builtin that clears the padding bits in object representation (but preserves value representation). Inside of unions it clears only those padding bits that are padding for all the union members (so that it never alters value representation). It handles trailing padding, padding in the middle of structs including bitfields (PDP11 unhandled, I've never figured out how those bitfields work), VLAs (doesn't handle variable length structures, but I think almost nobody uses them and it isn't worth the extra complexity). For VLAs and sufficiently large arrays it uses runtime clearing loop instead of emitting straight-line code (unless arrays are inside of a union). The way I think this can be used for atomics is e.g. if the structures are power of two sized and small enough that we use the hw atomics for say compare_exchange __builtin_clear_padding could be called first on the address of expected and desired arguments (for desired only if we want to ensure that most of the time the atomic memory will have padding bits cleared), then perform the weak cmpxchg and if that fails, we got the value from the atomic memory; we can call __builtin_clear_padding on a copy of that and then compare it with expected, and if it is the same with the padding bits masked off, we can use the original with whatever random padding bits in it as the new expected for next cmpxchg. __builtin_clear_padding itself is not atomic and therefore it shouldn't be called on the atomic memory itself, but compare_exchange*'s expected argument is a reference and normally the implementation may store there the current value from memory, so padding bits can be cleared in that, and desired is passed by value rather than reference, so clearing is fine too. When using libatomic, we can use it either that way, or add new libatomic APIs that accept another argument, pointer to the padding bit bitmask, and construct that in the template as alignas (_T) unsigned char _mask[sizeof (_T)]; std::memset (_mask, ~0, sizeof (_mask)); __builtin_clear_padding ((_T *) _mask); which will have bits cleared for padding bits and set for bits taking part in the value representation. Then libatomic could internally instead of using memcmp compare for (i = 0; i < N; i++) if ((val1[i] & mask[i]) != (val2[i] & mask[i])) 2020-11-20 Jakub Jelinek <jakub@redhat.com> PR libstdc++/88101 gcc/ * builtins.def (BUILT_IN_CLEAR_PADDING): New built-in function. * gimplify.c (gimplify_call_expr): Rewrite single argument BUILT_IN_CLEAR_PADDING into two-argument variant. * gimple-fold.c (clear_padding_unit, clear_padding_buf_size): New const variables. (struct clear_padding_struct): New type. (clear_padding_flush, clear_padding_add_padding, clear_padding_emit_loop, clear_padding_type, clear_padding_union, clear_padding_real_needs_padding_p, clear_padding_type_may_have_padding_p, gimple_fold_builtin_clear_padding): New functions. (gimple_fold_builtin): Handle BUILT_IN_CLEAR_PADDING. * doc/extend.texi (__builtin_clear_padding): Document. gcc/c-family/ * c-common.c (check_builtin_function_arguments): Handle BUILT_IN_CLEAR_PADDING. gcc/testsuite/ * c-c++-common/builtin-clear-padding-1.c: New test. * c-c++-common/torture/builtin-clear-padding-1.c: New test. * c-c++-common/torture/builtin-clear-padding-2.c: New test. * c-c++-common/torture/builtin-clear-padding-3.c: New test. * c-c++-common/torture/builtin-clear-padding-4.c: New test. * c-c++-common/torture/builtin-clear-padding-5.c: New test. * g++.dg/torture/builtin-clear-padding-1.C: New test. * g++.dg/torture/builtin-clear-padding-2.C: New test. * gcc.dg/builtin-clear-padding-1.c: New test.
2020-11-20C: Drop qualifiers during lvalue conversion [PR97702]Martin Uecker1-0/+13
2020-11-20 Martin Uecker <muecker@gwdg.de> gcc/ * gimplify.c (gimplify_modify_expr_rhs): Optimizie NOP_EXPRs that contain compound literals. gcc/c/ * c-typeck.c (convert_lvalue_to_rvalue): Drop qualifiers. gcc/testsuite/ * gcc.dg/cond-constqual-1.c: Adapt test. * gcc.dg/lvalue-11.c: New test. * gcc.dg/pr60195.c: Add warning.
2020-11-14openmp: Add support for non-VLA {,first}private allocate on omp taskJakub Jelinek1-12/+12
This patch adds support for custom allocators on private/firstprivate clauses for task (and taskloop) constructs. Private didn't need anything special, but firstprivate if it is passed by reference needs the GOMP_alloc calls in the copyfn and GOMP_free in the task body. 2020-11-14 Jakub Jelinek <jakub@redhat.com> * gimplify.c (gimplify_omp_for): Add OMP_CLAUSE_ALLOCATE_ALLOCATOR decls as firstprivate on task clauses even when allocate clause decl is not lastprivate. * omp-low.c (install_var_field): Don't dereference omp_is_reference types if mask is 33 rather than 1. (scan_sharing_clauses): Populate allocate_map even for task constructs. For now remove it back for variables mentioned in reduction and in_reduction clauses on task/taskloop constructs or on VLA task firstprivates. For firstprivate on task construct, install the var field into field_map with by_ref and 33 instead of false and 1 if mentioned in allocate clause. (lower_private_allocate): Set TREE_THIS_NOTRAP on the created MEM_REF. (lower_rec_input_clauses): Handle allocate for task firstprivatized non-VLA variables. (create_task_copyfn): Likewise. * testsuite/libgomp.c-c++-common/allocate-1.c (struct S): New type. (foo): Add tests for non-VLA private and firstprivate clauses on omp task. (bar): Likewise. Remove taking of address from private/firstprivate variables. * testsuite/libgomp.c++/allocate-1.C (struct S): New type. (foo): Add p, q, px and s arguments. Add tests for array reductions and for non-VLA private and firstprivate clauses on omp task. (bar): Removed. (main): Adjust foo caller. Don't call bar.
2020-11-12openmp: Implement allocate clause in omp lowering.Jakub Jelinek1-6/+55
For now, task/taskloop constructs aren't handled and C/C++ array reductions and reductions with task or inscan modifiers need further work. Instead of calling omp_alloc/omp_free (where the former doesn't have alignment argument and omp_aligned_alloc is 5.1 only feature), this calls GOMP_alloc/GOMP_free, so that the library can fail if it would fall back into NULL (exception is zero length allocations). 2020-11-12 Jakub Jelinek <jakub@redhat.com> gcc/ * builtin-types.def (BT_FN_PTR_SIZE_SIZE_PTRMODE): New function type. * omp-builtins.def (BUILT_IN_GOACC_DECLARE): Move earlier. (BUILT_IN_GOMP_ALLOC, BUILT_IN_GOMP_FREE): New builtins. * gimplify.c (gimplify_scan_omp_clauses): Force allocator into a decl if it is not NULL, INTEGER_CST or decl. (gimplify_adjust_omp_clauses): Clear GOVD_EXPLICIT on explicit clauses which are being removed. Remove allocate clauses for variables not seen if they are private, firstprivate or linear too. Call omp_notice_variable on the allocator otherwise. (gimplify_omp_for): Handle iterator vars mentioned in allocate clauses similarly to non-is_gimple_reg iterators. * omp-low.c (struct omp_context): Add allocate_map field. (delete_omp_context): Delete it. (scan_sharing_clauses): Fill it from allocate clauses. Remove it if mentioned also in shared clause. (lower_private_allocate): New function. (lower_rec_input_clauses): Handle allocate clause for privatized variables, except for task/taskloop, C/C++ array reductions for now and task/inscan variables. (lower_send_shared_vars): Don't consider variables in allocate_map as shared. * omp-expand.c (expand_omp_for_generic, expand_omp_for_static_nochunk, expand_omp_for_static_chunk): Use expand_omp_build_assign instead of gimple_build_assign + gsi_insert_after. * builtins.c (builtin_fnspec): Handle BUILTIN_GOMP_ALLOC and BUILTIN_GOMP_FREE. * tree-ssa-ccp.c (evaluate_stmt): Handle BUILTIN_GOMP_ALLOC. * tree-ssa-dce.c (mark_stmt_if_obviously_necessary): Handle BUILTIN_GOMP_ALLOC. (mark_all_reaching_defs_necessary_1): Handle BUILTIN_GOMP_ALLOC and BUILTIN_GOMP_FREE. (propagate_necessity): Likewise. gcc/fortran/ * f95-lang.c (ATTR_ALLOC_WARN_UNUSED_RESULT_SIZE_2_NOTHROW_LIST): Define. (gfc_init_builtin_functions): Add alloc_size and warn_unused_result attributes to __builtin_GOMP_alloc. * types.def (BT_PTRMODE): New primitive type. (BT_FN_VOID_PTR_PTRMODE, BT_FN_PTR_SIZE_SIZE_PTRMODE): New function types. libgomp/ * libgomp.map (GOMP_alloc, GOMP_free): Export at GOMP_5.0.1. * omp.h.in (omp_alloc): Add malloc and alloc_size attributes. * libgomp_g.h (GOMP_alloc, GOMP_free): Declare. * allocator.c (omp_aligned_alloc): New for now static function, add alignment argument and handle it. (omp_alloc): Reimplement using omp_aligned_alloc. (GOMP_alloc, GOMP_free): New functions. (omp_free): Add ialias. * testsuite/libgomp.c-c++-common/allocate-1.c: New test. * testsuite/libgomp.c++/allocate-1.C: New test.
2020-11-10Fortran: OpenMP 5.0 (in_,task_)reduction clause extensionsTobias Burnus1-2/+4
gcc/fortran/ChangeLog: * dump-parse-tree.c (show_omp_clauses): Handle new reduction enums. * gfortran.h (OMP_LIST_REDUCTION_INSCAN, OMP_LIST_REDUCTION_TASK, OMP_LIST_IN_REDUCTION, OMP_LIST_TASK_REDUCTION): Add enums. * openmp.c (enum omp_mask1): Add OMP_CLAUSE_IN_REDUCTION and OMP_CLAUSE_TASK_REDUCTION. (gfc_match_omp_clause_reduction): Extend reduction handling; moved from ... (gfc_match_omp_clauses): ... here. Add calls to it. (OMP_TASK_CLAUSES, OMP_TARGET_CLAUSES, OMP_TASKLOOP_CLAUSES): Add OMP_CLAUSE_IN_REDUCTION. (gfc_match_omp_taskgroup): Add task_reduction matching. (resolve_omp_clauses): Update for new reduction clause changes; remove removed nonmonotonic-schedule restrictions. (gfc_resolve_omp_parallel_blocks): Add new enums to switch. * trans-openmp.c (gfc_omp_clause_default_ctor, gfc_trans_omp_reduction_list, gfc_trans_omp_clauses, gfc_split_omp_clauses): Handle updated reduction clause. gcc/ChangeLog: * gimplify.c (gimplify_scan_omp_clauses, gimplify_omp_loop): Use 'do' instead of 'for' in error messages for Fortran. * omp-low.c (check_omp_nesting_restrictions): Likewise gcc/testsuite/ChangeLog: * gfortran.dg/gomp/schedule-modifiers-2.f90: Remove some dg-error. * gfortran.dg/gomp/reduction4.f90: New test. * gfortran.dg/gomp/reduction5.f90: New test. * gfortran.dg/gomp/workshare-reduction-1.f90: New test. * gfortran.dg/gomp/workshare-reduction-2.f90: New test. * gfortran.dg/gomp/workshare-reduction-3.f90: New test. * gfortran.dg/gomp/workshare-reduction-4.f90: New test. * gfortran.dg/gomp/workshare-reduction-5.f90: New test. * gfortran.dg/gomp/workshare-reduction-6.f90: New test. * gfortran.dg/gomp/workshare-reduction-7.f90: New test. * gfortran.dg/gomp/workshare-reduction-8.f90: New test. * gfortran.dg/gomp/workshare-reduction-9.f90: New test. * gfortran.dg/gomp/workshare-reduction-10.f90: New test. * gfortran.dg/gomp/workshare-reduction-11.f90: New test. * gfortran.dg/gomp/workshare-reduction-12.f90: New test. * gfortran.dg/gomp/workshare-reduction-13.f90: New test. * gfortran.dg/gomp/workshare-reduction-14.f90: New test. * gfortran.dg/gomp/workshare-reduction-15.f90: New test. * gfortran.dg/gomp/workshare-reduction-16.f90: New test. * gfortran.dg/gomp/workshare-reduction-17.f90: New test. * gfortran.dg/gomp/workshare-reduction-18.f90: New test. * gfortran.dg/gomp/workshare-reduction-19.f90: New test. * gfortran.dg/gomp/workshare-reduction-20.f90: New test. * gfortran.dg/gomp/workshare-reduction-21.f90: New test. * gfortran.dg/gomp/workshare-reduction-22.f90: New test. * gfortran.dg/gomp/workshare-reduction-23.f90: New test. * gfortran.dg/gomp/workshare-reduction-24.f90: New test. * gfortran.dg/gomp/workshare-reduction-25.f90: New test. * gfortran.dg/gomp/workshare-reduction-26.f90: New test. * gfortran.dg/gomp/workshare-reduction-27.f90: New test. * gfortran.dg/gomp/workshare-reduction-28.f90: New test. * gfortran.dg/gomp/workshare-reduction-29.f90: New test. * gfortran.dg/gomp/workshare-reduction-30.f90: New test. * gfortran.dg/gomp/workshare-reduction-31.f90: New test. * gfortran.dg/gomp/workshare-reduction-32.f90: New test. * gfortran.dg/gomp/workshare-reduction-33.f90: New test. * gfortran.dg/gomp/workshare-reduction-34.f90: New test. * gfortran.dg/gomp/workshare-reduction-35.f90: New test. * gfortran.dg/gomp/workshare-reduction-36.f90: New test. * gfortran.dg/gomp/workshare-reduction-37.f90: New test. * gfortran.dg/gomp/workshare-reduction-38.f90: New test. * gfortran.dg/gomp/workshare-reduction-39.f90: New test. * gfortran.dg/gomp/workshare-reduction-40.f90: New test. * gfortran.dg/gomp/workshare-reduction-41.f90: New test. * gfortran.dg/gomp/workshare-reduction-42.f90: New test. * gfortran.dg/gomp/workshare-reduction-43.f90: New test. * gfortran.dg/gomp/workshare-reduction-44.f90: New test. * gfortran.dg/gomp/workshare-reduction-45.f90: New test. * gfortran.dg/gomp/workshare-reduction-46.f90: New test. * gfortran.dg/gomp/workshare-reduction-47.f90: New test. * gfortran.dg/gomp/workshare-reduction-48.f90: New test. * gfortran.dg/gomp/workshare-reduction-49.f90: New test. * gfortran.dg/gomp/workshare-reduction-50.f90: New test. * gfortran.dg/gomp/workshare-reduction-51.f90: New test. * gfortran.dg/gomp/workshare-reduction-52.f90: New test. * gfortran.dg/gomp/workshare-reduction-53.f90: New test. * gfortran.dg/gomp/workshare-reduction-54.f90: New test. * gfortran.dg/gomp/workshare-reduction-55.f90: New test. * gfortran.dg/gomp/workshare-reduction-56.f90: New test. * gfortran.dg/gomp/workshare-reduction-57.f90: New test. * gfortran.dg/gomp/workshare-reduction-58.f90: New test.
2020-11-10openmp: Implement OpenMP 5.0 base-pointer attachement and clause orderingChung-Lin Tang1-44/+226
This patch implements some parts of the target variable mapping changes specified in OpenMP 5.0, including base-pointer attachment/detachment behavior for array section list-items in map clauses, and ordering of map clauses according to map kind. 2020-11-10 Chung-Lin Tang <cltang@codesourcery.com> gcc/c-family/ChangeLog: * c-common.h (c_omp_adjust_map_clauses): New declaration. * c-omp.c (struct map_clause): Helper type for c_omp_adjust_map_clauses. (c_omp_adjust_map_clauses): New function. gcc/c/ChangeLog: * c-parser.c (c_parser_omp_target_data): Add use of new c_omp_adjust_map_clauses function. Add GOMP_MAP_ATTACH_DETACH as handled map clause kind. (c_parser_omp_target_enter_data): Likewise. (c_parser_omp_target_exit_data): Likewise. (c_parser_omp_target): Likewise. * c-typeck.c (handle_omp_array_sections): Adjust COMPONENT_REF case to use GOMP_MAP_ATTACH_DETACH map kind for C_ORT_OMP region type. (c_finish_omp_clauses): Adjust bitmap checks to allow struct decl and same struct field access to co-exist on OpenMP construct. gcc/cp/ChangeLog: * parser.c (cp_parser_omp_target_data): Add use of new c_omp_adjust_map_clauses function. Add GOMP_MAP_ATTACH_DETACH as handled map clause kind. (cp_parser_omp_target_enter_data): Likewise. (cp_parser_omp_target_exit_data): Likewise. (cp_parser_omp_target): Likewise. * semantics.c (handle_omp_array_sections): Adjust COMPONENT_REF case to use GOMP_MAP_ATTACH_DETACH map kind for C_ORT_OMP region type. Fix interaction between reference case and attach/detach. (finish_omp_clauses): Adjust bitmap checks to allow struct decl and same struct field access to co-exist on OpenMP construct. gcc/ChangeLog: * gimplify.c (is_or_contains_p): New static helper function. (omp_target_reorder_clauses): New function. (gimplify_scan_omp_clauses): Add use of omp_target_reorder_clauses to reorder clause list according to OpenMP 5.0 rules. Add handling of GOMP_MAP_ATTACH_DETACH for OpenMP cases. * omp-low.c (is_omp_target): New static helper function. (scan_sharing_clauses): Add scan phase handling of GOMP_MAP_ATTACH/DETACH for OpenMP cases. (lower_omp_target): Add lowering handling of GOMP_MAP_ATTACH/DETACH for OpenMP cases. gcc/testsuite/ChangeLog: * c-c++-common/gomp/clauses-2.c: Remove dg-error cases now valid. * gfortran.dg/gomp/map-2.f90: Likewise. * c-c++-common/gomp/map-5.c: New testcase. libgomp/ChangeLog: * libgomp.h (enum gomp_map_vars_kind): Adjust enum values to be bit-flag usable. * oacc-mem.c (acc_map_data): Adjust gomp_map_vars argument flags to 'GOMP_MAP_VARS_OPENACC | GOMP_MAP_VARS_ENTER_DATA'. (goacc_enter_datum): Likewise for call to gomp_map_vars_async. (goacc_enter_data_internal): Likewise. * target.c (gomp_map_vars_internal): Change checks of GOMP_MAP_VARS_ENTER_DATA to use bit-and (&). Adjust use of gomp_attach_pointer for OpenMP cases. (gomp_exit_data): Add handling of GOMP_MAP_DETACH. (GOMP_target_enter_exit_data): Add handling of GOMP_MAP_ATTACH. * testsuite/libgomp.c-c++-common/ptr-attach-1.c: New testcase.
2020-10-30openmp: Fix handling of allocate clause on taskloopJakub Jelinek1-5/+50
This patch fixes gimplification of allocate clause on taskloop - puts allocate on inner taskloop only if there is allocate clause, because otherwise the data sharing clauses are only on the task construct in the construct sandwich. 2020-10-30 Jakub Jelinek <jakub@redhat.com> * gimplify.c (gimplify_scan_omp_clauses): Force OMP_CLAUSE_ALLOCATE_ALLOCATOR into a temporary if it is non-NULL and non-constant. (gimplify_omp_for): Only put allocate on inner taskloop if lastprivate for the same variable is going to be put there, and in that case if the OMP_CLAUSE_ALLOCATE_ALLOCATOR is non-NULL non-constant, make the allocator firstprivate on task. * c-c++-common/gomp/allocate-3.c: New test.
2020-10-28openmp: Parsing and some semantic analysis of OpenMP allocate clauseJakub Jelinek1-1/+24
This patch adds parsing of OpenMP allocate clause, but still ignores it during OpenMP lowering where we should for privatized variables with allocate clause use the corresponding allocators rather than allocating them on the stack. 2020-10-28 Jakub Jelinek <jakub@redhat.com> gcc/ * tree-core.h (enum omp_clause_code): Add OMP_CLAUSE_ALLOCATE. * tree.h (OMP_CLAUSE_ALLOCATE_ALLOCATOR, OMP_CLAUSE_ALLOCATE_COMBINED): Define. * tree.c (omp_clause_num_ops, omp_clause_code_name): Add allocate clause. (walk_tree_1): Handle OMP_CLAUSE_ALLOCATE. * tree-pretty-print.c (dump_omp_clause): Likewise. * gimplify.c (gimplify_scan_omp_clauses, gimplify_adjust_omp_clauses, gimplify_omp_for): Likewise. * tree-nested.c (convert_nonlocal_omp_clauses, convert_local_omp_clauses): Likewise. * omp-low.c (scan_sharing_clauses): Likewise. gcc/c-family/ * c-pragma.h (enum pragma_omp_clause): Add PRAGMA_OMP_CLAUSE_ALLOCATE. * c-omp.c: Include bitmap.h. (c_omp_split_clauses): Handle OMP_CLAUSE_ALLOCATE. gcc/c/ * c-parser.c (c_parser_omp_clause_name): Handle allocate. (c_parser_omp_clause_allocate): New function. (c_parser_omp_all_clauses): Handle PRAGMA_OMP_CLAUSE_ALLOCATE. (OMP_FOR_CLAUSE_MASK, OMP_SECTIONS_CLAUSE_MASK, OMP_PARALLEL_CLAUSE_MASK, OMP_SINGLE_CLAUSE_MASK, OMP_TASK_CLAUSE_MASK, OMP_TASKGROUP_CLAUSE_MASK, OMP_DISTRIBUTE_CLAUSE_MASK, OMP_TEAMS_CLAUSE_MASK, OMP_TARGET_CLAUSE_MASK, OMP_TASKLOOP_CLAUSE_MASK): Add PRAGMA_OMP_CLAUSE_ALLOCATE. * c-typeck.c (c_finish_omp_clauses): Handle OMP_CLAUSE_ALLOCATE. gcc/cp/ * parser.c (cp_parser_omp_clause_name): Handle allocate. (cp_parser_omp_clause_allocate): New function. (cp_parser_omp_all_clauses): Handle PRAGMA_OMP_CLAUSE_ALLOCATE. (OMP_FOR_CLAUSE_MASK, OMP_SECTIONS_CLAUSE_MASK, OMP_PARALLEL_CLAUSE_MASK, OMP_SINGLE_CLAUSE_MASK, OMP_TASK_CLAUSE_MASK, OMP_TASKGROUP_CLAUSE_MASK, OMP_DISTRIBUTE_CLAUSE_MASK, OMP_TEAMS_CLAUSE_MASK, OMP_TARGET_CLAUSE_MASK, OMP_TASKLOOP_CLAUSE_MASK): Add PRAGMA_OMP_CLAUSE_ALLOCATE. * semantics.c (finish_omp_clauses): Handle OMP_CLAUSE_ALLOCATE. * pt.c (tsubst_omp_clauses): Likewise. gcc/testsuite/ * c-c++-common/gomp/allocate-1.c: New test. * c-c++-common/gomp/allocate-2.c: New test. * c-c++-common/gomp/clauses-1.c (omp_allocator_handle_t): New typedef. (foo, bar, baz): Add allocate clauses where allowed.
2020-10-22Move nested function info out of cgraph_nodeJan Hubicka1-2/+5
this patch moves nested function information out of symbol table (to a summary). This saves memory (especially at WPA time) and also makes nested function support more contained. gcc/ChangeLog: 2020-10-22 Jan Hubicka <hubicka@ucw.cz> * cgraph.c: Include tree-nested.h (cgraph_node::create): Call maybe_record_nested_function. (cgraph_node::remove): Do not remove function from nested function infos. (cgraph_node::dump): Update. (cgraph_node::unnest): Move to tree-nested.c (cgraph_node::verify_node): Update. (cgraph_c_finalize): Call nested_function_info::release. * cgraph.h (struct symtab_node): Remove nested function info. * cgraphclones.c (cgraph_node::create_clone): Do not clone nested function info. * cgraphunit.c (cgraph_node::analyze): Update. (cgraph_node::expand): Do not worry about nested functions; they are lowered. (symbol_table::finalize_compilation_unit): Call nested_function_info::release. * gimplify.c: Include tree-nested.h (unshare_body): Update. (unvisit_body): Update. * omp-offload.c (omp_discover_implicit_declare_target): Update. * tree-nested.c: Include alloc-pool.h, tree-nested.h, symbol-summary.h (nested_function_sum): New static variable. (nested_function_info::get): New member function. (nested_function_info::get_create): New member function. (unnest_function): New function. (nested_function_info::~nested_function_info): New member function. (nested_function_info::release): New function. (maybe_record_nested_function): New function. (lookup_element_for_decl): Update. (check_for_nested_with_variably_modified): Update. (create_nesting_tree): Update. (unnest_nesting_tree_1): Update. (gimplify_all_functions): Update. (lower_nested_functions): Update. * tree-nested.h (class nested_function_info): New class. (maybe_record_nested_function): Declare. (unnest_function): Declare. (first_nested_function): New inline function. (next_nested_function): New inline function. (nested_function_origin): New inline function. gcc/ada/ChangeLog: 2020-10-22 Jan Hubicka <hubicka@ucw.cz> * gcc-interface/trans.c: Include tree-nested.h (walk_nesting_tree): Update for new nested function info. gcc/c-family/ChangeLog: 2020-10-22 Jan Hubicka <hubicka@ucw.cz> * c-gimplify.c: Include tree-nested.h (c_genericize): Update for new nested function info. gcc/d/ChangeLog: 2020-10-22 Jan Hubicka <hubicka@ucw.cz> * decl.cc: Include tree-nested.h (get_symbol_decl): Update for new nested function info.
2020-10-06[openacc] Fix acc declare for VLAsTom de Vries1-3/+10
Consider test-case test.c, with VLA A: ... int main (void) { int N = 1000; int A[N]; #pragma acc declare copy(A) return 0; } ... compiled using: ... $ gcc test.c -fopenacc -S -fdump-tree-all ... At original, we have: ... #pragma acc declare map(tofrom:A); ... but at gimple, we have a map (to:A.1), but not a map (from:A.1): ... int[0:D.2074] * A.1; { int A[0:D.2074] [value-expr: *A.1]; saved_stack.2 = __builtin_stack_save (); try { A.1 = __builtin_alloca_with_align (D.2078, 32); #pragma omp target oacc_declare map(to:(*A.1) [len: D.2076]) } finally { __builtin_stack_restore (saved_stack.2); } } ... This is caused by the following incompatibility. When storing the desired from clause in oacc_declare_returns, we use 'A.1' as the key: ... 10898 oacc_declare_returns->put (decl, c); (gdb) call debug_generic_expr (decl) A.1 (gdb) call debug_generic_expr (c) map(from:(*A.1)) ... but when looking it up, we use 'A' as the key: ... (gdb) 1471 tree *c = oacc_declare_returns->get (t); (gdb) call debug_generic_expr (t) A ... Fix this by extracing the 'A.1' lookup key from 'A' using the decl-expr. In addition, unshare the looked up value, to fix avoid running into an "incorrect sharing of tree nodes" error. Using these two fixes, we get our desired: ... finally { + #pragma omp target oacc_declare map(from:(*A.1)) __builtin_stack_restore (saved_stack.2); } ... Build on x86_64-linux with nvptx accelerator, tested libgomp. gcc/ChangeLog: 2020-10-06 Tom de Vries <tdevries@suse.de> PR middle-end/90861 * gimplify.c (gimplify_bind_expr): Handle lookup in oacc_declare_returns using key with decl-expr. libgomp/ChangeLog: 2020-10-06 Tom de Vries <tdevries@suse.de> PR middle-end/90861 * testsuite/libgomp.oacc-c-c++-common/declare-vla.c: Remove xfail.
2020-09-15OpenMP/Fortran: Fix (re)mapping of allocatable/pointer arrays [PR96668]Tobias Burnus1-9/+16
gcc/cp/ChangeLog: PR fortran/96668 * cp-gimplify.c (cxx_omp_finish_clause): Add bool openacc arg. * cp-tree.h (cxx_omp_finish_clause): Likewise * semantics.c (handle_omp_for_class_iterator): Update call. gcc/fortran/ChangeLog: PR fortran/96668 * trans.h (gfc_omp_finish_clause): Add bool openacc arg. * trans-openmp.c (gfc_omp_finish_clause): Ditto. Use GOMP_MAP_ALWAYS_POINTER with PSET for pointers. (gfc_trans_omp_clauses): Like the latter and also if the always modifier is used. gcc/ChangeLog: PR fortran/96668 * gimplify.c (gimplify_omp_for): Add 'bool openacc' argument; update omp_finish_clause calls. (gimplify_adjust_omp_clauses_1, gimplify_adjust_omp_clauses, gimplify_expr, gimplify_omp_loop): Update omp_finish_clause and/or gimplify_for calls. * langhooks-def.h (lhd_omp_finish_clause): Add bool openacc arg. * langhooks.c (lhd_omp_finish_clause): Likewise. * langhooks.h (lhd_omp_finish_clause): Likewise. * omp-low.c (scan_sharing_clauses): Keep GOMP_MAP_TO_PSET cause for 'declare target' vars. include/ChangeLog: PR fortran/96668 * gomp-constants.h (GOMP_MAP_ALWAYS_POINTER_P): Define. libgomp/ChangeLog: PR fortran/96668 * libgomp.h (struct target_var_desc): Add has_null_ptr_assoc member. * target.c (gomp_map_vars_existing): Add always_to_flag flag. (gomp_map_vars_existing): Update call to it. (gomp_map_fields_existing): Likewise (gomp_map_vars_internal): Update PSET handling such that if a nullptr is now allocated or if GOMP_MAP_POINTER is used PSET is updated and pointer remapped. (GOMP_target_enter_exit_data): Hanlde GOMP_MAP_ALWAYS_POINTER like GOMP_MAP_POINTER. * testsuite/libgomp.fortran/map-alloc-ptr-1.f90: New test. * testsuite/libgomp.fortran/map-alloc-ptr-2.f90: New test.
2020-08-13openmp: Add support for non-rectangular loops in taskloop constructJakub Jelinek1-63/+82
2020-08-13 Jakub Jelinek <jakub@redhat.com> * gimplify.c (gimplify_omp_taskloop_expr): New function. (gimplify_omp_for): Use it. For OMP_FOR_NON_RECTANGULAR loops adjust in outer taskloop the var-outer decls. * omp-expand.c (expand_omp_taskloop_for_inner): Handle non-rectangular loops. (expand_omp_for): Don't reject non-rectangular taskloop. * omp-general.c (omp_extract_for_data): Don't assert that non-rectangular loops have static schedule, instead treat loop->m1 or loop->m2 as if loop->n1 or loop->n2 is non-constant. * testsuite/libgomp.c/loop-22.c (main): Add some further tests. * testsuite/libgomp.c/loop-23.c (main): Likewise. * testsuite/libgomp.c/loop-24.c: New test.
2020-08-03openacc: No attach/detach present/release mappings for array descriptorsJulian Brown1-1/+6
Standalone attach and detach clauses should not create present/release mappings for Fortran array descriptors (e.g. used when we have a pointer to an array), both because it is unnecessary and because those mappings will be incorrectly subject to reference counting. Simply omitting the mappings means we just use GOMP_MAP_TO_PSET and GOMP_MAP_{ATTACH,DETACH} mappings for array descriptors. That requires a tweak in gimplify.c, since we may now see GOMP_MAP_TO_PSET without a preceding data-movement mapping. 2020-08-03 Julian Brown <julian@codesourcery.com> Thomas Schwinge <thomas@codesourcery.com> gcc/fortran/ * trans-openmp.c (gfc_trans_omp_clauses): Don't create present/release mappings for array descriptors. gcc/ * gimplify.c (gimplify_omp_target_update): Allow GOMP_MAP_TO_PSET without a preceding data-movement mapping. gcc/testsuite/ * gfortran.dg/goacc/attach-descriptor.f90: Update pattern output. Add scanning of gimplify dump. libgomp/ * testsuite/libgomp.oacc-fortran/attach-descriptor-1.f90: Don't run for shared-memory devices. Extend with further checking. Co-Authored-By: Thomas Schwinge <thomas@codesourcery.com>
2020-07-13openacc: Don't strip TO_PSET/POINTER for enter/exit dataJulian Brown1-10/+11
OpenACC 2.6 specifies that the array descriptor (when present) must be copied to the target before attaching pointers in Fortran. This patch reverses the stripping of GOMP_MAP_TO_PSET and GOMP_MAP_POINTER that was introduced by the "OpenACC reference count overhaul" patch. 2020-07-10 Julian Brown <julian@codesourcery.com> Thomas Schwinge <thomas@codesourcery.com> gcc/ * gimplify.c (gimplify_scan_omp_clauses): Do not strip GOMP_MAP_TO_PSET/GOMP_MAP_POINTER for OpenACC enter/exit data directives (see also PR92929). gcc/testsuite/ * gfortran.dg/goacc/finalize-1.f: Update expected dump output. libgomp/ * testsuite/libgomp.oacc-fortran/dynamic-pointer-1.f90: New test. Co-Authored-By: Thomas Schwinge <thomas@codesourcery.com>
2020-07-03Extend store merging to STRING_CSTEric Botcazou1-0/+1
The GIMPLE store merging pass doesn't merge STRING_CSTs in the general case, although they are accepted by native_encode_expr; the reason is that the pass only works with integral modes, i.e. with chunks whose size is a power of two. There are two possible ways of extending it to handle STRING_CSTs: 1) lift the condition of integral modes and treat STRING_CSTs as other _CST nodes but with arbitrary size; 2) implement a specific and separate handling for STRING_CSTs. The attached patch implements 2) for the following reasons: on the one hand, even in Ada where character strings are first-class citizens, cases where merging STRING_CSTs with other *_CST nodes would be possible are quite rare in practice; on the other hand, string concatenations happen more naturally and frequently thanks to the "&" operator, giving rise to merging opportunities. gcc/ChangeLog: * gimple-fold.c (gimple_fold_builtin_memory_op): Fold calls that were initially created for the assignment of a variable-sized object and whose source is now a string constant. * gimple-ssa-store-merging.c (struct merged_store_group): Document STRING_CST for rhs_code field. Add string_concatenation boolean field. (merged_store_group::merged_store_group): Initialize it as well as bit_insertion here. (merged_store_group::do_merge): Set it upon seeing a STRING_CST. Also set bit_insertion here upon seeing a BIT_INSERT_EXPR. (merged_store_group::apply_stores): Clear it for small regions. Do not create a power-of-2-sized buffer if it is still true. And do not set bit_insertion here again. (encode_tree_to_bitpos): Deal with BLKmode for the expression. (merged_store_group::can_be_merged_into): Deal with STRING_CST. (imm_store_chain_info::coalesce_immediate_stores): Set bit_insertion to true after changing MEM_REF stores into BIT_INSERT_EXPR stores. (count_multiple_uses): Return 0 for STRING_CST. (split_group): Do not split the group for a string concatenation. (imm_store_chain_info::output_merged_store): Constify and rename some local variables. Build an array type as destination type for a string concatenation, as well as a zero mask, and call build_string to build the source. (lhs_valid_for_store_merging_p): Return true for VIEW_CONVERT_EXPR. (pass_store_merging::process_store): Accept STRING_CST on the RHS. * gimple.h (gimple_call_alloca_for_var_p): New accessor function. * gimplify.c (gimplify_modify_expr_to_memcpy): Set alloca_for_var. * tree.h (CALL_ALLOCA_FOR_VAR_P): Document it for BUILT_IN_MEMCPY. gcc/testsuite/ChangeLog: * gnat.dg/opt87.adb: New test. * gnat.dg/opt87_pkg.ads: New helper. * gnat.dg/opt87_pkg.adb: Likewise.
2020-06-18[OpenMP, gimplifier] 'inform' after 'error' diagnosticThomas Schwinge1-5/+5
This is not a thorough review of the code, just a few cases I noticed while scanning 'gcc/gimplify.c' for "enclosing". gcc/ * gimplify.c (omp_notice_threadprivate_variable) (omp_default_clause, omp_notice_variable): 'inform' after 'error' diagnostic. Adjust all users. gcc/testsuite/ * c-c++-common/gomp/default-1.c: Update. * c-c++-common/gomp/defaultmap-3.c: Likewise. * c-c++-common/gomp/order-4.c: Likewise. * g++.dg/gomp/parallel-2.C: Likewise. * g++.dg/gomp/predetermined-1.C: Likewise. * g++.dg/gomp/sharing-1.C: Likewise. * gcc.dg/gomp/appendix-a/a.24.1.c: Likewise. * gcc.dg/gomp/parallel-2.c: Likewise. * gcc.dg/gomp/pr44085.c: Likewise. * gcc.dg/gomp/sharing-1.c: Likewise. * gcc.dg/gomp/vla-1.c: Likewise. * gfortran.dg/gomp/appendix-a/a.24.1.f90: Likewise. * gfortran.dg/gomp/crayptr3.f90: Likewise. * gfortran.dg/gomp/pr33439.f90: Likewise. * gfortran.dg/gomp/pr44036-1.f90: Likewise. * gfortran.dg/gomp/pr44085.f90: Likewise. * gfortran.dg/gomp/pr44536.f90: Likewise. * gfortran.dg/gomp/pr94672.f90: Likewise. * gfortran.dg/gomp/sharing-1.f90: Likewise. * gfortran.dg/gomp/sharing-2.f90: Likewise. * gfortran.dg/gomp/sharing-3.f90: Likewise.
2020-06-17Lower VEC_COND_EXPR into internal functions.Martin Liska1-14/+1
gcc/ChangeLog: * Makefile.in: Add new file. * expr.c (expand_expr_real_2): Add gcc_unreachable as we should not meet this condition. (do_store_flag): Likewise. * gimplify.c (gimplify_expr): Gimplify first argument of VEC_COND_EXPR to be a SSA name. * internal-fn.c (vec_cond_mask_direct): New. (vec_cond_direct): Likewise. (vec_condu_direct): Likewise. (vec_condeq_direct): Likewise. (expand_vect_cond_optab_fn): New. (expand_vec_cond_optab_fn): Likewise. (expand_vec_condu_optab_fn): Likewise. (expand_vec_condeq_optab_fn): Likewise. (expand_vect_cond_mask_optab_fn): Likewise. (expand_vec_cond_mask_optab_fn): Likewise. (direct_vec_cond_mask_optab_supported_p): Likewise. (direct_vec_cond_optab_supported_p): Likewise. (direct_vec_condu_optab_supported_p): Likewise. (direct_vec_condeq_optab_supported_p): Likewise. * internal-fn.def (VCOND): New OPTAB. (VCONDU): Likewise. (VCONDEQ): Likewise. (VCOND_MASK): Likewise. * optabs.c (get_rtx_code): Make it global. (expand_vec_cond_mask_expr): Removed. (expand_vec_cond_expr): Removed. * optabs.h (expand_vec_cond_expr): Likewise. (vector_compare_rtx): Make it global. * passes.def: Add new pass_gimple_isel pass. * tree-cfg.c (verify_gimple_assign_ternary): Add check for VEC_COND_EXPR about first argument. * tree-pass.h (make_pass_gimple_isel): New. * tree-ssa-forwprop.c (pass_forwprop::execute): Prevent propagation of the first argument of a VEC_COND_EXPR. * tree-ssa-reassoc.c (ovce_extract_ops): Support SSA_NAME as first argument of a VEC_COND_EXPR. (optimize_vec_cond_expr): Likewise. * tree-vect-generic.c (expand_vector_divmod): Make SSA_NAME for a first argument of created VEC_COND_EXPR. (expand_vector_condition): Fix coding style. * tree-vect-stmts.c (vectorizable_condition): Gimplify first argument. * gimple-isel.cc: New file. gcc/testsuite/ChangeLog: * g++.dg/vect/vec-cond-expr-eh.C: New test.
2020-06-16openmp: Initial part of OpenMP 5.0 non-rectangular loop supportJakub Jelinek1-4/+78
OpenMP 5.0 adds support for non-rectangular loop collapses, e.g. triangular and more complex. This patch deals just with the diagnostics so that they aren't rejected immediately as before. As the spec generally requires as before that the iteration variable initializer and bound in the comparison as invariant vs. the outermost loop, and just add some exceptional forms that can violate that, we need to avoid folding the expressions until we can detect them and in order to avoid folding it later on, I chose to use a TREE_VEC in those expressions to hold the var_outer * expr1 + expr2 triplet, the patch adds pretty-printing of that, gimplification etc. and just sorry_at during omp expansion for now. The next step will be to implement the different cases of that one by one. 2020-06-16 Jakub Jelinek <jakub@redhat.com> gcc/ * tree.h (OMP_FOR_NON_RECTANGULAR): Define. * gimplify.c (gimplify_omp_for): Diagnose schedule, ordered or dist_schedule clause on non-rectangular loops. Handle gimplification of non-rectangular lb/b expressions. When changing iteration variable, adjust also non-rectangular lb/b expressions referencing that. * omp-general.h (struct omp_for_data_loop): Add m1, m2 and outer members. (struct omp_for_data): Add non_rect member. * omp-general.c (omp_extract_for_data): Handle non-rectangular loops. Fill in non_rect, m1, m2 and outer. * omp-low.c (lower_omp_for): Handle non-rectangular lb/b expressions. * omp-expand.c (expand_omp_for): Emit sorry_at for unsupported non-rectangular loop cases and assert for cases that can't be non-rectangular. * tree-pretty-print.c (dump_mem_ref): Formatting fix. (dump_omp_loop_non_rect_expr): New function. (dump_generic_node): Handle non-rectangular OpenMP loops. * tree-pretty-print.h (dump_omp_loop_non_rect_expr): Declare. * gimple-pretty-print.c (dump_gimple_omp_for): Handle non-rectangular OpenMP loops. gcc/c-family/ * c-common.h (c_omp_check_loop_iv_exprs): Add an int argument. * c-omp.c (struct c_omp_check_loop_iv_data): Add maybe_nonrect and idx members. (c_omp_is_loop_iterator): New function. (c_omp_check_loop_iv_r): Use it. Add support for silent scanning if outer loop iterator is present. Perform duplicate checking through hash_set in the function rather than expecting caller to do that. Pass NULL instead of d->ppset to walk_tree_1. (c_omp_check_nonrect_loop_iv): New function. (c_omp_check_loop_iv): Use it. Fill in new members, allow non-rectangular loop forms, diagnose multiple associated loops with the same iterator. Pass NULL instead of &pset to walk_tree_1. (c_omp_check_loop_iv_exprs): Likewise. gcc/c/ * c-parser.c (c_parser_expr_no_commas): Save, clear and restore c_in_omp_for. (c_parser_omp_for_loop): Set c_in_omp_for around some calls to avoid premature c_fully_fold. Defer explicit c_fully_fold calls to after c_finish_omp_for. * c-tree.h (c_in_omp_for): Declare. * c-typeck.c (c_in_omp_for): Define. (build_modify_expr): Avoid c_fully_fold if c_in_omp_for. (digest_init): Likewise. (build_binary_op): Likewise. gcc/cp/ * semantics.c (handle_omp_for_class_iterator): Adjust c_omp_check_loop_iv_exprs caller. (finish_omp_for): Likewise. Don't call fold_build_cleanup_point_expr before calling c_finish_omp_for and c_omp_check_loop_iv, move it after those calls. * pt.c (tsubst_omp_for_iterator): Handle non-rectangular loops. gcc/testsuite/ * c-c++-common/gomp/loop-6.c: New test. * gcc.dg/gomp/loop-1.c: Don't expect diagnostics on valid non-rectangular loops. * gcc.dg/gomp/loop-2.c: New test. * g++.dg/gomp/loop-1.C: Don't expect diagnostics on valid non-rectangular loops. * g++.dg/gomp/loop-2.C: Likewise. * g++.dg/gomp/loop-5.C: New test. * g++.dg/gomp/loop-6.C: New test.
2020-06-15Optimize assignment to volatile aggregate variableEric Botcazou1-17/+36
gimplify_modify_expr_rhs has an optimization whereby the assignment to an aggregate variable from a read-only object with a DECL_INITIAL is optimized into the direct assignment of the DECL_INITIAL, provided that no temporary is created in the process. The optimization is blocked if the read-only object is volatile, which is OK as per the semantics of volatile, but also if the target variable is volatile, on the grounds that the modified assignment might end up being done on a per field basis, which is also OK. But this latter restriction is enforced a priori and there are cases where the modified assignment would be OK, for example if there is only one field or the DECL_INITIAL is equivalent to the empty CONSTRUCTOR, i.e. all zeros. So, in the latter case, the patch changes gimplify_modify_expr_rhs to ask gimplify_init_constructor whether the assignment would be done as a block, which is easy because gimplify_init_constructor knows that it must create a temporary if the LHS is volatile and this would not be the case, so it's just a matter of completing the NOTIFY_TEMP_CREATION mechanism. gcc/ChangeLog * gimplify.c (gimplify_init_constructor) <AGGREGATE_TYPE>: Declare new ENSURE_SINGLE_ACCESS constant and move variables down. If it is true and all elements are zero, then always clear. Return GS_ERROR if a temporary would be created for it and NOTIFY_TEMP_CREATION set. (gimplify_modify_expr_rhs) <VAR_DECL>: If the target is volatile but the type is aggregate non-addressable, ask gimplify_init_constructor whether it can generate a single access to the target. gcc/testsuite/ChangeLog * gnat.dg/aggr30.ads, gnat.dg/aggr30.adb: New test.
2020-06-12tsan: Add param to disable func-entry-exit instrumentationMarco Elver1-1/+2
Adds param tsan-instrument-func-entry-exit, which controls if __tsan_func_{entry,exit} calls should be emitted or not. The default behaviour is to emit the calls. This may be required by alternative race detection runtimes. One such runtime is the Kernel Concurrency Sanitizer (KCSAN): https://github.com/google/ktsan/wiki/KCSAN After this change, GCC should satisfy all requirements for KCSAN: https://lore.kernel.org/lkml/20200515150338.190344-7-elver@google.com/ gcc/ChangeLog: * gimplify.c (gimplify_function_tree): Optimize and do not emit IFN_TSAN_FUNC_EXIT in a finally block if we do not need it. * params.opt: Add --param=tsan-instrument-func-entry-exit=. * tsan.c (instrument_memory_accesses): Make fentry_exit_instrument bool depend on new param. gcc/testsuite/ChangeLog: * c-c++-common/tsan/func_entry_exit.c: New test. * c-c++-common/tsan/func_entry_exit_disabled.c: New test.
2020-06-05[OpenACC 'exit data'] Strip 'GOMP_MAP_STRUCT' mappingsThomas Schwinge1-1/+2
These are not itself necessary for OpenACC 'exit data' directives, and are skipped over (now) in libgomp. We might as well not emit them to start with, in line with the equivalent OpenMP directive. We keep the no-op handling in libgomp for the reason of backward compatibility. gcc/ * gimplify.c (gimplify_adjust_omp_clauses): Remove 'GOMP_MAP_STRUCT' mapping from OpenACC 'exit data' directives. gcc/testsuite/ * c-c++-common/goacc/struct-enter-exit-data-1.c: New file. libgomp/ * oacc-mem.c (goacc_exit_data_internal) <GOMP_MAP_STRUCT>: Explain special handling. Co-Authored-By: Julian Brown <julian@codesourcery.com>
2020-06-03[OpenMP] Fix mapping of artificial variables (PR94874)Tobias Burnus1-1/+12
gcc/c-family/ChangeLog: * c-common.h (c_omp_predetermined_mapping): Declare. * c-omp.c (c_omp_predetermined_mapping): New. gcc/c/ChangeLog: * c-objc-common.h (LANG_HOOKS_OMP_PREDETERMINED_MAPPING): Redefine. gcc/cp/ChangeLog: * cp-gimplify.c (cxx_omp_predetermined_mapping): New. * cp-objcp-common.h (LANG_HOOKS_OMP_PREDETERMINED_MAPPING): Redfine. * cp-tree.h (cxx_omp_predetermined_mapping): Declare. gcc/fortran/ChangeLog: * f95-lang.c (LANG_HOOKS_OMP_PREDETERMINED_MAPPING): Redefine. * trans-openmp.c (gfc_omp_predetermined_mapping): New. * trans.h (gfc_omp_predetermined_mapping): Declare. gcc/ChangeLog: * gimplify.c (omp_notice_variable): Use new hook. * langhooks-def.h (lhd_omp_predetermined_mapping): Declare. (LANG_HOOKS_OMP_PREDETERMINED_MAPPING): Define (LANG_HOOKS_DECLS): Add it. * langhooks.c (lhd_omp_predetermined_sharing): Remove bogus unused attr. (lhd_omp_predetermined_mapping): New. * langhooks.h (struct lang_hooks_for_decls): Add new hook. gcc/testsuite/ChangeLog 2020-06-03 Thomas Schwinge <thomas@codesourcery.com> Tobias Burnus <tobias@codesourcery.com> PR middle-end/94874 * c-c++-common/gomp/pr94874.c: New.
2020-05-26openmp: Ensure copy ctor for composite distribute parallel for class ↵Jakub Jelinek1-56/+0
iterators is instantiated [PR95197] During gimplification omp_finish_clause langhook is called in several places to add the language specific info to the clause like what default/copy ctors, dtors and assignment operators should be used. Unfortunately, if it refers to some not yet instantiated method, during gimplification it is too late and the methods will not be instantiated anymore. For other cases, the genericizer has code to detect those and instantiate whatever is needed, this change adds the same for distribute parallel for class iterators where we under the hood need a copy constructor for the iterator to implement it. 2020-05-26 Jakub Jelinek <jakub@redhat.com> PR c++/95197 * gimplify.c (find_combined_omp_for): Move to omp-general.c. * omp-general.h (find_combined_omp_for): Declare. * omp-general.c: Include tree-iterator.h. (find_combined_omp_for): New function, moved from gimplify.c. * cp-gimplify.c: Include omp-general.h. (cp_genericize_r) <case OMP_DISTRIBUTE>: For class iteration variables in composite distribute parallel for, instantiate copy ctor of their types.
2020-05-15[OpenMP] Fix 'omp exit data' for Fortran arrays (PR 94635)Tobias Burnus1-1/+3
gcc/ PR middle-end/94635 * gimplify.c (gimplify_scan_omp_clauses): For MAP_TO_PSET with OMP_TARGET_EXIT_DATA, use 'release:' unless the associated item is 'delete:'. gcc/testsuite PR middle-end/94635 * gfortran.dg/gomp/target-exit-data.f90: New.
2020-05-07extend DECL_GIMPLE_REG_P to all typesRichard Biener1-44/+2
This extends DECL_GIMPLE_REG_P to all types so we can clear TREE_ADDRESSABLE even for integers with partial defs, not just complex and vector variables. To make that transition easier the patch inverts DECL_GIMPLE_REG_P to DECL_NOT_GIMPLE_REG_P since that makes the default the current state for all other types besides complex and vectors. For the testcase in PR94703 we're able to expand the partial def'ed local integer to a register then, producing a single movl rather than going through the stack. On i?86 this execute FAILs gcc.dg/torture/pr71522.c because we now expand a round-trip through a long double automatic var to a register fld/fst which normalizes the value. For that during RTL expansion we're looking for problematic punnings of decls and avoid pseudos for those - I chose integer or BLKmode accesses on decls with modes where precision doesn't match bitsize which covers the XFmode case. 2020-05-07 Richard Biener <rguenther@suse.de> PR middle-end/94703 * tree-core.h (tree_decl_common::gimple_reg_flag): Rename ... (tree_decl_common::not_gimple_reg_flag): ... to this. * tree.h (DECL_GIMPLE_REG_P): Rename ... (DECL_NOT_GIMPLE_REG_P): ... to this. * gimple-expr.c (copy_var_decl): Copy DECL_NOT_GIMPLE_REG_P. (create_tmp_reg): Simplify. (create_tmp_reg_fn): Likewise. (is_gimple_reg): Check DECL_NOT_GIMPLE_REG_P for all regs. * gimplify.c (create_tmp_from_val): Simplify. (gimplify_bind_expr): Likewise. (gimplify_compound_literal_expr): Likewise. (gimplify_function_tree): Likewise. (prepare_gimple_addressable): Set DECL_NOT_GIMPLE_REG_P. * asan.c (create_odr_indicator): Do not clear DECL_GIMPLE_REG_P. (asan_add_global): Copy it. * cgraphunit.c (cgraph_node::expand_thunk): Force args to be GIMPLE regs. * function.c (gimplify_parameters): Copy DECL_NOT_GIMPLE_REG_P. * ipa-param-manipulation.c (ipa_param_body_adjustments::common_initialization): Simplify. (ipa_param_body_adjustments::reset_debug_stmts): Copy DECL_NOT_GIMPLE_REG_P. * omp-low.c (lower_omp_for_scan): Do not set DECL_GIMPLE_REG_P. * sanopt.c (sanitize_rewrite_addressable_params): Likewise. * tree-cfg.c (make_blocks_1): Simplify. (verify_address): Do not verify DECL_GIMPLE_REG_P setting. * tree-eh.c (lower_eh_constructs_2): Simplify. * tree-inline.c (declare_return_variable): Adjust and generalize. (copy_decl_to_var): Copy DECL_NOT_GIMPLE_REG_P. (copy_result_decl_to_var): Likewise. * tree-into-ssa.c (pass_build_ssa::execute): Adjust comment. * tree-nested.c (create_tmp_var_for): Simplify. * tree-parloops.c (separate_decls_in_region_name): Copy DECL_NOT_GIMPLE_REG_P. * tree-sra.c (create_access_replacement): Adjust and generalize partial def support. * tree-ssa-forwprop.c (pass_forwprop::execute): Set DECL_NOT_GIMPLE_REG_P on decls we introduce partial defs on. * tree-ssa.c (maybe_optimize_var): Handle clearing of TREE_ADDRESSABLE and setting/clearing DECL_NOT_GIMPLE_REG_P independently. * lto-streamer-out.c (hash_tree): Hash DECL_NOT_GIMPLE_REG_P. * tree-streamer-out.c (pack_ts_decl_common_value_fields): Stream DECL_NOT_GIMPLE_REG_P. * tree-streamer-in.c (unpack_ts_decl_common_value_fields): Likewise. * cfgexpand.c (avoid_type_punning_on_regs): New. (discover_nonconstant_array_refs): Call avoid_type_punning_on_regs to avoid unsupported mode punning. lto/ * lto-common.c (compare_tree_sccs_1): Compare DECL_NOT_GIMPLE_REG_P. c/ * gimple-parser.c (c_parser_parse_ssa_name): Do not set DECL_GIMPLE_REG_P. cp/ * optimize.c (update_cloned_parm): Copy DECL_NOT_GIMPLE_REG_P. * gcc.dg/tree-ssa/pr94703.c: New testcase.
2020-05-05Do not put incomplete CONSTRUCTORs into static memoryEric Botcazou1-1/+1
The CONSTRUCTOR_NO_CLEARING flag was invented to avoid generating a memset for CONSTRUCTORS that lack elements, but it turns out that the gimplifier can generate a memcpy for them instead, which is worse performance-wise, so this prevents it from doing that for them. * gimplify.c (gimplify_init_constructor): Do not put the constructor into static memory if it is not complete.
2020-04-17[OpenMP] Fix 'omp exit data' for Fortran arrays (PR 94635)Tobias Burnus1-4/+8
PR middle-end/94635 * gimplify.c (gimplify_scan_omp_clauses): Turn MAP_TO_PSET to MAP_DELETE. PR middle-end/94635 * testsuite/libgomp.fortran/target-enter-data-2.F90: New.
2020-04-07middle-end/94479 - fix gimplification of addressRichard Biener1-1/+3
When gimplifying an address operand we may expose an indirect ref via DECL_VALUE_EXPR for example. This is dealt with in the code already but it fails to consider that INDIRECT_REFs get gimplified to MEM_REFs. Fixed which makes the ICE observed on x86_64-netbsd go away. 2020-04-07 Richard Biener <rguenther@suse.de> PR middle-end/94479 * gimplify.c (gimplify_addr_expr): Also consider generated MEM_REFs. * gcc.dg/torture/pr94479.c: New testcase.
2020-03-26gimplify: Fix -fcompare-debug differences caused by gimplify_body [PR94281]Jakub Jelinek1-3/+32
The following testcase FAILs, because gimplify_body adds a GIMPLE_NOP only when there are no statements in the function and with -g there is a DEBUG_BEGIN_STMT, so it doesn't add it and due to -fno-tree-dce that never gets removed afterwards. Similarly, if the body seq after gimplification contains some DEBUG_BEGIN_STMTs plus a single gbind, then we could behave differently between -g0 and -g, by using that gbind as the body in the -g0 case and not in the -g case. This patch fixes that by ignoring DEBUG_BEGIN_STMTs (other debug stmts can't appear at this point yet thankfully) during decisions and if we pick the single gbind and there are DEBUG_BEGIN_STMTs next to it, it moves them into the gbind. While debugging this, I found also a bug in the gimple_seq_last_nondebug_stmt function, for a seq that has a single non-DEBUG_BEGIN_STMT statement followed by one or more DEBUG_BEGIN_STMTs it would return NULL rather than the first statement. 2020-03-26 Jakub Jelinek <jakub@redhat.com> PR debug/94281 * gimple.h (gimple_seq_first_nondebug_stmt): New function. (gimple_seq_last_nondebug_stmt): Don't return NULL if seq contains a single non-debug stmt followed by one or more debug stmts. * gimplify.c (gimplify_body): Use gimple_seq_first_nondebug_stmt instead of gimple_seq_first_stmt, use gimple_seq_first_nondebug_stmt and gimple_seq_last_nondebug_stmt instead of gimple_seq_first and gimple_seq_last to check if outer_stmt gbind could be reused and if yes and it is surrounded by any debug stmts, move them into the gbind body. * g++.dg/debug/pr94281.C: New test.
2020-02-27gimplify: Don't optimize register const vars to static [PR93949]Jakub Jelinek1-0/+1
The following testcase is rejected, while it was accepted in 3.4 and earlier (before tree-ssa merge). The problem is that we decide to promote the const variable to TREE_STATIC, but TREE_STATIC DECL_REGISTER VAR_DECLs may only be the global register vars and so assemble_variable/make_decl_rtl diagnoses it. Either we do what the following patch does, where we could consider register as a hint the user doesn't want such optimization, because if something is forced static, it is not "register" anymore and register static is not valid in C either, or we could clear DECL_REGISTER instead, but would still need to punt at least on DECL_HARD_REGISTER cases. 2020-02-27 Jakub Jelinek <jakub@redhat.com> PR c/93949 * gimplify.c (gimplify_init_constructor): Don't promote readonly DECL_REGISTER variables to TREE_STATIC. * gcc.c-torture/compile/pr93949.c: New test.
2020-02-09openmp: Optimize DECL_IN_CONSTANT_POOL vars in target regionsJakub Jelinek1-0/+16
DECL_IN_CONSTANT_POOL are shared and thus don't really get emitted in the BLOCK where they are used, so for OpenMP target regions that have initializers gimplified into copying from them we actually map them at runtime from host to offload devices. This patch instead marks them as "omp declare target", so that they are on the target device from the beginning and don't need to be copied there. 2020-02-09 Jakub Jelinek <jakub@redhat.com> * gimplify.c (gimplify_adjust_omp_clauses_1): Promote DECL_IN_CONSTANT_POOL variables into "omp declare target" to avoid copying them around between host and target. * testsuite/libgomp.c/target-38.c: New test.
2020-02-06openmp: Notice reduction decl in outer contexts after adding it to shared ↵Jakub Jelinek1-3/+7
[PR93515] If we call omp_add_variable, following omp_notice_variable will already find it on that construct and not go through outer constructs, the following patch fixes that. Note, this still doesn't follow OpenMP 5.0 semantics on target combined with other constructs with reduction/lastprivate/linear clauses, will handle that for GCC11. 2020-02-06 Jakub Jelinek <jakub@redhat.com> PR libgomp/93515 * gimplify.c (gimplify_scan_omp_clauses) <do_notice>: If adding shared clause, call omp_notice_variable on outer context if any.
2020-01-17gimplifier: handle POLY_INT_CST-sized TARGET_EXPRsRichard Sandiford1-3/+3
If a TARGET_EXPR has poly-int size, the gimplifier would treat it like a VLA and use gimplify_vla_decl. gimplify_vla_decl in turn would use an alloca and expect all references to be gimplified via the DECL_VALUE_EXPR. This caused confusion later in gimplify_var_or_parm_decl_1 when we (correctly) had direct rather than indirect references. For completeness, the patch also fixes similar tests in the RETURN_EXPR handling and OpenMP depend clauses. 2020-01-17 Richard Sandiford <richard.sandiford@arm.com> gcc/ * gimplify.c (gimplify_return_expr): Use poly_int_tree_p rather than testing directly for INTEGER_CST. (gimplify_target_expr, gimplify_omp_depend): Likewise. gcc/testsuite/ * g++.target/aarch64/sve/acle/general-c++/gimplify_1.C: New test.
2020-01-13PR c++/33799 - destroy return value if local cleanup throws.Jason Merrill1-0/+8
This is a pretty rare situation since the C++11 change to make all destructors default to noexcept, but it is still possible to define throwing destructors, and if a destructor for a local variable throws during the return, we've already constructed the return value, so now we need to destroy it. I handled this somewhat like the new-expression cleanup; as in that case, this cleanup can't properly nest with the cleanups for local variables, so I introduce a cleanup region around the whole function and a flag variable to indicate whether the return value actually needs to be destroyed. Setting the flag requires giving a COMPOUND_EXPR as the operand of a RETURN_EXPR, so I adjust gimplify_return_expr to handle that. This doesn't currently work with deduced return type because we don't know the type when we're deciding whether to introduce the cleanup region. gcc/ * gimplify.c (gimplify_return_expr): Handle COMPOUND_EXPR. gcc/cp/ * cp-tree.h (current_retval_sentinel): New macro. * decl.c (start_preparsed_function): Set up cleanup for retval. * typeck.c (check_return_expr): Set current_retval_sentinel.
2020-01-10Further changes for the OpenACC 'if_present' clause on the 'host_data' constructThomas Schwinge1-4/+11
gcc/ * tree.h (OMP_CLAUSE_USE_DEVICE_PTR_IF_PRESENT): New definition. * tree-core.h: Document it. * gimplify.c (gimplify_omp_workshare): Set it. * omp-low.c (lower_omp_target): Use it. * tree-pretty-print.c (dump_omp_clause): Print it. gcc/testsuite/ * c-c++-common/goacc/host_data-1.c: Extend. * gfortran.dg/goacc/host_data-tree.f95: Likewise. gcc/ * omp-low.c (lower_omp_target) <OMP_CLAUSE_USE_DEVICE_PTR etc.>: Assert that for OpenACC we always have 'GOMP_MAP_USE_DEVICE_PTR'. libgomp/ * target.c (gomp_map_vars_internal) <GOMP_MAP_USE_DEVICE_PTR_IF_PRESENT>: Clean up/elaborate code paths. From-SVN: r280149
2020-01-10PR c++/93173 - incorrect tree sharing.Jason Merrill1-1/+1
My patch for 93033 wasn't sufficient to handle all the possible sharing introduced by split_nonconstant_init, and it occurred to me that it would make sense to use the same unsharing technique as unshare_body, namely copy_if_shared. PR c++/93033 gcc/ * gimplify.c (copy_if_shared): No longer static. * gimplify.h: Declare it. gcc/cp/ * cp-gimplify.c (cp_gimplify_init_expr, cp_gimplify_expr): Use copy_if_shared after cp_genericize_tree. * typeck2.c (split_nonconstant_init): Don't unshare here. From-SVN: r280126
2020-01-09re PR tree-optimization/93054 (ICE in gimple_set_lhs, at gimple.c:1820)Richard Biener1-1/+2
2020-01-09 Richard Biener <rguenther@suse.de> PR middle-end/93054 * gimplify.c (gimplify_expr): Deal with NOP definitions. * gcc.dg/pr93054.c: New testcase. From-SVN: r280039
2020-01-01Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r279813
2019-12-20OpenACC 2.6 deep copy: middle-end partsJulian Brown1-24/+195
gcc/ * gimplify.c (gimplify_omp_var_data): Add GOVD_MAP_HAS_ATTACHMENTS. (insert_struct_comp_map): Support derived-type member mappings for arrays with descriptors which use GOMP_MAP_TO_PSET. Support GOMP_MAP_ATTACH_DETACH. (gimplify_scan_omp_clauses): Tidy up OACC_ENTER_DATA/OACC_EXIT_DATA mappings. Handle attach/detach clauses and component references. (gimplify_adjust_omp_clauses_1): Skip adjustments for explicit attach/detach clauses. (gimplify_omp_target_update): Handle struct mappings and finalize for detach operations. * omp-low.c (lower_omp_target): Support GOMP_MAP_ATTACH, GOMP_MAP_DETACH, GOMP_MAP_FORCE_DETACH. * tree-pretty-print.c (dump_omp_clause): Likewise, plus GOMP_MAP_ATTACH_DETACH. include/ * gomp-constants.h (gomp_map_kind): Add GOMP_MAP_ATTACH_DETACH. From-SVN: r279626
2019-12-20Factor out duplicate code in gimplify_scan_omp_clausesJulian Brown1-133/+157
gcc/ * gimplify.c (insert_struct_comp_map, extract_base_bit_offset): New. (gimplify_scan_omp_clauses): Outline duplicated code into calls to above two functions. From-SVN: r279623
2019-12-18[OpenACC] Elaborate/simplify 'exit data' 'finalize' handlingThomas Schwinge1-10/+13
No functional changes. gcc/ * gimplify.c (gimplify_omp_target_update): Elaborate 'exit data' 'finalize' handling. gcc/testsuite/ * c-c++-common/goacc/finalize-1.c: Extend. * gfortran.dg/goacc/finalize-1.f: Likewise. libgomp/ * oacc-mem.c (GOACC_enter_exit_data): Simplify 'exit data' 'finalize' handling. From-SVN: r279531
2019-12-03Don't install unnecessary ARRAY_REF element sizesRichard Sandiford1-17/+20
Even EXACT_DIV_EXPR doesn't distribute across addition for wrapping types, so in general we can't fold EXACT_DIV_EXPRs of POLY_INT_CSTs at compile time. This was causing an ICE when trying to gimplify the element size field in an ARRAY_REF. If the result of that EXACT_DIV_EXPR is an invariant, we don't bother recording it in the ARRAY_REF and simply read the element size from the element type. This avoids the overhead of doing: /* ??? tree_ssa_useless_type_conversion will eliminate casts to sizetype from another type of the same width and signedness. */ if (TREE_TYPE (aligned_size) != sizetype) aligned_size = fold_convert_loc (loc, sizetype, aligned_size); return size_binop_loc (loc, MULT_EXPR, aligned_size, size_int (TYPE_ALIGN_UNIT (elmt_type))); each time array_ref_element_size is called. So rather than read array_ref_element_size, do some arithmetic on it, and only then check whether the result is an invariant, we might as well check whether the element size is an invariant to start with. We're then directly testing whether array_ref_element_size gives a reusable value. For consistency, the patch makes the same change for the offset field in a COMPONENT_REF, although I don't think that can trigger yet. 2019-12-03 Richard Sandiford <richard.sandiford@arm.com> gcc/ * gimplify.c (gimplify_compound_lval): Don't gimplify and install an array element size if array_element_size is already an invariant. Similarly don't gimplify and install a field offset if component_ref_field_offset is already an invariant. gcc/testsuite/ * gcc.target/aarch64/sve/acle/general-c/struct_1.c: New test. From-SVN: r278942
2019-11-21Make more bad uses of fallthrough attribute into pedwarns.Joseph Myers1-4/+4
Various bad uses of the [[fallthrough]] attribute are constraint violations in C2x, so need pedwarns rather than warnings. This patch duly turns the relevant warnings into pedwarns. The relevant code is not specific to C, and does not know which form the attribute was given in ([[fallthrough]] or [[gnu::fallthrough]] or __attribute__((fallthrough))), but as I understand it these usages are also erroneous for C++ and it seems reasonable to give a pedwarn here even when a form other than [[fallthrough]] is being used. The precise meaning of the standard wording about "The next statement that would be executed" seems a but unclear in some corner cases; the tests added keep to cases where it is clear whether or not the next statement executed is of the required form. Bootstrapped with no regressions for x86_64-pc-linux-gnu. gcc: * gimplify.c (expand_FALLTHROUGH_r, expand_FALLTHROUGH): Use pedwarn instead of warning_at for fallthrough not preceding a case or default label. gcc/c-family: * c-attribs.c (handle_fallthrough_attribute): Use pedwarn instead of warning. gcc/testsuite: * gcc.dg/c2x-attr-fallthrough-6.c: New test. Split out from c2x-attr-fallthrough-3.c. * gcc.dg/c2x-attr-fallthrough-1.c: Add more tests. * gcc.dg/c2x-attr-fallthrough-2.c: Update expected diagnostics. * gcc.dg/c2x-attr-fallthrough-3.c: Split inside-switch part of test out to c2x-attr-fallthrough-6.c. From-SVN: r278599
2019-11-15gimplify.c (gimplify_call_expr): Don't call omp_resolve_declare_variant ↵Jakub Jelinek1-1/+4
after gimplification. * gimplify.c (gimplify_call_expr): Don't call omp_resolve_declare_variant after gimplification. * omp-general.c (omp_context_selector_matches): For isa that might match in some other function, defer if in declare simd function. (omp_context_compute_score): Don't look for " score" in construct trait set. Set *score to -1 if it can't ever match. (omp_resolve_declare_variant): If any variants need to be deferred, don't punt immediately, but compute scores of all variants and if ther eis a score winner that doesn't need to be deferred, return that. * c-c++-common/gomp/declare-variant-13.c: New test. From-SVN: r278280
2019-11-12Add OpenACC 2.6 `serial' construct supportMaciej W. Rozycki1-4/+18
The `serial' construct (cf. section 2.5.3 of the OpenACC 2.6 standard) is equivalent to a `parallel' construct with clauses `num_gangs(1) num_workers(1) vector_length(1)' implied. These clauses are therefore not supported with the `serial' construct. All the remaining clauses accepted with `parallel' are also accepted with `serial'. The `serial' construct is implemented like `parallel', except for hardcoding dimensions rather than taking them from the relevant clauses, in `expand_omp_target'. Separate codes are used to denote the `serial' construct throughout the middle end, even though the mapping of `serial' to an equivalent `parallel' construct could have been done in the individual language frontends. In particular, this allows to distinguish between compute constructs in warnings, error messages, dumps etc. 2019-11-12 Maciej W. Rozycki <macro@codesourcery.com> Tobias Burnus <tobias@codesourcery.com> Frederik Harwath <frederik@codesourcery.com> Thomas Schwinge <thomas@codesourcery.com> gcc/ * gimple.h (gf_mask): Add GF_OMP_TARGET_KIND_OACC_SERIAL enumeration constant. (is_gimple_omp_oacc): Handle GF_OMP_TARGET_KIND_OACC_SERIAL. (is_gimple_omp_offloaded): Likewise. * gimplify.c (omp_region_type): Add ORT_ACC_SERIAL enumeration constant. Adjust the value of ORT_NONE accordingly. (is_gimple_stmt): Handle OACC_SERIAL. (oacc_default_clause): Handle ORT_ACC_SERIAL. (gomp_needs_data_present): Likewise. (gimplify_adjust_omp_clauses): Likewise. (gimplify_omp_workshare): Handle OACC_SERIAL. (gimplify_expr): Likewise. * omp-expand.c (expand_omp_target): Handle GF_OMP_TARGET_KIND_OACC_SERIAL. (build_omp_regions_1, omp_make_gimple_edges): Likewise. * omp-low.c (is_oacc_parallel): Rename function to... (is_oacc_parallel_or_serial): ... this. Handle GF_OMP_TARGET_KIND_OACC_SERIAL. (scan_sharing_clauses): Adjust accordingly. (scan_omp_for): Likewise. (lower_oacc_head_mark): Likewise. (convert_from_firstprivate_int): Likewise. (lower_omp_target): Likewise. (check_omp_nesting_restrictions): Handle GF_OMP_TARGET_KIND_OACC_SERIAL. (lower_oacc_reductions): Likewise. (lower_omp_target): Likewise. * tree.def (OACC_SERIAL): New tree code. * tree-pretty-print.c (dump_generic_node): Handle OACC_SERIAL. * doc/generic.texi (OpenACC): Document OACC_SERIAL. gcc/c-family/ * c-pragma.h (pragma_kind): Add PRAGMA_OACC_SERIAL enumeration constant. * c-pragma.c (oacc_pragmas): Add "serial" entry. gcc/c/ * c-parser.c (OACC_SERIAL_CLAUSE_MASK): New macro. (c_parser_oacc_kernels_parallel): Rename function to... (c_parser_oacc_compute): ... this. Handle PRAGMA_OACC_SERIAL. (c_parser_omp_construct): Update accordingly. gcc/cp/ * constexpr.c (potential_constant_expression_1): Handle OACC_SERIAL. * parser.c (OACC_SERIAL_CLAUSE_MASK): New macro. (cp_parser_oacc_kernels_parallel): Rename function to... (cp_parser_oacc_compute): ... this. Handle PRAGMA_OACC_SERIAL. (cp_parser_omp_construct): Update accordingly. (cp_parser_pragma): Handle PRAGMA_OACC_SERIAL. Fix alphabetic order. * pt.c (tsubst_expr): Handle OACC_SERIAL. gcc/fortran/ * gfortran.h (gfc_statement): Add ST_OACC_SERIAL_LOOP, ST_OACC_END_SERIAL_LOOP, ST_OACC_SERIAL and ST_OACC_END_SERIAL enumeration constants. (gfc_exec_op): Add EXEC_OACC_SERIAL_LOOP and EXEC_OACC_SERIAL enumeration constants. * match.h (gfc_match_oacc_serial): New prototype. (gfc_match_oacc_serial_loop): Likewise. * dump-parse-tree.c (show_omp_node, show_code_node): Handle EXEC_OACC_SERIAL_LOOP and EXEC_OACC_SERIAL. * match.c (match_exit_cycle): Handle EXEC_OACC_SERIAL_LOOP. * openmp.c (OACC_SERIAL_CLAUSES): New macro. (gfc_match_oacc_serial_loop): New function. (gfc_match_oacc_serial): Likewise. (oacc_is_loop): Handle EXEC_OACC_SERIAL_LOOP. (resolve_omp_clauses): Handle EXEC_OACC_SERIAL. (oacc_code_to_statement): Handle EXEC_OACC_SERIAL and EXEC_OACC_SERIAL_LOOP. (gfc_resolve_oacc_directive): Likewise. * parse.c (decode_oacc_directive) <'s'>: Add case for "serial" and "serial loop". (next_statement): Handle ST_OACC_SERIAL_LOOP and ST_OACC_SERIAL. (gfc_ascii_statement): Likewise. Handle ST_OACC_END_SERIAL_LOOP and ST_OACC_END_SERIAL. (parse_oacc_structured_block): Handle ST_OACC_SERIAL. (parse_oacc_loop): Handle ST_OACC_SERIAL_LOOP and ST_OACC_END_SERIAL_LOOP. (parse_executable): Handle ST_OACC_SERIAL_LOOP and ST_OACC_SERIAL. (is_oacc): Handle EXEC_OACC_SERIAL_LOOP and EXEC_OACC_SERIAL. * resolve.c (gfc_resolve_blocks, gfc_resolve_code): Likewise. * st.c (gfc_free_statement): Likewise. * trans-openmp.c (gfc_trans_oacc_construct): Handle EXEC_OACC_SERIAL. (gfc_trans_oacc_combined_directive): Handle EXEC_OACC_SERIAL_LOOP. (gfc_trans_oacc_directive): Handle EXEC_OACC_SERIAL_LOOP and EXEC_OACC_SERIAL. * trans.c (trans_code): Likewise. gcc/testsuite/ * c-c++-common/goacc/parallel-dims.c: New test. * gfortran.dg/goacc/parallel-dims.f90: New test. libgomp/ * testsuite/libgomp.oacc-c-c++-common/parallel-dims.c: New test. * testsuite/libgomp.oacc-fortran/parallel-dims-aux.c: New test. * testsuite/libgomp.oacc-fortran/parallel-dims.f89: New test. * testsuite/libgomp.oacc-fortran/parallel-dims-2.f90: New test. Reviewed-by: Thomas Schwinge <thomas@codesourcery.com> Co-Authored-By: Frederik Harwath <frederik@codesourcery.com> Co-Authored-By: Thomas Schwinge <thomas@codesourcery.com> Co-Authored-By: Tobias Burnus <tobias@codesourcery.com> From-SVN: r278082
2019-11-11Assert 'offset2' instead of 'offset' in ↵Thomas Schwinge1-2/+2
'gcc/gimplify.c:gimplify_scan_omp_clauses' ... to fix a long-time typo/copy'n'past-o. gcc/ * gimplify.c (gimplify_scan_omp_clauses): Assert 'offset2' instead of 'offset'. From-SVN: r278038
2019-11-06introduce -fcallgraph-info optionEric Botcazou1-0/+4
This was first submitted many years ago https://gcc.gnu.org/ml/gcc-patches/2010-10/msg02468.html The command line option -fcallgraph-info is added and makes the compiler generate another output file (xxx.ci) for each compilation unit (or LTO partitoin), which is a valid VCG file (you can launch your favorite VCG viewer on it unmodified) and contains the "final" callgraph of the unit. "final" is a bit of a misnomer as this is actually the callgraph at RTL expansion time, but since most high-level optimizations are done at the Tree level and RTL doesn't usually fiddle with calls, it's final in almost all cases. Moreover, the nodes can be decorated with additional info: -fcallgraph-info=su adds stack usage info and -fcallgraph-info=da dynamic allocation info. for gcc/ChangeLog From Eric Botcazou <ebotcazou@adacore.com>, Alexandre Oliva <oliva@adacore.com> * common.opt (-fcallgraph-info[=]): New option. * doc/invoke.texi (Developer options): Document it. * opts.c (common_handle_option): Handle it. * builtins.c (expand_builtin_alloca): Record allocation if -fcallgraph-info=da. * calls.c (expand_call): If -fcallgraph-info, record the call. (emit_library_call_value_1): Likewise. * flag-types.h (enum callgraph_info_type): New type. * explow.c: Include stringpool.h. (set_stack_check_libfunc): Set SET_SYMBOL_REF_DECL on the symbol. * function.c (allocate_stack_usage_info): New. (allocate_struct_function): Call it for -fcallgraph-info. (prepare_function_start): Call it otherwise. (record_final_call, record_dynamic_alloc): New. * function.h (struct callinfo_callee): New. (CALLEE_FROM_CGRAPH_P): New. (struct callinfo_dalloc): New. (struct stack_usage): Add callees and dallocs. (record_final_call, record_dynamic_alloc): Declare. * gimplify.c (gimplify_decl_expr): Record dynamically-allocated object if -fcallgraph-info=da. * optabs-libfuncs.c (build_libfunc_function): Keep SYMBOL_REF_DECL. * print-tree.h (print_decl_identifier): Declare. (PRINT_DECL_ORIGIN, PRINT_DECL_NAME, PRINT_DECL_UNIQUE_NAME): New. * print-tree.c: Include print-tree.h. (print_decl_identifier): New function. * toplev.c: Include print-tree.h. (callgraph_info_file): New global variable. (callgraph_info_external_printed): Likewise. (output_stack_usage): Rename to... (output_stack_usage_1): ... this. Make it static, add cf parameter. If -fcallgraph-info=su, print stack usage to cf. If -fstack-usage, use print_decl_identifier for pretty-printing. (INDIRECT_CALL_NAME): New. (dump_final_node_vcg_start): New. (dump_final_callee_vcg, dump_final_node_vcg): New. (output_stack_usage): New. (lang_dependent_init): Open and start file if -fcallgraph-info. Allocated callgraph_info_external_printed. (finalize): If callgraph_info_file is not null, finish it, close it, and release callgraph_info_external_printed. for gcc/ada/ChangeLog * gcc-interface/misc.c (callgraph_info_file): Delete. Co-Authored-By: Alexandre Oliva <oliva@adacore.com> From-SVN: r277876
2019-11-06re PR inline-asm/92352 (ICE in force_constant_size)Jakub Jelinek1-3/+12
PR inline-asm/92352 * gimplify.c (gimplify_asm_expr): Reject VLA in output or input operands with non-memory constraints. * c-c++-common/pr92352.c: New test. From-SVN: r277873
2019-11-02gimplify.h (omp_construct_selector_matches): Change return type to int, add ↵Jakub Jelinek1-24/+73
a new SCORES argument. * gimplify.h (omp_construct_selector_matches): Change return type to int, add a new SCORES argument. * gimplify.c (omp_construct_selector_matches): Likewise. If SCORES is non-NULL, compute scores of each construct. * omp-general.h (omp_get_context_selector): Declare. * omp-general.c (omp_maybe_offloaded, omp_context_selector_matches): Adjust omp_construct_selector_matches callers. (omp_get_context_selector): New function, moved from c-family/c-omp.c. (omp_context_compute_score): New function. (omp_resolve_declare_variant): Compute scores and decide based on that. c-family/ * c-common.h (c_omp_get_context_selector): Remove. * c-omp.c (c_omp_get_context_selector): Moved to omp-general.c and renamed to omp_get_context_selector. c/ * c-parser.c (c_finish_omp_declare_variant): Use omp_get_context_selector instead of c_omp_get_context_selector. cp/ * decl.c (omp_declare_variant_finalize_one): Use omp_get_context_selector instead of c_omp_get_context_selector. testsuite/ * c-c++-common/gomp/declare-variant-12.c: New test. From-SVN: r277742