gcc/libgomp
Jakub Jelinek 650e915665 c++: Implement C++23 P2718R0 - Wording for P2644R1 Fix for Range-based for Loop [PR107637]
The following patch implements the C++23 P2718R0 paper
- Wording for P2644R1 Fix for Range-based for Loop.
The patch introduces a new option, -f{,no-}range-for-ext-temps so that
user can control the behavior even in older C++ versions.
The option is on by default in C++23 and later (-fno-range-for-ext-temps
is an error in that case) and in the -std=gnu++11 ... -std=gnu++20 modes
(one can use -fno-range-for-ext-temps to request previous behavior in that
case), and is not enabled by default in -std=c++11 ... -std=c++20 modes
but one can explicitly enable it with -frange-for-ext-temps.
As all the temporaries from __for_range initialization should have life
extended until the end of __for_range scope, this patch disables (for
-frange-for-ext-temps and if !processing_template_decl) CLEANUP_POINT_EXPR wrapping
of the __for_range declaration, also disables -Wdangling-reference warning
as well as the rest of extend_ref_init_temps (we know the __for_range temporary
is not TREE_STATIC and as all the temporaries from the initializer will be life
extended, we shouldn't try to handle temporaries referenced by references any
differently) and adds an extra push_stmt_list/pop_stmt_list before
cp_finish_decl of __for_range and after end of the for body and wraps all
that into CLEANUP_POINT_EXPR.
I had to repeat that also for OpenMP range loops because those are handled
differently.

2024-09-24  Jakub Jelinek  <jakub@redhat.com>

	PR c++/107637
gcc/
	* omp-general.cc (find_combined_omp_for, find_nested_loop_xform):
	Handle CLEANUP_POINT_EXPR like TRY_FINALLY_EXPR.
	* doc/invoke.texi (frange-for-ext-temps): Document.  Add
	-fconcepts to the C++ option list.
gcc/c-family/
	* c.opt (frange-for-ext-temps): New option.
	* c-opts.cc (c_common_post_options): Set flag_range_for_ext_temps
	for C++23 or later or for C++11 or later in !flag_iso mode if
	the option wasn't set by user.
	* c-cppbuiltin.cc (c_cpp_builtins): Change __cpp_range_based_for
	value for flag_range_for_ext_temps from 201603L to 202212L in C++17
	or later.
	* c-omp.cc (c_find_nested_loop_xform_r): Handle CLEANUP_POINT_EXPR
	like TRY_FINALLY_EXPR.
gcc/cp/
	* cp-tree.h: Implement C++23 P2718R0 - Wording for P2644R1 Fix for
	Range-based for Loop.
	(cp_convert_omp_range_for): Add bool tmpl_p argument.
	(find_range_for_decls): Declare.
	* parser.cc (cp_convert_range_for): For flag_range_for_ext_temps call
	push_stmt_list () before cp_finish_decl for range_temp and save it
	temporarily to FOR_INIT_STMT.
	(cp_convert_omp_range_for): Add tmpl_p argument.  If set, remember
	DECL_NAME of range_temp and for cp_finish_decl call restore it before
	clearing it again, if unset, don't adjust DECL_NAME of range_temp at
	all.
	(cp_parser_omp_loop_nest): For flag_range_for_ext_temps range for add
	CLEANUP_POINT_EXPR around sl.  Call find_range_for_decls and adjust
	DECL_NAMEs for range fors if not processing_template_decl.  Adjust
	cp_convert_omp_range_for caller.  Remove superfluous backslash at the
	end of line.
	* decl.cc (initialize_local_var): For flag_range_for_ext_temps
	temporarily clear stmts_are_full_exprs_p rather than set for
	for_range__identifier decls.
	* call.cc (extend_ref_init_temps): For flag_range_for_ext_temps return
	init early for for_range__identifier decls.
	* semantics.cc (find_range_for_decls): New function.
	(finish_for_stmt): Use it.  For flag_range_for_ext_temps if
	cp_convert_range_for set FOR_INIT_STMT, pop_stmt_list it and wrap
	into CLEANUP_POINT_EXPR.
	* pt.cc (tsubst_omp_for_iterator): Adjust tsubst_omp_for_iterator
	caller.
	(tsubst_stmt) <case OMP_FOR>: For flag_range_for_ext_temps if there
	are any range fors in the loop nest, add push_stmt_list starting
	before the initializations, pop_stmt_list it after the body and wrap
	into CLEANUP_POINT_EXPR.  Change DECL_NAME of range for temps from
	NULL to for_range_identifier.
