aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/parser.h
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2021-07-02 21:59:21 +0200
committerJakub Jelinek <jakub@redhat.com>2021-07-02 21:59:21 +0200
commit9984f63aab93a370101966b7eb198dc61130b3c8 (patch)
tree88a41229e3f99fe790101d1400024e8e30d90909 /gcc/cp/parser.h
parent2ca89394280da4afad6074ec3cb7136b6142af7b (diff)
downloadgcc-9984f63aab93a370101966b7eb198dc61130b3c8.zip
gcc-9984f63aab93a370101966b7eb198dc61130b3c8.tar.gz
gcc-9984f63aab93a370101966b7eb198dc61130b3c8.tar.bz2
openmp: Initial support for OpenMP directives expressed as C++11 attributes
This is an OpenMP 5.1 feature, but I think it is something very useful for OpenMP users, so I'm committing it now instead of waiting until all 5.0 work is done. The support is incomplete, only attributes on statements (or block local declarations) are supported right now, while for non-executable directives they should be also supported at namespace scope and at class scope, and for declarations in all places that appertain to the declarations rather than e.g. types. I need to also fix up handling of C++11 non-OpenMP attributes mixed with OpenMP attributes before block local declarations (currently it throws them away), probably reject if the directives appertain to labels etc. In order not to complicate all the OpenMP directive parsing, it is done by remembering the tokens from the attribute, slightly adjusting them and feeding them through a temporary new lexer to cp_parse_pragma. 2021-07-02 Jakub Jelinek <jakub@redhat.com> gcc/c-family/ * c-common.h (enum c_omp_directive_kind): New enum. (struct c_omp_directive): New type. (c_omp_categorize_directive): Declare. * c-omp.c (omp_directives): New variable. (c_omp_categorize_directive): New function. gcc/cp/ * parser.h (struct cp_lexer): Add in_omp_attribute_pragma member. (struct cp_omp_declare_simd_data): Likewise. * cp-tree.h (enum cp_tree_index): Add CPTI_OMP_IDENTIFIER. (omp_identifier): Define. * parser.c (cp_parser_skip_to_pragma_eol): Handle in_omp_attribute_pragma CPP_PRAGMA_EOL followed by CPP_EOF. (cp_parser_require_pragma_eol): Likewise. (struct cp_omp_attribute_data): New type. (cp_parser_handle_statement_omp_attributes): New function. (cp_parser_statement): Handle OpenMP directives in statement's attribute-specifier-seq. (cp_parser_omp_directive_args, cp_parser_omp_sequence_args): New functions. (cp_parser_std_attribute): Handle omp::directive and omp::sequence attributes. (cp_parser_omp_all_clauses): If in_omp_attribute_pragma, allow a comma also before the first clause. (cp_parser_omp_allocate): Likewise. (cp_parser_omp_atomic): Likewise. (cp_parser_omp_depobj): Likewise. (cp_parser_omp_flush): Likewise. (cp_parser_omp_ordered): Likewise. (cp_parser_omp_declare_simd): Save in_omp_attribute_pragma into struct cp_omp_declare_simd_data. (cp_finish_omp_declare_variant): Add in_omp_attribute_pragma argument. If set, allow a comma also before match clause. (cp_parser_late_parsing_omp_declare_simd): If in_omp_attribute_pragma, allow a comma also before the first clause. Adjust cp_finish_omp_declare_variant caller. (cp_parser_omp_declare_target): If in_omp_attribute_pragma, allow a comma also before the first clause. (cp_parser_omp_declare_reduction_exprs): Likewise. (cp_parser_omp_requires): Likewise. * decl.c (initialize_predefined_identifiers): Initialize omp_identifier. * decl2.c (cplus_decl_attributes): Reject omp::directive and omp::sequence attributes. gcc/testsuite/ * g++.dg/gomp/attrs-1.C: New test. * g++.dg/gomp/attrs-2.C: New test. * g++.dg/gomp/attrs-3.C: New test.
Diffstat (limited to 'gcc/cp/parser.h')
-rw-r--r--gcc/cp/parser.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/gcc/cp/parser.h b/gcc/cp/parser.h
index a468b69..5ef7047 100644
--- a/gcc/cp/parser.h
+++ b/gcc/cp/parser.h
@@ -113,6 +113,10 @@ struct GTY (()) cp_lexer {
/* True if we're in the context of parsing a pragma, and should not
increment past the end-of-line marker. */
bool in_pragma;
+
+ /* True if we're in the context of OpenMP directives written as C++11
+ attributes turned into pragma. */
+ bool in_omp_attribute_pragma;
};
@@ -208,6 +212,8 @@ struct cp_omp_declare_simd_data {
bool error_seen; /* Set if error has been reported. */
bool fndecl_seen; /* Set if one fn decl/definition has been seen already. */
bool variant_p; /* Set for #pragma omp declare variant. */
+ bool in_omp_attribute_pragma; /* True if declare simd/variant comes from
+ C++11 attribute rather than pragma. */
vec<cp_token_cache_ptr> tokens;
tree clauses;
};