On 4/21/25 6:46 AM, Nathaniel Shead wrote:
I don't really know how OpenMP works, hopefully this makes sense.
Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk?
And for 15 (I guess after release)?
This is OK with a FIXME; presumably if we want to support running static
constructors on the offload target we will eventually want to support
that in modules as well.
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.
PR c++/119864
gcc/cp/ChangeLog:
* decl2.cc (start_objects): Only use module initialized for
host.
gcc/testsuite/ChangeLog:
* g++.dg/modules/openmp-1.C: New test.
Signed-off-by: Nathaniel Shead <nathanielosh...@gmail.com>
---
gcc/cp/decl2.cc | 4 +++-
gcc/testsuite/g++.dg/modules/openmp-1.C | 9 +++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/g++.dg/modules/openmp-1.C
diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index 21156f1dd3b..5ce2fa76ce2 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -4184,7 +4184,9 @@ 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 ();
+ bool is_module_init = (default_init
+ && !omp_target
+ && module_global_init_needed ());
tree name = NULL_TREE;
if (is_module_init)
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 00000000000..b5a30ad8c91
--- /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();