aboutsummaryrefslogtreecommitdiff
path: root/gcc/c
AgeCommit message (Collapse)AuthorFilesLines
2025-04-03Daily bump.GCC Administrator1-0/+16
2025-04-02c: Fix ICEs with -fsanitize=pointer-{subtract,compare} [PR119582]Jakub Jelinek1-4/+4
The following testcase ICEs because c_fully_fold isn't performed on the arguments of __sanitizer_ptr_{sub,cmp} builtins and so e.g. C_MAYBE_CONST_EXPR can leak into the gimplifier where it ICEs. 2025-04-02 Jakub Jelinek <jakub@redhat.com> PR c/119582 * c-typeck.cc (pointer_diff, build_binary_op): Call c_fully_fold on __sanitizer_ptr_sub or __sanitizer_ptr_cmp arguments. * gcc.dg/asan/pr119582.c: New test.
2025-04-02OpenMP: Require target and/or targetsync init modifier [PR118965]Sandra Loosemore1-31/+13
As noted in PR 118965, the initial interop implementation overlooked the requirement in the OpenMP spec that at least one of the "target" and "targetsync" modifiers is required in both the interop construct init clause and the declare variant append_args clause. Adding the check was fairly straightforward, but it broke about a gazillion existing test cases. In particular, things like "init (x, y)" which were previously accepted (and tested for being accepted) aren't supposed to be allowed by the spec, much less things like "init (target)" where target was previously interpreted as a variable name instead of a modifier. Since one of the effects of the change is that at least one modifier is always required, I found that deleting all the code that was trying to detect and handle the no-modifier case allowed for better diagnostics. gcc/c/ChangeLog PR middle-end/118965 * c-parser.cc (c_parser_omp_clause_init_modifiers): Adjust error message. (c_parser_omp_clause_init): Remove code for recognizing clauses without modifiers. Diagnose missing target/targetsync modifier. (c_finish_omp_declare_variant): Diagnose missing target/targetsync modifier. gcc/cp/ChangeLog PR middle-end/118965 * parser.cc (c_parser_omp_clause_init_modifiers): Adjust error message. (cp_parser_omp_clause_init): Remove code for recognizing clauses without modifiers. Diagnose missing target/targetsync modifier. (cp_finish_omp_declare_variant): Diagnose missing target/targetsync modifier. gcc/fortran/ChangeLog PR middle-end/118965 * openmp.cc (gfc_parser_omp_clause_init_modifiers): Fix some inconsistent code indentation. Remove code for recognizing clauses without modifiers. Diagnose prefer_type without a following paren. Adjust error message for an unrecognized modifier. Diagnose missing target/targetsync modifier. (gfc_match_omp_init): Fix more inconsistent code indentation. gcc/testsuite/ChangeLog PR middle-end/118965 * c-c++-common/gomp/append-args-1.c: Add target/targetsync modifiers so tests do what they were previously supposed to do. Adjust expected output. * c-c++-common/gomp/append-args-7.c: Likewise. * c-c++-common/gomp/append-args-8.c: Likewise. * c-c++-common/gomp/append-args-9.c: Likewise. * c-c++-common/gomp/interop-1.c: Likewise. * c-c++-common/gomp/interop-2.c: Likewise. * c-c++-common/gomp/interop-3.c: Likewise. * c-c++-common/gomp/interop-4.c: Likewise. * c-c++-common/gomp/pr118965-1.c: New. * c-c++-common/gomp/pr118965-2.c: New. * g++.dg/gomp/append-args-1.C: Add target/targetsync modifiers and adjust expected output. * g++.dg/gomp/append-args-2.C: Likewise. * g++.dg/gomp/append-args-6.C: Likewise. * g++.dg/gomp/append-args-7.C: Likewise. * g++.dg/gomp/append-args-8.C: Likewise. * g++.dg/gomp/interop-5.C: Likewise. * gfortran.dg/gomp/append_args-1.f90: Add target/targetsync modifiers and adjust expected output. * gfortran.dg/gomp/append_args-2.f90: Likewise. * gfortran.dg/gomp/append_args-3.f90: Likewise. * gfortran.dg/gomp/append_args-4.f90: Likewise. * gfortran.dg/gomp/interop-1.f90: Likewise. * gfortran.dg/gomp/interop-2.f90: Likewise. * gfortran.dg/gomp/interop-3.f90: Likewise. * gfortran.dg/gomp/interop-4.f90: Likewise. * gfortran.dg/gomp/pr118965-1.f90: New. * gfortran.dg/gomp/pr118965-2.f90: New.
2025-03-29Daily bump.GCC Administrator1-0/+5
2025-03-28srcextra fixesJakub Jelinek1-2/+1
Here is a patch which uses sed to fix up the copies of the generated files by flex/bison in the source directories (i.e. what we ship in release tarballs). In that case the generated files are in the same directory as the files they are generated from, so there should be no absolute or relative directories, just the filenames. Furthermore, c.srcextra was duplicating the work of gcc.srcextra, there is nothing C FE specific on gengtype-lex.l. 2025-03-28 Jakub Jelinek <jakub@redhat.com> gcc/ * Makefile.in (gcc.srcextra): Use sed to turn .../gcc/gengtype-lex.l in #line directives into just gengtype-lex.l. gcc/c/ * Make-lang.in (c.srcextra): Don't depend on anything and don't copy anything. gcc/cobol/ * Make-lang.in (cobol.srcextra): Use sed to turn .../gcc/cobol/*.{y,l,h,cc} and cobol/*.{y,l,h,cc} in #line directives into just *.{y,l,h,cc}.
2025-03-28Daily bump.GCC Administrator1-0/+8
2025-03-27c: Fix tagname confusion for typedef redefinitions [PR118765]Martin Uecker2-0/+7
When we redefine a typedef for a tagged type that has just been redefined, merge_decls may produce invalid TYPE_DECLS that are not consistent with what set_underlying_type produces. This is fixed by updating DECL_ORIGINAL_TYPE. PR c/118765 gcc/c/ChangeLog: * c-decl.cc (merge_decls): For TYPE_DECLS copy DECL_ORIGINAL_TYPE from the old declaration. * c-typeck.cc (tagged_types_tu_compatible_p): Add checking assertions. gcc/testsuite/ChangeLog: * gcc.dg/pr118765-2.c: New test. * gcc.dg/pr118765-3.c: New test. * gcc.dg/typedef-redecl3.c: New test.
2025-03-22Daily bump.GCC Administrator1-0/+6
2025-03-21OpenMP: 'interop' construct - add ME support + target-independent libgompPaul-Antoine Arras1-1/+5
This patch partially enables use of the OpenMP interop construct by adding middle end support, mostly in the omplower pass, and in the target-independent part of the libgomp runtime. It follows up on previous patches for C, C++ and Fortran front ends support. The full interop feature requires another patch to enable foreign runtime support in libgomp plugins. gcc/ChangeLog: * builtin-types.def (BT_FN_VOID_INT_INT_PTR_PTR_PTR_INT_PTR_INT_PTR_UINT_PTR): New. * gimple-low.cc (lower_stmt): Handle GIMPLE_OMP_INTEROP. * gimple-pretty-print.cc (dump_gimple_omp_interop): New function. (pp_gimple_stmt_1): Handle GIMPLE_OMP_INTEROP. * gimple.cc (gimple_build_omp_interop): New function. (gimple_copy): Handle GIMPLE_OMP_INTEROP. * gimple.def (GIMPLE_OMP_INTEROP): Define. * gimple.h (gimple_build_omp_interop): Declare. (gimple_omp_interop_clauses): New function. (gimple_omp_interop_clauses_ptr): Likewise. (gimple_omp_interop_set_clauses): Likewise. (gimple_return_set_retval): Handle GIMPLE_OMP_INTEROP. * gimplify.cc (gimplify_scan_omp_clauses): Handle OMP_CLAUSE_INIT, OMP_CLAUSE_USE and OMP_CLAUSE_DESTROY. (gimplify_omp_interop): New function. (gimplify_expr): Replace sorry with call to gimplify_omp_interop. * omp-builtins.def (BUILT_IN_GOMP_INTEROP): Define. * omp-low.cc (scan_sharing_clauses): Handle OMP_CLAUSE_INIT, OMP_CLAUSE_USE and OMP_CLAUSE_DESTROY. (scan_omp_1_stmt): Handle GIMPLE_OMP_INTEROP. (lower_omp_interop_action_clauses): New function. (lower_omp_interop): Likewise. (lower_omp_1): Handle GIMPLE_OMP_INTEROP. gcc/c/ChangeLog: * c-parser.cc (c_parser_omp_clause_destroy): Make addressable. (c_parser_omp_clause_init): Make addressable. gcc/cp/ChangeLog: * parser.cc (cp_parser_omp_clause_init): Make addressable. gcc/fortran/ChangeLog: * trans-openmp.cc (gfc_trans_omp_clauses): Make OMP_CLAUSE_DESTROY and OMP_CLAUSE_INIT addressable. * types.def (BT_FN_VOID_INT_INT_PTR_PTR_PTR_INT_PTR_INT_PTR_UINT_PTR): New. include/ChangeLog: * gomp-constants.h (GOMP_DEVICE_DEFAULT_OMP_61, GOMP_INTEROP_TARGET, GOMP_INTEROP_TARGETSYNC, GOMP_INTEROP_FLAG_NOWAIT): Define. libgomp/ChangeLog: * icv-device.c (omp_set_default_device): Check GOMP_DEVICE_DEFAULT_OMP_61. * libgomp-plugin.h (struct interop_obj_t): New. (enum gomp_interop_flag): New. (GOMP_OFFLOAD_interop): Declare. (GOMP_OFFLOAD_get_interop_int): Declare. (GOMP_OFFLOAD_get_interop_ptr): Declare. (GOMP_OFFLOAD_get_interop_str): Declare. (GOMP_OFFLOAD_get_interop_type_desc): Declare. * libgomp.h (_LIBGOMP_OMP_LOCK_DEFINED): Define. (struct gomp_device_descr): Add interop_func, get_interop_int_func, get_interop_ptr_func, get_interop_str_func, get_interop_type_desc_func. * libgomp.map: Add GOMP_interop. * libgomp_g.h (GOMP_interop): Declare. * target.c (resolve_device): Handle GOMP_DEVICE_DEFAULT_OMP_61. (omp_get_interop_int): Replace stub with actual implementation. (omp_get_interop_ptr): Likewise. (omp_get_interop_str): Likewise. (omp_get_interop_type_desc): Likewise. (struct interop_data_t): Define. (gomp_interop_internal): New function. (GOMP_interop): Likewise. (gomp_load_plugin_for_device): Load symbols for get_interop_int, get_interop_ptr, get_interop_str and get_interop_type_desc. * testsuite/libgomp.c-c++-common/interop-1.c: New test. gcc/testsuite/ChangeLog: * c-c++-common/gomp/interop-1.c: Remove dg-prune-output "sorry". * c-c++-common/gomp/interop-2.c: Likewise. * c-c++-common/gomp/interop-3.c: Likewise. * c-c++-common/gomp/interop-4.c: Remove dg-message "not supported". * g++.dg/gomp/interop-5.C: Likewise. * gfortran.dg/gomp/interop-4.f90: Likewise. * c-c++-common/gomp/interop-5.c: New test. * gfortran.dg/gomp/interop-5.f90: New test. Co-authored-by: Tobias Burnus <tburnus@baylibre.com>
2025-03-20Daily bump.GCC Administrator1-0/+19
2025-03-19c: pedwarn on flexible array member initialization with {} for C23+ [PR119350]Jakub Jelinek1-6/+11
Even in C23/C2Y any initialization of flexible array member is still invalid, so we should emit a pedwarn on it. But we no longer do for initialization with {}. The reason is that for C17 and earlier, we already emitted a pedwarn on the {} initializer and so emitting another pedwarn on the flexible array member initialization would be diagnosing the same thing multiple times. In C23 we no longer pedwarn on {}, it is standard. The following patch arranges a pedwarning for that for C23+, so that at least one pedwarning is emitted. So that we don't "regress" from C17 to C23 on nested flexible array member initialization with no -pedantic/-pedantic-errors/-Wpedantic, the patch emits even the initialization of flexible array member in a nested context diagnostic as pedwarn in the {} case, after all, it doesn't cause much trouble, we just ignore it like before, it wouldn't initialize anything. 2025-03-19 Jakub Jelinek <jakub@redhat.com> PR c/119350 * c-typeck.cc (pop_init_level): Don't ignore empty brackets for flag_isoc23, still set constructor_type to NULL in that case but emit a pedwarn_init in that case. * gcc.dg/pr119350-1.c: New test. * gcc.dg/pr119350-2.c: New test. * gcc.dg/pr119350-3.c: New test.
2025-03-19c: Fix bug in typedef redefinitions of tagged types [PR118765]Martin Uecker1-2/+2
When we redefine a tagged type we incorrectly update TYPE_STUB_DECL of the previously defined type instead of the new one. Because TYPE_STUB_DECL is used when determining whether two such types are the same, this can cause valid typedef redefinitions to be rejected later. This is only a partial fix for PR118765. PR c/118765 gcc/c/ChangeLog: * c-decl.cc (finish_struct,finish_enum): Swap direction when copying TYPE_STRUB_DECL in redefinitions. gcc/testsuite/ChangeLog: * gcc.dg/pr118765.c: New test.
2025-03-19c: Fix ICE in error recovery when checking struct compatibility [PR118061]Martin Uecker1-0/+3
Return early when comparing two structures for compatibility and the type of a member is erroneous. PR c/118061 gcc/c/ChangeLog: * c-typeck.cc (tagged_types_tu_compatible_p): Handle errors in types of struct members. gcc/testsuite/ChangeLog: * gcc.dg/pr118061.c: New test.
2025-03-19Daily bump.GCC Administrator1-0/+16
2025-03-18c: Fix handling of [[gnu::musttail] return in if and else bodies [PR119311]Jakub Jelinek1-4/+4
The following new testcase FAILs with C (and succeeds with C++). c_parser_handle_musttail is used in c_parser_compound_statement_nostart where it is directly passed to c_parser_statement_after_labels, and in c_parser_all_labels where it is returned. Now, out of the 3 c_parser_all_labels callers, c_parser_statement passes it down to c_parser_statement_after_labels, but c_parser_if_body and c_parser_else_body don't, so if there are return statements with [[gnu::musttail]] or [[clang::musttail]] directly in if or else bodies rather than wrapped with {}s, we throw that information away. 2025-03-18 Jakub Jelinek <jakub@redhat.com> PR c/119311 * c-parser.cc (c_parser_if_body): Pass result of c_parser_all_labels as last argument to c_parser_statement_after_labels. (c_parser_else_body): Likewise. * c-c++-common/musttail14.c: Use * instead of \* in the regexps. * c-c++-common/musttail25.c: New test.
2025-03-18c, c++: Support musttail attribute even using __attribute__ form [PR116545]Jakub Jelinek1-2/+48
Apparently some programs in the wild use #if __has_attribute(musttail) __attribute__((musttail)) return foo (); #else return foo (); #endif clang supports musttail both as a standard attribute ([[clang::musttail]] which we also support for compatibility) and the above worked just fine with GCC 14 which had __has_attribute(musttail) 0. Now that it is 0, this doesn't compile anymore. So, either we need to ensure that __has_attribute(musttail) is 0 and just __has_c{,pp}_attribute({gnu,clang}::musttail) are non-zero, or IMHO better we just make it work in the attribute form, especially for C < C23 I can see why some projects would prefer that form. While [[gnu::musttail]] is rejected as an error in C11 etc. before GCC 15, rather than just handled as an unknown attribute. I view this as both a regression and compatibility issue. The patch handles it in similar spots to fallthrough/assume attributes inside of __attribute__ for C, and for C++ enables mixing of standard [[]] and GNU __attribute__(()) attributes at the start of statements in any order. While working on it, I've noticed we weren't diagnosing arguments to the clang::musttail attribute (fixed by the c-attribs.cc hunk) and newly on the __attribute__ form attribute (in that case the arguments aren't just skipped, they are always parsed and because we don't call decl_attributes etc., it wouldn't be diagnosed without a manual check). 2025-03-18 Jakub Jelinek <jakub@redhat.com> PR c/116545 gcc/ * doc/extend.texi (musttail statement attribute): Document that musttail GNU attribute can be used as well. gcc/c-family/ * c-attribs.cc (c_common_clang_attributes): Add musttail. gcc/c/ * c-parser.cc (c_parser_declaration_or_fndef): Parse __attribute__((musttail)) return. (c_parser_handle_musttail): Diagnose attribute arguments. (c_parser_statement_after_labels): Parse __attribute__((musttail)) return. gcc/cp/ * parser.cc (cp_parser_statement): Call cp_parser_attributes_opt rather than cp_parser_std_attribute_spec_seq. (cp_parser_jump_statement): Diagnose gnu::musttail attributes with no arguments. gcc/testsuite/ * c-c++-common/attr-fallthrough-2.c: Adjust expected diagnostics for C++. * c-c++-common/musttail15.c: New test. * c-c++-common/musttail16.c: New test. * c-c++-common/musttail17.c: New test. * c-c++-common/musttail18.c: New test. * c-c++-common/musttail19.c: New test. * c-c++-common/musttail20.c: New test. * c-c++-common/musttail21.c: New test. * c-c++-common/musttail22.c: New test. * c-c++-common/musttail23.c: New test. * c-c++-common/musttail24.c: New test. * g++.dg/musttail7.C: New test. * g++.dg/musttail8.C: New test. * g++.dg/musttail12.C: New test. * g++.dg/musttail13.C: New test. * g++.dg/musttail14.C: New test. * g++.dg/ext/pr116545.C: New test.
2025-03-12Daily bump.GCC Administrator1-0/+17
2025-03-11c: Don't emit -Wunterminated-string-initialization warning for ↵Jakub Jelinek1-1/+5
multi-dimensional nonstring array initializers [PR117178] My/Kees' earlier patches adjusted -Wunterminated-string-initialization warning so that it doesn't warn about initializers of nonstring decls and that nonstring attribute is allowed on multi-dimensional arrays. Unfortunately as this testcase shows, we still warn about initializers of multi-dimensional array nonstring decls. The problem is that in that case field passed to output_init_element is actually INTEGER_CST, index into the array. For RECORD_OR_UNION_TYPE_P (constructor_type) field is a FIELD_DECL which we want to use, but otherwise (in arrays) IMHO we want to use constructor_fields (which is the innermost FIELD_DECL whose part is being initialized), or - if that is NULL - constructor_decl, the whole decl being initialized with multi-dimensional array type. 2025-03-11 Jakub Jelinek <jakub@redhat.com> PR c/117178 * c-typeck.cc (output_init_element): Pass field to digest_init only for record/union types, otherwise pass constructor_fields if non-NULL and constructor_decl if constructor_fields is NULL. * gcc.dg/Wunterminated-string-initialization-2.c: New test.
2025-03-11OpenMP/C: Store location in cp_parser_omp_var_list for kind=0 [PR118579]Sandra Loosemore1-22/+14
This patch is the C equivalent of commit r15-6512-gcf94ba812ca496 for C++, to improve the location information for individual items in an OpenMP variable list. gcc/c/ChangeLog PR c/118579 * c-parser.cc (c_parser_omp_variable_list): Capture location information when KIND is OMP_CLAUSE_ERROR. (c_parser_oacc_data_clause_deviceptr): Use the improved location for diagnostics, and remove the FIXME. (c_finish_omp_declare_variant): Likewise. (c_parser_omp_threadprivate): Likewise. gcc/testsuite/ChangeLog PR c/118579 * c-c++-common/gomp/pr118579.c: New testcase.
2025-03-08Daily bump.GCC Administrator1-0/+21
2025-03-07c: do not warn about truncating NUL char when initializing nonstring arrays ↵Jakub Jelinek1-25/+37
[PR117178] When initializing a nonstring char array when compiled with -Wunterminated-string-initialization the warning trips even when truncating the trailing NUL character from the string constant. Only warn about this when running under -Wc++-compat since under C++ we should not initialize nonstrings from C strings. This patch separates the -Wunterminated-string-initialization and -Wc++-compat warnings, they are now independent option, the former implied by -Wextra, the latter not implied by anything. If -Wc++-compat is in effect, it takes precedence over -Wunterminated-string-initialization and warns regardless of nonstring attribute, otherwise if -Wunterminated-string-initialization is enabled, it warns only if there isn't nonstring attribute. In all cases, the warnings and also pedwarn_init for even larger sizes now provide details on the lengths. 2025-03-07 Kees Cook <kees@kernel.org> Jakub Jelinek <jakub@redhat.com> PR c/117178 gcc/ * doc/invoke.texi (Wunterminated-string-initialization): Document the new interaction between this warning and -Wc++-compat and that initialization of decls with nonstring attribute aren't warned about. gcc/c-family/ * c.opt (Wunterminated-string-initialization): Don't depend on -Wc++-compat. gcc/c/ * c-typeck.cc (digest_init): Add DECL argument. Adjust wording of pedwarn_init for too long strings and provide details on the lengths, for string literals where just the trailing NULL doesn't fit warn for warn_cxx_compat with OPT_Wc___compat, wording which mentions "for C++" and provides details on lengths, otherwise for warn_unterminated_string_initialization adjust the warning, provide details on lengths and don't warn if get_attr_nonstring_decl (decl). (build_c_cast, store_init_value, output_init_element): Adjust digest_init callers. gcc/testsuite/ * gcc.dg/Wunterminated-string-initialization.c: Add additional test coverage. * gcc.dg/Wcxx-compat-14.c: Check in dg-warning for "for C++" part of the diagnostics. * gcc.dg/Wcxx-compat-23.c: New test. * gcc.dg/Wcxx-compat-24.c: New test. Signed-off-by: Kees Cook <kees@kernel.org>
2025-03-07c: Fix warning after an error on a return statment [PR60440]Andrew Pinski1-1/+6
Like r5-6912-g3dbb84276aca10 but this is for the C front-end. Basically we have an error on a return statement, we just return error_mark_node and then the warning happens as there is no return statement. Anyways instead mark the current function for supression of the warning instead. PR c/60440 gcc/c/ChangeLog: * c-typeck.cc (c_finish_return): Mark the current function for supression of the -Wreturn-type if there was an error on the return statement. gcc/testsuite/ChangeLog: * gcc.dg/Wreturn-mismatch-2.c: Change dg-warning for the last -Wreturn-type to dg-bogus. * gcc.dg/pr60440-1.c: New test. Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2025-02-27Daily bump.GCC Administrator1-0/+9
2025-02-26c: Assorted fixes for flexible array members in unions [PR119001]Jakub Jelinek1-2/+40
r15-209 allowed flexible array members inside of unions, but as the following testcase shows, not everything has been adjusted for that. Unlike structures, in unions flexible array member (as an extension) can be any of the members, not just the last one, as in union all members are effectively last. The first hunk is about an ICE on the initialization of the FAM in union which is not the last FIELD_DECL with a string literal, the second hunk just formatting fix, third hunk fixes a bug in which we were just throwing away the initializers (except for with string literal) of FAMs in unions which aren't the last FIELD_DECL, and the last hunk is to diagnose FAM errors in unions the same as for structures, in particular trying to initialize a FAM with non-constant or initialization in nested context. 2025-02-26 Jakub Jelinek <jakub@redhat.com> PR c/119001 gcc/ * varasm.cc (output_constructor_regular_field): Don't fail assertion if next is non-NULL and FIELD_DECL if TREE_CODE (local->type) is UNION_TYPE. gcc/c/ * c-typeck.cc (pop_init_level): Don't clear constructor_type if DECL_CHAIN of constructor_fields is NULL but p->type is UNION_TYPE. Formatting fix. (process_init_element): Diagnose non-static initialization of flexible array member in union or FAM in union initialization in nested context. gcc/testsuite/ * gcc.dg/pr119001-1.c: New test. * gcc.dg/pr119001-2.c: New test.
2025-02-26Daily bump.GCC Administrator1-0/+7
2025-02-25openmp: Mark OpenMP atomic write expression as read [PR119000]Jakub Jelinek1-12/+10
The following testcase was emitting false positive warning that the rhs of #pragma omp atomic write was stored but not read, when the atomic actually does read it. The following patch fixes that by calling default_function_array_read_conversion on it, so that it is marked as read as well as converted from lvalue to rvalue. Furthermore, the code had if (code == NOP_EXPR) ... else ... if (code == NOP_EXPR) ... with none of ... parts changing code, so I've merged the two ifs. 2025-02-25 Jakub Jelinek <jakub@redhat.com> PR c/119000 * c-parser.cc (c_parser_omp_atomic): For omp write call default_function_array_read_conversion on the rhs expression. Merge the two adjacent if (code == NOP_EXPR) blocks. * c-c++-common/gomp/pr119000.c: New test.
2025-02-12Daily bump.GCC Administrator1-0/+6
2025-02-11OpenMP: Pass a 3-way flag to omp_check_context_selector instead of a bool.Sandra Loosemore1-2/+4
The OpenMP "begin declare variant" directive has slightly different requirements for context selectors than regular "declare variant", so something more than a bool is required to tell the error-checking routine what to check. gcc/ChangeLog * omp-general.cc (omp_check_context_selector): Change metadirective_p argument to a 3-way flag. Add extra check for OMP_CTX_BEGIN_DECLARE_VARIANT. * omp-general.h (enum omp_ctx_directive): New. (omp_check_context_selector): Adjust declaration. gcc/c/ChangeLog * c-parser.cc (c_finish_omp_declare_variant): Update call to omp_check_context_selector. (c_parser_omp_metadirective): Likewise. gcc/cp/ChangeLog * parser.cc (cp_finish_omp_declare_variant): Update call to omp_check_context_selector. (cp_parser_omp_metadirective): Likewise. gcc/fortran/ChangeLog * trans-openmp.cc (gfc_trans_omp_declare_variant): Update call to omp_check_context_selector. (gfc_trans_omp_metadirective): Likewise.
2025-02-08Daily bump.GCC Administrator1-0/+8
2025-02-07c++: Fix up handling of for/while loops with declarations in condition [PR86769]Jakub Jelinek1-2/+3
As the following testcase show (note, just for-{3,4,6,7,8}.C, constexpr-86769.C and stmtexpr27.C FAIL without the patch, the rest is just that I couldn't find coverage for some details and so added tests we don't regress or for5.C is from Marek's attempt in the PR), we weren't correctly handling for/while loops with declarations as conditions. The C++ FE has the simplify_loop_decl_cond function which transforms such loops as mentioned in the comment: while (A x = 42) { } for (; A x = 42;) { } becomes while (true) { A x = 42; if (!x) break; } for (;;) { A x = 42; if (!x) break; } For for loops this is not enough, as the x declaration should be still in scope when expr (if any) is executed, and injecting the expr expression into the body in the FE needs to have the continue label in between, something normally added by the c-family genericization. One of my thoughts was to just add there an artificial label plus the expr expression in the FE and tell c-family about that label, so that it doesn't create it but uses what has been emitted. Unfortunately break/continue are resolved to labels only at c-family genericization time and by moving the condition (and its preparation statements such as the DECL_EXPR) into the body (and perhaps by also moving there the (increment) expr as well) we resolve incorrectly any break/continue statement appearing in cond (or newly perhaps also expr) expression(s). While in standard C++ one can't have something like that there, with statement expressions they are possible there, and we actually have testsuite coverage that when they appear outside of the body of the loop they bind to an outer loop rather than the inner one. When the FE moves everything into the body, c-family can't distinguish any more between the user body vs. the condition/preparation statements vs. expr expression. So, the following patch instead keeps them separate and does the merging only at the c-family loop genericization time. For that the patch introduces two new operands of FOR_STMT and WHILE_STMT, *_COND_PREP which is forced to be a BIND_EXPR which contains the preparation statements like DECL_EXPR, and the initialization of that variable, so basically what {FOR,WHILE}_BODY has when we encounter the function dealing with this, except one optional CLEANUP_STMT at the end which holds cleanups for the variable if it needs to be destructed. This CLEANUP_STMT is removed and the actual cleanup saved into another new operand, *_COND_CLEANUP. The c-family loop genericization handles such loops roughly the way https://eel.is/c++draft/stmt.for and https://eel.is/c++draft/stmt.while specifies, so the body is (if *_COND_CLEANUP is non-NULL) { A x = 42; try { if (!x) break; body; cont_label: expr; } finally { cleanup; } } and otherwise { A x = 42; if (!x) break; body; cont_label: expr; } i.e. the *_COND, *_BODY, optional continue label, FOR_EXPR are appended into the body of the *_COND_PREP BIND_EXPR. And when doing constexpr evaluation of such FOR/WHILE loops, we treat it similarly, first evaluate *_COND_PREP except the for (tree decl = BIND_EXPR_VARS (t); decl; decl = DECL_CHAIN (decl)) destroy_value_checked (ctx, decl, non_constant_p); part of BIND_EXPR handling for it, then evaluate *_COND (and decide based on whether it was false or true like before), then *_BODY, then FOR_EXPR, then *_COND_CLEANUP (similarly to the way how CLEANUP_STMT handling handles that) and finally do those destroy_value_checked. Note, the constexpr-86769.C testcase FAILs with both clang++ and MSVC (note, the rest of tests PASS with clang++) but I believe it must be just a bug in those compilers, new int is done in all the constructors and delete is done in the destructor, so when clang++ reports one of the new int weren't deallocated during constexpr evaluation I don't see how that would be possible. When the same test has all the constexpr stuff, all the new int are properly deleted at runtime when compiled by both compilers and valgrind is happy about it, no leaks. 2025-02-07 Jakub Jelinek <jakub@redhat.com> Jason Merrill <jason@redhat.com> PR c++/86769 gcc/c-family/ * c-common.def (FOR_STMT): Add 2 operands and document them. (WHILE_STMT): Likewise. * c-common.h (WHILE_COND_PREP, WHILE_COND_CLEANUP): Define. (FOR_COND_PREP, FOR_COND_CLEANUP): Define. * c-gimplify.cc (genericize_c_loop): Add COND_PREP and COND_CLEANUP arguments, handle them if they are non-NULL. (genericize_for_stmt, genericize_while_stmt, genericize_do_stmt): Adjust callers. gcc/c/ * c-parser.cc (c_parser_while_statement): Add 2 further NULL_TREE operands to build_stmt. (c_parser_for_statement): Likewise. gcc/cp/ * semantics.cc (set_one_cleanup_loc): New function. (set_cleanup_locs): Use it. (simplify_loop_decl_cond): Remove. (adjust_loop_decl_cond): New function. (begin_while_stmt): Add 2 further NULL_TREE operands to build_stmt. (finish_while_stmt_cond): Call adjust_loop_decl_cond instead of simplify_loop_decl_cond. (finish_while_stmt): Call do_poplevel also on WHILE_COND_PREP if non-NULL and also use pop_stmt_list rather than do_poplevel for WHILE_BODY in that case. Call set_one_cleanup_loc. (begin_for_stmt): Add 2 further NULL_TREE operands to build_stmt. (finish_for_cond): Call adjust_loop_decl_cond instead of simplify_loop_decl_cond. (finish_for_stmt): Call do_poplevel also on FOR_COND_PREP if non-NULL and also use pop_stmt_list rather than do_poplevel for FOR_BODY in that case. Call set_one_cleanup_loc. * constexpr.cc (cxx_eval_loop_expr): Handle {WHILE,FOR}_COND_{PREP,CLEANUP}. (check_for_return_continue): Handle {WHILE,FOR}_COND_PREP. (potential_constant_expression_1): RECUR on {WHILE,FOR}_COND_{PREP,CLEANUP}. gcc/testsuite/ * g++.dg/diagnostic/redeclaration-7.C: New test. * g++.dg/expr/for3.C: New test. * g++.dg/expr/for4.C: New test. * g++.dg/expr/for5.C: New test. * g++.dg/expr/for6.C: New test. * g++.dg/expr/for7.C: New test. * g++.dg/expr/for8.C: New test. * g++.dg/ext/stmtexpr27.C: New test. * g++.dg/cpp2a/constexpr-86769.C: New test. * g++.dg/cpp26/name-independent-decl7.C: New test. * g++.dg/cpp26/name-independent-decl8.C: New test.
2025-02-05Daily bump.GCC Administrator1-0/+7
2025-02-04c/118742 - gimple FE parsing of unary operators of C promoted argsRichard Biener1-8/+41
The GIMPLE FE currently invokes parser_build_unary_op to build unary GENERIC which has the operand subject to C promotion rules which does not match GIMPLE. The following adds a wrapper around the build_unary_op worker which conveniently has an argument to indicate whether to skip such promotion. PR c/118742 gcc/c/ * gimple-parser.cc (gimple_parser_build_unary_op): New wrapper around build_unary_op. (c_parser_gimple_unary_expression): Use it. gcc/testsuite/ * gcc.dg/gimplefe-56.c: New testcase.
2025-01-31Daily bump.GCC Administrator1-0/+5
2025-01-30OpenMP: append_args clause fixes + Fortran supportTobias Burnus1-15/+27
This fixes a large number of smaller and larger issues with the append_args clause to 'declare variant' and adds Fortran support for it; it also contains a larger number of testcases. In particular, for Fortran, it also handles passing allocatable, pointer, optional arguments to an interop dummy argument with or without value attribute. And it changes the internal representation such that dumping the tree does not lead to an ICE. gcc/c/ChangeLog: * c-parser.cc (c_finish_omp_declare_variant): Modify how append_args is saved internally. gcc/cp/ChangeLog: * parser.cc (cp_finish_omp_declare_variant): Modify how append_args is saved internally. * pt.cc (tsubst_attribute): Likewise. (tsubst_omp_clauses): Remove C_ORT_OMP_DECLARE_SIMD from interop handling as no longer called for it. * decl.cc (omp_declare_variant_finalize_one): Update append_args changes; fixes for ADL input. gcc/fortran/ChangeLog: * gfortran.h (gfc_omp_declare_variant): Add append_args_list. * openmp.cc (gfc_parser_omp_clause_init_modifiers): New; splitt of from ... (gfc_match_omp_init): ... here; call it. (gfc_match_omp_declare_variant): Update to handle append_args clause; some syntax handling fixes. * trans-openmp.cc (gfc_trans_omp_declare_variant): Handle append_args clause; add some diagnostic. gcc/ChangeLog: * gimplify.cc (gimplify_call_expr): For OpenMP's append_args clause processed by 'omp dispatch', update for internal-representation changes; fix handling of hidden arguments, add some comments and handle Fortran's value dummy and optional/pointer/allocatable actual args. libgomp/ChangeLog: * libgomp.texi (Impl. Status): Update for accumpulated changes related to 'dispatch' and interop. gcc/testsuite/ChangeLog: * c-c++-common/gomp/append-args-1.c: Update dg-*. * c-c++-common/gomp/append-args-3.c: Likewise. * g++.dg/gomp/append-args-1.C: Likewise. * gfortran.dg/gomp/adjust-args-1.f90: Likewise. * gfortran.dg/gomp/adjust-args-3.f90: Likewise. * gfortran.dg/gomp/declare-variant-2.f90: Likewise. * c-c++-common/gomp/append-args-6.c: New test. * c-c++-common/gomp/append-args-7.c: New test. * c-c++-common/gomp/append-args-8.c: New test. * c-c++-common/gomp/append-args-9.c: New test. * g++.dg/gomp/append-args-4.C: New test. * g++.dg/gomp/append-args-5.C: New test. * g++.dg/gomp/append-args-6.C: New test. * g++.dg/gomp/append-args-7.C: New test. * gcc.dg/gomp/append-args-1.c: New test. * gfortran.dg/gomp/append_args-1.f90: New test. * gfortran.dg/gomp/append_args-2.f90: New test. * gfortran.dg/gomp/append_args-3.f90: New test. * gfortran.dg/gomp/append_args-4.f90: New test.
2025-01-29Daily bump.GCC Administrator1-0/+6
2025-01-28c: For array element type drop qualifiers but keep other properties of the ↵Jakub Jelinek1-1/+1
element type [PR116357] In the following testcase we error on the first case because it is trying to construct an array from overaligned type, but if there are qualifiers, we accept it silently (unlike in C++ which diagnoses all 3). The problem is that grokdeclarator if TYPE_QUALS (element_type) is non-zero just uses TYPE_MAIN_VARIANT; that loses not just the qualifiers but also attributes, alignment etc. The following patch uses c_build_qualified_type with TYPE_UNQUALIFIED instead, which will be in the common case the same as TYPE_MAIN_VARIANT if the checks are satisfied for it, but if not, will look up different unqualified type or even create it if there is none. 2025-01-28 Jakub Jelinek <jakub@redhat.com> PR c/116357 * c-decl.cc (grokdeclarator): Use c_build_qualified_type with TYPE_UNQUALIFIED instead of TYPE_MAIN_VARIANT. * gcc.dg/pr116357.c: New test.
2025-01-26Daily bump.GCC Administrator1-0/+6
2025-01-25c: Diagnose ,) at the end of OpenMP clauses [PR118639]Jakub Jelinek1-5/+1
This is something the C++ FE has been diagnosing but C FE only complained if there wasn't an identifier right after opening ( 2025-01-25 Jakub Jelinek <jakub@redhat.com> PR c/118639 * c-parser.cc (c_parser_omp_variable_list): Remove first variable and emit "expected identifier" error regardless of it. * c-c++-common/gomp/pr118639.c: New test. * c-c++-common/goacc/cache-2.c: Remove one xfail for c.
2025-01-24Daily bump.GCC Administrator1-0/+6
2025-01-23c++: Fix weird expression in test for clauses other than ↵Jakub Jelinek1-1/+1
when/default/otherwise [PR118604] Some clang analyzer warned about if (!strcmp (p, "when") == 0 && !default_p) which really looks weird, it is better to use strcmp (p, "when") != 0 or !!strcmp (p, "when"). Furthermore, as a micro optimization, it is cheaper to evaluate default_p than calling strcmp, so that can be put first in the &&. The C test for the same thing wasn't that weird, but I think for consistency it is better to use the same test rather than trying to be creative. 2025-01-23 Jakub Jelinek <jakub@redhat.com> PR c++/118604 gcc/c/ * c-parser.cc (c_parser_omp_metadirective): Rewrite condition for clauses other than when, default and otherwise. gcc/cp/ * parser.cc (cp_parser_omp_metadirective): Test !default_p first and use strcmp () != 0 rather than !strcmp () == 0.
2025-01-22Daily bump.GCC Administrator1-0/+5
2025-01-21c, c++: Return 1 for __has_builtin(__builtin_va_arg) and ↵Jakub Jelinek1-0/+2
__has_builtin(__builtin_c23_va_start) The Linux kernel uses its own copy of stdarg.h. Now, before GCC 15, our stdarg.h had #if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L #define va_start(v, ...) __builtin_va_start(v, 0) #else #define va_start(v,l) __builtin_va_start(v,l) #endif va_start definition but GCC 15 has: #if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L #define va_start(...) __builtin_c23_va_start(__VA_ARGS__) #else #define va_start(v,l) __builtin_va_start(v,l) #endif I wanted to suggest to the kernel people during their porting to C23 that they'd better use C23 compatible va_start macro definition, but to make it portable, I think they really want something like #if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L #define va_start(v, ...) __builtin_va_start(v, 0) #ifdef __has_builtin #if __has_builtin(__builtin_c23_va_start) #undef va_start #define va_start(...) __builtin_c23_va_start(__VA_ARGS__) #endif #else #define va_start(v,l) __builtin_va_start(v,l) #endif or so (or with >= 202311L), as GCC 13-14 and clang don't support __builtin_c23_va_start (yet?) and one gets better user experience with that. Except it seems __has_builtin(__builtin_c23_va_start) doesn't actually work, it works for most of the stdarg.h __builtin_va_*, doesn't work for __builtin_va_arg (neither C nor C++) and didn't work for __builtin_c23_va_start if it was available. The following patch wires __has_builtin for those. 2025-01-21 Jakub Jelinek <jakub@redhat.com> gcc/c/ * c-decl.cc (names_builtin_p): Return 1 for RID_C23_VA_START and RID_VA_ARG. gcc/cp/ * cp-objcp-common.cc (names_builtin_p): Return 1 for RID_VA_ARG. gcc/testsuite/ * c-c++-common/cpp/has-builtin-4.c: New test.
2025-01-17Daily bump.GCC Administrator1-0/+31
2025-01-16OpenMP: Improve error message for invalid directive in "assumes".Sandra Loosemore1-7/+12
gcc/c/ChangeLog * c-parser.cc (c_parser_omp_assumption_clauses): Give a more specific error message for invalid directives vs unknown names. gcc/cp/ChangeLog * parser.cc (cp_parser_omp_assumption_clauses): Give a more specific error message for invalid directives vs unknown names. gcc/fortran/ChangeLog * openmp.cc (gfc_omp_absent_contains_clause): Use an Oxford comma in the message. gcc/testsuite/ChangeLog * c-c++-common/gomp/assume-2.c: Adjust expected diagnostics. * c-c++-common/gomp/assumes-2.c: Likewise. * c-c++-common/gomp/begin-assumes-2.c: Likewise. * gfortran.dg/gomp/allocate-6.f90: Likewise. * gfortran.dg/gomp/assumes-2.f90: Likewise.
2025-01-16OpenMP: Update "declare target"/OpenMP context interactionSandra Loosemore1-6/+2
The code and test case previously implemented the OpenMP 5.0 spec, which said in section 2.3.1: "For functions within a declare target block, the target trait is added to the beginning of the set..." In OpenMP 5.1, this was changed to "For device routines, the target trait is added to the beginning of the set..." In OpenMP 5.2 and TR12, it says: "For procedures that are determined to be target function variants by a declare target directive..." The definition of "device routine" in OpenMP 5.1 is confusing, but certainly the intent of the later versions of the spec is clear that it doesn't just apply to functions within a begin declare target/end declare target block. The only use of the "omp declare target block" function attribute was to support the 5.0 language, so it can be removed. This patch changes the context augmentation to use the "omp declare target" attribute instead. gcc/c-family/ChangeLog * c-attribs.cc (c_common_gnu_attributes): Delete "omp declare target block". gcc/c/ChangeLog * c-decl.cc (c_decl_attributes): Don't add "omp declare target block". gcc/cp/ChangeLog * decl2.cc (cplus_decl_attributes): Don't add "omp declare target block". gcc/ChangeLog * omp-general.cc (omp_complete_construct_context): Check "omp declare target" attribute, not "omp declare target block". gcc/testsuite/ChangeLog * c-c++-common/gomp/declare-target-indirect-2.c : Adjust expected output for removal of "omp declare target block". * c-c++-common/gomp/declare-variant-8.c: Likewise, the variant call to f20 is now resolved differently. * c-c++-common/gomp/reverse-offload-1.c: Adjust expected output. * gfortran.dg/gomp/declare-variant-8.f90: Likewise, both f18 and f20 now resolve to the variant. Delete obsolete comments.
2025-01-16OpenMP: Add C support for metadirectives and dynamic selectors.Sandra Loosemore1-11/+478
Additional shared C/C++ testcases are included in a subsequent patch in this series. gcc/c-family/ChangeLog PR middle-end/112779 PR middle-end/113904 * c-common.h (enum c_omp_directive_kind): Add C_OMP_DIR_META. (c_omp_expand_variant_construct): Declare. * c-gimplify.cc: Include omp-general.h. (genericize_omp_metadirective_stmt): New. (c_genericize_control_stmt): Add case for OMP_METADIRECTIVE. * c-omp.cc (c_omp_directives): Fix entries for metadirective. (c_omp_expand_variant_construct_r): New. (c_omp_expand_variant_construct): New. * c-pragma.cc (omp_pragmas): Add metadirective. * c-pragma.h (enum pragma_kind): Add PRAGMA_OMP_METADIRECTIVE. gcc/c/ChangeLog PR middle-end/112779 PR middle-end/113904 * c-parser.cc (struct c_parser): Add omp_metadirective_state field. (c_parser_skip_to_end_of_block_or_statement): Add metadirective_p parameter and handle skipping over the parentheses in a "for" statement. (struct omp_metadirective_parse_data): New. (mangle_metadirective_region_label): New. (c_parser_label): Mangle label names in a metadirective body. (c_parser_statement_after_labels): Likewise. (c_parser_pragma): Handle PRAGMA_OMP_METADIRECTIVE. (c_parser_omp_context_selector): Allow arbitrary expressions in device_num and condition properties. (c_parser_omp_assumption_clauses): Handle C_OMP_DIR_META. (analyze_metadirective_body): New. (c_parser_omp_metadirective): New. gcc/testsuite/ PR middle-end/112779 * c-c++-common/gomp/declare-variant-2.c: Adjust expected output for C. * gcc.dg/gomp/metadirective-1.c: New. Co-Authored-By: Kwok Cheung Yeung <kcy@codesourcery.com> Co-Authored-By: Sandra Loosemore <sandra@codesourcery.com>
2025-01-15Daily bump.GCC Administrator1-0/+29
2025-01-14OpenMP: Re-work and extend context selector resolutionSandra Loosemore1-2/+2
This patch reimplements the middle-end support for "declare variant" and extends the resolution mechanism to also handle metadirectives (PR112779). It also adds partial support for dynamic selectors (PR113904) and fixes a selector scoring bug reported as PR114596. I hope this rewrite also improves the engineering aspect of the code, e.g. more comments to explain what it is doing. In most cases, variant constructs can be resolved either in the front end or during gimplification; if the variant with the highest score has a static selector, then only that one is emitted. In the case where it has a dynamic selector, it is resolved into a (possibly nested) if/then/else construct, testing the run-time predicate for each selector sorted by decreasing order of score until a static selector is found. In some cases, notably a variant construct in a "declare simd" function which may or may not expand into a simd clone, it may not be possible to score or sort the variants until later in compilation (the ompdevlow pass). In this case the gimplifier emits a loop containing a switch statement with the variants in arbitrary order and uses the OMP_NEXT_VARIANT tree node as a placeholder to control which variant is tested on each iteration of the loop. It looks something like: switch_var = OMP_NEXT_VARIANT (0, state); loop_label: switch (switch_var) { case 1: if (dynamic_selector_predicate_1) { alternative_1; goto end_label; } else { switch_var = OMP_NEXT_VARIANT (1, state); goto loop_label; } case 2: ... } end_label: Note that when there are no dynamic selectors, the loop is unnecessary and only the switch is emitted. Finally, in the ompdevlow pass, the OMP_NEXT_VARIANT magic cookies are resolved and replaced with constants. When compiling with -O we can expect that the loop and switch will be discarded by subsequent optimizations and replaced with direct jumps between the cases, eventually arriving at code with similar control flow to the early-resolution cases. This approach is somewhat simpler than the one currently used for handling declare variant in that all possible code paths are already included in the output of the gimplifier, so it is not necessary to maintain hidden references or data structures pointing to expansions of not-yet-resolved variant constructs and special logic for passing them through LTO (see PR lto/96680). A possible disadvantage of this expansion strategy is that dead code for unused variants in the switch can remain when compiling without -O. If this turns out to be a critical problem (e.g., an unused case includes calls to functions not available to the linker) perhaps some further processing could be performed by default after ompdevlow to simplify such constructs. In order to make this patch more readable for review purposes, it leaves the existing code for "declare variant" resolution (including the above-mentioned LTO hack) in place, in some cases just ifdef-ing out functions that won't compile due to changed interfaces for dependencies. The next patch in the series will delete all the now-unused code. gcc/ChangeLog PR middle-end/114596 PR middle-end/112779 PR middle-end/113904 * Makefile.in (GTFILES): Move omp-general.h earlier; required because of moving score_wide_int declaration to that file. * cgraph.h (struct cgraph_node): Add has_omp_variant_constructs flag. * cgraphclones.cc (cgraph_node::create_clone): Propagate has_omp_variant_constructs flag. * gimplify.cc (omp_resolved_variant_calls): New. (expand_late_variant_directive): New. (find_supercontext): New. (gimplify_variant_call_expr): New. (gimplify_call_expr): Adjust parameters to make fallback available. Update processing for "declare variant" substitution. (is_gimple_stmt): Add OMP_METADIRECTIVE. (omp_construct_selector_matches): Ifdef out unused function. (omp_get_construct_context): New. (gimplify_omp_dispatch): Replace call to deleted function omp_resolve_declare_variant with equivalent logic. (expand_omp_metadirective): New. (expand_late_variant_directive): New. (gimplify_omp_metadirective): New. (gimplify_expr): Adjust arguments to gimplify_call_expr. Add cases for OMP_METADIRECTIVE, OMP_NEXT_VARIANT, and OMP_TARGET_DEVICE_MATCHES. (gimplify_function_tree): Initialize/clean up omp_resolved_variant_calls. * gimplify.h (omp_construct_selector_matches): Delete declaration. (omp_get_construct_context): Declare. * lto-cgraph.cc (lto_output_node): Write has_omp_variant_constructs. (input_overwrite_node): Read has_omp_variant_constructs. * omp-builtins.def (BUILT_IN_OMP_GET_NUM_DEVICES): New. * omp-expand.cc (expand_omp_taskreg): Propagate has_omp_variant_constructs. (expand_omp_target): Likewise. * omp-general.cc (omp_maybe_offloaded): Add construct_context parameter; use it instead of querying gimplifier state. Add comments. (omp_context_name_list_prop): Do not test lang_GNU_Fortran in offload compiler, just use the string as-is. (expr_uses_parm_decl): New. (omp_check_context_selector): Add metadirective_p parameter. Remove sorry for target_device selector. Add additional checks specific to metadirective or declare variant. (make_omp_metadirective_variant): New. (omp_construct_traits_match): New. (omp_context_selector_matches): Temporarily ifdef out the previous code, and add a new implementation based on the old one with different parameters, some unnecessary loops removed, and code re-indented. (omp_target_device_matches_on_host): New. (resolve_omp_target_device_matches): New. (omp_construct_simd_compare): Support matching of "simdlen" and "aligned" clauses. (omp_context_selector_set_compare): Make static. Adjust call to omp_construct_simd_compare. (score_wide_int): Move declaration to omp-general.h. (omp_selector_is_dynamic): New. (omp_device_num_check): New. (omp_dynamic_cond): New. (omp_context_compute_score): Ifdef out the old version and re-implement with different parameters. (omp_complete_construct_context): New. (omp_resolve_late_declare_variant): Ifdef out. (omp_declare_variant_remove_hook): Likewise. (omp_resolve_declare_variant): Likewise. (sort_variant): New. (omp_get_dynamic_candidates): New. (omp_declare_variant_candidates): New. (omp_metadirective_candidates): New. (omp_early_resolve_metadirective): New. (omp_resolve_variant_construct): New. * omp-general.h (score_wide_int): Moved here from omp-general.cc. (struct omp_variant): New. (make_omp_metadirective_variant): Declare. (omp_construct_traits_to_codes): Delete declaration. (omp_check_context_selector): Adjust parameters. (omp_context_selector_matches): Likewise. (omp_context_selector_set_compare): Delete declaration. (omp_resolve_declare_variant): Likewise. (omp_declare_variant_candidates): Declare. (omp_metadirective_candidates): Declare. (omp_get_dynamic_candidates): Declare. (omp_early_resolve_metadirective): Declare. (omp_resolve_variant_construct): Declare. (omp_dynamic_cond): Declare. * omp-offload.cc (resolve_omp_variant_cookies): New. (execute_omp_device_lower): Call the above function to resolve variant directives. Remove call to omp_resolve_declare_variant. (pass_omp_device_lower::gate): Check has_omp_variant_construct bit. * omp-simd-clone.cc (simd_clone_create): Propagate has_omp_variant_constructs bit. * tree-inline.cc (expand_call_inline): Likewise. (tree_function_versioning): Likewise. gcc/c/ChangeLog PR middle-end/114596 PR middle-end/112779 PR middle-end/113904 * c-parser.cc (c_finish_omp_declare_variant): Update for changes to omp-general.h interfaces. gcc/cp/ChangeLog PR middle-end/114596 PR middle-end/112779 PR middle-end/113904 * decl.cc (omp_declare_variant_finalize_one): Update for changes to omp-general.h interfaces. * parser.cc (cp_finish_omp_declare_variant): Likewise. gcc/fortran/ChangeLog PR middle-end/114596 PR middle-end/112779 PR middle-end/113904 * trans-openmp.cc (gfc_trans_omp_declare_variant): Update for changes to omp-general.h interfaces. gcc/testsuite/ PR middle-end/114596 PR middle-end/112779 PR middle-end/113904 * c-c++-common/gomp/declare-variant-12.c: Adjust expected behavior per PR114596. * c-c++-common/gomp/declare-variant-13.c: Test that this is resolvable after gimplification, not just final resolution. * c-c++-common/gomp/declare-variant-14.c: Tweak testcase to ensure that -O causes dead code to be optimized away. * gfortran.dg/gomp/declare-variant-12.f90: Adjust expected behavior per PR114596. * gfortran.dg/gomp/declare-variant-13.f90: Test that this is resolvable after gimplification, not just final resolution. * gfortran.dg/gomp/declare-variant-14.f90: Tweak testcase to ensure that -O causes dead code to be optimized away. Co-Authored-By: Kwok Cheung Yeung <kcy@codesourcery.com> Co-Authored-By: Sandra Loosemore <sandra@codesourcery.com> Co-Authored-By: Marcel Vollweiler <marcel@codesourcery.com>
2025-01-13c: improve UX for -Wincompatible-pointer-types (v3) [PR116871]David Malcolm1-36/+139
PR c/116871 notes that our diagnostics about incompatible function types could be improved. In particular, for the case of migrating to C23 I'm seeing a lot of build failures with signal handlers similar to this (simplified from alsa-tools-1.2.11, envy24control/profiles.c; see rhbz#2336278): typedef void (*__sighandler_t) (int); extern __sighandler_t signal (int __sig, __sighandler_t __handler) __attribute__ ((__nothrow__ , __leaf__)); void new_process(void) { void (*int_stat)(); int_stat = signal(2, ((__sighandler_t) 1)); signal(2, int_stat); } Before this patch, cc1 fails with this message: t.c: In function 'new_process': t.c:18:12: error: assignment to 'void (*)(void)' from incompatible pointer type '__sighandler_t' {aka 'void (*)(int)'} [-Wincompatible-pointer-types] 18 | int_stat = signal(2, ((__sighandler_t) 1)); | ^ t.c:20:13: error: passing argument 2 of 'signal' from incompatible pointer type [-Wincompatible-pointer-types] 20 | signal(2, int_stat); | ^~~~~~~~ | | | void (*)(void) t.c:11:57: note: expected '__sighandler_t' {aka 'void (*)(int)'} but argument is of type 'void (*)(void)' 11 | extern __sighandler_t signal (int __sig, __sighandler_t __handler) | ~~~~~~~~~~~~~~~^~~~~~~~~ With this patch, cc1 emits: t.c: In function 'new_process': t.c:18:12: error: assignment to 'void (*)(void)' from incompatible pointer type '__sighandler_t' {aka 'void (*)(int)'} [-Wincompatible-pointer-types] 18 | int_stat = signal(2, ((__sighandler_t) 1)); | ^ t.c:9:16: note: '__sighandler_t' declared here 9 | typedef void (*__sighandler_t) (int); | ^~~~~~~~~~~~~~ t.c:20:13: error: passing argument 2 of 'signal' from incompatible pointer type [-Wincompatible-pointer-types] 20 | signal(2, int_stat); | ^~~~~~~~ | | | void (*)(void) t.c:11:57: note: expected '__sighandler_t' {aka 'void (*)(int)'} but argument is of type 'void (*)(void)' 11 | extern __sighandler_t signal (int __sig, __sighandler_t __handler) | ~~~~~~~~~~~~~~~^~~~~~~~~ t.c:9:16: note: '__sighandler_t' declared here 9 | typedef void (*__sighandler_t) (int); | ^~~~~~~~~~~~~~ showing the location of the pertinent typedef ("__sighandler_t") Another example, simplfied from a52dec-0.7.4: src/a52dec.c (rhbz#2336013): typedef void (*__sighandler_t) (int); extern __sighandler_t signal (int __sig, __sighandler_t __handler) __attribute__ ((__nothrow__ , __leaf__)); /* Mismatching return type. */ static RETSIGTYPE signal_handler (int sig) { } static void print_fps (int final) { signal (42, signal_handler); } Before this patch, cc1 emits: t2.c: In function 'print_fps': t2.c:22:15: error: passing argument 2 of 'signal' from incompatible pointer type [-Wincompatible-pointer-types] 22 | signal (42, signal_handler); | ^~~~~~~~~~~~~~ | | | int (*)(int) t2.c:11:57: note: expected '__sighandler_t' {aka 'void (*)(int)'} but argument is of type 'int (*)(int)' 11 | extern __sighandler_t signal (int __sig, __sighandler_t __handler) | ~~~~~~~~~~~~~~~^~~~~~~~~ With this patch cc1 emits: t2.c: In function 'print_fps': t2.c:22:15: error: passing argument 2 of 'signal' from incompatible pointer type [-Wincompatible-pointer-types] 22 | signal (42, signal_handler); | ^~~~~~~~~~~~~~ | | | int (*)(int) t2.c:11:57: note: expected '__sighandler_t' {aka 'void (*)(int)'} but argument is of type 'int (*)(int)' 11 | extern __sighandler_t signal (int __sig, __sighandler_t __handler) | ~~~~~~~~~~~~~~~^~~~~~~~~ t2.c:16:19: note: 'signal_handler' declared here 16 | static RETSIGTYPE signal_handler (int sig) | ^~~~~~~~~~~~~~ t2.c:9:16: note: '__sighandler_t' declared here 9 | typedef void (*__sighandler_t) (int); | ^~~~~~~~~~~~~~ showing the location of the pertinent fndecl ("signal_handler"), and, as before, the pertinent typedef. The patch also updates the colorization in the messages to visually link and contrast the different types and typedefs. My hope is that this make it easier for users to decipher build failures seen with the new C23 default. Further improvements could be made to colorization in convert_for_assignment, and similar improvements to C++, but I'm punting those to GCC 16. gcc/c/ChangeLog: PR c/116871 * c-typeck.cc (pedwarn_permerror_init): Return bool for whether a warning was emitted. Only call print_spelling if we warned. (pedwarn_init): Return bool for whether a warning was emitted. (permerror_init): Likewise. (warning_init): Return bool for whether a warning was emitted. Only call print_spelling if we warned. (class pp_element_quoted_decl): New. (maybe_inform_typedef_location): New. (convert_for_assignment): For OPT_Wincompatible_pointer_types, move auto_diagnostic_group to cover all cases. Use %e and pp_element rather than %qT and tree to colorize the types. Capture whether a warning was emitted, and, if it was, show various notes: for a pointer to a function, show the function decl, for typedef types, and show the decls. gcc/testsuite/ChangeLog: PR c/116871 * gcc.dg/c23-mismatching-fn-ptr-a52dec.c: New test. * gcc.dg/c23-mismatching-fn-ptr-alsatools.c: New test. * gcc.dg/c23-mismatching-fn-ptr.c: New test. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-01-13Daily bump.GCC Administrator1-0/+16