summaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c++/bdv_module2.C
diff options
context:
space:
mode:
authorSandra Loosemore <sloosemore@baylibre.com>2025-11-20 21:45:09 +0000
committerSandra Loosemore <sloosemore@baylibre.com>2025-11-22 17:05:22 +0000
commita469cf3df2ac97944a44948891e9fe22ba2f1d10 (patch)
tree735f89ddef0e2968b4f87611fc31724a68b9a210 /libgomp/testsuite/libgomp.c++/bdv_module2.C
parent31107ba466715f3f662e9ddcefd5c33c483d0a31 (diff)
OpenMP: C++ front end support for "begin declare variant"
This patch implements C++ support for the "begin declare variant" construct. The OpenMP specification is hazy on interaction of this feature with C++ language features. Variant functions in classes are supported but must be defined as members in the class definition, using an unqualified name for the base function which also must be present in that class. Similarly variant functions in a namespace can only be defined in that namespace using an unqualified name for a base function already declared in that namespace. Variants for template functions or inside template classes seem to (mostly) work. gcc/c-family/ChangeLog * c-omp.cc (c_omp_directives): Uncomment "begin declare variant" and "end declare variant". gcc/cp/ChangeLog * cp-tree.h (struct cp_omp_declare_variant_attr): New. (struct saved_scope): Add omp_declare_variant_attribute field. * decl.cc (omp_declare_variant_finalize_one): Add logic to inject "this" parameter for method calls. * parser.cc (cp_parser_skip_to_pragma_omp_end_declare_variant): New. (cp_parser_translation_unit): Handle leftover "begin declare variant" functions. (omp_start_variant_function): New. (omp_finish_variant_function): New. (omp_maybe_record_variant_base): New. (cp_parser_init_declarator): Handle variant functions. (cp_parser_class_specifier): Handle deferred lookup of base functions when the entire class has been seen. (cp_parser_member_declaration): Handle variant functions. (cp_finish_omp_declare_variant): Merge context selectors if in a "begin declare variant" block. (cp_parser_omp_begin): Match "omp begin declare variant". Adjust error messages. (cp_parser_omp_end): Match "omp end declare variant". * parser.h (struct omp_begin_declare_variant_map_entry): New. (struct cp_parser): Add omp_begin_declare_variant_map field. * semantics.cc (finish_translation_unit): Detect unmatched "omp begin declare variant". gcc/testsuite/ChangeLog * g++.dg/gomp/delim-declare-variant-1.C: New. * g++.dg/gomp/delim-declare-variant-2.C: New. * g++.dg/gomp/delim-declare-variant-3.C: New. * g++.dg/gomp/delim-declare-variant-4.C: New. * g++.dg/gomp/delim-declare-variant-5.C: New. * g++.dg/gomp/delim-declare-variant-6.C: New. * g++.dg/gomp/delim-declare-variant-7.C: New. * g++.dg/gomp/delim-declare-variant-40.C: New. * g++.dg/gomp/delim-declare-variant-41.C: New. * g++.dg/gomp/delim-declare-variant-50.C: New. * g++.dg/gomp/delim-declare-variant-51.C: New. * g++.dg/gomp/delim-declare-variant-52.C: New. * g++.dg/gomp/delim-declare-variant-70.C: New. * g++.dg/gomp/delim-declare-variant-71.C: New. libgomp/ * testsuite/libgomp.c++/bdv_module1.C: New. * testsuite/libgomp.c++/bdv_module1_main.C: New. * testsuite/libgomp.c++/bdv_module2.C: New. * testsuite/libgomp.c++/bdv_module2_impl.C: New. * testsuite/libgomp.c++/bdv_module2_main.C: New. * testsuite/libgomp.c++/bdv_module3.C: New. * testsuite/libgomp.c++/bdv_module3_impl.C: New. * testsuite/libgomp.c++/bdv_module3_main.C: New. * testsuite/libgomp.c++/delim-declare-variant-1.C: New. * testsuite/libgomp.c++/delim-declare-variant-2.C: New. * testsuite/libgomp.c++/delim-declare-variant-7.C: New. Co-Authored-By: Julian Brown <julian@codesourcery.com> Co-Authored-By: waffl3x <waffl3x@baylibre.com>
Diffstat (limited to 'libgomp/testsuite/libgomp.c++/bdv_module2.C')
-rw-r--r--libgomp/testsuite/libgomp.c++/bdv_module2.C15
1 files changed, 15 insertions, 0 deletions
diff --git a/libgomp/testsuite/libgomp.c++/bdv_module2.C b/libgomp/testsuite/libgomp.c++/bdv_module2.C
new file mode 100644
index 00000000000..5152d324d3f
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c++/bdv_module2.C
@@ -0,0 +1,15 @@
+// Test that "begin declare variant" in a module implementation unit is
+// visible only in that unit.
+
+// { dg-additional-sources "bdv_module2_impl.C bdv_module2_main.C" }
+// { dg-additional-options "-fmodules" }
+
+export module bdv_module2;
+
+export int
+test ()
+{
+ return 0;
+}
+
+export void doit ();