aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common
AgeCommit message (Collapse)AuthorFilesLines
2025-12-05OpenMP: C/C++ parser support for dyn_groupprivateTobias Burnus2-0/+100
Follow-up to the Fortran patch r16-5633-g26d41e245dbba3, which (besides other changes) added parser support for the 'dyn_groupprivate' clause to the target directive. This commit adds now the parser support to C/C++ and moves the not-yet-implemented 'sorry' to the early middle end. gcc/c-family/ChangeLog: * c-omp.cc (c_omp_split_clauses): Handle OMP_CLAUSE_DYN_GROUPPRIVATE, sort target clauses alphabetically. * c-pragma.h (enum pragma_omp_clause): Add PRAGMA_OMP_CLAUSE_DYN_GROUPPRIVATE. gcc/c/ChangeLog: * c-parser.cc (c_parser_omp_clause_dyn_groupprivate): New. (OMP_TARGET_CLAUSE_MASK): Add PRAGMA_OMP_CLAUSE_DYN_GROUPPRIVATE; sort clauses alphabetically. (c_parser_omp_clause_name, c_parser_omp_all_clauses): Handle 'dyn_groupprivate' clause. * c-typeck.cc (c_finish_omp_clauses): Likewise. gcc/cp/ChangeLog: * pt.cc (tsubst_omp_clauses): Handle OMP_CLAUSE_DYN_GROUPPRIVATE. * semantics.cc (finish_omp_clauses): Likewise. * parser.cc (cp_parser_omp_clause_dyn_groupprivate): New. (cp_parser_omp_clause_name, cp_parser_omp_all_clauses): Handle 'dyn_groupprivate' clause. (OMP_TARGET_CLAUSE_MASK): Add PRAGMA_OMP_CLAUSE_DYN_GROUPPRIVATE; sort clauses alphabetically. gcc/fortran/ChangeLog: * openmp.cc (resolve_omp_clauses): Permit zero with DYN_GROUPPRIVATE clause. * trans-openmp.cc (fallback): Generate TREE code for DYN_GROUPPRIVATE and remove 'sorry'. gcc/ChangeLog: * gimplify.cc (gimplify_scan_omp_clauses): Handle OMP_CLAUSE_DYN_GROUPPRIVATE by printing 'sorry, unimplemented'. * tree-core.h (enum omp_clause_code): Add OMP_CLAUSE_DYN_GROUPPRIVATE. (enum omp_clause_fallback_kind): New. (struct tree_omp_clause): Add fallback_kind union member. * tree-nested.cc (convert_nonlocal_omp_clauses, convert_local_omp_clauses): Handle OMP_CLAUSE_DYN_GROUPPRIVATE. * tree.cc (omp_clause_num_ops, omp_clause_code_name): Add OMP_CLAUSE_DYN_GROUPPRIVATE. * tree-pretty-print.cc (dump_omp_clause): Handle OMP_CLAUSE_DYN_GROUPPRIVATE. * tree.h (OMP_CLAUSE_DYN_GROUPPRIVATE_EXPR, OMP_CLAUSE_DYN_GROUPPRIVATE_KIND): New #define. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/dyn_groupprivate-1.f90: Add scan-dump test. * gfortran.dg/gomp/dyn_groupprivate-2.f90: Extend and update. * c-c++-common/gomp/dyn_groupprivate-1.c: New test. * c-c++-common/gomp/dyn_groupprivate-2.c: New test.
2025-11-27reassociation: Fix canonical ordering in some casesAndrew Pinski1-2/+2
This was noticed in PR122843 were sometimes reassociation would create the uncanonical order of operands. This fixes the problem by swapping the order as the rewrite happens. Wstringop-overflow.c needed to be xfailed since it started not to warn because well the warning is too dependent on the order of operands to MIN_EXPR. This testcase failed if we had supplied -fno-tree-reassoc before too; but nothing in the IR changes except the order of 2 operands of MIN_EXPR. I filed PR 122881 for this xfail. Bootstrapped and tested on x86_64-linux-gnu. gcc/ChangeLog: * tree-ssa-reassoc.cc (rewrite_expr_tree): Swap oe1 and oe2 if commutative code and not in canonical order. gcc/testsuite/ChangeLog: * c-c++-common/Wstringop-overflow.c: Xfail, PR 122881. Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-11-25gimplify, ubsan: Fix -fopenmp -fsanitize=bounds ICE [PR120052]Jakub Jelinek1-0/+32
The following testcase ICEs, because 1) -fsanitize=bounds uses TYPE_MAX_VALUE (TYPE_DOMAIN (type)) with 1 or 2 added as last argument of .UBSAN_BOUNDS call and that expression at that point is some NOP_EXPR around SAVE_EXPR with testing for negative sizes 2) during gimplification, gimplify_type_sizes is invoked on the DECL_EXPR outside of an OpenMP region, and forces TYPE_MAX_VALUE into a pseudo instead, with the SAVE_EXPR obviously being evaluated before that 3) the OpenMP gimplification sees an implicit or explicit data sharing of a VLA and among other things arranges to firstprivatize TYPE_MAX_VALUE 4) when gimplifying the .UBSAN_BOUNDS call inside of the OpenMP region, it sees a SAVE_EXPR and just gimplifies it to the already initialized s.1 temporary; but nothing marks s.1 for firstprivatization on the containing construct(s). The problem is that with SAVE_EXPR we never know if the first use is within the same statement (typical use) or somewhere earlier in the same OpenMP construct or in an outer OpenMP construct or its parent etc., the SAVE_EXPR temporary is a function local var, not something that is added to the innermost scope where it is used (and it can't because it perhaps could be used outside of it); so for OpenMP purposes, SAVE_EXPRs better should be used only within the same OpenMP region and not across the whole function The following patch fixes it by deferring the addition of TYPE_MAX_VALUE in the last argument of .UBSAN_BOUNDS until gimplification for VLAs, if it sees a VLA, instead of making the first argument 0 with pointer to the corresponding array type, it sets the first argument to 1 with the same type and only sets the last argument to the addend (1 or 2). And then gimplification can detect this case and add the TYPE_MAX_VALUE (which in the meantime should have gone through gimplify_type_sizes). 2025-11-25 Jakub Jelinek <jakub@redhat.com> PR middle-end/120052 gcc/ * gimplify.cc (gimplify_call_expr): For IFN_UBSAN_BOUNDS call with integer_onep first argument, change that argument to 0 and add TYPE_MAX_VALUE (TYPE_DOMAIN (arr_type)) to 3rd argument before gimplification. gcc/c-family/ * c-ubsan.cc (ubsan_instrument_bounds): For VLAs use 1 instead of 0 as first IFN_UBSAN_BOUNDS argument and only use the addend without TYPE_MAX_VALUE (TYPE_DOMAIN (type)) in the 3rd argument. gcc/testsuite/ * c-c++-common/gomp/pr120052.c: New test.
2025-11-25openmp: Fix up OpenMP expansion of collapsed loops [PR120564]Jakub Jelinek1-0/+15
Most of gimple_build_cond_empty callers call just build2 to prepare condition which is put into GIMPLE_COND, but this one spot has been using incorrectly fold_build2. Now the arguments of the *build2 were already gimplified, but the folding of some conditions can turn say unsigned_var > INT_MAX into (int) unsigned_var < 0 etc. and thus turn the condition into something invalid in gimple, because we only try to regimplify the operands if they refer to some decl which needs to be regimplified (has DECL_VALUE_EXPR on it). Fixed by also using build2 instead of fold_build2. 2025-11-25 Jakub Jelinek <jakub@redhat.com> PR middle-end/120564 * omp-expand.cc (extract_omp_for_update_vars): Use build2 instead of fold_build2 to build argument for gimple_build_cond_empty. * c-c++-common/gomp/pr120564.c: New test.
2025-11-23OpenMP: Fix "begin declare variant" test failure with -m32Sandra Loosemore1-2/+2
As reported by Haochen Jiang, this recently-added test case was failing on x86_64 with -m32; the target hook for matching the "arch" selector won't match "x86_64" in that case, even if gcc was configured for that target. It does match plain "x86" for both 64 and 32 bit targets, so I've switched the testcase to use that instead. Committed as obvious (at least in retrospect). gcc/testsuite/ChangeLog * c-c++-common/gomp/delim-declare-variant-6.c (f3): Use "x86" instead of "x86_64" in the arch selector, to match both 64- and 32-bit targets.
2025-11-22OpenMP: C/C++ common testcases for "omp begin declare variant"Sandra Loosemore9-0/+425
gcc/testsuite/ChangeLog * c-c++-common/gomp/delim-declare-variant-1.c: New. * c-c++-common/gomp/delim-declare-variant-2.c: New. * c-c++-common/gomp/delim-declare-variant-3.c: New. * c-c++-common/gomp/delim-declare-variant-4.c: New. * c-c++-common/gomp/delim-declare-variant-5.c: New. * c-c++-common/gomp/delim-declare-variant-6.c: New. * c-c++-common/gomp/delim-declare-variant-7.c: New. * c-c++-common/gomp/delim-declare-variant-8.c: New. * c-c++-common/gomp/delim-declare-variant-9.c: New. libgomp/ChangeLog * testsuite/libgomp.c-c++-common/delim-declare-variant-1.c: New. * testsuite/libgomp.c-c++-common/delim-declare-variant-2.c: New. Co-Authored-By: Tobias Burnus <tburnus@baylibre.com>
2025-11-19Fix typo in sol2.hRainer Orth1-1/+1
I noticed that gcc/config/sol2.h uses USE_GNU_LD as a guard in one place only. This is a cross of USE_GLD and HAVE_GNU_LD which doesn't exist so the gld variant is never used. This went unnoticed since the wrong versions of LD_WHOLE_ARCHIVE_OPTION and LD_NO_WHOLE_ARCHIVE_OPTION are only ever used in LIBASAN_EARLY_SPEC and only effective when -static-libasan is used. gld would only warn about the unsupported -z options here. The issue wasn't noticed before since the only testcase using -static-libasan isn't run on Solaris, which this patch also corrects. Bootstrapped without regressions on i386-pc-solaris2.11 and sparc-sun-solaris2.11 (both as/ld and gas/gld). 2025-11-18 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> gcc: * config/sol2.h: Check USE_GLD instead of USE_GNU_LD. gcc/testsuite: * c-c++-common/asan/pr59063-2.c: Enable on Solaris.
2025-11-17Improve LIM dump and some testcasesRichard Biener1-1/+1
The following avoids the newline between 'Moving statement' and the actual stmt in dumps to make specific scanning easier. * tree-ssa-loop-im.cc (move_computations_worker): Avoid newline between 'Moving statement' and actual statement dump in dumpfile. * gcc.dg/vect/slp-9.c: Use noipa function attribute, drop -fno-early-inlining option. * c-c++-common/restrict-2.c: Explicitly look for hoisted loads. * gfortran.dg/pr104466.f90: Adjust.
2025-11-17OpenMP/OpenACC tests. vs C++26Jakub Jelinek41-203/+207
OpenMP/OpenACC array sections, generally expr[expr:expr] or expr[expr:expr:expr] can have any of the exprs between [ and ] omitted, low-bound (first defaults to 0, last (stride) defaults to 1 and the middle (length) for some arrays defaults to ceil((size − lower_bound)/stride). People have been writing this for years without spaces between [ and : and : and ] when that expr has been omitted, but guess for C++26 one needs to add a space. I think [ :: ] isn't going to be parsed as the same as [ : : ] either. gcc/testsuite/ * c-c++-common/goacc/cache-3-1.c: Add dg-skip-if for c++26. * g++.dg/goacc/data-clause-2.C: Likewise. * g++.dg/gomp/allocate-3.C: Likewise. * c-c++-common/gomp/affinity-2.c: Use { c || c++23_down } effective target. * c-c++-common/goacc/cache-3-2.c: Replace [: in OpenMP or OpenACC pragmas or attributes with [ : and :] with : ]. * c-c++-common/goacc/data-clause-1.c: Likewise. * c-c++-common/goacc/data-clause-2.c: Likewise. * c-c++-common/goacc/data-clause-duplicate-1.c: Likewise. * c-c++-common/goacc/mdc-2.c: Likewise. * c-c++-common/goacc/readonly-1.c: Likewise. * c-c++-common/gomp/allocate-4.c: Likewise. * c-c++-common/gomp/clauses-3.c: Likewise. * c-c++-common/gomp/declare-mapper-3.c: Likewise. * c-c++-common/gomp/depend-1.c: Likewise. * c-c++-common/gomp/depend-2.c: Likewise. * c-c++-common/gomp/depend-3.c: Likewise. * c-c++-common/gomp/depend-4.c: Likewise. * c-c++-common/gomp/depend-5.c: Likewise. * c-c++-common/gomp/depend-6.c: Likewise. * c-c++-common/gomp/dispatch-1.c: Likewise. * c-c++-common/gomp/loop-5.c: Likewise. * c-c++-common/gomp/map-1.c: Likewise. * c-c++-common/gomp/map-2.c: Likewise. * c-c++-common/gomp/map-4.c: Likewise. * c-c++-common/gomp/map-7.c: Likewise. * c-c++-common/gomp/pr100902-1.c: Likewise. * c-c++-common/gomp/pr103642.c: Likewise. * c-c++-common/gomp/pr120180-1.c: Likewise. * c-c++-common/gomp/pr61486-1.c: Likewise. * c-c++-common/gomp/pr81006.c: Likewise. * c-c++-common/gomp/pr91920.c: Likewise. * c-c++-common/gomp/pr96867.c: Likewise. * c-c++-common/gomp/pr99928-16.c: Likewise. * c-c++-common/gomp/reduction-1.c: Likewise. * c-c++-common/gomp/scan-1.c: Likewise. * c-c++-common/gomp/target-data-1.c: Likewise. * c-c++-common/gomp/target-enter-data-1.c: Likewise. * c-c++-common/gomp/target-has-device-addr-1.c: Likewise. * c-c++-common/gomp/target-implicit-map-2.c: Likewise. * c-c++-common/gomp/target-map-iterators-1.c: Likewise. * c-c++-common/gomp/target-map-iterators-3.c: Likewise. * c-c++-common/gomp/target-update-iterators-1.c: Likewise. * c-c++-common/gomp/target-update-iterators-3.c: Likewise. * g++.dg/goacc/cache-3-1.C: Likewise. * g++.dg/goacc/cache-3-2.C: Likewise. * g++.dg/goacc/data-clause-1.C: Likewise. * g++.dg/goacc/mdc.C: Likewise. * g++.dg/gomp/array-section-2.C: Likewise. * g++.dg/gomp/bad-array-section-10.C: Likewise. * g++.dg/gomp/bad-array-section-11.C: Likewise. * g++.dg/gomp/bad-array-section-9.C: Likewise. * g++.dg/gomp/declare-mapper-1.C: Likewise. * g++.dg/gomp/declare-mapper-2.C: Likewise. * g++.dg/gomp/depend-1.C: Likewise. * g++.dg/gomp/depend-2.C: Likewise. * g++.dg/gomp/ind-base-3.C: Likewise. * g++.dg/gomp/map-1.C: Likewise. * g++.dg/gomp/map-2.C: Likewise. * g++.dg/gomp/map-ptrmem-1.C: Likewise. * g++.dg/gomp/map-ptrmem-2.C: Likewise. * g++.dg/gomp/member-array-2.C: Likewise. * g++.dg/gomp/target-this-3.C: Likewise. * g++.dg/gomp/target-this-4.C: Likewise. libgomp/ * testsuite/libgomp.c++/allocate-1.C: Replace [: in OpenMP or OpenACC pragmas or attributes with [ : and :] with : ]. * testsuite/libgomp.c++/baseptrs-3.C: Likewise. * testsuite/libgomp.c++/baseptrs-5.C: Likewise. * testsuite/libgomp.c++/class-array-1.C: Likewise. * testsuite/libgomp.c++/examples-4/target_data-5.C: Likewise. * testsuite/libgomp.c++/lvalue-tofrom-2.C: Likewise. * testsuite/libgomp.c++/pr101544-1.C: Likewise. * testsuite/libgomp.c++/pr108286.C: Likewise. * testsuite/libgomp.c++/reduction-10.C: Likewise. * testsuite/libgomp.c++/reduction-11.C: Likewise. * testsuite/libgomp.c++/reduction-12.C: Likewise. * testsuite/libgomp.c++/reduction-5.C: Likewise. * testsuite/libgomp.c++/reduction-6.C: Likewise. * testsuite/libgomp.c++/reduction-7.C: Likewise. * testsuite/libgomp.c++/reduction-8.C: Likewise. * testsuite/libgomp.c++/reduction-9.C: Likewise. * testsuite/libgomp.c++/target-18.C: Likewise. * testsuite/libgomp.c++/target-19.C: Likewise. * testsuite/libgomp.c++/target-2.C: Likewise. * testsuite/libgomp.c++/target-22.C: Likewise. * testsuite/libgomp.c++/target-23.C: Likewise. * testsuite/libgomp.c++/target-9.C: Likewise. * testsuite/libgomp.c++/target-flex-100.C: Likewise. * testsuite/libgomp.c++/target-flex-101.C: Likewise. * testsuite/libgomp.c++/target-flex-12.C: Likewise. * testsuite/libgomp.c++/target-flex-2003.C: Likewise. * testsuite/libgomp.c++/target-flex-30.C: Likewise. * testsuite/libgomp.c++/target-flex-300.C: Likewise. * testsuite/libgomp.c++/target-flex-32.C: Likewise. * testsuite/libgomp.c++/target-flex-33.C: Likewise. * testsuite/libgomp.c++/target-flex-41.C: Likewise. * testsuite/libgomp.c++/target-flex-60.C: Likewise. * testsuite/libgomp.c++/target-flex-61.C: Likewise. * testsuite/libgomp.c++/target-flex-62.C: Likewise. * testsuite/libgomp.c++/target-flex-80.C: Likewise. * testsuite/libgomp.c++/target-flex-81.C: Likewise. * testsuite/libgomp.c++/target-has-device-addr-7.C: Likewise. * testsuite/libgomp.c++/target-in-reduction-1.C: Likewise. * testsuite/libgomp.c++/target-in-reduction-2.C: Likewise. * testsuite/libgomp.c++/target-lambda-1.C: Likewise. * testsuite/libgomp.c++/target-lambda-3.C: Likewise. * testsuite/libgomp.c++/target-map-class-1.C: Likewise. * testsuite/libgomp.c++/target-std__array-concurrent.C: Likewise. * testsuite/libgomp.c++/target-std__bitset-concurrent.C: Likewise. * testsuite/libgomp.c++/target-std__deque-concurrent.C: Likewise. * testsuite/libgomp.c++/target-std__flat_map-concurrent.C: Likewise. * testsuite/libgomp.c++/target-std__flat_multimap-concurrent.C: Likewise. * testsuite/libgomp.c++/target-std__flat_multiset-concurrent.C: Likewise. * testsuite/libgomp.c++/target-std__flat_set-concurrent.C: Likewise. * testsuite/libgomp.c++/target-std__forward_list-concurrent.C: Likewise. * testsuite/libgomp.c++/target-std__list-concurrent.C: Likewise. * testsuite/libgomp.c++/target-std__map-concurrent.C: Likewise. * testsuite/libgomp.c++/target-std__multimap-concurrent.C: Likewise. * testsuite/libgomp.c++/target-std__multiset-concurrent.C: Likewise. * testsuite/libgomp.c++/target-std__set-concurrent.C: Likewise. * testsuite/libgomp.c++/target-std__span-concurrent.C: Likewise. * testsuite/libgomp.c++/target-std__unordered_map-concurrent.C: Likewise. * testsuite/libgomp.c++/target-std__unordered_multimap-concurrent.C: Likewise. * testsuite/libgomp.c++/target-std__unordered_multiset-concurrent.C: Likewise. * testsuite/libgomp.c++/target-std__unordered_set-concurrent.C: Likewise. * testsuite/libgomp.c++/target-std__valarray-1.C: Likewise. * testsuite/libgomp.c++/target-std__valarray-concurrent.C: Likewise. * testsuite/libgomp.c++/target-std__vector-concurrent.C: Likewise. * testsuite/libgomp.c++/target-this-3.C: Likewise. * testsuite/libgomp.c++/target-this-4.C: Likewise. * testsuite/libgomp.c++/target-virtual-1.C: Likewise. * testsuite/libgomp.c++/task-reduction-11.C: Likewise. * testsuite/libgomp.c++/task-reduction-12.C: Likewise. * testsuite/libgomp.c++/task-reduction-13.C: Likewise. * testsuite/libgomp.c++/task-reduction-17.C: Likewise. * testsuite/libgomp.c++/task-reduction-18.C: Likewise. * testsuite/libgomp.c++/task-reduction-19.C: Likewise. * testsuite/libgomp.c++/task-reduction-4.C: Likewise. * testsuite/libgomp.c++/task-reduction-5.C: Likewise. * testsuite/libgomp.c++/task-reduction-6.C: Likewise. * testsuite/libgomp.c++/task-reduction-7.C: Likewise. * testsuite/libgomp.c++/taskloop-reduction-2.C: Likewise. * testsuite/libgomp.c++/taskloop-reduction-3.C: Likewise. * testsuite/libgomp.c++/taskloop-reduction-4.C: Likewise. * testsuite/libgomp.c-c++-common/allocate-1.c: Likewise. * testsuite/libgomp.c-c++-common/allocate-3.c: Likewise. * testsuite/libgomp.c-c++-common/baseptrs-2.c: Likewise. * testsuite/libgomp.c-c++-common/dispatch-1.c: Likewise. * testsuite/libgomp.c-c++-common/dispatch-2.c: Likewise. * testsuite/libgomp.c-c++-common/interop-2.c: Likewise. * testsuite/libgomp.c-c++-common/matrix-omp-target-teams-distribute-parallel-for-1.c: Likewise. * testsuite/libgomp.c-c++-common/ptr-attach-1.c: Likewise. * testsuite/libgomp.c-c++-common/ptr-attach-2.c: Likewise. * testsuite/libgomp.c-c++-common/refcount-1.c: Likewise. * testsuite/libgomp.c-c++-common/struct-elem-4.c: Likewise. * testsuite/libgomp.c-c++-common/target-2.c: Likewise. * testsuite/libgomp.c-c++-common/target-has-device-addr-1.c: Likewise. * testsuite/libgomp.c-c++-common/target-implicit-map-2.c: Likewise. * testsuite/libgomp.c-c++-common/target-implicit-map-5.c: Likewise. * testsuite/libgomp.c-c++-common/target-in-reduction-1.c: Likewise. * testsuite/libgomp.c-c++-common/target-in-reduction-2.c: Likewise. * testsuite/libgomp.c-c++-common/target-map-iterators-1.c: Likewise. * testsuite/libgomp.c-c++-common/target-map-iterators-2.c: Likewise. * testsuite/libgomp.c-c++-common/target-map-iterators-3.c: Likewise. * testsuite/libgomp.c-c++-common/target-map-zlas-1.c: Likewise. * testsuite/libgomp.c-c++-common/target-update-iterators-1.c: Likewise. * testsuite/libgomp.c-c++-common/target-update-iterators-2.c: Likewise. * testsuite/libgomp.c-c++-common/target-update-iterators-3.c: Likewise. * testsuite/libgomp.c-c++-common/task-reduction-11.c: Likewise. * testsuite/libgomp.c-c++-common/task-reduction-12.c: Likewise. * testsuite/libgomp.c-c++-common/task-reduction-16.c: Likewise. * testsuite/libgomp.c-c++-common/task-reduction-3.c: Likewise. * testsuite/libgomp.c-c++-common/task-reduction-7.c: Likewise. * testsuite/libgomp.c-c++-common/task-reduction-9.c: Likewise. * testsuite/libgomp.c-c++-common/taskloop-reduction-2.c: Likewise. * testsuite/libgomp.c-c++-common/teams-nteams-icv-1.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/deep-copy-1.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/deep-copy-16.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/deep-copy-3.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/deep-copy-4.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/deep-copy-5.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/deep-copy-6.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/deep-copy-7.c: Likewise. * testsuite/libgomp.oacc-c-c++-common/deep-copy-8.c: Likewise.
2025-11-15testsuite: Fix up c-c++-common/asan/asan-stack-small.c testJakub Jelinek1-4/+12
Here is a fix for the test I've talked about today in the libsanitizer update mail. The test relied on a coming before b coming before c, all with 32 byte distances, but gcc can actually emit them in the exact opposite order or some other one. 2025-11-15 Jakub Jelinek <jakub@redhat.com> * c-c++-common/asan/asan-stack-small.c (pa, pb, pc): Make these vars volatile. (uintptr_t): New typedef. (main): Use access of b using pa pointer with offset depending on how exactly the 3 variables are laid out in the frame.
2025-10-30gimple-fold: Remove assume_aligned foldingAndrew Pinski1-1/+3
So in the end I agree with Richi's comment at https://gcc.gnu.org/pipermail/gcc-patches/2025-October/698856.html: > I see. I wonder whether it would be better to leave __builtin_assume_aligned > around then, because that inherently introduces the copy and it would show why. > TER / SSA coalescing might make a mess our of the copies you leave in place > anyway, no? This leaves __builtin_assume_aligned around. Will also push the revert of r16-4637-g8590b32deac05e along side this. gcc/ChangeLog: * gimple-fold.cc (gimple_fold_builtin_assume_aligned): Remove. (gimple_fold_builtin): Don't fold __builtin_assume_aligned gcc/testsuite/ChangeLog: * c-c++-common/ubsan/align-5.c: Xfail. * gcc.dg/pr107389.c: Move to... * gcc.dg/torture/pr107389.c: ...here. Skip for lto. * gcc.dg/builtin-assume-aligned-1.c: Instead of testing for deleting of assume-align, test for the alignment/misalignment. Also disable the vectorizer. Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-10-30Revert "forwprop: Fix copy prop for alignment after the final folding ↵Andrew Pinski1-3/+1
[PR122086]" This reverts commit 8590b32deac05e6eb368b72bd353749134120a1f.
2025-10-26forwprop: Fix copy prop for alignment after the final folding [PR122086]Andrew Pinski1-1/+3
After r16-4081-g966cdec2b2 which added folding of __builtin_assume_aligned, forwprop would propagate pointers that lower alignment replacing ones with greater alignment. This causes us to lose alignment information that __builtin_assume_aligned provided to expand. Normally this just loses some optimizations except in the s390 case where the alignment is specifically checked and was for inlining of the atomics; without this patch an infininite loop would happen. Note this was previously broken for -Og before r16-4081-g966cdec2b2. This fixes -Og case as forwprop is used instead of copyprop. This moves the testcase for pr107389.c to torture to get a generic testcase. pr107389.c was originally for -O0 case but we should test for other optimization levels so this is not lost again. align-5.c is xfailed because __builtin_assume_aligned is not instrumented for ubsan alignment and ubsan check to see pointer is aligned before emitting a check for the load (based on the known alignment in compiling). See PR 122038 too. I had mentioned this issue previously in r16-4081-g966cdec2b2 too. PR middle-end/107389 PR tree-optimization/122086 gcc/ChangeLog: * tree-ssa-forwprop.cc (forwprop_may_propagate_copy): New function. (pass_forwprop::execute): Use forwprop_may_propagate_copy instead of may_propagate_copy. gcc/testsuite/ChangeLog: * gcc.dg/pr107389.c: Move to... * gcc.dg/torture/pr107389.c: ...here. Skip for lto. Use dg-additional-options rather than dg-options. * c-c++-common/ubsan/align-5.c: xfail. Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-10-24OpenMP: Fix bogus diagnostics with intervening code [PR121452]Paul-Antoine Arras2-0/+34
The introduction in r14-3488-ga62c8324e7e31a of OMP_STRUCTURED_BLOCK (to diagnose invalid intervening code) caused a regression rejecting the valid use of the Fortran CONTINUE statement to end a collapsed loop. This patch fixes the incorrect error checking in the OMP lowering pass. It also fixes a check in the Fortran front end that erroneously rejects a similar statement in an ordered loop. Co-authored by: Tobias Burnus <tburnus@baylibre.com> PR fortran/121452 gcc/fortran/ChangeLog: * openmp.cc (resolve_omp_do): Allow CONTINUE as end statement of a perfectly nested loop. gcc/ChangeLog: * omp-low.cc (check_omp_nesting_restrictions): Accept an OMP_STRUCTURED_BLOCK in a collapsed simd region and in an ordered loop. gcc/testsuite/ChangeLog: * c-c++-common/gomp/pr121452-1.c: New test. * c-c++-common/gomp/pr121452-2.c: New test. * gfortran.dg/gomp/pr121452-1.f90: New test. * gfortran.dg/gomp/pr121452-2.f90: New test. * gfortran.dg/gomp/pr121452-3.f90: New test.
2025-10-22testsuite: Fix local labels [PR122378]Paul-Antoine Arras2-2/+2
r16-4540-g80af807e52e4f4 exposed a bug in two testcases where the declaration of local labels was wrongly commented out. That caused "duplicate label" errors. Uncommenting declarations fixes it. PR middle-end/122378 gcc/testsuite/ChangeLog: * c-c++-common/gomp/attrs-metadirective-2.c: Uncomment local label declaration. * c-c++-common/gomp/metadirective-2.c: Likewise.
2025-10-21OpenMP: Handle non-executable directives in intervening code [PR120180,PR122306]Paul-Antoine Arras4-5/+71
OpenMP 6 permits non-executable directives in intervening code; this commit adds support for a sensible subset, namely metadirectives, nothing, assume, and 'error at(compilation)'. Also handle the special case where a metadirective can be resolved at parse time to 'omp nothing'. This fixes a build issue that affects 10 out 12 SPECaccel benchmarks. Co-authored by: Tobias Burnus <tburnus@baylibre.com> PR c/120180 PR fortran/122306 gcc/c/ChangeLog: * c-parser.cc (c_parser_pragma): Accept a subset of non-executable OpenMP directives in intervening code. (c_parser_omp_error): Reject 'error at(execution)' in intervening code. (c_parser_omp_metadirective): Return early if only one selector matches and it resolves to 'omp nothing'. gcc/cp/ChangeLog: * parser.cc (cp_parser_omp_metadirective): Return early if only one selector matches and it resolves to 'omp nothing'. (cp_parser_omp_error): Reject 'error at(execution)' in intervening code. (cp_parser_pragma): Accept a subset of non-executable OpenMP directives as intervening code. gcc/fortran/ChangeLog: * gfortran.h (enum gfc_exec_op): Add EXEC_OMP_FIRST_OPENMP_EXEC and EXEC_OMP_LAST_OPENMP_EXEC. * openmp.cc (gfc_match_omp_context_selector): Remove static. Remove checks on score. Add cleanup. Remove checks on trait properties. (gfc_match_omp_context_selector_specification): Remove static. Adjust calls to gfc_match_omp_context_selector. (gfc_match_omp_declare_variant): Adjust call to gfc_match_omp_context_selector_specification. (match_omp_metadirective): Likewise. (icode_code_error_callback): Reject all statements except 'assume' and 'metadirective'. (gfc_resolve_omp_context_selector): New function. (resolve_omp_metadirective): Skip metadirectives which context selectors can be statically resolved to false. Replace metadirective by its body if only 'nothing' remains. (gfc_resolve_omp_declare): Call gfc_resolve_omp_context_selector for each variant. gcc/testsuite/ChangeLog: * c-c++-common/gomp/imperfect1.c: Adjust dg-error. * c-c++-common/gomp/imperfect4.c: Likewise. * c-c++-common/gomp/pr120180.c: Move to... * c-c++-common/gomp/pr120180-1.c: ...here. Remove dg-error. * g++.dg/gomp/attrs-imperfect1.C: Adjust dg-error. * g++.dg/gomp/attrs-imperfect4.C: Likewise. * gfortran.dg/gomp/declare-variant-2.f90: Adjust dg-error. * gfortran.dg/gomp/declare-variant-20.f90: Likewise. * c-c++-common/gomp/pr120180-2.c: New test. * g++.dg/gomp/pr120180-1.C: New test. * gfortran.dg/gomp/pr120180-1.f90: New test. * gfortran.dg/gomp/pr120180-2.f90: New test. * gfortran.dg/gomp/pr122306-1.f90: New file. * gfortran.dg/gomp/pr122306-2.f90: New file.
2025-10-21OpenMP: Update directive arrays used for 'omp assume(s)' with contains/absentTobias Burnus3-3/+5
Both Fortran and C/C++ have an array with classifications of directives; currently, this array is only used to handle the restrictions of the contains/absent clauses to the assume/assumes directives. For C/C++, uncommenting 'declare mapper' was missed. Additionally, 'end ...' is a directive but not a directive name; hence, those are now rejected as 'unknown directive' instead of as 'invalid' directive. Additionally, both lists now list newer entries (commented out) for OpenMP 6.x - and a note (comment) was added for C/C++'s 'begin metadirective' and for Fortran's 'allocate', respectively. gcc/c-family/ChangeLog: * c-omp.cc (c_omp_directives): Uncomment 'declare mapper', add comment to 'begin metadirective', add 6.x unimplemented directives as comment-out entries. gcc/c/ChangeLog: * c-parser.cc (c_parser_omp_assumption_clauses): Switch to 'unknown' not 'invalid' directive name for end directives. gcc/cp/ChangeLog: * parser.cc (cp_parser_omp_assumption_clauses): Switch to 'unknown' not 'invalid' directive name for end directives. gcc/fortran/ChangeLog: * openmp.cc (gfc_omp_directive): Add comment to 'allocate'; add 6.x unimplemented directives as comment-out entries. gcc/testsuite/ChangeLog: * c-c++-common/gomp/assumes-2.c: Change for 'invalid' to 'unknown' change for end directives. * c-c++-common/gomp/begin-assumes-2.c: Likewise. * c-c++-common/gomp/assume-2.c: Likewise. Check 'declare mapper'.
2025-10-20c++, gimplify: Implement C++26 P2795R5 - Erroneous behavior for ↵Thomas Schwinge1-0/+2
uninitialized reads: Adjust 'c-c++-common/goacc/kernels-decompose-pr100280-1.c' [PR114457] With commit r16-4212-gf256a13f8aed833fe964a2ba541b7b30ad9b4a76 "c++, gimplify: Implement C++26 P2795R5 - Erroneous behavior for uninitialized reads [PR114457]", we acquired: @@ -181180,8 +184423,8 @@ PASS: c-c++-common/goacc/kernels-decompose-pr100280-1.c -std=c++26 at line 14 PASS: c-c++-common/goacc/kernels-decompose-pr100280-1.c -std=c++26 at line 15 (test for warnings, line 12) PASS: c-c++-common/goacc/kernels-decompose-pr100280-1.c -std=c++26 at line 16 (test for warnings, line 12) PASS: c-c++-common/goacc/kernels-decompose-pr100280-1.c -std=c++26 (test for excess errors) [-XFAIL:-]{+XPASS:+} c-c++-common/goacc/kernels-decompose-pr100280-1.c -std=c++26 TODO at line 18 (test for warnings, line 19) [-XFAIL:-]{+XPASS:+} c-c++-common/goacc/kernels-decompose-pr100280-1.c -std=c++26 TODO location at line 17 (test for bogus messages, line 10) As in other OpenACC 'kernels' test cases, the underlying issue again is PR121975 "Various goacc failures with -ftrivial-auto-var-init=zero" (to be resolved later on). PR c++/114457 gcc/testsuite/ * c-c++-common/goacc/kernels-decompose-pr100280-1.c: Skip for c++26 until PR121975 is fixed.
2025-10-10testsuite: Fix vector-subscript-4.c [PR116421]Stefan Schulze Frielinghaus1-3/+5
Verify we don't have any vector temporaries in the IL at least until ISEL which may introduce VEC_EXTRACTs on targets which support non-constant indices (see PR116421). As a pass I chose NRV for no particular reason except that it is literally the last pass prior ISEL. At least at time of writing this. gcc/testsuite/ChangeLog: PR testsuite/116421 * c-c++-common/vector-subscript-4.c: Check for vectors prior ISEL.
2025-10-09c++: C++26 va_start - part of P3348R4 - C++26 should refer to C23 not C17Jakub Jelinek2-2/+2
The C++26 https://wg21.link/P3348R4 C++26 should refer to C23 not C17 paper among other things changes va_start macro in the similar way how C23 has changed it. Now, unlike C17 and older, C++ has since forever allowed int (...) but just one wasn't able to use va_start/va_arg/va_end in such functions. With the current C++26 draft wording, we'd have to #define va_start(V, ...) __builtin_va_start (V, 0) like we've used for C23 before the PR107980 change. But Jonathan has kindly filed https://cplusplus.github.io/LWG/issue4388 which similarly to C23 will if accepted allow to define it as #define va_start(...) __builtin_c23_va_start(__VA_ARGS__) and let the compiler diagnose undesirable cases (see stdarg6.C testcase in the patch for what it can diagnose, basically anything that isn't either va_start (ap) or va_start (ap, i) where i is the last argument's identifier). This patch implements what assumes LWG4388 will pass. It also defines #define __STDC_VERSION_STDARG_H__ 202311L also for C++26. The hardest part is actually something different. C23 had to differentiate between C99 void foo (); i.e. unspecified arguments (but not stdarg) and the new C23 void bar (...); which is stdarg, but in both cases TYPE_ARG_TYPES (fntype) is NULL. This has been implemented through the new TYPE_NO_NAMED_ARGS_STDARG_P flag, fntypes with that flag set are considered stdarg_p and allow va_start in those, while fntypes with NULL TYPE_ARG_TYPES but the flag cleared are not stdarg_p, can accept any number of arguments but can't use va_start. So, I had to change various places in the C++ FE to pass true as the third argument to build_function_type for calls which are meant to be (...) so that one can actually use va_start in those. Done only for C++26 in order not to disturb older versions too much. And there is a problem with some of the builtins and #pragma weak which are using (...) declarations more in the sense of C17 unspecified arguments rather than this call has variable arguments. So, structural_comptypes now considers the non-C++26 (...) used for selected builtins and #pragma weak incompatible with C++26 (...) to avoid ICEs. 2025-10-09 Jakub Jelinek <jakub@redhat.com> gcc/ * ginclude/stdarg.h (va_start): Use __builtin_c23_va_start also for C++26. (__STDC_VERSION_STDARG_H__): Also define for C++26. gcc/c-family/ * c-common.h (D_CXX26): Define. * c-common.cc (c_common_resword): Add D_CXX26 to __builtin_c23_va_start flags, mention D_CXX26 in comment. gcc/cp/ * cp-tree.h (cp_build_function_type): Declare. * lex.cc: Implement va_start changes from P3348R4 - C++26 should refer to C23 not C17 paper. (init_reswords): Set D_CXX26 in mask for C++23 and older. * parser.cc (cp_parser_primary_expression): Handle RID_C23_VA_START. (cp_parser_builtin_c23_va_start): New function. * cp-objcp-common.cc (names_builtin_p): Likewise. * decl.cc (grokfndecl, check_function_type): Pass TYPE_NO_NAMED_ARGS_STDARG_P as last arg to build_function_type. (grokdeclarator, static_fn_type): Use cp_build_function_type instead of build_function_type. * typeck.cc (merge_types): Likewise. (structural_comptypes): Return false for TYPE_NO_NAMED_ARGS_STDARG_P differences. * lambda.cc (maybe_add_lambda_conv_op): Use cp_build_function_type instead of build_function_type. * tree.cc (cp_build_function_type): New function. (strip_typedefs): Pass TYPE_NO_NAMED_ARGS_STDARG_P as last arg to build_function_type. * name-lookup.cc (push_local_extern_decl_alias): Likewise. * module.cc (trees_in::tree_node): Use cp_build_function_type instead of build_function_type. * pt.cc (copy_default_args_to_explicit_spec, rebuild_function_or_method_type, build_deduction_guide): Likewise. (alias_ctad_tweaks): Pass TYPE_NO_NAMED_ARGS_STDARG_P as last arg to build_function_type. * decl2.cc (change_return_type, cp_reconstruct_complex_type): Likewise. gcc/testsuite/ * c-c++-common/cpp/has-builtin-4.c: Expect __has_builtin (__builtin_c23_va_start) == 1 also for C++26. * c-c++-common/Wvarargs.c (foo3): Don't expect undefined behavior warning for C++26. * g++.dg/cpp26/stdarg1.C: New test. * g++.dg/cpp26/stdarg2.C: New test. * g++.dg/cpp26/stdarg3.C: New test. * g++.dg/cpp26/stdarg4.C: New test. * g++.dg/cpp26/stdarg5.C: New test. * g++.dg/cpp26/stdarg6.C: New test. * g++.dg/cpp26/stdarg7.C: New test. * g++.dg/cpp26/stdarg8.C: New test. * g++.dg/cpp26/stdarg9.C: New test. * g++.dg/opt/pr60849.C (foo): Add explicit cast.
2025-10-08Update to Unicode 17.0.0Jakub Jelinek1-0/+1
The following patch updates GCC from Unicode 16.0.0 to 17.0.0. I've followed what the README says and updated also one script from glibc, but that needed another Unicode file - HangulSyllableType.txt - around as well, so I'm adding it. I've added one new test to named-universal-char-escape-1.c for randomly chosen character from new CJK block. Note, Unicode 17.0.0 authors forgot to adjust the 4-8 table, I've filed bugreports about that but the UnicodeData.txt changes for the range ends and the new range seems to match e.g. what is in the glyph tables, so the patch follows UnicodeData.txt and not 4-8 table here. Another thing was that makeuname2c.cc didn't handle correctly when the size of the generated string table modulo 77 was 76 or 77, in which case it forgot to emit a semicolon after the string literal and so failed to compile. And as can be seen in the emoji-data.txt diff, some properties like Extended_Pictographic have been removed from certain characters, e.g. from the Mahjong cards characters except U+1F004, and one libstdc++ test was testing that property exactly on U+1F000. Dunno why that was changed, but U+1F004 is the only colored one among tons of black and white ones. 2025-10-08 Jakub Jelinek <jakub@redhat.com> contrib/ * unicode/README: Add HangulSyllableType.txt file to the list as newest utf8_gen.py from glibc now needs it. Adjust git commit hash and change unicode 16 version to 17. * unicode/from_glibc/utf8_gen.py: Updated from glibc. * unicode/DerivedCoreProperties.txt: Updated from Unicode 17.0.0. * unicode/emoji-data.txt: Likewise. * unicode/PropList.txt: Likewise. * unicode/GraphemeBreakProperty.txt: Likewise. * unicode/DerivedNormalizationProps.txt: Likewise. * unicode/NameAliases.txt: Likewise. * unicode/UnicodeData.txt: Likewise. * unicode/EastAsianWidth.txt: Likewise. * unicode/DerivedGeneralCategory.txt: Likewise. * unicode/HangulSyllableType.txt: New file. gcc/testsuite/ * c-c++-common/cpp/named-universal-char-escape-1.c: Add test for \N{CJK UNIFIED IDEOGRAPH-3340E}. libcpp/ * makeucnid.cc (write_copyright): Adjust copyright year. * makeuname2c.cc (generated_ranges): Adjust end points for a couple of ranges based on UnicodeData.txt Last changes and add a whole new CJK UNIFIED IDEOGRAPH- entry. None of these changes are in the 4-8 table, but clearly it has just been forgotten. (write_copyright): Adjust copyright year. (write_dict): Fix up condition when to print semicolon. * generated_cpp_wcwidth.h: Regenerate. * ucnid.h: Regenerate. * uname2c.h: Regenerate. libstdc++-v3/ * include/bits/unicode-data.h: Regenerate. * testsuite/ext/unicode/properties.cc: Test __is_extended_pictographic on U+1F004 rather than U+1F000.
2025-10-08gimplify: Fix up __builtin_c[lt]zg gimplification [PR122188]Jakub Jelinek1-0/+15
The following testcase ICEs during gimplification. The problem is that save_expr sometimes doesn't create a SAVE_EXPR but returns the original complex tree (COND_EXPR) and the code then uses that tree in 2 different spots without unsharing. As this is done during gimplification it wasn't unshared when whole body is unshared and because gimplification is destructive, the first time we gimplify it we destruct it and second time we try to gimplify it we ICE on it. Now, we could replace one a use with unshare_expr (a), but because this is a gimplification hook, I think easier than trying to create a save_expr is just gimplify the argument, then we know it is is_gimple_val and so something without side-effects and can safely use it twice. That argument would be the first thing to gimplify after return GS_OK anyway, so it doesn't change argument sequencing etc. 2025-10-08 Jakub Jelinek <jakub@redhat.com> PR c/122188 * c-gimplify.cc (c_gimplify_expr): Gimplify CALL_EXPR_ARG (*expr_p, 0) instead of calling save_expr on it. * c-c++-common/pr122188.c: New test.
2025-10-06stmt: Handle %cc[name] in resolve_asm_operand_names [PR122133]Jakub Jelinek1-0/+12
Last year I've extended the asm template syntax in inline asm to support %cc0 etc., apparently the first 2 letter generic operand modifier. As the following testcase shows, I forgot to tweak the [foo] handling for it though. As final.cc will error on any % ISALPHA not followed by digit (with the exception of % c c digit), I think we can safely handle this for any 2 letters in between % and [, instead of hardcoding it for now only for %cc[ and changing it again next time we add something two-letter. 2025-10-06 Jakub Jelinek <jakub@redhat.com> PR middle-end/122133 * stmt.cc (resolve_asm_operand_names): Handle % and 2 letters followed by open square. * c-c++-common/toplevel-asm-9.c: New test.
2025-10-05Disable some testcase for -OgAndrew Pinski1-2/+3
Running the testsuite with ADDITIONAL_TORTURE_OPTIONS set include "-Og -g", there are a few extra failures in the torture testsuite. These 2 failures are expected so let's skip them in the same way for -O0. asm-inline.c is because inlining does not happen as much at -Og. restrict-8.c fails due to not building the points to aliasing info at -Og. gcc/testsuite/ChangeLog: * c-c++-common/torture/asm-inline.c: Disable at -Og. * gcc.dg/torture/restrict-8.c: Likewise. Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-10-04c++, gimplify: Implement C++26 P2795R5 - Erroneous behavior for ↵Jakub Jelinek14-11/+22
uninitialized reads [PR114457] The following patch implements the C++26 P2795R5 paper by enabling something like -ftrivial-auto-var-init=zero by default for -std=c++26/-std=gnu++26. There is an important difference between explicit -ftrivial-auto-var-init=zero and the implicitly enabled one, in particular the explicit one will try to clear padding bits on vars with explicit initializers, while the default C++26 mode does not - C++26 says that using the padding bits for anything but copying structures around is still undefined behavior rather than erroneous behavior. Users can still override the default C++26 behavior in both directions, with -ftrivial-auto-var-init=uninitialized even C++26 will act as C++23 with treating all uninitialized var reads (except for copying) as UB rather than EB, with -ftrivial-auto-var-init=zero it will also clear padding bits on explicit initialization and with -ftrivial-auto-var-init=pattern it will initialize to pattern with clearing padding bits in between. There are other changes that had to be implemented. First of all, we need to magicly preinitialize also temporary objects; this is implemented for both the C++26 implicit mode and explicit -ftrivial-auto-var-init={zero,pattern} by emitting .DEFERRED_INIT before construction of TARGET_EXPR temporaries (if they have void type initializers, i.e. are initialized by code rather than some value). Second needed change is dropping *this ={v} {CLOBBER(bob)}; statements at the start of the constructors for -flifetime-dse=2, that says the old content of *this is irrelevant, which is not true anymore for C++26, where we want to treat it like that for -W*uninitialized purposes, but at runtime actually initialize the values. Instead for -flifetime-dse=2 we emit such {CLOBBER(bob)} before calling whole object constructor (on TARGET_EXPR with void type initializer or on DECL_EXPR). And a separate patch added and another one will be adding more {CLOBBER(bob)} to new expressions. The third needed change is about gotos and switches across vacuous initialization. C++26 says those are still valid, but don't make an exception for those in the EB rules. The patch now includes redirecting of forward/backward gotos which cross vacuous initializations for -std=c++26 and -ftrivial-auto-var-init={zero,pattern} by adding an artificial if (0) { lab1: v1 = .DEFERRED_INIT (...); lab2: v2 = .DEFERRED_INIT (...); } etc. hunk before the user label (or for case labels moving the case label into it). Only one per adjacent set of labels, with perhaps multiple artificial labels in it. I believe (and testing seems to confirm that) that one only needs one set of such initialized vars per the adjacent label group, if some forward or backward jump crosses more vacuous inits, it will always cross a subset or superset of the others and when the vars are ordered right, it can jump into different positions in the same if (0). Furthermore, -Wimplicit-fallthrough and -Wswitch-unreachable warnings have been adjusted to deal with that. These changes mean that -Wtrivial-auto-var-init warning now doesn't make sense for C++, as there is nothing to warn about, all the switches and all the gotos are handled right for -ftrivial-auto-var-init= and are handled that way both for the implicit C++26 mode and for explicit -ftrivial-auto-var-init= options. The fourth change is to avoid regressions for code like struct A { int f, g; A () { f = g; // { dg-warning "g. is used uninitialized" } } } a; where with -flifetime-dse=2 -Wuninitialized we were able to warn about bugs like this because of the *this ={v} {CLOBBER(bob)}; statements at the start of the constructors, but with their removal wouldn't warn about it. Instead we now add a magic "clobber *this" attribute to the this PARM_DECL and use it in -W*uninitialized handling only as an implicit *this ={v} {CLOBBER(bob)}; at the start of the function. If a function is inlined, this disappears, but that shouldn't be a problem, either it is inlined into another constructor and that should have "clobber *this" for its this argument or it is inlined into whole object construction spot and there should be an explicit {CLOBBER(bob)} for the variable or temporary object. The fifth change is adding [[indeterminate]] attribute support and using it to avoid .DEFERRED_INIT calls (like [[gnu::uninitialized]] is handled). Some regressions caused by this patch had bugs filed (but for cases where those already didn't work before with explicit -ftrivial-auto-var-init=zero), those have been xfailed for now. See PR121975 and PR122044. 2025-10-04 Jakub Jelinek <jakub@redhat.com> PR c++/114457 gcc/ * flag-types.h (enum auto_init_type): Add AUTO_INIT_CXX26. * tree.h (VACUOUS_INIT_LABEL_P): Define. * gimplify.cc (is_var_need_auto_init): Renamed to ... (var_needs_auto_init_p): ... this. Don't return true for vars with "indeterminate" attribute. Formatting fixes. (gimplify_decl_expr): Use var_needs_auto_init_p instead of is_var_need_auto_init. (emit_warn_switch_unreachable): Remove the flag_auto_var_init special cases. (warn_switch_unreachable_and_auto_init_r): Handle them here by doing just returning NULL. (last_stmt_in_scope): Don't skip just debug stmts to find the last stmt in seq, skip for flag_auto_var_init > AUTO_INIT_UNINITIALIZED also IFN_DEFERRED_INIT calls. (collect_fallthrough_labels): For flag_auto_var_init > AUTO_INIT_UNINITIALIZED ignore IFN_DEFERRED_INIT calls and GIMPLE_GOTOs to VACUOUS_INIT_LABEL_P. (should_warn_for_implicit_fallthrough): For flag_auto_var_init > AUTO_INIT_UNINITIALIZED also skip over IFN_DEFERRED_INIT calls. (expand_FALLTHROUGH_r): Likewise, and handle GIMPLE_GOTOs to VACUOUS_INIT_LABEL_P. (gimplify_init_constructor): Use var_needs_auto_init_p instead of is_var_need_auto_init and for flag_auto_var_init AUTO_INIT_CXX26 don't call gimple_add_padding_init_for_auto_var. (gimplify_target_expr): If var_needs_auto_init_p and init has void type, call gimple_add_init_for_auto_var and for AUTO_INIT_PATTERN also gimple_add_padding_init_for_auto_var. * tree-ssa-uninit.cc (maybe_warn_operand): Handle loads from *this at the start of the function with "clobber *this" attribute on the PARM_DECL. * ipa-split.cc (split_function): Remove "clobber *this" attribute from the first PARM_DECL (if any). * doc/invoke.texi (ftrivial-auto-var-init=): Adjust documentation. gcc/c-family/ * c-opts.cc (c_common_post_options): For C++26 set flag_auto_var_init to AUTO_INIT_CXX26 if not specified explicitly. For C++ disable warn_trivial_auto_var_init. gcc/cp/ * cp-tree.h: Implement C++26 P2795R5 - Erroneous behavior for uninitialized reads. (IF_STMT_VACUOUS_INIT_P): Define. (check_goto): Change argument type from tree to tree *. * call.cc (build_over_call): Add indeterminate attribute to TARGET_EXPR slots for indeterminate parameters. * constexpr.cc (cxx_eval_internal_function): Handle IFN_DEFERRED_INIT. (cxx_eval_store_expression): Temporarily work around PR121965 bug. * cp-gimplify.cc (genericize_if_stmt): Handle IF_STMT_VACUOUS_INIT_P. (maybe_emit_clobber_object_begin): New function. (cp_gimplify_expr): Call it for DECL_EXPRs and TARGET_EXPRs with void type non-NULL TARGET_EXPR_INITIAL. * decl.cc (struct named_label_fwd_direct_goto, struct named_label_bck_direct_goto): New types. (struct named_label_use_entry): Add direct_goto member. Formatting fix. (struct named_label_entry): Add direct_goto member. Turn bool members into bool : 1. Add has_bad_decls bitfield. (adjust_backward_gotos): New function. (pop_labels): For flag_auto_var_init > AUTO_INIT_UNINITIALIZED call adjust_backward_gotos if needed. (poplevel_named_label_1): For decl_jump_unsafe also set ent->has_bad_decls, and for decl_instrument_init_bypass_p decls push them into ent->bad_decls vector too. (duplicate_decls): Complain if indeterminate attribute on function parameter isn't present on the first function declaration. (decl_instrument_init_bypass_p): New function. (build_deferred_init_call): Likewise. (maybe_add_deferred_init_calls): Likewise. (adjust_backward_goto): Likewise. (check_previous_goto_1): Add direct_goto and case_label arguments. For decl_instrument_init_bypass_p decls seen if direct_goto || case_label move case label if needed, call maybe_add_deferred_init_calls and adjust GOTO_EXPR operands remembered in direct_goto. Change return type from bool to int, return 0 on error, 1 for success with no need to adjust vacuous inits and 2 for success with need to adjust those. (check_previous_goto): Adjust check_previous_goto_1 call, vec_free direct_goto vector. (check_switch_goto): Add case_label argument, adjust check_previous_goto_1 call. Change return type from bool to int. (check_goto_1): Remove computed argument, add declp argument. Don't reuse previous ent->uses if ent->binding_level != current_binding_level. Push declp into direct_goto vectors if needed. (check_goto): Remove decl argument, add declp argument. Adjust check_goto_1 calls. (finish_case_label): Call check_switch_goto up to twice, first time to detect errors and find out if second call will be needed, and after c_add_case_label second time if needed. In the first case pass NULL_TREE as new argument to it, in the second case r. (start_preparsed_function): Don't emit CLOBBER_OBJECT_BEGIN here for -flifetime-dse=2, instead add "clobber *this" attribute to current_class_ptr. * parser.cc (cp_parser_asm_label_list): Call check_goto only after the TREE_LIST is created and pass address of its TREE_VALUE to it instead of the label. * semantics.cc (finish_goto_stmt): Call check_goto only after build_stmt has been called and pass it address of its first operand rather than destination. * tree.cc (handle_indeterminate_attribute): New function. (cxx_gnu_attributes): Add entry for indeterminate attribute. gcc/testsuite/ * g++.dg/cpp1y/vla-initlist1.C: Remove dg-skip-if for powerpc. Initialize i to 43 for ctor from initializer_list and expect value 43 instead of 42. * g++.dg/cpp26/attr-indeterminate1.C: New test. * g++.dg/cpp26/attr-indeterminate2.C: New test. * g++.dg/cpp26/attr-indeterminate3.C: New test. * g++.dg/cpp26/attr-indeterminate4.C: New test. * g++.dg/cpp26/erroneous1.C: New test. * g++.dg/cpp26/erroneous2.C: New test. * g++.dg/cpp26/erroneous3.C: New test. * g++.dg/cpp26/erroneous4.C: New test. * g++.dg/opt/store-merging-1.C: Add -ftrivial-auto-var-init=uninitialized to dg-options. * g++.dg/uninit-pred-loop-1_b.C: Expect a warning for C++26. * g++.dg/warn/Wuninitialized-13.C: Expect warning on a different line. * c-c++-common/ubsan/vla-1.c: Add -ftrivial-auto-var-init=uninitialized to dg-options. * c-c++-common/uninit-17.c: For c++26 expect warning on a different line. * g++.dg/warn/Warray-bounds-20.C: Expect warning on a different line. * c-c++-common/analyzer/invalid-shift-1.c: Xfail for c++26 until PR122044 is fixed. * g++.dg/analyzer/exception-value-2.C: Skip for c++26 until PR122044 is fixed. * c-c++-common/goacc-gomp/nesting-1.c: Skip for c++26 until PR121975 is fixed. * c-c++-common/goacc/kernels-decompose-2.c: Likewise. * c-c++-common/goacc/kernels-decompose-pr100400-1-1.c: Likewise. * c-c++-common/goacc/kernels-decompose-pr100400-1-3.c: Likewise. * c-c++-common/goacc/kernels-decompose-pr104061-1-1.c: Likewise. * c-c++-common/goacc/kernels-decompose-pr104061-1-3.c: Likewise. * c-c++-common/goacc/kernels-decompose-pr104061-1-4.c: Likewise. * c-c++-common/goacc/kernels-decompose-pr104132-1.c: Likewise. * c-c++-common/goacc/kernels-decompose-pr104133-1.c: Likewise. * c-c++-common/goacc/kernels-decompose-pr104774-1.c: Likewise. * c-c++-common/goacc/mdc-1.c: Likewise.
2025-09-24gimple-fold/fab: Move ASSUME_ALIGNED handling to gimple-fold [PR121762]Andrew Pinski2-4/+21
This is the next patch in the series of removing fab. This one is simplier than builtin_constant_p because the only time we want to simplify this builtin is at the final folding step. Note align-5.c needs to change slightly as __builtin_assume_aligned is no longer taken into account for the same reason as why PR 111875 is closed as invalid and why the testcase is failing at -Og I added a new testcase align-5a.c where the pointer is explictly aligned so that the check is gone there. Note __builtin_assume_aligned should really be instrumented for UBSAN, I filed PR 122038 for that. Bootstrapped and tested on x86_64-linux-gnu. PR tree-optimization/121762 gcc/ChangeLog: * gimple-fold.cc (gimple_fold_builtin_assume_aligned): New function. (gimple_fold_builtin): Call gimple_fold_builtin_assume_aligned for BUILT_IN_ASSUME_ALIGNED. * tree-ssa-ccp.cc (pass_fold_builtins::execute): Remove handling of BUILT_IN_ASSUME_ALIGNED. gcc/testsuite/ChangeLog: * c-c++-common/ubsan/align-5.c: Update as __builtin_assume_aligned is no longer taked into account. * c-c++-common/ubsan/align-5a.c: New test. Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-09-11testsuite: Add tests for PR c/107419 and PR c++/107393H.J. Lu3-0/+50
Both C and C++ frontends should set a tentative TLS model in grokvardecl and update TLS mode with the default TLS access model after a TLS variable has been fully processed if the default TLS access model is stronger. PR c/107419 PR c++/107393 * c-c++-common/tls-attr-common.c: New test. * c-c++-common/tls-attr-le-pic.c: Likewise. * c-c++-common/tls-attr-le-pie.c: Likewise. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-26testsuite; Fix unprotected-allocas-1.c at -O3 [PR121684]Andrew Pinski1-2/+2
The problem here is after r16-101, the 2 functions containing alloca/VLA start to be cloned and then we un-VLA happens in using_vararray so this is no longer testing what it should be testing. The obvious fix is to mark using_vararray and using_alloca as noclone too. Pushed as obvious after a quick test to make sure it is now working. gcc/testsuite/ChangeLog: PR testsuite/121684 * c-c++-common/hwasan/unprotected-allocas-0.c: Mark using_vararray and using_alloca as noclone too. Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
2025-08-26OpenMP: Improve front-end error-checking for "declare variant"Sandra Loosemore1-2/+2
This patch fixes a number of problems with parser error checking of "declare variant", especially in the C front end. The new C testcase unprototyped-variant.c added by this patch used to ICE when gimplifying the call site, at least in part because the variant was being recorded even after it was diagnosed as invalid. There was also a large block of dead code in the C front end that was supposed to fix up an unprototyped declaration of a variant function to match the base function declaration, that was never executed because it was nested in a conditional that could never be true. I've fixed those problems by rearranging the code and only recording the variant if it passes the correctness checks. I also tried to add some comments and re-work some particularly confusing bits of code, so that it's easier to understand. The OpenMP specification doesn't say what the behavior of "declare variant" with the "append_args" clause should be when the base function is unprototyped. The additional arguments are supposed to be inserted between the last fixed argument of the base function and any varargs, but without a prototype, for any given call we have no idea which arguments are fixed and which are varargs, and therefore no idea where to insert the additional arguments. This used to trigger some other diagnostics (which one depending on whether the variant was also unprototyped), but I thought it was better to just reject this with an explicit "sorry". Finally, I also observed that a missing "match" clause was only rejected if "append_args" or "adjust_args" was present. Per the spec, "match" has the "required" property, so if it's missing it should be diagnosed unconditionally. The C++ and Fortran front ends had the same issue so I fixed this one there too. gcc/c/ChangeLog * c-parser.cc (c_finish_omp_declare_variant): Rework diagnostic code. Do not record variant if there are errors. Make check for a missing "match" clause unconditional. gcc/cp/ChangeLog * parser.cc (cp_finish_omp_declare_variant): Structure diagnostic code similarly to C front end. Make check for a missing "match" clause unconditional. gcc/fortran/ChangeLog * openmp.cc (gfc_match_omp_declare_variant): Make check for a missing "match" clause unconditional. gcc/testsuite/ChangeLog * c-c++-common/gomp/append-args-1.c: Adjust expected output. * g++.dg/gomp/adjust-args-1.C: Likewise. * g++.dg/gomp/adjust-args-3.C: Likewise. * gcc.dg/gomp/adjust-args-1.c: Likewise: * gcc.dg/gomp/append-args-1.c: Likewise. * gcc.dg/gomp/unprototyped-variant.c: New. * gfortran.dg/gomp/adjust-args-1.f90: Adjust expected output. * gfortran.dg/gomp/append_args-1.f90: Likewise.
2025-08-15c++: Warn on #undef/#define of remaining cpp.predefined macros [PR120778]Jakub Jelinek1-6/+6
We already warn on #undef or pedwarn on #define (but not on #define after #undef) of some builtin macros mentioned in cpp.predefined. The C++26 P2843R3 paper changes it from (compile time) undefined behavior to ill-formed. The following patch arranges for warning (for #undef) and pedwarn (on #define) for the remaining cpp.predefined macros. __cpp_* feature test macros only for C++20 which added some of them to cpp.predefined, in earlier C++ versions it was just an extension and for pedantic diagnostic I think we don't need to diagnose anything, __STDCPP_* and __cplusplus macros for all C++ versions where they appeared. Like the earlier posted -Wkeyword-macro diagnostics (which is done regardless whether the identifier is defined as a macro or not, obviously most likely none of the keywords are defined as macros initially), this one also warns on #undef when a macro isn't defined or later #define after #undef. 2025-08-15 Jakub Jelinek <jakub@redhat.com> PR preprocessor/120778 PR target/121520 gcc/c-family/ * c-cppbuiltin.cc (c_cpp_builtins): Implement C++26 DR 2581. Add cpp_define_warn lambda and use it as well as cpp_warn where needed. In the if (c_dialect_cxx ()) block with __cpp_* predefinitions add cpp_define lambda. Formatting fixes. gcc/c/ * c-decl.cc (c_init_decl_processing): Use cpp_warn instead of cpp_lookup and NODE_WARN bit setting. gcc/cp/ * lex.cc (cxx_init): Remove warn_on lambda. Use cpp_warn instead of cpp_lookup and NODE_WARN bit setting or warn_on. gcc/testsuite/ * g++.dg/DRs/dr2581-1.C: New test. * g++.dg/DRs/dr2581-2.C: New test. * c-c++-common/cpp/pr92296-2.c: Expect warnings also on defining special macros after undefining them. libcpp/ * include/cpplib.h (struct cpp_options): Add suppress_builtin_macro_warnings member. (cpp_warn): New inline functions. * init.cc (cpp_create_reader): Clear suppress_builtin_macro_warnings. (cpp_init_builtins): Call cpp_warn on __cplusplus, __STDC__, __STDC_VERSION__, __STDC_MB_MIGHT_NEQ_WC__ and __STDCPP_STRICT_POINTER_SAFETY__ when appropriate. * directives.cc (do_undef): Warn on undefining NODE_WARN macros if not cpp_keyword_p. Don't emit any NODE_WARN related diagnostics if CPP_OPTION (pfile, suppress_builtin_macro_warnings). (cpp_define, _cpp_define_builtin, cpp_undef): Temporarily set CPP_OPTION (pfile, suppress_builtin_macro_warnings) around run_directive calls. * macro.cc (_cpp_create_definition): Warn on defining NODE_WARN macros if they weren't previously defined and not cpp_keyword_p. Ignore NODE_WARN for diagnostics if CPP_OPTION (pfile, suppress_builtin_macro_warnings).
2025-08-08tailc: Handle other forms of finally_tmp.N conditional cleanups after ↵Jakub Jelinek4-0/+196
musttail [PR121389] My earlier r16-1886 PR120608 change incorrectly assumed that the finally_tmp.N vars introduced by eh pass will be only initialized to values 0 and 1 and there will be only EQ_EXPR/NE_EXPR comparisons of those. The following testcases show that is a bad assumption, the eh pass sets finally_tmp.N vars to 0 up to some highest index depending on hoiw many different exits there are from the finally region. And it emits then switch (finally_tmp.N) statement for all the different cases. So, if it uses more than 0/1 indexes, the lowering of the switch can turn it into a series of GIMPLE_CONDs, if (finally_tmp.N_M > 15) goto ... else goto ... if (finally_tmp.N_M > 7) goto ... else goto ... etc. (and that also means no longer single uses). And if unlucky, we can see a non-lowered GIMPLE_SWITCH as well. So, the following patch removes the assumption that it has to be 0/1 and EQ_EXPR/NE_EXPR, allows all the normal integral comparisons and handles GIMPLE_SWITCH too. 2025-08-08 Jakub Jelinek <jakub@redhat.com> PR middle-end/121389 * tree-tailcall.cc (find_tail_calls): For finally_tmp.N handle not just GIMPLE_CONDs with EQ_EXPR/NE_EXPR and only values 0 and 1, but arbitrary non-negative values, arbitrary comparisons in conditions and also GIMPLE_SWITCH next to GIMPLE_CONDs. * c-c++-common/asan/pr121389-1.c: New test. * c-c++-common/asan/pr121389-2.c: New test. * c-c++-common/asan/pr121389-3.c: New test. * c-c++-common/asan/pr121389-4.c: New test.
2025-08-06c++: Add test for vt/ff in line commentsJakub Jelinek2-0/+24
P2843R3 dropped the "If there is a form-feed or a vertical-tab character in such a comment, only whitespace characters shall appear between it and the new-line that terminates the comment; no diagnostic is required." sentence from [lex.comment]. AFAIK we've never diagnosed nor checked for that and C23 doesn't have anything like that, so the following testcase merely tests that we don't diagnose anything on it. 2025-08-06 Jakub Jelinek <jakub@redhat.com> PR preprocessor/120778 * c-c++-common/cpp/comment-ff-1.c: New test. * c-c++-common/cpp/comment-vtab-1.c: New test.
2025-08-06openmp: Add support for iterators in 'target update' clauses (C/C++)Kwok Cheung Yeung3-0/+61
This adds support for iterators in 'to' and 'from' clauses in the 'target update' OpenMP directive. gcc/c/ * c-parser.cc (c_parser_omp_clause_from_to): Parse 'iterator' modifier. * c-typeck.cc (c_finish_omp_clauses): Finish iterators for to/from clauses. gcc/cp/ * parser.cc (cp_parser_omp_clause_from_to): Parse 'iterator' modifier. * semantics.cc (finish_omp_clauses): Finish iterators for to/from clauses. gcc/ * gimplify.cc (remove_unused_omp_iterator_vars): Display unused variable warning for 'to' and 'from' clauses. (gimplify_scan_omp_clauses): Add argument for iterator loop sequence. Gimplify the clause decl and size into the iterator loop if iterators are used. (gimplify_omp_workshare): Add argument for iterator loops sequence in call to gimplify_scan_omp_clauses. (gimplify_omp_target_update): Call remove_unused_omp_iterator_vars and build_omp_iterators_loops. Add loop sequence as argument when calling gimplify_scan_omp_clauses, gimplify_adjust_omp_clauses and building the Gimple statement. * tree-pretty-print.cc (dump_omp_clause): Call dump_omp_iterators for to/from clauses with iterators. * tree.cc (omp_clause_num_ops): Add extra operand for OMP_CLAUSE_FROM and OMP_CLAUSE_TO. * tree.h (OMP_CLAUSE_HAS_ITERATORS): Add check for OMP_CLAUSE_TO and OMP_CLAUSE_FROM. (OMP_CLAUSE_ITERATORS): Likewise. gcc/testsuite/ * c-c++-common/gomp/target-update-iterators-1.c: New. * c-c++-common/gomp/target-update-iterators-2.c: New. * c-c++-common/gomp/target-update-iterators-3.c: New. libgomp/ * target.c (gomp_update): Call gomp_merge_iterator_maps. Free allocated variables. * testsuite/libgomp.c-c++-common/target-update-iterators-1.c: New. * testsuite/libgomp.c-c++-common/target-update-iterators-2.c: New. * testsuite/libgomp.c-c++-common/target-update-iterators-3.c: New.
2025-08-06openmp: Add support for iterators in map clauses (C/C++)Kwok Cheung Yeung5-10/+115
This adds preliminary support for iterators in map clauses within OpenMP 'target' constructs (which includes constructs such as 'target enter data'). Iterators with non-constant loop bounds are not currently supported. gcc/c/ * c-parser.cc (c_parser_omp_variable_list): Use location of the map expression as the clause location. (c_parser_omp_clause_map): Parse 'iterator' modifier. * c-typeck.cc (c_finish_omp_clauses): Finish iterators. Apply iterators to generated clauses. gcc/cp/ * parser.cc (cp_parser_omp_clause_map): Parse 'iterator' modifier. * semantics.cc (finish_omp_clauses): Finish iterators. Apply iterators to generated clauses. gcc/ * gimple-pretty-print.cc (dump_gimple_omp_target): Print expanded iterator loops. * gimple.cc (gimple_build_omp_target): Add argument for iterator loops sequence. Initialize iterator loops field. * gimple.def (GIMPLE_OMP_TARGET): Set GSS symbol to GSS_OMP_TARGET. * gimple.h (gomp_target): Set GSS symbol to GSS_OMP_TARGET. Add extra field for iterator loops. (gimple_build_omp_target): Add argument for iterator loops sequence. (gimple_omp_target_iterator_loops): New. (gimple_omp_target_iterator_loops_ptr): New. (gimple_omp_target_set_iterator_loops): New. * gimplify.cc (find_var_decl): New. (copy_omp_iterator): New. (remap_omp_iterator_var_1): New. (remap_omp_iterator_var): New. (remove_unused_omp_iterator_vars): New. (struct iterator_loop_info_t): New type. (iterator_loop_info_map_t): New type. (build_omp_iterators_loops): New. (enter_omp_iterator_loop_context_1): New. (enter_omp_iterator_loop_context): New. (enter_omp_iterator_loop_context): New. (exit_omp_iterator_loop_context): New. (gimplify_adjust_omp_clauses): Add argument for iterator loop sequence. Gimplify the clause decl and size into the iterator loop if iterators are used. (gimplify_omp_workshare): Call remove_unused_omp_iterator_vars and build_omp_iterators_loops for OpenMP target expressions. Add loop sequence as argument when calling gimplify_adjust_omp_clauses and building the Gimple statement. * gimplify.h (enter_omp_iterator_loop_context): New prototype. (exit_omp_iterator_loop_context): New prototype. * gsstruct.def (GSS_OMP_TARGET): New. * omp-low.cc (lower_omp_map_iterator_expr): New. (lower_omp_map_iterator_size): New. (finish_omp_map_iterators): New. (lower_omp_target): Add sorry if iterators used with deep mapping. Call lower_omp_map_iterator_expr before assigning to sender ref. Call lower_omp_map_iterator_size before setting the size. Insert iterator loop sequence before the statements for the target clause. * tree-nested.cc (convert_nonlocal_reference_stmt): Walk the iterator loop sequence of OpenMP target statements. (convert_local_reference_stmt): Likewise. (convert_tramp_reference_stmt): Likewise. * tree-pretty-print.cc (dump_omp_iterators): Dump extra iterator information if present. (dump_omp_clause): Call dump_omp_iterators for iterators in map clauses. * tree.cc (omp_clause_num_ops): Add operand for OMP_CLAUSE_MAP. (walk_tree_1): Do not walk last operand of OMP_CLAUSE_MAP. * tree.h (OMP_CLAUSE_HAS_ITERATORS): New. (OMP_CLAUSE_ITERATORS): New. gcc/testsuite/ * c-c++-common/gomp/map-6.c (foo): Amend expected error message. * c-c++-common/gomp/target-map-iterators-1.c: New. * c-c++-common/gomp/target-map-iterators-2.c: New. * c-c++-common/gomp/target-map-iterators-3.c: New. * c-c++-common/gomp/target-map-iterators-4.c: New. libgomp/ * target.c (kind_to_name): New. (gomp_merge_iterator_maps): New. (gomp_map_vars_internal): Call gomp_merge_iterator_maps. Copy address of only the first iteration to target vars. Free allocated variables. * testsuite/libgomp.c-c++-common/target-map-iterators-1.c: New. * testsuite/libgomp.c-c++-common/target-map-iterators-2.c: New. * testsuite/libgomp.c-c++-common/target-map-iterators-3.c: New. Co-authored-by: Andrew Stubbs <ams@baylibre.com>
2025-08-05libcpp: Add testcase for CWG2579 [PR120778]Jakub Jelinek1-5/+5
Another easy part from the paper. Part of the CWG2579 has been already done in an earlier paper (with test commits by Marek) and the remaining part is implemented correctly, we diagnose as error when token pasting doesn't form a valid token. Except that message pasting """" and """" does not give a valid preprocessing token looked weird and so I've updated the message to use %< and %> instead of \" quoting. 2025-08-05 Jakub Jelinek <jakub@redhat.com> PR preprocessor/120778 * macro.cc (paste_tokens): Use %< and %> instead of \" in diagnostics around %.*s. * g++.dg/DRs/dr2579.C: New test. * c-c++-common/cpp/va-opt-6.c: Expect ' rather than \" around tokens in incorrect pasting diagnostics. * gcc.dg/c23-attr-syntax-6.c: Likewise. * gcc.dg/cpp/paste12.c: Likewise. * gcc.dg/cpp/paste12-2.c: Likewise. * gcc.dg/cpp/paste14.c: Likewise. * gcc.dg/cpp/paste14-2.c: Likewise.
2025-07-29calls: Allow musttail calls to noreturn [PR121159]Jakub Jelinek1-0/+17
In the PR119483 r15-9003 change we've allowed musttail calls to noreturn functions, after all the decision not to normally tail call noreturn functions is not because it is not possible to tail call those, but because it screws up backtraces. As the following testcase shows, we've done that only for functions not declared [[noreturn]]/_Noreturn but later on discovered through IPA as noreturn. Functions explicitly declared [[noreturn]] have (for historical reasons) volatile FUNCTION_TYPE and the FUNCTION_DECLs are volatile as well, so in order to support those we shouldn't complain on ECF_NORETURN (we've stopped doing so for musttail in PR119483) but also shouldn't complain about TYPE_VOLATILE on their FUNCTION_TYPE (something that IPA doesn't change, I think it only sets TREE_THIS_VOLATILE on the FUNCTION_DECL). volatile on function type really means noreturn as well, it has no other meaning. 2025-07-29 Jakub Jelinek <jakub@redhat.com> PR middle-end/121159 * calls.cc (can_implement_as_sibling_call_p): Don't reject declared noreturn functions in musttail calls. * c-c++-common/pr121159.c: New test. * gcc.dg/plugin/must-tail-call-2.c (test_5): Don't expect an error.
2025-07-15c, c++: Fix unused result for empty types [PR82134]Jeremy Rifkin1-0/+16
Hi, This fixes PR c/82134 which concerns gcc emitting an incorrect unused result diagnostic for empty types. This diagnostic is emitted from tree-cfg.cc because of a couple code paths which attempt to avoid copying empty types, resulting in GIMPLE that isn't using the returned value of a call. To fix this I've added suppress_warning in three locations and a corresponding check in do_warn_unused_result. Cheers, Jeremy PR c/82134 gcc/cp/ChangeLog: * call.cc (build_call_a): Add suppress_warning * cp-gimplify.cc (cp_gimplify_expr): Add suppress_warning gcc/ChangeLog: * gimplify.cc (gimplify_modify_expr): Add suppress_warning * tree-cfg.cc (do_warn_unused_result): Check warning_suppressed_p gcc/testsuite/ChangeLog: * c-c++-common/attr-warn-unused-result-2.c: New test. Signed-off-by: Jeremy Rifkin <jeremy@rifkin.dev>
2025-07-15c, c++: Extend -Wunused-but-set-* warnings [PR44677]Jakub Jelinek13-2/+662
The -Wunused-but-set-* warnings work by using 2 bits on VAR_DECLs & PARM_DECLs, TREE_USED and DECL_READ_P. If neither is set, we typically emit -Wunused-variable or -Wunused-parameter warning, that is for variables which are just declared (including initializer) and completely unused. If TREE_USED is set and DECL_READ_P is unset, -Wunused-but-set-* warnings are emitted, i.e. for variables which can appear on the lhs of an assignment expression but aren't actually used elsewhere. The DECL_READ_P marking is done through mark_exp_read called from lots of places (e.g. lvalue to rvalue conversions etc.). LLVM has an extension on top of that in that it doesn't count pre/post inc/decrements as use (i.e. DECL_READ_P for GCC). The following patch does that too, though because we had the current behavior for 11+ years already and lot of people is -Wunused-but-set-* warning free in the current GCC behavior and not in the clang one (including GCC sources), it allows users to choose. Furthermore, it implements another level, where also var @= expr uses of var (except when it is also used in expr) aren't counted as DECL_READ_P. I think it would be nice to also handle var = var @ expr or var = expr @ var but unfortunately mark_exp_read is then done in both FEs during parsing of var @ expr or expr @ var and the code doesn't know it is rhs of an assignment with var as lhs. The patch works mostly by checking if DECL_READ_P is clear at some point and then clearing it again after some operation which might have set it. -Wunused or -Wall or -Wunused -Wextra or -Wall -Wextra turn on the 3 level of the new warning (i.e. the one which ignores also var++, ++var etc. as well as var @= expr), so does -Wunused-but-set-{variable,parameter}, but users can use explicit -Wunused-but-set-{variable,parameter}={1,2} to select a different level. 2025-07-15 Jakub Jelinek <jakub@redhat.com> Jason Merrill <jason@redhat.com> PR c/44677 gcc/ * common.opt (Wunused-but-set-parameter=, Wunused-but-set-variable=): New options. (Wunused-but-set-parameter, Wunused-but-set-variable): Turn into aliases. * common.opt.urls: Regenerate. * diagnostic-spec.cc (nowarn_spec_t::nowarn_spec_t): Use OPT_Wunused_but_set_variable_ instead of OPT_Wunused_but_set_variable and OPT_Wunused_but_set_parameter_ instead of OPT_Wunused_but_set_parameter. * gimple-ssa-store-merging.cc (find_bswap_or_nop_1): Remove unused but set variable tmp. * ipa-strub.cc (pass_ipa_strub::execute): Cast named_args to (void) if ATTR_FNSPEC_DECONST_WATERMARK is not defined. * doc/invoke.texi (Wunused-but-set-parameter=, Wunused-but-set-variable=): Document new options. (Wunused-but-set-parameter, Wunused-but-set-variable): Adjust documentation now that they are just aliases. gcc/c-family/ * c-opts.cc (c_common_post_options): Change warn_unused_but_set_parameter and warn_unused_but_set_variable from 1 to 3 if they were set only implicitly. * c-attribs.cc (build_attr_access_from_parms): Remove unused but set variable nelts. gcc/c/ * c-parser.cc (c_parser_unary_expression): Clear DECL_READ_P after default_function_array_read_conversion for -Wunused-but-set-{parameter,variable}={2,3} on PRE{IN,DE}CREMENT_EXPR argument. (c_parser_postfix_expression_after_primary): Similarly for POST{IN,DE}CREMENT_EXPR. * c-decl.cc (pop_scope): Use OPT_Wunused_but_set_variable_ instead of OPT_Wunused_but_set_variable. (finish_function): Use OPT_Wunused_but_set_parameter_ instead of OPT_Wunused_but_set_parameter. * c-typeck.cc (mark_exp_read): Handle {PRE,POST}{IN,DE}CREMENT_EXPR and don't handle it when cast to void. (build_modify_expr): Clear DECL_READ_P after build_binary_op for -Wunused-but-set-{parameter,variable}=3. gcc/cp/ * cp-gimplify.cc (cp_fold): Clear DECL_READ_P on lhs of MODIFY_EXPR after cp_fold_rvalue if it wasn't set before. * decl.cc (poplevel): Use OPT_Wunused_but_set_variable_ instead of OPT_Wunused_but_set_variable. (finish_function): Use OPT_Wunused_but_set_parameter_ instead of OPT_Wunused_but_set_parameter. * expr.cc (mark_use): Clear read_p for {PRE,POST}{IN,DE}CREMENT_EXPR cast to void on {VAR,PARM}_DECL for -Wunused-but-set-{parameter,variable}={2,3}. (mark_exp_read): Handle {PRE,POST}{IN,DE}CREMENT_EXPR and don't handle it when cast to void. * module.cc (trees_in::fn_parms_fini): Remove unused but set variable ix. * semantics.cc (finish_unary_op_expr): Return early for PRE{IN,DE}CREMENT_EXPR. * typeck.cc (cp_build_unary_op): Clear DECL_READ_P after mark_lvalue_use for -Wunused-but-set-{parameter,variable}={2,3} on PRE{IN,DE}CREMENT_EXPR argument. (cp_build_modify_expr): Clear DECL_READ_P after cp_build_binary_op for -Wunused-but-set-{parameter,variable}=3. gcc/go/ * gofrontend/gogo.cc (Function::export_func_with_type): Remove unused but set variable i. gcc/cobol/ * gcobolspec.cc (lang_specific_driver): Remove unused but set variable n_cobol_files. gcc/testsuite/ * c-c++-common/Wunused-parm-1.c: New test. * c-c++-common/Wunused-parm-2.c: New test. * c-c++-common/Wunused-parm-3.c: New test. * c-c++-common/Wunused-parm-4.c: New test. * c-c++-common/Wunused-parm-5.c: New test. * c-c++-common/Wunused-parm-6.c: New test. * c-c++-common/Wunused-var-7.c (bar, baz): Expect warning on a. * c-c++-common/Wunused-var-19.c: New test. * c-c++-common/Wunused-var-20.c: New test. * c-c++-common/Wunused-var-21.c: New test. * c-c++-common/Wunused-var-22.c: New test. * c-c++-common/Wunused-var-23.c: New test. * c-c++-common/Wunused-var-24.c: New test. * g++.dg/cpp26/name-independent-decl1.C (foo): Expect one set but not used warning. * g++.dg/warn/Wunused-parm-12.C: New test. * g++.dg/warn/Wunused-parm-13.C: New test. * g++.dg/warn/Wunused-var-2.C (f2): Expect set but not used warning on parameter x and variable a. * g++.dg/warn/Wunused-var-40.C: New test. * g++.dg/warn/Wunused-var-41.C: New test. * gcc.dg/memchr-3.c (test_find): Change return type from void to int, and add return n; statement. * gcc.dg/unused-9.c (g): Move dg-bogus to the correct line and expect a warning on i.
2025-07-11testsuite: Add testcase for already fixed PR [PR120954]Jakub Jelinek1-0/+21
This was a regression introduced by r16-1893 (and its backports) for C++, though for C it had false positive warning for years. Fixed by r16-2000 (and its backports). 2025-07-11 Jakub Jelinek <jakub@redhat.com> PR c++/120954 * c-c++-common/Warray-bounds-11.c: New test.
2025-07-11ipa: Disallow signature changes in fun->has_musttail functions [PR121023]Jakub Jelinek1-0/+23
As the following testcase shows e.g. on ia32, letting IPA opts change signature of functions which have [[{gnu,clang}::musttail]] calls can turn programs that would be compiled normally into something that is rejected because the caller has fewer argument stack slots than the function being tail called. The following patch prevents signature changes for such functions. It is perhaps too big hammer in some cases, but it might be hard to try to figure out what signature changes are still acceptable and which are not at IPA time. 2025-07-11 Jakub Jelinek <jakub@redhat.com> Martin Jambor <mjambor@suse.cz> PR ipa/121023 * ipa-fnsummary.cc (compute_fn_summary): Disallow signature changes on cfun->has_musttail functions. * c-c++-common/musttail32.c: New test.
2025-07-03OpenMP: Add omp_get_initial_device/omp_get_num_devices builtins: Fix test casesThomas Schwinge1-2/+2
With this fix-up for commit 387209938d2c476a67966c6ddbdbf817626f24a2 "OpenMP: Add omp_get_initial_device/omp_get_num_devices builtins", we progress: PASS: c-c++-common/gomp/omp_get_num_devices_initial_device.c (test for excess errors) PASS: c-c++-common/gomp/omp_get_num_devices_initial_device.c scan-tree-dump-not optimized "abort" -FAIL: c-c++-common/gomp/omp_get_num_devices_initial_device.c scan-tree-dump-times optimized "omp_get_num_devices;" 1 +PASS: c-c++-common/gomp/omp_get_num_devices_initial_device.c scan-tree-dump-times optimized "omp_get_num_devices" 1 PASS: c-c++-common/gomp/omp_get_num_devices_initial_device.c scan-tree-dump optimized "_1 = __builtin_omp_get_num_devices \\(\\);[\\r\\n]+[ ]+return _1;" ... etc. for offloading configurations. gcc/testsuite/ * c-c++-common/gomp/omp_get_num_devices_initial_device.c: Fix. * gfortran.dg/gomp/omp_get_num_devices_initial_device.f90: Likewise.
2025-07-01tailc: Handle musttail in case of non-cleaned-up cleanups, especially ASan ↵Jakub Jelinek2-0/+66
related [PR120608] The following testcases FAIL at -O0 -fsanitize=address. The problem is we end up with something like _26 = foo (x_24(D)); [must tail call] // predicted unlikely by early return (on trees) predictor. finally_tmp.3_27 = 0; goto <bb 5>; [INV] ... <bb 5> : # _6 = PHI <_26(3), _23(D)(4)> # finally_tmp.3_8 = PHI <finally_tmp.3_27(3), finally_tmp.3_22(4)> .ASAN_MARK (POISON, &c, 4); if (finally_tmp.3_8 == 1) goto <bb 7>; [INV] else goto <bb 6>; [INV] <bb 6> : <L4>: finally_tmp.4_31 = 0; goto <bb 8>; [INV] ... <bb 8> : # finally_tmp.4_9 = PHI <finally_tmp.4_31(6), finally_tmp.4_30(7)> .ASAN_MARK (POISON, &b, 4); if (finally_tmp.4_9 == 1) goto <bb 9>; [INV] else goto <bb 10>; [INV] ... <bb 10> : # _7 = PHI <_6(8), _34(9)> .ASAN_MARK (POISON, &a, 4); <bb 11> : <L11>: return _7; before the sanopt pass. This is -O0, we don't try to do forward propagation, jump threading etc. And what is worse, the sanopt pass lowers the .ASAN_MARK calls that the tailc/musttail passes already handle into somewthing that they can't easily pattern match. The following patch fixes that by 1) moving the musttail pass 2 passes earlier (this is mostly just for -O0/-Og, for normal optimization levels musttail calls are handled in the tailc pass), i.e. across the sanopt and cleanup_eh passes 2) recognizes these finally_tmp SSA_NAME assignments, PHIs using those and GIMPLE_CONDs deciding based on those both on the backwards walk (when we start from the edges to EXIT) and forwards walk (when we find a candidate tail call and process assignments after those up to the return statement). For backwards walk, ESUCC argument has been added which is either NULL for the noreturn musttail case, or the succ edge through which we've reached bb and if it sees GIMPLE_COND with such comparison, based on the ESUCC and comparison it will remember which later edges to ignore later on and which bb must be walked up to the start during tail call discovery (the one with the PHI). 3) the move of musttail pass across cleanup_eh pass resulted in g++.dg/opt/pr119613.C regressions but moving cleanup_eh before sanopt doesn't work too well, so I've extended empty_eh_cleanup to also handle resx which doesn't throw externally I know moving a pass on release branches feels risky, though the musttail pass is only relevant to functions with musttail calls, so something quite rare and only at -O0/-Og (unless one e.g. disables the tailc pass). 2025-07-01 Jakub Jelinek <jakub@redhat.com> PR middle-end/120608 * passes.def (pass_musttail): Move before pass_sanopt. * tree-tailcall.cc (empty_eh_cleanup): Handle GIMPLE_RESX which doesn't throw externally through recursion on single eh edge (if any and cnt still allows that). (find_tail_calls): Add ESUCC, IGNORED_EDGES and MUST_SEE_BBS arguments. Handle GIMPLE_CONDs for non-simplified cleanups with finally_tmp temporaries both on backward and forward walks, adjust recursive call. (tree_optimize_tail_calls_1): Adjust find_tail_calls callers. * c-c++-common/asan/pr120608-3.c: New test. * c-c++-common/asan/pr120608-4.c: New test. * g++.dg/asan/pr120608-3.C: New test. * g++.dg/asan/pr120608-4.C: New test.
2025-06-30diagnostics: remove "json" output formatDavid Malcolm9-204/+0
The "json" output format for diagnostics was deprecated in GCC 15, with advice to users seeking machine-readable diagnostics from GCC to use SARIF instead. This patch eliminates it from GCC 16, simplifying the diagnostics subsystem somewhat. Note that the Ada frontend seems to have its own implementation of this in errout.adb (Output_JSON_Message), and documented in gnat_ugn.texi. This patch does not touch Ada. gcc/ChangeLog: * Makefile.in (OBJS-libcommon): Drop diagnostic-format-json.o. * common.opt (fdiagnostics-format=): Drop "json|json-stderr|json-file". (diagnostics_output_format): Drop values "json", "json-stderr", and "json-file". * diagnostic-format-json.cc: Delete file. * diagnostic-format.h (diagnostic_output_format_init_json_stderr): Delete. (diagnostic_output_format_init_json_file): Delete. * diagnostic.cc (diagnostic_output_format_init): Delete cases for DIAGNOSTICS_OUTPUT_FORMAT_JSON_STDERR and DIAGNOSTICS_OUTPUT_FORMAT_JSON_FILE. * diagnostic.h (DIAGNOSTICS_OUTPUT_FORMAT_JSON_STDERR): Delete. (DIAGNOSTICS_OUTPUT_FORMAT_JSON_FILE): Delete. * doc/invoke.texi: Remove references to json output format. * doc/ux.texi: Likewise. * selftest-run-tests.cc (selftest::run_tests): Drop call to deleted selftest::diagnostic_format_json_cc_tests. * selftest.h (selftest::diagnostic_format_json_cc_tests): Delete. gcc/testsuite/ChangeLog: * c-c++-common/analyzer/out-of-bounds-diagram-1-json.c: Deleted test. * c-c++-common/diagnostic-format-json-1.c: Deleted test. * c-c++-common/diagnostic-format-json-2.c: Deleted test. * c-c++-common/diagnostic-format-json-3.c: Deleted test. * c-c++-common/diagnostic-format-json-4.c: Deleted test. * c-c++-common/diagnostic-format-json-5.c: Deleted test. * c-c++-common/diagnostic-format-json-file-1.c: Deleted test. * c-c++-common/diagnostic-format-json-stderr-1.c: Deleted test. * c-c++-common/pr106133.c: Deleted test. * g++.dg/pr90462.C: Deleted test. * gcc.dg/plugin/diagnostic-test-paths-3.c: Deleted test. * gcc.dg/plugin/plugin.exp (plugin_test_list): Remove deleted test. * gfortran.dg/diagnostic-format-json-1.F90: Deleted test. * gfortran.dg/diagnostic-format-json-2.F90: Deleted test. * gfortran.dg/diagnostic-format-json-3.F90: Deleted test. * gfortran.dg/diagnostic-format-json-pr105916.F90: Deleted test. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-06-30Extend nonnull_if_nonzero attribute [PR120520]Jakub Jelinek2-0/+73
C2Y voted in the https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3466.pdf paper, which clarifies some of the conditional nonnull cases. For strncat/__strncat_chk no changes are necessary, we already use __attribute__((nonnull (1), nonnull_if_nonzero (2, 3))) attributes on the builtin and glibc can do the same too, meaning that first argument must be nonnull always and second must be nonnull if the third one is nonzero. The problem is with the fread/fwrite changes, where the paper adds: If size or nmemb is zero, +ptr may be a null pointer, fread returns zero and the contents of the array and the state of the stream remain unchanged. and ditto for fwrite, so the two argument nonnull_if_nonzero attribute isn't usable to express that, because whether the pointer can be null depends on 2 integral arguments rather than one. The following patch extends the nonnull_if_nonzero attribute, so that instead of requiring 2 arguments it allows 2 or 3, the first one is still the pointer argument index which sometimes must not be null and the other one or two are integral arguments, if there are 2, the invalid case is only if pointer is null and both the integral arguments are nonzero. 2025-06-30 Jakub Jelinek <jakub@redhat.com> PR c/120520 PR c/117023 gcc/ * builtin-attrs.def (DEF_LIST_INT_INT_INT): Define it and use for 1,2,3. (ATTR_NONNULL_IF123_LIST): New DEF_ATTR_TREE_LIST. (ATTR_NONNULL_4_IF123_LIST): Likewise. * builtins.def (BUILT_IN_FWRITE): Use ATTR_NONNULL_4_IF123_LIST instead of ATTR_NONNULL_LIST. (BUILT_IN_FWRITE_UNLOCKED): Likewise. * gimple.h (infer_nonnull_range_by_attribute): Add another optional tree * argument defaulted to NULL. * gimple.cc (infer_nonnull_range_by_attribute): Add OP3 argument, handle 3 argument nonnull_if_nonzero attribute. * builtins.cc (validate_arglist): Handle 3 argument nonnull_if_nonzero attribute. * tree-ssa-ccp.cc (pass_post_ipa_warn::execute): Likewise. * ubsan.cc (instrument_nonnull_arg): Adjust infer_nonnull_range_by_attribute caller, handle 3 argument nonnull_if_nonzero attribute. * gimple-range-infer.cc (gimple_infer_range::gimple_infer_range): Handle 3 argument nonnull_if_nonzero attribute. * doc/extend.texi (nonnull_if_nonzero): Document 3 argument version of the attribute. gcc/c-family/ * c-attribs.cc (c_common_gnu_attributes): Allow 2 or 3 arguments for nonnull_if_nonzero attribute instead of only 2. (handle_nonnull_if_nonzero_attribute): Handle 3 argument nonnull_if_nonzero. * c-common.cc (struct nonnull_arg_ctx): Rename other member to other1, add other2 member. (check_function_nonnull): Clear a if nonnull attribute has an argument. Adjust for nonnull_arg_ctx changes. Handle 3 argument nonnull_if_nonzero attribute. (check_nonnull_arg): Adjust for nonnull_arg_ctx changes, emit different diagnostics for 3 argument nonnull_if_nonzero attributes. (check_function_arguments): Adjust ctx var initialization. gcc/analyzer/ * sm-malloc.cc (malloc_state_machine::on_stmt): Handle 3 argument nonnull_if_nonzero attribute. gcc/testsuite/ * gcc.dg/nonnull-9.c: Tweak for 3 argument nonnull_if_nonzero attribute support, add further tests. * gcc.dg/nonnull-12.c: New test. * gcc.dg/nonnull-13.c: New test. * gcc.dg/nonnull-14.c: New test. * c-c++-common/ubsan/nonnull-8.c: New test. * c-c++-common/ubsan/nonnull-9.c: New test.
2025-06-23OpenACC: Add 'if' clause to 'acc wait' directiveTobias Burnus1-0/+51
OpenACC 3.0 added the 'if' clause to four directives; this patch only adds it to 'acc wait'. gcc/c-family/ChangeLog: * c-omp.cc (c_finish_oacc_wait): Handle if clause. gcc/c/ChangeLog: * c-parser.cc (OACC_WAIT_CLAUSE_MASK): Add if clause. gcc/cp/ChangeLog: * parser.cc (OACC_WAIT_CLAUSE_MASK): Ass if clause. gcc/fortran/ChangeLog: * openmp.cc (OACC_WAIT_CLAUSES): Add if clause. * trans-openmp.cc (gfc_trans_oacc_wait_directive): Handle it. gcc/testsuite/ChangeLog: * c-c++-common/goacc/acc-wait-1.c: New test. * gfortran.dg/goacc/acc-wait-1.f90: New test.
2025-06-23tailc: Allow musttail tail calls with -fsanitize=address [PR120608]Jakub Jelinek2-0/+82
These testcases show another problem with -fsanitize=address vs. musttail tail calls. In particular, there can be .ASAN_MARK (POISON, &a, 4); etc. calls after a tail call and those just prevent the tailc pass to mark the musttail calls as [tail call]. Normally, the sanopt pass (which comes after tailc) will optimize those away, the optimization is if there are no .ASAN_CHECK calls or normal function calls dominated by those .ASAN_MARK (POSION, ...) calls, the poison is not needed, because in the epilog sequence (the one dealt with in the patch posted earlier today) all the stack slots are unpoisoned anyway (or poisoned for use-after-return). Unlike __builtin_tsan_exit_function, .ASAN_MARK is not a real function and is always expanded inline, so can be never tail called successfully, so the patch just ignores those for the cfun->has_musttail && diag_musttail cases. If there is a non-musttail call, it will fail worst case during expansion because there is the epilog asan sequence. 2025-06-12 Jakub Jelinek <jakub@redhat.com> PR middle-end/120608 * tree-tailcall.cc (empty_eh_cleanup): Ignore .ASAN_MARK (POISON) internal calls for the cfun->has_musttail case and diag_musttail. (find_tail_calls): Likewise. * c-c++-common/asan/pr120608-1.c: New test. * c-c++-common/asan/pr120608-2.c: New test.
2025-06-11c/c++: Handle '#pragma GCC target optimize' early [PR48026]Gwenole Beauchesne1-0/+10
Handle '#pragma GCC optimize' earlier as the __OPTIMIZE__ macro may need to be defined as well for certain usages. Add additional tests for the '#pragma GCC target' case with auto-vectorization enabled and multiple combinations of namespaces and/or class member functions. This is similar to what was done for `#pramga GCC target` in r14-4967-g8697d3a1dcf327, to fix the similar issue there. Add more complete tests for PR c++/41201 after git commit r14-4967-g8697d3a1dcf327. PR c++/41201 PR c++/48026 gcc/c-family/ChangeLog: * c-pragma.cc (init_pragma): Use c_register_pragma_with_early_handler instead of c_register_pragma for `#pragma GCC optimize`. gcc/testsuite/ChangeLog: * c-c++-common/pragma-optimize-1.c: New test. * g++.target/i386/vect-pragma-target-1.C: New test. * g++.target/i386/vect-pragma-target-2.C: New test. * gcc.target/i386/vect-pragma-target-1.c: New test. * gcc.target/i386/vect-pragma-target-2.c: New test. Signed-off-by: Gwenole Beauchesne <gb.devel@gmail.com> Co-authored-by: Andrew Pinski <quic_apinski@quicinc.com>
2025-06-06OpenMP: Add omp_get_initial_device/omp_get_num_devices builtinsTobias Burnus2-0/+61
By adding omp_get_initial_device and omp_get_num_devices builtins for C, C++, and Fortran, the following can be achieved: * By making them pure, multiple calls can be avoiding in some cases. * Some comparisons can be optimized at compile time. omp_get_initial_device will be converted to omp_get_num_devices for consistency; note that OpenMP 6 also permits omp_initial_device (== -1) as value. If GCC has not been configure for offloading, either intrinsic will leads to 0 - and on the offload side, -1 (= omp_initial_device) is returned for omp_initial_device. gcc/fortran/ChangeLog: * f95-lang.cc (ATTR_PURE_NOTHROW_LIST): Define. * trans-expr.cc (get_builtin_fn): Handle omp_get_num_devices and omp_get_intrinsic_device. * gfortran.h (gfc_option_t): Add disable_omp_... for them. * options.cc (gfc_handle_option): Handle them with -fno-builtin-. gcc/ChangeLog: * gimple-fold.cc (gimple_fold_builtin_omp_get_initial_device, gimple_fold_builtin_omp_get_num_devices): New. (gimple_fold_builtin): Call them. * omp-builtins.def (BUILT_IN_OMP_GET_INITIAL_DEVICE): Add (BUILT_IN_OMP_GET_NUM_DEVICES): Make uservisible + pure. libgomp/ChangeLog: * libgomp.texi (omp_get_num_devices, omp_get_intrinsic_device): Document builtin handling. gcc/testsuite/ChangeLog: * c-c++-common/gomp/omp_get_num_devices_initial_device-2.c: New test. * c-c++-common/gomp/omp_get_num_devices_initial_device.c: New test. * gfortran.dg/gomp/omp_get_num_devices_initial_device-2.f90: New test. * gfortran.dg/gomp/omp_get_num_devices_initial_device.f90: New test. Co-authored-by: Sandra Loosemore <sloosemore@baylibre.com>
2025-06-02OpenMP: Handle more cases in user/condition selectorSandra Loosemore4-3/+46
Tobias had noted that the C front end was not treating C23 constexprs as constant in the user/condition selector property, which led to missed opportunities to resolve metadirectives at parse time. Additionally neither C nor C++ was permitting the expression to have pointer or floating-point type -- the former being a common idiom in other C/C++ conditional expressions. By using the existing front-end hooks for the implicit conversion to bool in conditional expressions, we also get free support for using a C++ class object that has a bool conversion operator in the user/condition selector. gcc/c/ChangeLog * c-parser.cc (c_parser_omp_context_selector): Call convert_lvalue_to_rvalue and c_objc_common_truthvalue_conversion on the expression for OMP_TRAIT_PROPERTY_BOOL_EXPR. gcc/cp/ChangeLog * cp-tree.h (maybe_convert_cond): Declare. * parser.cc (cp_parser_omp_context_selector): Call maybe_convert_cond and fold_build_cleanup_point_expr on the expression for OMP_TRAIT_PROPERTY_BOOL_EXPR. * pt.cc (tsubst_omp_context_selector): Likewise. * semantics.cc (maybe_convert_cond): Remove static declaration. gcc/testsuite/ChangeLog * c-c++-common/gomp/declare-variant-2.c: Update expected output. * c-c++-common/gomp/metadirective-condition-constexpr.c: New. * c-c++-common/gomp/metadirective-condition.c: New. * c-c++-common/gomp/metadirective-error-recovery.c: Update expected output. * g++.dg/gomp/metadirective-condition-class.C: New. * g++.dg/gomp/metadirective-condition-template.C: New.
2025-05-30OpenMP: Support OpenMP 5.0 "declare mapper" directives for CJulian Brown11-18/+88
This patch adds support for "declare mapper" directives (and the "mapper" modifier on "map" clauses) for C. gcc/c/ChangeLog: * c-decl.cc (c_omp_mapper_id, c_omp_mapper_decl, c_omp_mapper_lookup, c_omp_extract_mapper_directive, c_omp_map_array_section, c_omp_scan_mapper_bindings_r, c_omp_scan_mapper_bindings): New functions. * c-objc-common.h (LANG_HOOKS_OMP_FINISH_MAPPER_CLAUSES, LANG_HOOKS_OMP_MAPPER_LOOKUP, LANG_HOOKS_OMP_EXTRACT_MAPPER_DIRECTIVE, LANG_HOOKS_OMP_MAP_ARRAY_SECTION): Define langhooks for C. * c-parser.cc (c_parser_omp_clause_map): Add declare_mapper_p parameter; handle mapper modifier. (c_parser_omp_all_clauses): Update call to c_parser_omp_clause_map. (c_parser_omp_target): Instantiate explicit mappers and record bindings for implicit mappers. (c_parser_omp_declare_mapper): Parse "declare mapper" directives. (c_parser_omp_declare): Support "declare mapper". (c_parser_omp_declare_reduction): Use inform not error_at. * c-tree.h (c_omp_finish_mapper_clauses, c_omp_mapper_lookup, c_omp_extract_mapper_directive, c_omp_map_array_section, c_omp_mapper_id, c_omp_mapper_decl, c_omp_scan_mapper_bindings, c_omp_instantiate_mappers): Add prototypes. * c-typeck.cc (c_finish_omp_clauses): Handle GOMP_MAP_PUSH_MAPPER_NAME and GOMP_MAP_POP_MAPPER_NAME. (c_omp_finish_mapper_clauses): New function (langhook). libgomp/ChangeLog: * testsuite/libgomp.c-c++-common/declare-mapper-9.c: Enable for C. * testsuite/libgomp.c-c++-common/declare-mapper-10.c: Likewise. * testsuite/libgomp.c-c++-common/declare-mapper-11.c: Likewise. * testsuite/libgomp.c-c++-common/declare-mapper-12.c: Likewise. * testsuite/libgomp.c-c++-common/declare-mapper-13.c: Likewise. * testsuite/libgomp.c-c++-common/declare-mapper-14.c: Likewise. gcc/testsuite/ChangeLog: * c-c++-common/gomp/declare-mapper-3.c: Enable for C. * c-c++-common/gomp/declare-mapper-4.c: Likewise. * c-c++-common/gomp/declare-mapper-5.c: Likewise. * c-c++-common/gomp/declare-mapper-6.c: Likewise. * c-c++-common/gomp/declare-mapper-7.c: Likewise. * c-c++-common/gomp/declare-mapper-8.c: Likewise. * c-c++-common/gomp/declare-mapper-9.c: Likewise. * c-c++-common/gomp/declare-mapper-10.c: Likewise. * c-c++-common/gomp/declare-mapper-12.c: Likewise. * c-c++-common/gomp/map-6.c: Update dg-error. * gcc.dg/gomp/udr-3.c: Update for change to dg-note. * c-c++-common/gomp/declare-mapper-11.c: New. * gcc.dg/gomp/declare-mapper-10.c: New test. * gcc.dg/gomp/declare-mapper-11.c: New test. * gcc.dg/gomp/declare-mapper-13.c: New test.