aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathaniel Shead <nathanieloshead@gmail.com>2025-04-21 20:40:29 +1000
committerNathaniel Shead <nathanieloshead@gmail.com>2025-05-14 19:26:24 +1000
commit79b7e37ea3fbbc43958190f69f6da3be3d809c9c (patch)
tree83c1accdd20dbb71ac22afd5c2c90a5587bcf3fa
parent011ea36d0e5828e9db848f4a46b9a17f634ed2c0 (diff)
downloadgcc-79b7e37ea3fbbc43958190f69f6da3be3d809c9c.zip
gcc-79b7e37ea3fbbc43958190f69f6da3be3d809c9c.tar.gz
gcc-79b7e37ea3fbbc43958190f69f6da3be3d809c9c.tar.bz2
c++: Fix OpenMP support with C++20 modules [PR119864]
In r15-2799-gf1bfba3a9b3f31, a new kind of global constructor was added. Unfortunately this broke C++20 modules, as both the host and target constructors were given the same mangled name. This patch ensures that only the host constructor gets the module name mangling for now, and stops forcing the creation of the target constructor even when no such initialization is required. PR c++/119864 gcc/cp/ChangeLog: * decl2.cc (start_objects): Only use module initialized for host. (c_parse_final_cleanups): Don't always create an OMP offload init function in modules. gcc/testsuite/ChangeLog: * g++.dg/modules/openmp-1.C: New test. Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com> Reviewed-by: Jason Merrill <jason@redhat.com>
-rw-r--r--gcc/cp/decl2.cc14
-rw-r--r--gcc/testsuite/g++.dg/modules/openmp-1.C9
2 files changed, 16 insertions, 7 deletions
diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index 15db1d6..a08d173 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -4186,7 +4186,11 @@ start_objects (bool initp, unsigned priority, bool has_body,
bool omp_target = false)
{
bool default_init = initp && priority == DEFAULT_INIT_PRIORITY;
- bool is_module_init = default_init && module_global_init_needed ();
+ /* FIXME: We may eventually want to treat OpenMP offload initializers
+ in modules specially as well. */
+ bool is_module_init = (default_init
+ && !omp_target
+ && module_global_init_needed ());
tree name = NULL_TREE;
if (is_module_init)
@@ -5878,12 +5882,8 @@ c_parse_final_cleanups (void)
if (static_init_fini_fns[true]->get_or_insert (DEFAULT_INIT_PRIORITY))
has_module_inits = true;
- if (flag_openmp)
- {
- if (!static_init_fini_fns[2 + true])
- static_init_fini_fns[2 + true] = priority_map_t::create_ggc ();
- static_init_fini_fns[2 + true]->get_or_insert (DEFAULT_INIT_PRIORITY);
- }
+ /* FIXME: We need to work out what static constructors on OpenMP offload
+ target in modules will look like. */
}
/* Generate initialization and destruction functions for all
diff --git a/gcc/testsuite/g++.dg/modules/openmp-1.C b/gcc/testsuite/g++.dg/modules/openmp-1.C
new file mode 100644
index 0000000..b5a30ad
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/openmp-1.C
@@ -0,0 +1,9 @@
+// PR c++/119864
+// { dg-do assemble }
+// { dg-additional-options "-fmodules -fopenmp" }
+// { dg-require-effective-target "fopenmp" }
+
+export module M;
+
+int foo();
+int x = foo();