aboutsummaryrefslogtreecommitdiff
path: root/gcc/c
AgeCommit message (Collapse)AuthorFilesLines
2024-03-09Daily bump.GCC Administrator1-0/+8
2024-03-08dwarf2out: Emit DW_AT_export_symbols on anon unions/structs [PR113918]Jakub Jelinek3-0/+27
DWARF5 added DW_AT_export_symbols both for use on inline namespaces (where we emit it), but also on anonymous unions/structs (and we didn't emit that attribute there). The following patch fixes it. 2024-03-08 Jakub Jelinek <jakub@redhat.com> PR debug/113918 gcc/ * dwarf2out.cc (gen_field_die): Emit DW_AT_export_symbols on anonymous unions or structs for -gdwarf-5 or -gno-strict-dwarf. gcc/c/ * c-tree.h (c_type_dwarf_attribute): Declare. * c-objc-common.h (LANG_HOOKS_TYPE_DWARF_ATTRIBUTE): Redefine. * c-objc-common.cc: Include dwarf2.h. (c_type_dwarf_attribute): New function. gcc/cp/ * cp-objcp-common.cc (cp_type_dwarf_attribute): Return 1 for DW_AT_export_symbols on anonymous structs or unions. gcc/testsuite/ * c-c++-common/dwarf2/pr113918.c: New test.
2024-02-27Daily bump.GCC Administrator1-0/+8
2024-02-26c: Improve some diagnostics for __builtin_stdc_bit_* [PR114042]Jakub Jelinek1-0/+21
The PR complains that for the __builtin_stdc_bit_* "builtins" the diagnostics doesn't mention the name of the builtin the user used, but instead __builtin_{clz,ctz,popcount}g instead (which is what the FE immediately lowers it to). The following patch repeats the checks from check_builtin_function_arguments which are there done on BUILT_IN_{CLZ,CTZ,POPCOUNT}G, such that they diagnose it with the name of the "builtin" user actually used before it is gone. 2024-02-26 Jakub Jelinek <jakub@redhat.com> PR c/114042 * c-parser.cc (c_parser_postfix_expression): Diagnose __builtin_stdc_bit_* argument with ENUMERAL_TYPE or BOOLEAN_TYPE type or if signed here rather than on the replacement builtins in check_builtin_function_arguments. * gcc.dg/builtin-stdc-bit-2.c: Adjust testcase for actual builtin names rather than names of builtin replacements.
2024-02-23Daily bump.GCC Administrator1-0/+11
2024-02-22c: Handle scoped attributes in __has*attribute and scoped attribute parsing ↵Jakub Jelinek1-8/+6
changes in -std=c11 etc. modes [PR114007] We aren't able to parse __has_attribute (vendor::attr) (and __has_c_attribute and __has_cpp_attribute) in strict C < C23 modes. While in -std=gnu* modes or in -std=c23 there is CPP_SCOPE token, in -std=c* (except for -std=c23) there are is just a pair of CPP_COLON tokens. The c-lex.cc hunk adds support for that. That leads to a question if we should return 1 or 0 from __has_attribute (gnu::unused) or not, because while [[gnu::unused]] is parsed fine in -std=gnu*/-std=c23 modes (sure, with pedwarn for < C23), we do not parse it at all in -std=c* (except for -std=c23), we only parse [[__extension__ gnu::unused]] there. While the __extension__ in there helps to avoid the pedwarn, I think it is better to be consistent between GNU and strict C < C23 modes and parse [[gnu::unused]] too; on the other side, I think parsing [[__extension__ gnu : : unused]] is too weird and undesirable. So, the following patch adds a flag during preprocessing at the point where we normally create CPP_SCOPE tokens out of 2 consecutive colons on the first CPP_COLON to mark the consecutive case (as we are tight on the bits, I've reused the PURE_ZERO flag, which is used just by the C++ FE and only ever set (both C and C++) on CPP_NUMBER tokens, this new flag has the same value and is only ever used on CPP_COLON tokens) and instead of checking loose_scope_p argument (i.e. whether it is [[__extension__ ...]] or not), it just parses CPP_SCOPE or CPP_COLON with CLONE_SCOPE flag followed by another CPP_COLON the same. The latter will never appear in >= C23 or -std=gnu* modes, though guarding its use say with flag_iso && !flag_isoc23 && doesn't really work because the __extension__ case temporarily clears flag_iso flag. This makes the -std=c11 etc. behavior more similar to -std=gnu11 or -std=c23, the only difference I'm aware of are the #define JOIN2(A, B) A##B [[vendor JOIN2(:,:) attr]] [[__extension__ vendor JOIN2(:,:) attr]] cases, which are accepted in the latter modes, but results in error in -std=c11; but the error is during preprocessing that :: doesn't form a valid preprocessing token, which is true, so just don't do that if you try to have __STRICT_ANSI__ && __STDC_VERSION__ <= 201710L compatibility. 2024-02-22 Jakub Jelinek <jakub@redhat.com> PR c/114007 gcc/ * doc/extend.texi: (__extension__): Remove comments about scope tokens vs. two colons. gcc/c-family/ * c-lex.cc (c_common_has_attribute): Parse 2 CPP_COLONs with the first one with COLON_SCOPE flag the same as CPP_SCOPE. gcc/c/ * c-parser.cc (c_parser_std_attribute): Remove loose_scope_p argument. Instead of checking it, parse 2 CPP_COLONs with the first one with COLON_SCOPE flag the same as CPP_SCOPE. (c_parser_std_attribute_list): Remove loose_scope_p argument, don't pass it to c_parser_std_attribute. (c_parser_std_attribute_specifier): Adjust c_parser_std_attribute_list caller. gcc/testsuite/ * gcc.dg/c23-attr-syntax-6.c: Adjust testcase for :: being valid even in -std=c11 even without __extension__ and : : etc. not being valid anymore even with __extension__. * gcc.dg/c23-attr-syntax-7.c: Likewise. * gcc.dg/c23-attr-syntax-8.c: New test. libcpp/ * include/cpplib.h (COLON_SCOPE): Define to PURE_ZERO. * lex.cc (_cpp_lex_direct): When lexing CPP_COLON with another colon after it, if !CPP_OPTION (pfile, scope) set COLON_SCOPE flag on the first CPP_COLON token.
2024-02-14Daily bump.GCC Administrator1-0/+6
2024-02-13OpenMP: Reject non-const 'condition' trait in FortranTobias Burnus1-1/+2
OpenMP 5.0 only permits constant expressions for the 'condition' trait in context selectors; this is relaxed in 5.2 but not implemented. In order to avoid wrong code, it is now rejected. Additionally, in Fortran, 'condition' should not accept an integer expression, which is now ensured. Additionally, as 'device_num' should be a conforming device number, there is now a check on the value. PR middle-end/113904 gcc/c/ChangeLog: * c-parser.cc (c_parser_omp_context_selector): Handle splitting of OMP_TRAIT_PROPERTY_EXPR into OMP_TRAIT_PROPERTY_{DEV_NUM,BOOL}_EXPR. gcc/cp/ChangeLog: * parser.cc (cp_parser_omp_context_selector): Handle splitting of OMP_TRAIT_PROPERTY_EXPR into OMP_TRAIT_PROPERTY_{DEV_NUM,BOOL}_EXPR. gcc/fortran/ChangeLog: * trans-openmp.cc (gfc_trans_omp_declare_variant): Handle splitting of OMP_TRAIT_PROPERTY_EXPR into OMP_TRAIT_PROPERTY_{DEV_NUM,BOOL}_EXPR. * openmp.cc (gfc_match_omp_context_selector): Likewise; rejects non-const device_num/condition; improve diagnostic. gcc/ChangeLog: * omp-general.cc (struct omp_ts_info): Update for splitting of OMP_TRAIT_PROPERTY_EXPR into OMP_TRAIT_PROPERTY_{DEV_NUM,BOOL}_EXPR. * omp-selectors.h (enum omp_tp_type): Replace OMP_TRAIT_PROPERTY_EXPR by OMP_TRAIT_PROPERTY_{DEV_NUM,BOOL}_EXPR. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/declare-variant-1.f90: Change 'condition' trait's argument from integer to a logical expression. * gfortran.dg/gomp/declare-variant-11.f90: Likewise. * gfortran.dg/gomp/declare-variant-12.f90: Likewise. * gfortran.dg/gomp/declare-variant-13.f90: Likewise. * gfortran.dg/gomp/declare-variant-2.f90: Likewise. * gfortran.dg/gomp/declare-variant-2a.f90: Likewise. * gfortran.dg/gomp/declare-variant-3.f90: Likewise. * gfortran.dg/gomp/declare-variant-4.f90: Likewise. * gfortran.dg/gomp/declare-variant-6.f90: Likewise. * gfortran.dg/gomp/declare-variant-8.f90: Likewise. * gfortran.dg/gomp/declare-variant-20.f90: New test.
2024-02-11Daily bump.GCC Administrator1-0/+5
2024-02-10Use HOST_SIZE_T_PRINT_* and HOST_WIDE_INT_T_PRINT_* some moreJakub Jelinek1-2/+2
I went through suspicios %l in format strings of *printf family functions combined with casts to (long) or (unsigned long) and tried to find out the types of the original expressions that were cast. Quite a few had size_t type, so I've used the new HOST_SIZE_T_PRINT_* macros together with cast to fmt_size_t for those, and then there were quite a few HOST_WIDE_INTs cast to long, used HOST_WIDE_INT_PRINT_* for those without casts. There was one case of a weird unsigned int variable used with %lu and (long) cast too. 2024-02-10 Jakub Jelinek <jakub@redhat.com> gcc/ * ipa-icf.cc (sem_item_optimizer::process_cong_reduction, sem_item_optimizer::dump_cong_classes): Use HOST_SIZE_T_PRINT_UNSIGNED and casts to fmt_size_t instead of "%lu" and casts to unsigned long. * tree.cc (print_debug_expr_statistics): Use HOST_SIZE_T_PRINT_DEC and casts to fmt_size_t instead of "%ld" and casts to long. (print_value_expr_statistics, print_type_hash_statistics): Likewise. * dwarf2out.cc (output_macinfo_op): Use HOST_WIDE_INT_PRINT_UNSIGNED instead of "%lu" and casts to unsigned long. * gcov-dump.cc (dump_gcov_file): Use %u instead of %lu and casts to unsigned long. * tree-ssa-dom.cc (htab_statistics): Use HOST_SIZE_T_PRINT_DEC and casts to fmt_size_t instead of "%ld" and casts to long. * cfgexpand.cc (dump_stack_var_partition): Use HOST_SIZE_T_PRINT_UNSIGNED and casts to fmt_size_t instead of "%lu" and casts to unsigned long. * gengtype.cc (adjust_field_rtx_def): Likewise. * tree-into-ssa.cc (htab_statistics): Use HOST_SIZE_T_PRINT_DEC and casts to fmt_size_t instead of "%ld" and casts to long. * postreload-gcse.cc (dump_hash_table): Likewise. * ggc-page.cc (alloc_page): Use HOST_SIZE_T_PRINT_UNSIGNED and casts to fmt_size_t instead of "%lu" and casts to unsigned long. (ggc_internal_alloc, ggc_free): Likewise. * genpreds.cc (write_lookup_constraint_1): Likewise. (write_insn_constraint_len): Likewise. * tree-dfa.cc (dump_dfa_stats): Use HOST_SIZE_T_PRINT_DEC and casts to fmt_size_t instead of "%ld" and casts to long. * varasm.cc (output_constant_pool_contents): Use HOST_WIDE_INT_PRINT_DEC instead of "%ld" and casts to long. * var-tracking.cc (dump_var): Likewise. gcc/c-family/ * c-ada-spec.cc (dump_template_types): Use HOST_SIZE_T_PRINT_UNSIGNED and casts to fmt_size_t instead of "%lu" and casts to unsigned long. gcc/c/ * c-decl.cc (get_parm_array_spec): Use HOST_WIDE_INT_PRINT_UNSIGNED instead of "%lu" and casts to unsigned long or unsigned long long. gcc/cp/ * tree.cc (debug_binfo): Use HOST_WIDE_INT_PRINT_DEC instead of "%ld" and casts to long. * pt.cc (print_template_statistics): Use HOST_SIZE_T_PRINT_DEC and casts to fmt_size_t instead of "%ld" and casts to long. * class.cc (dump_class_hierarchy_1): Use HOST_WIDE_INT_PRINT_UNSIGNED instead of "%lu" and casts to unsigned long. For TYPE_ALIGN, use %u instead of %lu and drop casts to unsigned long. * parser.cc (cp_lexer_peek_nth_token): Use HOST_SIZE_T_PRINT_DEC and casts to fmt_size_t instead of "%ld" and casts to long. gcc/fortran/ * trans-common.cc (build_common_decl): Use %wu instead of %lu and casts to unsigned long. * resolve.cc (resolve_ordinary_assign): Use %wd instead of %ld and casts to long. * array.cc (gfc_resolve_character_array_constructor): Likewise. * data.cc (create_character_initializer): Likewise. gcc/jit/ * jit-playback.cc (new_bitcast): Use HOST_WIDE_INT_PRINT_DEC instead of "%ld" and casts to long. gcc/lto/ * lto-common.cc (print_lto_report_1): Use HOST_SIZE_T_PRINT_DEC and casts to fmt_size_t instead of "%ld" and casts to long. Use %d instead of %ld and casts to long for searches and collisions.
2024-02-09Daily bump.GCC Administrator1-0/+7
2024-02-08c: Fix boolean conversion of floating constant as integer constant ↵Joseph Myers1-1/+11
expression [PR113776] My fix for bug 111059 and bug 111911 caused a conversion of a floating constant to boolean to wrongly no longer be considered an integer constant expression, because logic to insert a NOP_EXPR in c_objc_common_truthvalue_conversion for an argument not an integer constant expression itself now took place after rather than before the conversion to bool. In the specific case of casting a floating constant to bool, the result is an integer constant expression even though the argument isn't (build_c_cast deals with ensuring that casts to integer type of anything of floating type more complicated than a single floating constant don't get wrongly treated as integer constant expressions even if they fold to constants), so fix the logic in c_objc_common_truthvalue_conversion to handle that special case. Bootstrapped with no regressions for x86_64-pc-linux-gnu. PR c/113776 gcc/c * c-typeck.cc (c_objc_common_truthvalue_conversion): Return an integer constant expression for boolean conversion of floating constant. gcc/testsuite/ * gcc.dg/pr113776-1.c, gcc.dg/pr113776-2.c, gcc.dg/pr113776-3.c, gcc.dg/pr113776-4.c: New tests.
2024-02-06Daily bump.GCC Administrator1-0/+7
2024-02-05c: Avoid ICE with _BitInt(N) : 0 bitfield [PR113740]Jakub Jelinek1-1/+1
finish_struct already made sure not to call build_bitint_type for signed _BitInt(2) : 1; or signed _BitInt(2) : 0; bitfields (but instead build a zero precision integral type, we remove it later), this patch makes sure we do it also for unsigned _BitInt(1) : 0; because of the build_bitint_type assertion that precision is >= (unsigned ? 1 : 2). 2024-02-05 Jakub Jelinek <jakub@redhat.com> PR c/113740 * c-decl.cc (finish_struct): Only use build_bitint_type if bit-field has width larger or equal to minimum _BitInt precision. * gcc.dg/bitint-85.c: New test.
2024-02-01Daily bump.GCC Administrator1-0/+25
2024-01-31c: Fix ICE for nested enum redefinitions with/without fixed underlying type ↵Joseph Myers1-2/+5
[PR112571] Bug 112571 reports an ICE-on-invalid for cases where an enum is defined, without a fixed underlying type, inside the enum type specifier for a definition of that same enum with a fixed underlying type. The ultimate cause is attempting to access ENUM_UNDERLYING_TYPE in a case where it is NULL. Avoid this by clearing ENUM_FIXED_UNDERLYING_TYPE_P in thie case of inconsistent definitions. Bootstrapped wth no regressions for x86_64-pc-linux-gnu. PR c/112571 gcc/c/ * c-decl.cc (start_enum): Clear ENUM_FIXED_UNDERLYING_TYPE_P when defining without a fixed underlying type an enumeration previously declared with a fixed underlying type. gcc/testsuite/ * gcc.dg/c23-enum-9.c, gcc.dg/c23-enum-10.c: New tests.
2024-01-31Fix ICE with -g and -std=c23 when forming composite types [PR113438]Martin Uecker1-0/+5
Set TYPE_STUB_DECL to an artificial decl when creating a new structure as a composite type. PR c/113438 gcc/c/ * c-typeck.cc (composite_type_internal): Set TYPE_STUB_DECL. gcc/testsuite/ * gcc.dg/pr113438.c: New test.
2024-01-31c: Fix ICEs casting expressions with integer constant operands to bool ↵Joseph Myers3-9/+28
[PR111059, PR111911] C front-end bugs 111059 and 111911 both report ICEs with conversions to boolean of expressions with integer constant operands that can appear in an integer constant expression as long as they are not evaluated (such as division by zero). The issue is a nested C_MAYBE_CONST_EXPR, with the inner one generated in build_binary_op to indicate that a subexpression has been fully folded and should not be folded again, and the outer one in build_c_cast to indicate that the expression has integer constant operands. To avoid the inner one from build_binary_op, c_objc_common_truthvalue_conversion should be given an argument properly marked as having integer constant operands rather than that information having been removed by the caller - but because c_convert would then also wrap a C_MAYBE_CONST_EXPR with a NOP_EXPR converting to boolean, it seems most convenient to have c_objc_common_truthvalue_conversion produce the NE_EXPR directly in the desired type (boolean in this case), before generating any C_MAYBE_CONST_EXPR there, rather than it always producing a comparison in integer_type_node and doing a conversion to boolean in the caller. The same issue as in those PRs also applies for conversion to enums with a boolean fixed underlying type; that case is also fixed and tests added for it. Note that not all the tests added failed before the patch (in particular, the issue was specific to casts and did not apply for implicit conversions, but some tests of those are added as well). Bootstrapped with no regressions for x86_64-pc-linux-gnu. PR c/111059 PR c/111911 gcc/c/ * c-tree.h (c_objc_common_truthvalue_conversion): Add third argument. * c-convert.cc (c_convert): For conversions to boolean, pass third argument to c_objc_common_truthvalue_conversion rather than converting here. * c-typeck.cc (build_c_cast): Ensure arguments with integer operands are marked as such for conversion to boolean. (c_objc_common_truthvalue_conversion): Add third argument TYPE. gcc/testsuite/ * gcc.c-torture/compile/pr111059-1.c, gcc.c-torture/compile/pr111059-2.c, gcc.c-torture/compile/pr111059-3.c, gcc.c-torture/compile/pr111059-4.c, gcc.c-torture/compile/pr111059-5.c, gcc.c-torture/compile/pr111059-6.c, gcc.c-torture/compile/pr111059-7.c, gcc.c-torture/compile/pr111059-8.c, gcc.c-torture/compile/pr111059-9.c, gcc.c-torture/compile/pr111059-10.c, gcc.c-torture/compile/pr111059-11.c, gcc.c-torture/compile/pr111059-12.c, gcc.c-torture/compile/pr111911-1.c, gcc.c-torture/compile/pr111911-2.c: New tests.
2024-01-22Daily bump.GCC Administrator1-0/+7
2024-01-21C23: Fix ICE for composite type for structs with unsigned bitfields [PR113492]Martin Uecker1-1/+1
This patch fixes a bug when forming a composite type from structs that contain an unsigned bitfield declared with int while using -funsigned-bitfields. In such structs the unsigned integer type was not compatible to the regular unsigned integer type used elsewhere in the C FE. PR c/113492 gcc/c: * c-decl.cc (grokdeclarator): Use c_common_unsigned_type instead of unsigned_type_for to create the unsigned type for bitfields declared with int when using -funsigned-bitfields. gcc/testsuite: * gcc.dg/pr113492.c: New test.
2024-01-13Daily bump.GCC Administrator1-0/+6
2024-01-12c: Avoid _BitInt indexes > sizetype in ARRAY_REFs [PR113315]Jakub Jelinek1-0/+4
When build_array_ref doesn't use ARRAY_REF, it casts the index to sizetype already, performs POINTER_PLUS_EXPR and then dereferences. While when emitting ARRAY_REF, we try to keep index expression as is in whatever type it had, which is reasonable e.g. for signed or unsigned types narrower than sizetype for loop optimizations etc. But if the index is wider than sizetype, we are unnecessarily computing bits beyond what is needed. For {,unsigned }__int128 on 64-bit arches or {,unsigned }long long on 32-bit arches we've been doing that for decades, so the following patch doesn't propose to change that (might be stage1 material), but for _BitInt at least the _BitInt lowering code doesn't expect to see large/huge _BitInt in the ARRAY_REF indexes, I was expecting one would see just casts of those to sizetype. So, the following patch makes sure that large/huge _BitInt indexes don't appear in ARRAY_REFs. 2024-01-12 Jakub Jelinek <jakub@redhat.com> PR c/113315 * c-typeck.cc (build_array_ref): If index has BITINT_TYPE type with precision larger than sizetype precision, convert it to sizetype. * gcc.dg/bitint-65.c: New test. * gcc.dg/bitint-66.c: New test.
2024-01-12Daily bump.GCC Administrator1-0/+32
2024-01-11OpenMP: lvalue parsing for map/to/from clauses (C)Julian Brown3-37/+229
This patch adds support for parsing general lvalues ("locator list item types") for OpenMP "map", "to" and "from" clauses to the C front-end, similar to the previously-posted patch for C++. Such syntax is permitted for OpenMP 5.0 and above. It was previously posted for mainline here: https://gcc.gnu.org/pipermail/gcc-patches/2022-December/609038.html and for the og13 branch here: https://gcc.gnu.org/pipermail/gcc-patches/2023-June/623355.html 2024-01-11 Julian Brown <julian@codesourcery.com> gcc/c-family/ * c-pretty-print.cc (c_pretty_printer::postfix_expression, c_pretty_printer::expression): Add OMP_ARRAY_SECTION support. gcc/c/ * c-parser.cc (c_parser_braced_init, c_parser_conditional_expression): Don't allow OpenMP array section. (c_parser_postfix_expression): Don't allow array section in statement expression. (c_parser_postfix_expression_after_primary): Add support for OpenMP array section parsing. (c_parser_expr_list): Don't allow OpenMP array section here. (c_parser_omp_variable_list): Change ALLOW_DEREF parameter to MAP_LVALUE. Support parsing of general lvalues in "map", "to" and "from" clauses. (c_parser_omp_var_list_parens): Change ALLOW_DEREF parameter to MAP_LVALUE. Update call to c_parser_omp_variable_list. (c_parser_oacc_data_clause): Update calls to c_parser_omp_var_list_parens. (c_parser_omp_clause_reduction): Use OMP_ARRAY_SECTION tree node instead of TREE_LIST for array sections. (c_parser_omp_target): Allow GOMP_MAP_ATTACH. * c-tree.h (c_omp_array_section_p): Add extern declaration. (build_omp_array_section): Add prototype. * c-typeck.cc (c_omp_array_section_p): Add flag. (mark_exp_read): Support OMP_ARRAY_SECTION. (build_omp_array_section): Add function. (build_external_ref): Tweak error path for OpenMP array sections. (handle_omp_array_sections_1): Use OMP_ARRAY_SECTION tree code instead of TREE_LIST. Handle more kinds of expressions. (c_oacc_check_attachments): Use OMP_ARRAY_SECTION instead of TREE_LIST for array sections. (c_finish_omp_clauses): Use OMP_ARRAY_SECTION instead of TREE_LIST. Check for supported expression types. gcc/testsuite/ * gcc.dg/gomp/bad-array-section-c-1.c: New test. * gcc.dg/gomp/bad-array-section-c-2.c: New test. * gcc.dg/gomp/bad-array-section-c-3.c: New test. * gcc.dg/gomp/bad-array-section-c-4.c: New test. * gcc.dg/gomp/bad-array-section-c-5.c: New test. * gcc.dg/gomp/bad-array-section-c-6.c: New test. * gcc.dg/gomp/bad-array-section-c-7.c: New test. * gcc.dg/gomp/bad-array-section-c-8.c: New test. libgomp/ * libgomp.texi: C/C++ lvalues are supported now for map/to/from. * testsuite/libgomp.c-c++-common/ind-base-4.c: New test. * testsuite/libgomp.c-c++-common/unary-ptr-1.c: New test.
2024-01-10Daily bump.GCC Administrator1-0/+5
2024-01-09frontend: don't ice with pragma NOVECTOR if loop has no condition [PR113267]Tamar Christina1-1/+1
In C you can have loops without a condition, the original version of the patch was rejecting the use of #pragma GCC novector, however during review it was changed to not due this with the reason that we didn't want to give a compile error with such cases. However because annotations seem to be only be allowed on conditions (unless I'm mistaken?) the attached example ICEs because there's no condition. This will have it ignore the pragma instead of ICEing. I don't know if this is the best solution, but as far as I can tell we can't attach the annotation to anything else. gcc/c/ChangeLog: PR c/113267 * c-parser.cc (c_parser_for_statement): Skip the pragma is no cond. gcc/testsuite/ChangeLog: PR c/113267 * gcc.dg/pr113267.c: New test.
2024-01-04Daily bump.GCC Administrator1-0/+5
2024-01-03openmp: Adjust position of OMP_CLAUSE_INDIRECT in OpenMP clausesKwok Cheung Yeung1-2/+2
Move OMP_CLAUSE_INDIRECT so that it is outside of the range checked by OMP_CLAUSE_SIZE and OMP_CLAUSE_DECL. 2024-01-03 Kwok Cheung Yeung <kcy@codesourcery.com> gcc/c/ * c-parser.cc (c_parser_omp_clause_name): Move handling of indirect clause to correspond to alphabetical order. gcc/cp/ * parser.cc (cp_parser_omp_clause_name): Move handling of indirect clause to correspond to alphabetical order. gcc/ * tree-core.h (enum omp_clause_code): Move OMP_CLAUSE_INDIRECT to before OMP_CLAUSE__SIMDUID_. * tree.cc (omp_clause_num_ops): Update position of entry for OMP_CLAUSE_INDIRECT to correspond with omp_clause_code. (omp_clause_code_name): Likewise.
2024-01-03Update copyright years.Jakub Jelinek19-19/+19
2024-01-03Update Copyright year in ChangeLog filesJakub Jelinek1-1/+1
2023 -> 2024
2023-12-31Daily bump.GCC Administrator1-0/+4
2023-12-30C: Fix type compatibility for structs with variable sized fields.Martin Uecker1-11/+8
This fixes the test gcc.dg/gnu23-tag-4.c introduced by commit 23fee88f which fails for -march=... because the DECL_FIELD_BIT_OFFSET are set inconsistently for types with and without variable-sized field. This is fixed by testing for DECL_ALIGN instead. The code is further simplified by removing some unnecessary conditions, i.e. anon_field is set unconditionaly and all fields are assumed to be DECL_FIELDs. gcc/c: * c-typeck.cc (tagged_types_tu_compatible_p): Revise. gcc/testsuite: * gcc.dg/c23-tag-9.c: New test.
2023-12-23Daily bump.GCC Administrator1-0/+9
2023-12-22c23: construct composite type for tagged typesMartin Uecker2-27/+134
Support for constructing composite types for structs and unions in C23. gcc/c: * c-typeck.cc (composite_type_internal): Adapted from composite_type to support structs and unions. (composite_type): New wrapper function. (build_conditional_operator): Return composite type. * c-decl.cc (finish_struct): Allow NULL for enclosing_struct_parse_info. gcc/testsuite: * gcc.dg/c23-tag-alias-6.c: New test. * gcc.dg/c23-tag-alias-7.c: New test. * gcc.dg/c23-tag-composite-1.c: New test. * gcc.dg/c23-tag-composite-2.c: New test. * gcc.dg/c23-tag-composite-3.c: New test. * gcc.dg/c23-tag-composite-4.c: New test. * gcc.dg/c23-tag-composite-5.c: New test. * gcc.dg/c23-tag-composite-6.c: New test. * gcc.dg/c23-tag-composite-7.c: New test. * gcc.dg/c23-tag-composite-8.c: New test. * gcc.dg/c23-tag-composite-9.c: New test. * gcc.dg/c23-tag-composite-10.c: New test. * gcc.dg/gnu23-tag-composite-1.c: New test. * gcc.dg/gnu23-tag-composite-2.c: New test. * gcc.dg/gnu23-tag-composite-3.c: New test. * gcc.dg/gnu23-tag-composite-4.c: New test. * gcc.dg/gnu23-tag-composite-5.c: New test.
2023-12-22Daily bump.GCC Administrator1-0/+41
2023-12-21c23: aliasing of compatible tagged typesMartin Uecker4-1/+87
Tell the backend which types are equivalent by setting TYPE_CANONICAL to one struct in the set of equivalent structs. Structs are considered equivalent by ignoring all sizes of arrays nested in types below field level. The following two structs are incompatible and lvalues with these types can be assumed not to alias: struct foo { int a[3]; }; struct foo { int a[4]; }; The following two structs are also incompatible, but will get the same TYPE_CANONICAL and it is then not exploited that lvalues with those types can not alias: struct bar { int (*p)[3]; }; struct bar { int (*p)[4]; }; The reason is that both are compatible to struct bar { int (*p)[]; }; and therefore are in the same equivalence class. For the same reason all enums with the same underyling type are in the same equivalence class. Tests are added for the expected aliasing behavior with optimization. gcc/c: * c-decl.cc (c_struct_hasher): Hash stable for struct types. (c_struct_hasher::hash, c_struct_hasher::equal): New functions. (finish_struct): Set TYPE_CANONICAL to first struct in equivalence class. * c-objc-common.cc (c_get_alias_set): Let structs or unions with variable size alias anything. * c-tree.h (comptypes_equiv): New prototype. * c-typeck.cc (comptypes_equiv): New function. (comptypes_internal): Implement equivalence mode. (tagged_types_tu_compatible): Implement equivalence mode. gcc/testsuite: * gcc.dg/c23-tag-2.c: Activate. * gcc.dg/c23-tag-5.c: Activate. * gcc.dg/c23-tag-alias-1.c: New test. * gcc.dg/c23-tag-alias-2.c: New test. * gcc.dg/c23-tag-alias-3.c: New test. * gcc.dg/c23-tag-alias-4.c: New test. * gcc.dg/c23-tag-alias-5.c: New test. * gcc.dg/gnu23-tag-alias-1.c: New test. * gcc.dg/gnu23-tag-alias-2.c: New test. * gcc.dg/gnu23-tag-alias-3.c: New test. * gcc.dg/gnu23-tag-alias-4.c: New test. * gcc.dg/gnu23-tag-alias-5.c: New test. * gcc.dg/gnu23-tag-alias-6.c: New test. * gcc.dg/gnu23-tag-alias-7.c: New test.
2023-12-21c23: tag compatibility rules for enumsMartin Uecker4-12/+66
Allow redefinition of enum types and enumerators. Diagnose nested redefinitions including redefinitions in the enum specifier for enum types with fixed underlying type. gcc/c: * c-tree.h (c_parser_enum_specifier): Add parameter. * c-decl.cc (start_enum): Allow redefinition. (finish_enum): Diagnose conflicts. (build_enumerator): Set context. (diagnose_mismatched_decls): Diagnose conflicting enumerators. (push_decl): Preserve context for enumerators. * c-typeck.cc (tagged_types_tu_compatible_p): Adapt. * c-parser.cc (c_parser_enum_specifier): Remember when seen is from an enum type which is not yet defined. gcc/testsuite: * gcc.dg/c23-tag-enum-1.c: New test. * gcc.dg/c23-tag-enum-2.c: New test. * gcc.dg/c23-tag-enum-3.c: New test. * gcc.dg/c23-tag-enum-4.c: New test. * gcc.dg/c23-tag-enum-5.c: New test. * gcc.dg/gnu23-tag-enum-1.c: Mew test.
2023-12-21c23: tag compatibility rules for struct and unionsMartin Uecker3-12/+99
Implement redeclaration and compatibility rules for structures and unions in C23. gcc/c/: * c-decl.cc (previous_tag): New function. (parser_xref_tag): Find earlier definition. (get_parm_info): Turn off warning for C23. (start_struct): Allow redefinitons. (finish_struct): Diagnose conflicts. * c-tree.h (comptypes_same_p): Add prototype. * c-typeck.cc (comptypes_same_p): New function. (comptypes_internal): Activate comparison of tagged types. (convert_for_assignment): Ignore qualifiers. (digest_init): Add error. (initialized_elementwise_p): Allow compatible types. gcc/testsuite/: * gcc.dg/c23-enum-7.c: Remove warning. * gcc.dg/c23-tag-1.c: New test. * gcc.dg/c23-tag-2.c: New deactivated test. * gcc.dg/c23-tag-3.c: New test. * gcc.dg/c23-tag-4.c: New test. * gcc.dg/c23-tag-5.c: New deactivated test. * gcc.dg/c23-tag-6.c: New test. * gcc.dg/c23-tag-7.c: New test. * gcc.dg/c23-tag-8.c: New test. * gcc.dg/gnu23-tag-1.c: New test. * gcc.dg/gnu23-tag-2.c: New test. * gcc.dg/gnu23-tag-3.c: New test. * gcc.dg/gnu23-tag-4.c: New test. * gcc.dg/pr112488-2.c: Remove warning.
2023-12-21Daily bump.GCC Administrator1-0/+11
2023-12-20c: Split -Wcalloc-transposed-args warning from -Walloc-size, -Walloc-size fixesJakub Jelinek2-28/+31
The following patch changes -Walloc-size warning to no longer warn about int *p = calloc (1, sizeof (int));, because as discussed earlier, the size is IMNSHO sufficient in that case, for alloc_size with 2 arguments warns if the product of the 2 arguments is insufficiently small. Also, it warns also for explicit casts of malloc/calloc etc. calls rather than just implicit, so not just int *p = malloc (1); but also int *p = (int *) malloc (1); It also fixes some ICEs where the code didn't verify the alloc_size arguments properly (Walloc-size-5.c testcase ICEs with vanilla trunk). And lastly, it introduces a coding style warning, -Wcalloc-transposed-args to warn for calloc (sizeof (struct S), 1) and similar calls (regardless of what they are cast to, warning whenever first argument is sizeof and the second is not). 2023-12-20 Jakub Jelinek <jakub@redhat.com> gcc/ * doc/invoke.texi (-Walloc-size): Add to the list of warning options, remove unnecessary line-break. (-Wcalloc-transposed-args): Document new warning. gcc/c-family/ * c.opt (Wcalloc-transposed-args): New warning. * c-common.h (warn_for_calloc, warn_for_alloc_size): Declare. * c-warn.cc (warn_for_calloc, warn_for_alloc_size): New functions. gcc/c/ * c-parser.cc (c_parser_postfix_expression_after_primary): Grow sizeof_arg and sizeof_arg_loc arrays to 6 elements. Call warn_for_calloc if warn_calloc_transposed_args for functions with alloc_size type attribute with 2 arguments. (c_parser_expr_list): Use 6 instead of 3. * c-typeck.cc (build_c_cast): Call warn_for_alloc_size for casts of calls to functions with alloc_size type attribute. (convert_for_assignment): Likewise. gcc/testsuite/ * gcc.dg/Walloc-size-4.c: New test. * gcc.dg/Walloc-size-5.c: New test. * gcc.dg/Wcalloc-transposed-args-1.c: New test.
2023-12-20Daily bump.GCC Administrator1-0/+22
2023-12-19OpenMP: Use enumerators for names of trait-sets and traitsSandra Loosemore1-160/+82
This patch introduces enumerators to represent trait-set names and trait names, which makes it easier to use tables to control other behavior and for switch statements to dispatch on the tags. The tags are stored in the same place in the TREE_LIST structure (OMP_TSS_ID or OMP_TS_ID) and are encoded there as integer constants. gcc/ChangeLog * omp-selectors.h: New file. * omp-general.h: Include omp-selectors.h. (OMP_TSS_CODE, OMP_TSS_NAME): New. (OMP_TS_CODE, OMP_TS_NAME): New. (make_trait_set_selector, make_trait_selector): Adjust declarations. (omp_construct_traits_to_codes): Likewise. (omp_context_selector_set_compare): Likewise. (omp_get_context_selector): Likewise. (omp_get_context_selector_list): New. * omp-general.cc (omp_construct_traits_to_codes): Pass length in as argument instead of returning it. Make it table-driven. (omp_tss_map): New. (kind_properties, vendor_properties, extension_properties): New. (atomic_default_mem_order_properties): New. (omp_ts_map): New. (omp_check_context_selector): Simplify lookup and dispatch logic. (omp_mark_declare_variant): Ignore variants with unknown construct selectors. Adjust for new representation. (make_trait_set_selector, make_trait_selector): Adjust for new representations. (omp_context_selector_matches): Simplify dispatch logic. Avoid fixed-sized buffers and adjust call to omp_construct_traits_to_codes. (omp_context_selector_props_compare): Adjust for new representations and simplify dispatch logic. (omp_context_selector_set_compare): Likewise. (omp_context_selector_compare): Likewise. (omp_get_context_selector): Adjust for new representations, and split out... (omp_get_context_selector_list): New function. (omp_lookup_tss_code): New. (omp_lookup_ts_code): New. (omp_context_compute_score): Adjust for new representations. Avoid fixed-sized buffers and magic numbers. Adjust call to omp_construct_traits_to_codes. * gimplify.cc (omp_construct_selector_matches): Avoid use of fixed-size buffer. Adjust call to omp_construct_traits_to_codes. gcc/c/ChangeLog * c-parser.cc (omp_construct_selectors): Delete. (omp_device_selectors): Delete. (omp_implementation_selectors): Delete. (omp_user_selectors): Delete. (c_parser_omp_context_selector): Adjust for new representations and simplify dispatch logic. Uniformly warn instead of sometimes error when an unknown selector is found. Adjust error messages for extraneous/incorrect score. (c_parser_omp_context_selector_specification): Likewise. (c_finish_omp_declare_variant): Adjust for new representations. gcc/cp/ChangeLog * decl.cc (omp_declare_variant_finalize_one): Adjust for new representations. * parser.cc (omp_construct_selectors): Delete. (omp_device_selectors): Delete. (omp_implementation_selectors): Delete. (omp_user_selectors): Delete. (cp_parser_omp_context_selector): Adjust for new representations and simplify dispatch logic. Uniformly warn instead of sometimes error when an unknown selector is found. Adjust error messages for extraneous/incorrect score. (cp_parser_omp_context_selector_specification): Likewise. * pt.cc (tsubst_attribute): Adjust for new representations. gcc/fortran/ChangeLog * gfortran.h: Include omp-selectors.h. (enum gfc_omp_trait_property_kind): Delete, and replace all references with equivalent omp_tp_type enumerators. (struct gfc_omp_trait_property): Update for omp_tp_type. (struct gfc_omp_selector): Replace string name with new enumerator. (struct gfc_omp_set_selector): Likewise. * openmp.cc (gfc_free_omp_trait_property_list): Update for omp_tp_type. (omp_construct_selectors): Delete. (omp_device_selectors): Delete. (omp_implementation_selectors): Delete. (omp_user_selectors): Delete. (gfc_ignore_trait_property_extension): New. (gfc_ignore_trait_property_extension_list): New. (gfc_match_omp_selector): Adjust for new representations and simplify dispatch logic. Uniformly warn instead of sometimes error when an unknown selector is found. (gfc_match_omp_context_selector): Adjust for new representations. Adjust error messages for extraneous/incorrect score. (gfc_match_omp_context_selector_specification): Likewise. * trans-openmp.cc (gfc_trans_omp_declare_variant): Adjust for new representations. gcc/testsuite/ * c-c++-common/gomp/declare-variant-1.c: Expect warning on unknown selectors. * c-c++-common/gomp/declare-variant-2.c: Likewise. Also adjust messages for score errors. * c-c++-common/gomp/declare-variant-no-score.c: New. * gfortran.dg/gomp/declare-variant-1.f90: Expect warning on unknown selectors. * gfortran.dg/gomp/declare-variant-2.f90: Likewise. Also adjust messages for score errors. * gfortran.dg/gomp/declare-variant-no-score.f90: New.
2023-12-19OpenMP: Unify representation of name-list properties.Sandra Loosemore1-2/+3
Previously, name-list properties specified as identifiers were stored in the TREE_PURPOSE/OMP_TP_NAME slot, while those specified as strings were stored in the TREE_VALUE/OMP_TP_VALUE slot. This patch puts both representations in OMP_TP_VALUE with a magic cookie in OMP_TP_NAME. gcc/ChangeLog * omp-general.h (OMP_TP_NAMELIST_NODE): New. * omp-general.cc (omp_context_name_list_prop): Move earlier in the file, and adjust for new representation. (omp_check_context_selector): Adjust this too. (omp_context_selector_props_compare): Likewise. gcc/c/ChangeLog * c-parser.cc (c_parser_omp_context_selector): Adjust for new namelist property representation. gcc/cp/ChangeLog * parser.cc (cp_parser_omp_context_selector): Adjust for new namelist property representation. * pt.cc (tsubst_attribute): Likewise. gcc/fortran/ChangeLog * trans-openmp.cc (gfc_trans_omp_declare_varaint): Adjust for new namelist property representation.
2023-12-19OpenMP: Introduce accessor macros and constructors for context selectors.Sandra Loosemore1-10/+17
This patch hides the underlying nested TREE_LIST structure of context selectors behind accessor macros that have more meaningful names than the generic TREE_PURPOSE/TREE_VALUE accessors. There is a slight change to the representation in that the score expression in trait-selectors has a distinguished tag and is separated from the ordinary properties, although internally it is still represented as the first item in the TREE_VALUE of the selector. This patch also renames some local variables with slightly more descriptive names so it is easier to track whether something is a selector-set, selector, or property. gcc/ChangeLog * omp-general.h (OMP_TS_SCORE_NODE): New. (OMP_TSS_ID, OMP_TSS_TRAIT_SELECTORS): New. (OMP_TS_ID, OMP_TS_SCORE, OMP_TS_PROPERTIES): New. (OMP_TP_NAME, OMP_TP_VALUE): New. (make_trait_set_selector): Declare. (make_trait_selector): Declare. (make_trait_property): Declare. (omp_constructor_traits_to_codes): Rename to omp_construct_traits_to_codes. * omp-general.cc (omp_constructor_traits_to_codes): Rename to omp_construct_traits_to_codes. Use new accessors. (omp_check_context_selector): Use new accessors. (make_trait_set_selector): New. (make_trait_selector): New. (make_trait_property): New. (omp_context_name_list_prop): Use new accessors. (omp_context_selector_matches): Use new accessors. (omp_context_selector_props_compare): Use new accessors. (omp_context_selector_set_compare): Use new accessors. (omp_get_context_selector): Use new accessors. (omp_context_compute_score): Use new accessors. * gimplify.cc (omp_construct_selector_matches): Adjust for renaming of omp_constructor_traits_to_codes. gcc/c/ChangeLog * c-parser.cc (c_parser_omp_context_selector): Use new constructors. gcc/cp/ChangeLog * parser.cc (cp_parser_omp_context_selector): Use new constructors. * pt.cc: Include omp-general.h. (tsubst_attribute): Use new context selector accessors and constructors. gcc/fortran/ChangeLog * trans-openmp.cc (gfc_trans_omp_declare_variant): Use new constructors.
2023-12-19Daily bump.GCC Administrator1-0/+6
2023-12-18c/111975 - GIMPLE FE dumping and parsing of TARGET_MEM_REFRichard Biener1-9/+57
The following adds dumping of TARGET_MEM_REF in -gimple form and adds parsing of it to the GIMPLE FE. PR c/111975 gcc/c/ * gimple-parser.cc (c_parser_gimple_postfix_expression): Parse TARGET_MEM_REF extended operands for __MEM. gcc/ * tree-pretty-print.cc (dump_mem_ref): Use TDF_GIMPLE path also for TARGET_MEM_REF and amend it. gcc/testsuite/ * gcc.dg/gimplefe-52.c: New testcase.
2023-12-14Daily bump.GCC Administrator1-0/+26
2023-12-13c-family: rename warn_for_address_or_pointer_of_packed_memberJason Merrill1-2/+2
Following the last patch, let's rename the functions to reflect the change in behavior. gcc/c-family/ChangeLog: * c-warn.cc (check_address_or_pointer_of_packed_member): Rename to check_address_of_packed_member. (check_and_warn_address_or_pointer_of_packed_member): Rename to check_and_warn_address_of_packed_member. (warn_for_address_or_pointer_of_packed_member): Rename to warn_for_address_of_packed_member. * c-common.h: Adjust. gcc/c/ChangeLog: * c-typeck.cc (convert_for_assignment): Adjust call to warn_for_address_of_packed_member. gcc/cp/ChangeLog: * call.cc (convert_for_arg_passing) * typeck.cc (convert_for_assignment): Adjust call to warn_for_address_of_packed_member.
2023-12-13OpenMP/OpenACC: Rework clause expansion and nested struct handlingJulian Brown2-247/+197
This patch reworks clause expansion in the C, C++ and (to a lesser extent) Fortran front ends for OpenMP and OpenACC mapping nodes used in GPU offloading support. At present a single clause may be turned into several mapping nodes, or have its mapping type changed, in several places scattered through the front- and middle-end. The analysis relating to which particular transformations are needed for some given expression has become quite hard to follow. Briefly, we manipulate clause types in the following places: 1. During parsing, in c_omp_adjust_map_clauses. Depending on a set of rules, we may change a FIRSTPRIVATE_POINTER (etc.) mapping into ATTACH_DETACH, or mark the decl addressable. 2. In semantics.cc or c-typeck.cc, clauses are expanded in handle_omp_array_sections (called via {c_}finish_omp_clauses, or in finish_omp_clauses itself. The two cases are for processing array sections (the former), or non-array sections (the latter). 3. In gimplify.cc, we build sibling lists for struct accesses, which groups and sorts accesses along with their struct base, creating new ALLOC/RELEASE nodes for pointers. 4. In gimplify.cc:gimplify_adjust_omp_clauses, mapping nodes may be adjusted or created. This patch doesn't completely disrupt this scheme, though clause types are no longer adjusted in c_omp_adjust_map_clauses (step 1). Clause expansion in step 2 (for C and C++) now uses a single, unified mechanism, parts of which are also reused for analysis in step 3. Rather than the kind-of "ad-hoc" pattern matching on addresses used to expand clauses used at present, a new method for analysing addresses is introduced. This does a recursive-descent tree walk on expression nodes, and emits a vector of tokens describing each "part" of the address. This tokenized address can then be translated directly into mapping nodes, with the assurance that no part of the expression has been inadvertently skipped or misinterpreted. In this way, all the variations of ways pointers, arrays, references and component accesses might be combined can be teased apart into easily-understood cases - and we know we've "parsed" the whole address before we start analysis, so the right code paths can easily be selected. For example, a simple access "arr[idx]" might parse as: base-decl access-indexed-array or "mystruct->foo[x]" with a pointer "foo" component might parse as: base-decl access-pointer component-selector access-pointer A key observation is that support for "array" bases, e.g. accesses whose root nodes are not structures, but describe scalars or arrays, and also *one-level deep* structure accesses, have first-class support in gimplify and beyond. Expressions that use deeper struct accesses or e.g. multiple indirections were more problematic: some cases worked, but lots of cases didn't. This patch reimplements the support for those in gimplify.cc, again using the new "address tokenization" support. An expression like "mystruct->foo->bar[0:10]" used in a mapping node will translate the right-hand access directly in the front-end. The base for the access will be "mystruct->foo". This is handled recursively in gimplify.cc -- there may be several accesses of "mystruct"'s members on the same directive, so the sibling-list building machinery can be used again. (This was already being done for OpenACC, but the new implementation differs somewhat in details, and is more robust.) For OpenMP, in the case where the base pointer itself, i.e. "mystruct->foo" here, is NOT mapped on the same directive, we create a "fragile" mapping. This turns the "foo" component access into a zero-length allocation (which is a new feature for the runtime, so support has been added there too). A couple of changes have been made to how mapping clauses are turned into mapping nodes: The first change is based on the observation that it is probably never correct to use GOMP_MAP_ALWAYS_POINTER for component accesses (e.g. for references), because if the containing struct is already mapped on the target then the host version of the pointer in question will be corrupted if the struct is copied back from the target. This patch removes all such uses, across each of C, C++ and Fortran. The second change is to the way that GOMP_MAP_ATTACH_DETACH nodes are processed during sibling-list creation. For OpenMP, for pointer components, we must map the base pointer separately from an array section that uses the base pointer, so e.g. we must have both "map(mystruct.base)" and "map(mystruct.base[0:10])" mappings. These create nodes such as: GOMP_MAP_TOFROM mystruct.base G_M_TOFROM *mystruct.base [len: 10*elemsize] G_M_ATTACH_DETACH mystruct.base Instead of using the first of these directly when building the struct sibling list then skipping the group using GOMP_MAP_ATTACH_DETACH, leading to: GOMP_MAP_STRUCT mystruct [len: 1] GOMP_MAP_TOFROM mystruct.base we now introduce a new "mini-pass", omp_resolve_clause_dependencies, that drops the GOMP_MAP_TOFROM for the base pointer, marks the second group as having had a base-pointer mapping, then omp_build_struct_sibling_lists can create: GOMP_MAP_STRUCT mystruct [len: 1] GOMP_MAP_ALLOC mystruct.base [len: ptrsize] This ends up working better in many cases, particularly those involving references. (The "alloc" space is immediately overwritten by a pointer attachment, so this is mildly more efficient than a redundant TO mapping at runtime also.) There is support in the address tokenizer for "arbitrary" base expressions which aren't rooted at a decl, but that is not used as present because such addresses are disallowed at parse time. In the front-ends, the address tokenization machinery is mostly only used for clause expansion and not for diagnostics at present. It could be used for those too, which would allow more of my previous "address inspector" implementation to be removed. The new bits in gimplify.cc work with OpenACC also. This version of the patch addresses several first-pass review comments from Tobias, and fixes a few previously-missed cases for manually-managed ragged array mappings (including cases using references). Some arbitrary differences between handling of clause expansion for C vs. C++ have also been fixed, and some fragments from later in the patch series have been moved forward (where they were useful for fixing bugs). Several new test cases have been added. 2023-11-29 Julian Brown <julian@codesourcery.com> gcc/c-family/ * c-common.h (c_omp_region_type): Add C_ORT_EXIT_DATA, C_ORT_OMP_EXIT_DATA and C_ORT_ACC_TARGET. (omp_addr_token): Add forward declaration. (c_omp_address_inspector): New class. * c-omp.cc (c_omp_adjust_map_clauses): Mark decls addressable here, but do not change any mapping node types. (c_omp_address_inspector::unconverted_ref_origin, c_omp_address_inspector::component_access_p, c_omp_address_inspector::check_clause, c_omp_address_inspector::get_root_term, c_omp_address_inspector::map_supported_p, c_omp_address_inspector::get_origin, c_omp_address_inspector::maybe_unconvert_ref, c_omp_address_inspector::maybe_zero_length_array_section, c_omp_address_inspector::expand_array_base, c_omp_address_inspector::expand_component_selector, c_omp_address_inspector::expand_map_clause): New methods. (omp_expand_access_chain): New function. gcc/c/ * c-parser.cc (c_parser_oacc_all_clauses): Add TARGET_P parameter. Use to select region type for c_finish_omp_clauses call. (c_parser_oacc_loop): Update calls to c_parser_oacc_all_clauses. (c_parser_oacc_compute): Likewise. (c_parser_omp_target_data, c_parser_omp_target_enter_data): Support ATTACH kind. (c_parser_omp_target_exit_data): Support DETACH kind. (check_clauses): Handle GOMP_MAP_POINTER and GOMP_MAP_ATTACH here. * c-typeck.cc (handle_omp_array_sections_1, handle_omp_array_sections, c_finish_omp_clauses): Use c_omp_address_inspector class and OMP address tokenizer to analyze and expand map clause expressions. Fix some diagnostics. Fix "is OpenACC" condition for C_ORT_ACC_TARGET addition. gcc/cp/ * parser.cc (cp_parser_oacc_all_clauses): Add TARGET_P parameter. Use to select region type for finish_omp_clauses call. (cp_parser_omp_target_data, cp_parser_omp_target_enter_data): Support GOMP_MAP_ATTACH kind. (cp_parser_omp_target_exit_data): Support GOMP_MAP_DETACH kind. (cp_parser_oacc_declare): Update call to cp_parser_oacc_all_clauses. (cp_parser_oacc_loop): Update calls to cp_parser_oacc_all_clauses. (cp_parser_oacc_compute): Likewise. * pt.cc (tsubst_expr): Use C_ORT_ACC_TARGET for call to tsubst_omp_clauses for OpenACC compute regions. * semantics.cc (cp_omp_address_inspector): New class, derived from c_omp_address_inspector. (handle_omp_array_sections_1, handle_omp_array_sections, finish_omp_clauses): Use cp_omp_address_inspector class and OMP address tokenizer to analyze and expand OpenMP map clause expressions. Fix some diagnostics. Support C_ORT_ACC_TARGET. (finish_omp_target): Handle GOMP_MAP_POINTER. gcc/fortran/ * trans-openmp.cc (gfc_trans_omp_array_section): Add OPENMP parameter. Use GOMP_MAP_ATTACH_DETACH instead of GOMP_MAP_ALWAYS_POINTER for derived type components. (gfc_trans_omp_clauses): Update calls to gfc_trans_omp_array_section. gcc/ * gimplify.cc (build_struct_comp_nodes): Don't process GOMP_MAP_ATTACH_DETACH "middle" nodes here. (omp_mapping_group): Add REPROCESS_STRUCT and FRAGILE booleans for nested struct handling. (omp_strip_components_and_deref, omp_strip_indirections): Remove functions. (omp_get_attachment): Handle GOMP_MAP_DETACH here. (omp_group_last): Handle GOMP_MAP_*, GOMP_MAP_DETACH, GOMP_MAP_ATTACH_DETACH groups for "exit data" of reference-to-pointer component array sections. (omp_gather_mapping_groups_1): Initialise reprocess_struct and fragile fields. (omp_group_base): Handle GOMP_MAP_ATTACH_DETACH after GOMP_MAP_STRUCT. (omp_index_mapping_groups_1): Skip reprocess_struct groups. (omp_get_nonfirstprivate_group, omp_directive_maps_explicitly, omp_resolve_clause_dependencies, omp_first_chained_access_token): New functions. (omp_check_mapping_compatibility): Adjust accepted node combinations for "from" clauses using release instead of alloc. (omp_accumulate_sibling_list): Add GROUP_MAP, ADDR_TOKENS, FRAGILE_P, REPROCESSING_STRUCT, ADDED_TAIL parameters. Use OMP address tokenizer to analyze addresses. Reimplement nested struct handling, and implement "fragile groups". (omp_build_struct_sibling_lists): Adjust for changes to omp_accumulate_sibling_list. Recalculate bias for ATTACH_DETACH nodes after GOMP_MAP_STRUCT nodes. (gimplify_scan_omp_clauses): Call omp_resolve_clause_dependencies. Use OMP address tokenizer. (gimplify_adjust_omp_clauses_1): Use build_fold_indirect_ref_loc instead of build_simple_mem_ref_loc. * omp-general.cc (omp-general.h, tree-pretty-print.h): Include. (omp_addr_tokenizer): New namespace. (omp_addr_tokenizer::omp_addr_token): New. (omp_addr_tokenizer::omp_parse_component_selector, omp_addr_tokenizer::omp_parse_ref, omp_addr_tokenizer::omp_parse_pointer, omp_addr_tokenizer::omp_parse_access_method, omp_addr_tokenizer::omp_parse_access_methods, omp_addr_tokenizer::omp_parse_structure_base, omp_addr_tokenizer::omp_parse_structured_expr, omp_addr_tokenizer::omp_parse_array_expr, omp_addr_tokenizer::omp_access_chain_p, omp_addr_tokenizer::omp_accessed_addr): New functions. (omp_parse_expr, debug_omp_tokenized_addr): New functions. * omp-general.h (omp_addr_tokenizer::access_method_kinds, omp_addr_tokenizer::structure_base_kinds, omp_addr_tokenizer::token_type, omp_addr_tokenizer::omp_addr_token, omp_addr_tokenizer::omp_access_chain_p, omp_addr_tokenizer::omp_accessed_addr): New. (omp_addr_token, omp_parse_expr): New. * omp-low.cc (scan_sharing_clauses): Skip error check for references to pointers. * tree.h (OMP_CLAUSE_ATTACHMENT_MAPPING_ERASED): New macro. gcc/testsuite/ * c-c++-common/gomp/clauses-2.c: Fix error output. * c-c++-common/gomp/target-implicit-map-2.c: Adjust scan output. * c-c++-common/gomp/target-50.c: Adjust scan output. * c-c++-common/gomp/target-enter-data-1.c: Adjust scan output. * g++.dg/gomp/static-component-1.C: New test. * gcc.dg/gomp/target-3.c: Adjust scan output. * gfortran.dg/gomp/map-9.f90: Adjust scan output. libgomp/ * target.c (gomp_map_pointer): Modify zero-length array section pointer handling. (gomp_attach_pointer): Likewise. (gomp_map_fields_existing): Use gomp_map_0len_lookup. (gomp_attach_pointer): Allow attaching null pointers (or Fortran "unassociated" pointers). (gomp_map_vars_internal): Handle zero-sized struct members. Add diagnostic for unmapped struct pointer members. * testsuite/libgomp.c-c++-common/baseptrs-1.c: New test. * testsuite/libgomp.c-c++-common/baseptrs-2.c: New test. * testsuite/libgomp.c-c++-common/baseptrs-6.c: New test. * testsuite/libgomp.c-c++-common/baseptrs-7.c: New test. * testsuite/libgomp.c-c++-common/ptr-attach-2.c: New test. * testsuite/libgomp.c-c++-common/target-implicit-map-2.c: Fix missing "free". * testsuite/libgomp.c-c++-common/target-implicit-map-5.c: New test. * testsuite/libgomp.c-c++-common/target-map-zlas-1.c: New test. * testsuite/libgomp.c++/class-array-1.C: New test. * testsuite/libgomp.c++/baseptrs-3.C: New test. * testsuite/libgomp.c++/baseptrs-4.C: New test. * testsuite/libgomp.c++/baseptrs-5.C: New test. * testsuite/libgomp.c++/baseptrs-8.C: New test. * testsuite/libgomp.c++/baseptrs-9.C: New test. * testsuite/libgomp.c++/ref-mapping-1.C: New test. * testsuite/libgomp.c++/target-48.C: New test. * testsuite/libgomp.c++/target-49.C: New test. * testsuite/libgomp.c++/target-exit-data-reftoptr-1.C: New test. * testsuite/libgomp.c++/target-lambda-1.C: Update for OpenMP 5.2 semantics. * testsuite/libgomp.c++/target-this-3.C: Likewise. * testsuite/libgomp.c++/target-this-4.C: Likewise. * testsuite/libgomp.fortran/struct-elem-map-1.f90: Add temporary XFAIL. * testsuite/libgomp.fortran/target-enter-data-6.f90: Likewise.
2023-12-13OpenMP/OpenACC: Reindent TO/FROM/_CACHE_ stanza in {c_}finish_omp_clauseJulian Brown1-296/+301
This patch trivially adds braces and reindents the OMP_CLAUSE_TO/OMP_CLAUSE_FROM/OMP_CLAUSE__CACHE_ stanza in c_finish_omp_clause and finish_omp_clause, in preparation for the following patch (to clarify the diff a little). 2022-09-13 Julian Brown <julian@codesourcery.com> gcc/c/ * c-typeck.cc (c_finish_omp_clauses): Add braces and reindent OMP_CLAUSE_TO/OMP_CLAUSE_FROM/OMP_CLAUSE__CACHE_ stanza. gcc/cp/ * semantics.cc (finish_omp_clause): Add braces and reindent OMP_CLAUSE_TO/OMP_CLAUSE_FROM/OMP_CLAUSE__CACHE_ stanza.