gcc/testsuite/
	* g++.dg/cpp23/range-for1.C: New test.
	* g++.dg/cpp23/range-for2.C: New test.
	* g++.dg/cpp23/range-for3.C: New test.
	* g++.dg/cpp23/range-for4.C: New test.
	* g++.dg/cpp23/range-for5.C: New test.
	* g++.dg/cpp23/range-for6.C: New test.
	* g++.dg/cpp23/range-for7.C: New test.
	* g++.dg/cpp23/range-for8.C: New test.
	* g++.dg/cpp23/feat-cxx2b.C (__cpp_range_based_for): Check for
	202212L rather than 201603L.
	* g++.dg/cpp26/feat-cxx26.C (__cpp_range_based_for): Likewise.
	* g++.dg/warn/Wdangling-reference4.C: Don't expect warning for C++23
	or newer.  Use dg-additional-options rather than dg-options.
libgomp/
	* testsuite/libgomp.c++/range-for-1.C: New test.
	* testsuite/libgomp.c++/range-for-2.C: New test.
	* testsuite/libgomp.c++/range-for-3.C: New test.
	* testsuite/libgomp.c++/range-for-4.C: New test.
	* testsuite/libgomp.c++/range-for-5.C: New test.
2024-09-24 20:24:57 +02:00
..
config OpenMP: Add get_device_from_uid/omp_get_uid_from_device routines 2024-09-20 09:25:33 +02:00
plugin OpenMP: Add support for 'self_maps' to the 'require' directive 2024-09-24 10:53:59 +02:00
testsuite c++: Implement C++23 P2718R0 - Wording for P2644R1 Fix for Range-based for Loop [PR107637] 2024-09-24 20:24:57 +02:00
.gitattributes libgomp: Fixes + cleanup for OpenACC's Fortran module + openacc_lib.h 2020-02-19 09:13:44 +01:00
acc_prof.h Update copyright years. 2024-01-03 12:19:35 +01:00
acinclude.m4 libgomp: fix typo in mold linker detection 2022-06-28 10:35:32 +02:00
aclocal.m4 libgomp: Regenerate configure files with automake 1.15.1 2020-10-02 12:08:47 +02:00
affinity-fmt.c Update copyright years. 2024-01-03 12:19:35 +01:00
affinity.c Update copyright years. 2024-01-03 12:19:35 +01:00
alloc.c Update copyright years. 2024-01-03 12:19:35 +01:00
allocator.c libgomp, openmp: Add ompx_gnu_pinned_mem_alloc 2024-07-01 10:59:59 +00:00
atomic.c Update copyright years. 2024-01-03 12:19:35 +01:00
barrier.c Update copyright years. 2024-01-03 12:19:35 +01:00
basic-allocator.c Update copyright years. 2024-01-03 12:19:35 +01:00
ChangeLog Daily bump. 2024-09-24 00:18:14 +00:00
ChangeLog.graphite
config.h.in Refactor '-ldl' handling for libgomp proper and plugins 2022-05-12 15:11:30 +02:00
configure libgomp: Fix up FLOCK fallback handling [PR113192] 2024-01-10 13:32:02 +01:00
configure.ac libgomp: Fix up FLOCK fallback handling [PR113192] 2024-01-10 13:32:02 +01:00
configure.tgt libgomp: Define config_path for hppa*-*-linux* 2024-02-11 20:23:14 +00:00
critical.c Update copyright years. 2024-01-03 12:19:35 +01:00
env.c libgomp, openmp: Add ompx_gnu_pinned_mem_alloc 2024-07-01 10:59:59 +00:00
error.c Update copyright years. 2024-01-03 12:19:35 +01:00
fortran.c OpenMP: Fix omp_get_device_from_uid, minor cleanup 2024-09-23 15:58:39 +02:00
hashtab.h Update copyright years. 2024-01-03 12:19:35 +01:00
icv-device.c Update copyright years. 2024-01-03 12:19:35 +01:00
icv.c Update copyright years. 2024-01-03 12:19:35 +01:00
iter_ull.c Update copyright years. 2024-01-03 12:19:35 +01:00
iter.c Update copyright years. 2024-01-03 12:19:35 +01:00
libgomp_f.h.in Update copyright years. 2024-01-03 12:19:35 +01:00
libgomp_g.h Update copyright years. 2024-01-03 12:19:35 +01:00
libgomp-plugin.c Update copyright years. 2024-01-03 12:19:35 +01:00
libgomp-plugin.h OpenMP: Add get_device_from_uid/omp_get_uid_from_device routines 2024-09-20 09:25:33 +02:00
libgomp.h OpenMP: Add get_device_from_uid/omp_get_uid_from_device routines 2024-09-20 09:25:33 +02:00
libgomp.map OpenMP: Fix omp_get_device_from_uid, minor cleanup 2024-09-23 15:58:39 +02:00
libgomp.spec.in
libgomp.texi OpenMP: Add support for 'self_maps' to the 'require' directive 2024-09-24 10:53:59 +02:00
lock.c Update copyright years. 2024-01-03 12:19:35 +01:00
loop_ull.c Update copyright years. 2024-01-03 12:19:35 +01:00
loop.c Update copyright years. 2024-01-03 12:19:35 +01:00
Makefile.am build: Derive object names in make_sunver.pl 2024-05-07 13:14:05 +02:00
Makefile.in build: Derive object names in make_sunver.pl 2024-05-07 13:14:05 +02:00
oacc-async.c Update copyright years. 2024-01-03 12:19:35 +01:00
oacc-cuda.c Update copyright years. 2024-01-03 12:19:35 +01:00
oacc-host.c OpenMP: Fix omp_get_device_from_uid, minor cleanup 2024-09-23 15:58:39 +02:00
oacc-init.c Update copyright years. 2024-01-03 12:19:35 +01:00
oacc-int.h Update copyright years. 2024-01-03 12:19:35 +01:00
oacc-mem.c OpenACC 2.7: Adjust acc_map_data/acc_unmap_data interaction with reference counters 2024-04-16 09:04:11 +00:00
oacc-parallel.c Update copyright years. 2024-01-03 12:19:35 +01:00
oacc-plugin.c Update copyright years. 2024-01-03 12:19:35 +01:00
oacc-plugin.h Update copyright years. 2024-01-03 12:19:35 +01:00
oacc-profiling.c Update copyright years. 2024-01-03 12:19:35 +01:00
oacc-target.c
omp_lib.f90.in OpenMP: Fix omp_get_device_from_uid, minor cleanup 2024-09-23 15:58:39 +02:00
omp_lib.h.in OpenMP: Fix omp_get_device_from_uid, minor cleanup 2024-09-23 15:58:39 +02:00
omp.h.in OpenMP: Add get_device_from_uid/omp_get_uid_from_device routines 2024-09-20 09:25:33 +02:00
openacc_lib.h OpenACC: Add Fortran routines acc_{alloc,free,hostptr,deviceptr,memcpy_{to,from}_device*} 2024-02-27 17:30:38 +01:00
openacc.f90 OpenACC: Add Fortran routines acc_{alloc,free,hostptr,deviceptr,memcpy_{to,from}_device*} 2024-02-27 17:30:38 +01:00
openacc.h Update copyright years. 2024-01-03 12:19:35 +01:00
ordered.c Update copyright years. 2024-01-03 12:19:35 +01:00
parallel.c Update copyright years. 2024-01-03 12:19:35 +01:00
priority_queue.c Update copyright years. 2024-01-03 12:19:35 +01:00
priority_queue.h Fix up duplicated words mostly in comments, part 1 2024-04-02 13:39:11 +02:00
scope.c Update copyright years. 2024-01-03 12:19:35 +01:00
sections.c Update copyright years. 2024-01-03 12:19:35 +01:00
secure_getenv.h Update copyright years. 2024-01-03 12:19:35 +01:00
single.c Update copyright years. 2024-01-03 12:19:35 +01:00
splay-tree.c Update copyright years. 2024-01-03 12:19:35 +01:00
splay-tree.h Update copyright years. 2024-01-03 12:19:35 +01:00
target-indirect.c Update copyright years. 2024-01-03 12:19:35 +01:00
target.c libgomp: with USM, init 'link' variables with host address 2024-09-24 17:41:39 +02:00
task.c Update copyright years. 2024-01-03 12:19:35 +01:00
taskloop.c Update copyright years. 2024-01-03 12:19:35 +01:00
team.c Update copyright years. 2024-01-03 12:19:35 +01:00
teams.c Update copyright years. 2024-01-03 12:19:35 +01:00
work.c Update copyright years. 2024-01-03 12:19:35 +01:00