summaryrefslogtreecommitdiff
path: root/gcc/cp/parser.h
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 /gcc/cp/parser.h
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 'gcc/cp/parser.h')
-rw-r--r--gcc/cp/parser.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/gcc/cp/parser.h b/gcc/cp/parser.h
index 3a17be993f1..3e7251c38a9 100644
--- a/gcc/cp/parser.h
+++ b/gcc/cp/parser.h
@@ -233,6 +233,13 @@ struct cp_oacc_routine_data : cp_omp_declare_simd_data {
tree clauses;
};
+/* Helper data structure for parsing #pragma omp begin declare variant. */
+struct GTY(()) omp_begin_declare_variant_map_entry {
+ tree variant; /* The variant decl. */
+ tree id; /* Name of base function. */
+ tree ctx; /* The context selector associated with the variant. */
+};
+
/* The cp_parser structure represents the C++ parser. */
struct GTY(()) cp_parser {
@@ -458,6 +465,11 @@ struct GTY(()) cp_parser {
outside that file. */
struct omp_metadirective_parse_data * GTY((skip))
omp_metadirective_state;
+
+ /* Recorded information about functions in OpenMP "begin declare variant"
+ constructs that still need to be registered with their base functions. */
+ vec<omp_begin_declare_variant_map_entry, va_gc> *
+ omp_begin_declare_variant_map;
};
/* In parser.cc */