Re: [Patch] Fortran: invoke.texi - link to OpenCoarrays.org + mention libcaf_single

2024-05-19 Thread Sandra Loosemore

On 5/19/24 02:01, Tobias Burnus wrote:
I noticed that gfortran's coarray support did not link to the 
http://www.opencoarrays.org/ >

[snip]

diff --git a/gcc/fortran/invoke.texi b/gcc/fortran/invoke.texi
index 40e8e4a7cdd..78a2910b8d8 100644
--- a/gcc/fortran/invoke.texi
+++ b/gcc/fortran/invoke.texi
@@ -1753,7 +1753,10 @@ Single-image mode, i.e. @code{num_images()} is always 
one.
 
 @item @samp{lib}

 Library-based coarray parallelization; a suitable GNU Fortran coarray
-library needs to be linked.
+library needs to be linked such as @url{http://opencoarrays.org}.


This would read better as

library such as @url{http://opencoarrays.org} needs to be linked.


+Alternatively, GCC's @code{libcaf_single} library can be linked,
+albeit it only supports a single image.
+
 @end table


OK with that tweak.

-Sandra





[PATCH 09/12] OpenMP: Extend dynamic selector support to declare variant

2024-05-04 Thread Sandra Loosemore
This patch extends the mechanisms previously added to support dynamic
selectors in metavariant constructs to also apply to "declare
variant".  The front-end mechanisms used to handle "declare variant"
via attributes attached to the function decls remain the same, but the
gimplifier now uses the same internal data structures and helper
functions as metadirective to score and sort "declare variant"
alternatives, and constructs a gomp_metadirective node for variant
calls that cannot be resolved at gimplification time.  During late
resolution, this gomp_metadirective is processed in exactly the same
way as for real metadirectives.

During implementation of this functionality, a number of bugs were
discovered in the previous selector scoring and matching code:

* Metadirective resolution was failing to account for scoring in
  "declare simd" clones, and was also relying on calling a function to
  match construct constructors that's only useful during
  gimplification during late resolution long after that pass.

* The construct constructor scoring was previously implemented backwards
  from the specification (PR114596); a number of testcases were also broken
  in the same way as the implementation.

* The special rules for matching simdlen and aligned properties on simd
  selectors were not implemented (nor were these properties on metadirectives
  being rejected per the OpenMP spec).

This patch includes a new implementation of this functionality that
has cleaner interfaces and is hopefully(!) easier to correlate to
requirements of the OpenMP specification.  Instead of relying on the
gimplifier to score construct selectors, the scoring code has been
consolidated in omp-general.cc with the gimplifier only providing
the OpenMP construct context surrounding the metadirective or variant
call.  This is cached on the gomp_metadirective if necessary for late
resolution.

An additional improvement added in this patch is that for both
metadirective and "declare variant", if late resolution is required the
gimplifier now discards all alternatives that are known not to match.

Note that this patch leaves a substantial amount of dead code that
was used to support the former late "declare variant" resolution strategy,
notably the declare_variant_alt and calls_declare_variant_alt flags on
cgraph_node and all the code that touches those fields.  The next
patch in this series removes that unused code.

Another issue not addressed in this patch is the special scoping rules
for expressions in "declare variant" dynamic selectors, which is still
under discussion in PR113904.  We expect this to be fixed separately.

gcc/c/ChangeLog
* c-parser.c (c_parser_omp_context_selector): Remove metadirective_p
parameter and conditionalization.
(c_parser_omp_context_selector_specification): Remove metadirective_p
parameter and adjust call not to pass it on.
(c_finish_omp_declare_variant): Adjust arguments on calls to
c_parser_omp_context_selector_specification and
omp_context_selector_matches.
(c_parser_omp_metadirective): Likewise.

gcc/cp/ChangeLog
* cp-tree.h (struct saved_scope): Add new field
x_processing_omp_trait_property_expr.
(processing_omp_trait_property_expr): Define
* decl.cc (omp_declare_variant_finalize_one): Adjust arguments
to omp_context_selector_matches.
* parser.cc (cp_parser_omp_context_selector): Remove metadirective_p
argument and conditionalization.
(cp_parser_omp_context_selector_specification): Remove metadirective_p
argument and adjust call not to pass it on.
(cp_finish_omp_declare_variant): Adjust arguments on call to above.
(cp_parser_omp_metadirective): Likewise.
* pt.cc (tsubst_omp_context_selector): Adjust error behavior.
(tsubst_stmt): Adjust call to omp_context_selector_matches.
* semantics.cc (finish_id_expression_1): Do not diagnose error
for use of parameter in declare variant selector here.

gcc/fortran/ChangeLog
* trans-openmp.cc (gfc_trans_omp_declare_variant): Adjust arguments
to omp_context_selector_matches.
(gfc_trans_omp_metadirective): Likewise.

gcc/Changelog
* gimple-streamer-in.cc (input_gimple_stmt): Restore
gomp_metadirective context.
* gimple-streamer-out.cc (output_gimple_stmt): Save
gomp_metadirective context.
* gimple.cc (gimple_build_omp_metadirective): Initialize
gomp_metadirective context.
* gimple.def (GIMPLE_OMP_METADIRECTIVE): Update comments.
* gimple.h (gomp_metadirective): Add context field and update comments.
(gimple_omp_metadirective_context): New.
(gimple_omp_metadirective_set_context): New.
* gimplify.cc (omp_resolved_variant_calls): New.
(gimplify_variant_call_expr): New.
(gimplify_call_expr): Adjust parameters.  Call
gimplify_variant_call_expr to handle 

[PATCH 07/12] OpenMP: Fortran front-end support for metadirectives.

2024-05-04 Thread Sandra Loosemore
etadirective test.
* gfortran.dg/gomp/pure-2.f90: Remove metadirective test.

libgomp/ChangeLog
* testsuite/libgomp.fortran/metadirective-1.f90: New.
* testsuite/libgomp.fortran/metadirective-2.f90: New.
* testsuite/libgomp.fortran/metadirective-3.f90: New.
* testsuite/libgomp.fortran/metadirective-4.f90: New.
* testsuite/libgomp.fortran/metadirective-5.f90: New.
* testsuite/libgomp.fortran/metadirective-6.f90: New.

Co-Authored-By: Kwok Cheung Yeung 
Co-Authored-By: Sandra Loosemore 
Co-Authored-By: Tobias Burnus 
Co-Authored-By: Paul-Antoine Arras 
---
 gcc/fortran/decl.cc   |  29 +
 gcc/fortran/dump-parse-tree.cc|  21 +
 gcc/fortran/gfortran.h|  20 +-
 gcc/fortran/io.cc |   2 +-
 gcc/fortran/match.h   |   2 +
 gcc/fortran/openmp.cc | 294 +++--
 gcc/fortran/parse.cc  | 571 +++---
 gcc/fortran/parse.h   |   8 +-
 gcc/fortran/resolve.cc|   6 +
 gcc/fortran/st.cc |   4 +
 gcc/fortran/symbol.cc |  25 +-
 gcc/fortran/trans-decl.cc |   5 +-
 gcc/fortran/trans-openmp.cc   | 233 ---
 gcc/fortran/trans-stmt.h  |   1 +
 gcc/fortran/trans.cc  |   1 +
 .../gfortran.dg/gomp/metadirective-1.f90  |  55 ++
 .../gfortran.dg/gomp/metadirective-10.f90 |  40 ++
 .../gfortran.dg/gomp/metadirective-11.f90 |  33 +
 .../gfortran.dg/gomp/metadirective-2.f90  |  62 ++
 .../gfortran.dg/gomp/metadirective-3.f90  |  34 ++
 .../gfortran.dg/gomp/metadirective-4.f90  |  39 ++
 .../gfortran.dg/gomp/metadirective-5.f90  |  30 +
 .../gfortran.dg/gomp/metadirective-6.f90  |  31 +
 .../gfortran.dg/gomp/metadirective-7.f90  |  36 ++
 .../gfortran.dg/gomp/metadirective-8.f90  |  22 +
 .../gfortran.dg/gomp/metadirective-9.f90  |  30 +
 .../gomp/metadirective-construct.f90  | 260 
 .../gomp/metadirective-no-score.f90   | 122 
 gcc/testsuite/gfortran.dg/gomp/pure-1.f90 |   7 +
 gcc/testsuite/gfortran.dg/gomp/pure-2.f90 |   8 -
 .../libgomp.fortran/metadirective-1.f90   |  61 ++
 .../libgomp.fortran/metadirective-2.f90   |  40 ++
 .../libgomp.fortran/metadirective-3.f90   |  29 +
 .../libgomp.fortran/metadirective-4.f90   |  46 ++
 .../libgomp.fortran/metadirective-5.f90   |  44 ++
 .../libgomp.fortran/metadirective-6.f90   |  58 ++
 36 files changed, 1947 insertions(+), 362 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-1.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-10.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-11.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-2.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-3.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-4.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-5.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-6.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-7.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-8.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-9.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-construct.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-no-score.f90
 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-1.f90
 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-2.f90
 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-3.f90
 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-4.f90
 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-5.f90
 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-6.f90

diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index b8308aeee55..b6633a913e7 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -8422,6 +8422,7 @@ gfc_match_end (gfc_statement *st)
 
 case COMP_CONTAINS:
 case COMP_DERIVED_CONTAINS:
+case COMP_OMP_BEGIN_METADIRECTIVE:
   state = gfc_state_stack->previous->state;
   block_name = gfc_state_stack->previous->sym == NULL
 ? NULL : gfc_state_stack->previous->sym->name;
@@ -8429,6 +8430,28 @@ gfc_match_end (gfc_statement *st)
&& gfc_state_stack->previous->sym->abr_modproc_decl;
   break;
 
+case COMP_OMP_METADIRECTIVE:
+  {
+   /* Metadirectives can be nested, so we need to drill down to the
+  first state that is not COMP_OMP_METADIRECTIVE.  */
+   gfc_state_data *state_data = gfc_state_stack;
+
+   d

[PATCH 11/12] OpenMP: Update "declare target"/OpenMP context interaction

2024-05-04 Thread Sandra Loosemore
The code and test case previously implemented the OpenMP 5.0 spec,
which said in section 2.3.1:

"For functions within a declare target block, the target trait is added
to the beginning of the set..."

In OpenMP 5.1, this was changed to
"For device routines, the target trait is added to the beginning of
the set..."

In OpenMP 5.2 and TR12, it says:
"For procedures that are determined to be target function variants
by a declare target directive..."

The definition of "device routine" in OpenMP 5.1 is confusing, but
certainly the intent of the later versions of the spec is clear that
it doesn't just apply to functions within a begin declare target/end
declare target block.

The only use of the "omp declare target block" function attribute was
to support the 5.0 language, so it can be removed.  This patch changes
the context augmentation to use the "omp declare target" attribute
instead.

gcc/c-family/ChangeLog
* c-attribs.cc (c_common_gnu_attributes): Delete "omp declare
target block".

gcc/c/ChangeLog
* c-decl.cc (c_decl_attributes): Don't add "omp declare target
block".

gcc/cp/decl2.cc
* decl2.cc (cplus_decl_attributes): Don't add "omp declare target
block".

gcc/ChangeLog
* omp-general.cc (omp_complete_construct_context): Check
"omp declare target" attribute, not "omp declare target block".

gcc/testsuite/ChangeLog
* c-c++-common/gomp/declare-target-indirect-2.c : Adjust
expected output for removal of "omp declare target block".
* c-c++-common/gomp/declare-variant-8.c: Likewise, the variant
call to f20 is now resolved differently.
* c-c++-common/gomp/reverse-offload-1.c: Adjust expected output.
* gfortran.dg/gomp/declare-variant-8.f90: Likewise, both f18
and f20 now resolve to the variant.  Delete obsolete comments.
---
 gcc/c-family/c-attribs.cc|  2 --
 gcc/c/c-decl.cc  |  8 ++--
 gcc/cp/decl2.cc  |  9 ++---
 gcc/omp-general.cc   |  2 +-
 .../c-c++-common/gomp/declare-target-indirect-2.c| 10 +-
 gcc/testsuite/c-c++-common/gomp/declare-variant-8.c  |  4 ++--
 gcc/testsuite/c-c++-common/gomp/reverse-offload-1.c  |  2 +-
 gcc/testsuite/gfortran.dg/gomp/declare-variant-8.f90 | 12 ++--
 8 files changed, 15 insertions(+), 34 deletions(-)

diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc
index 04e39b41bdf..582d99ada1b 100644
--- a/gcc/c-family/c-attribs.cc
+++ b/gcc/c-family/c-attribs.cc
@@ -570,8 +570,6 @@ const struct attribute_spec c_common_gnu_attributes[] =
  handle_omp_declare_target_attribute, NULL },
   { "omp declare target nohost", 0, 0, true, false, false, false,
  handle_omp_declare_target_attribute, NULL },
-  { "omp declare target block", 0, 0, true, false, false, false,
- handle_omp_declare_target_attribute, NULL },
   { "non overlapping",   0, 0, true, false, false, false,
  handle_non_overlapping_attribute, NULL },
   { "alloc_align",   1, 1, false, true, true, false,
diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index 52af8f32998..4ab7cd86030 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -5414,12 +5414,8 @@ c_decl_attributes (tree *node, tree attributes, int 
flags)
attributes = tree_cons (get_identifier ("omp declare target implicit"),
NULL_TREE, attributes);
   else
-   {
- attributes = tree_cons (get_identifier ("omp declare target"),
- NULL_TREE, attributes);
- attributes = tree_cons (get_identifier ("omp declare target block"),
- NULL_TREE, attributes);
-   }
+   attributes = tree_cons (get_identifier ("omp declare target"),
+   NULL_TREE, attributes);
   if (TREE_CODE (*node) == FUNCTION_DECL)
{
  int device_type
diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index 806a2a4bc69..028105a5b26 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -1777,13 +1777,8 @@ cplus_decl_attributes (tree *decl, tree attributes, int 
flags)
  = tree_cons (get_identifier ("omp declare target implicit"),
   NULL_TREE, attributes);
  else
-   {
- attributes = tree_cons (get_identifier ("omp declare target"),
- NULL_TREE, attributes);
- attributes
-   = tree_cons (get_identifier ("omp declare target block"),
-NULL_TREE, attributes);
-   }
+   attributes = tree_cons (get_identifier ("omp declare target"),
+   NULL_TREE, attributes);
  if (TREE_CODE (*decl) == FUNCTION_DECL)
{

[PATCH 10/12] OpenMP: Remove dead code from declare variant reimplementation

2024-05-04 Thread Sandra Loosemore
After reimplementing late resolution of "declare variant" to use the
same mechanisms as metadirective, the declare_variant_alt and
calls_declare_variant_alt flags on struct cgraph_node are no longer
used by anything.  For the purposes of marking functions that need
late resolution, the has_metadirectives flag has replaced
calls_declare_variant_alt.

Likewise struct omp_declare_variant_entry, struct
omp_declare_variant_base_entry, and the hash tables used to store
these structures are no longer needed, since the information needed for
late resolution is now stored in the gomp_metadirective nodes.

There are no functional changes in this patch, just removing dead code.

gcc/ChangeLog
* cgraph.cc (symbol_table::create_edge): Don't set
calls_declare_variant_alt in the caller.
* cgraph.h (struct cgraph_node): Remove declare_variant_alt
and calls_declare_variant_alt flags.
* cgraphclones.cc (cgraph_node::create_clone): Don't copy
calls_declare_variant_alt bit.
* ipa-free-lang-data.cc (free_lang_data_in_decl): Adjust code
referencing declare_variant_alt bit.
* ipa.cc (symbol_table::remove_unreachable_nodes): Likewise.
* lto-cgraph.cc (lto_output_node): Remove references to deleted
bits.
(output_refs): Adjust code referencing declare_variant_alt bit.
(input_overwrite_node): Remove references to deleted bits.
(input_refs): Adjust code referencing declare_variant_alt bit.
* lto-streamer-out.cc (lto_output): Likewise.
* lto-streamer.h (omp_lto_output_declare_variant_alt): Delete.
(omp_lto_input_declare_variant_alt): Delete.
* lto/lto-partition.cc (lto_balanced_map): Adjust code referencing
deleted declare_variant_alt bit.
* omp-expand.cc (expand_omp_target): Use has_metadirectives bit to
trigger pass_omp_device_lower instead of calls_declare_variant_alt.
* omp-general.cc (struct omp_declare_variant_entry): Delete.
(struct omp_declare_variant_base_entry): Delete.
(struct omp_declare_variant_hasher): Delete.
(omp_declare_variant_hasher::hash): Delete.
(omp_declare_variant_hasher::equal): Delete.
(omp_declare_variants): Delete.
(omp_declare_variant_alt_hasher): Delete.
(omp_declare_variant_alt_hasher::hash): Delete.
(omp_declare_variant_alt_hasher::equal): Delete.
(omp_declare_variant_alt): Delete.
(omp_lto_output_declare_variant_alt): Delete.
(omp_lto_input_declare_variant_alt): Delete.
(includes): Delete unnecessary include of gt-omp-general.h.
* omp-offload.cc (execute_omp_device_lower): Remove references
to deleted bit.
(pass_omp_device_lower::gate): Likewise.
* omp-simd-clone.cc (simd_clone_create): Likewise.
* passes.cc (ipa_write_summaries): Likeise.
* symtab.cc (symtab_node::get_partitioning_class): Likewise.
* tree-inline.cc (expand_call_inline): Likewise.
(tree_function_versioning): Likewise.
---
 gcc/cgraph.cc |   2 -
 gcc/cgraph.h  |  11 +-
 gcc/cgraphclones.cc   |   1 -
 gcc/ipa-free-lang-data.cc |   2 +-
 gcc/ipa.cc|   3 -
 gcc/lto-cgraph.cc |  10 --
 gcc/lto-streamer-out.cc   |   3 +-
 gcc/lto-streamer.h|   6 --
 gcc/lto/lto-partition.cc  |   5 +-
 gcc/omp-expand.cc |   2 +-
 gcc/omp-general.cc| 218 --
 gcc/omp-offload.cc|   8 +-
 gcc/omp-simd-clone.cc |   2 -
 gcc/passes.cc |   3 +-
 gcc/symtab.cc |   2 +-
 gcc/tree-inline.cc|   4 -
 16 files changed, 10 insertions(+), 272 deletions(-)

diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc
index 473d8410bc9..103bc2c0332 100644
--- a/gcc/cgraph.cc
+++ b/gcc/cgraph.cc
@@ -931,8 +931,6 @@ symbol_table::create_edge (cgraph_node *caller, cgraph_node 
*callee,
  caller->decl);
   else
 edge->in_polymorphic_cdtor = caller->thunk;
-  if (callee)
-caller->calls_declare_variant_alt |= callee->declare_variant_alt;
 
   if (callee && symtab->state != LTO_STREAMING
   && edge->callee->comdat_local_p ())
diff --git a/gcc/cgraph.h b/gcc/cgraph.h
index 6653ce19c3e..dd210842df7 100644
--- a/gcc/cgraph.h
+++ b/gcc/cgraph.h
@@ -897,10 +897,8 @@ struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public 
symtab_node
   split_part (false), indirect_call_target (false), local (false),
   versionable (false), can_change_signature (false),
   redefined_extern_inline (false), tm_may_enter_irr (false),
-  ipcp_clone (false), declare_variant_alt (false),
-  calls_declare_variant_alt (false), gc_candidate (false),
-  called_by_ifunc_resolver (false),
-  has_metadirectives (false),
+  ipcp_clone (false), gc_candidate (false),
+  called_by_ifunc_resolver (false), has_metadirectives (false),
   m_uid (uid), m_summary_id (-1)
 

[PATCH 05/12] OpenMP: C++ front-end support for metadirectives

2024-05-04 Thread Sandra Loosemore
This patch adds C++ support for metadirectives.  It uses the
c-family support committed with the corresponding C front end patch
to do early parse-time metadirective resolution when possible.

Additional C/C++ common testcases are provided in a subsequent
patch in the series.

gcc/cp/ChangeLog
* parser.cc (cp_parser_skip_to_end_of_block_or_statement): Add
metadirective_p parameter, use it to control brace/parentheses
behavior for metadirectives.
(mangle_metadirective_region_label): New.
(cp_parser_label_for_labeled_statement): Use it.
(cp_parser_jump_statement): Likewise.
(cp_parser_omp_context_selector): Add metadirective_p
parameter, use it to control error behavior for non-constant exprs
properties.
(cp_parser_omp_context_selector_specification): Add metadirective_p
parameter, use it for cp_parser_omp_context_selector call.
(cp_finish_omp_declare_variant): Adjust call to
cp_parser_omp_context_selector_specification.
(analyze_metadirective_body): New.
(cp_parser_omp_metadirective): New.
(cp_parser_pragma): Handle PRAGMA_OMP_METADIRECTIVE.
* parser.h (struct cp_parser): Add fields for metadirective parsing
state.
* pt.cc (tsubst_omp_context_selector): New.
(tsubst_stmt): Handle OMP_METADIRECTIVE.

gcc/testsuite/ChangeLog
* g++.dg/gomp/attrs-metadirective-1.C: New.
* g++.dg/gomp/attrs-metadirective-2.C: New.
* g++.dg/gomp/attrs-metadirective-3.C: New.
* g++.dg/gomp/attrs-metadirective-4.C: New.
* g++.dg/gomp/attrs-metadirective-5.C: New.
* g++.dg/gomp/attrs-metadirective-6.C: New.
* g++.dg/gomp/attrs-metadirective-7.C: New.
* g++.dg/gomp/attrs-metadirective-8.C: New.

libgomp/ChangeLog
* testsuite/libgomp.c++/metadirective-template-1.C: New.
* testsuite/libgomp.c++/metadirective-template-2.C: New.
* testsuite/libgomp.c++/metadirective-template-3.C: New.

Co-Authored-By: Kwok Cheung Yeung 
Co-Authored-By: Sandra Loosemore 
---
 gcc/cp/parser.cc  | 524 +-
 gcc/cp/parser.h   |   7 +
 gcc/cp/pt.cc  | 119 
 .../g++.dg/gomp/attrs-metadirective-1.C   |  40 ++
 .../g++.dg/gomp/attrs-metadirective-2.C   |  74 +++
 .../g++.dg/gomp/attrs-metadirective-3.C   |  31 ++
 .../g++.dg/gomp/attrs-metadirective-4.C   |  41 ++
 .../g++.dg/gomp/attrs-metadirective-5.C   |  24 +
 .../g++.dg/gomp/attrs-metadirective-6.C   |  31 ++
 .../g++.dg/gomp/attrs-metadirective-7.C   |  31 ++
 .../g++.dg/gomp/attrs-metadirective-8.C   |  16 +
 .../libgomp.c++/metadirective-template-1.C|  37 ++
 .../libgomp.c++/metadirective-template-2.C|  41 ++
 .../libgomp.c++/metadirective-template-3.C|  41 ++
 14 files changed, 1044 insertions(+), 13 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-1.C
 create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-2.C
 create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-3.C
 create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-4.C
 create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-5.C
 create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-6.C
 create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-7.C
 create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-8.C
 create mode 100644 libgomp/testsuite/libgomp.c++/metadirective-template-1.C
 create mode 100644 libgomp/testsuite/libgomp.c++/metadirective-template-2.C
 create mode 100644 libgomp/testsuite/libgomp.c++/metadirective-template-3.C

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 8b819b2ebfd..4bb9b086095 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -3001,7 +3001,7 @@ static void cp_parser_skip_to_end_of_statement
 static void cp_parser_consume_semicolon_at_end_of_statement
   (cp_parser *);
 static void cp_parser_skip_to_end_of_block_or_statement
-  (cp_parser *);
+  (cp_parser *, bool = false);
 static bool cp_parser_skip_to_closing_brace
   (cp_parser *);
 static bool cp_parser_skip_entire_template_parameter_list
@@ -4177,9 +4177,11 @@ cp_parser_consume_semicolon_at_end_of_statement 
(cp_parser *parser)
have consumed a non-nested `;'.  */
 
 static void
-cp_parser_skip_to_end_of_block_or_statement (cp_parser* parser)
+cp_parser_skip_to_end_of_block_or_statement (cp_parser* parser,
+bool metadirective_p)
 {
   int nesting_depth = 0;
+  int bracket_depth = 0;
 
   /* Unwind generic function template scope if necessary.  */
   if (parser->fully_implicit_function_template_p)
@@ -4201,7 +4203,7 @@ cp_parser_skip_to_end_of_block_or_statement (cp_parser* 
parser)
 
case CPP_SEMICOLON:
  /* Stop if this is an unnested ';'. */
- if (!nesting_de

[PATCH 06/12] OpenMP: common c/c++ testcases for metadirectives

2024-05-04 Thread Sandra Loosemore
gcc/testsuite/ChangeLog
* c-c++-common/gomp/metadirective-1.c: New.
* c-c++-common/gomp/metadirective-2.c: New.
* c-c++-common/gomp/metadirective-3.c: New.
* c-c++-common/gomp/metadirective-4.c: New.
* c-c++-common/gomp/metadirective-5.c: New.
* c-c++-common/gomp/metadirective-6.c: New.
* c-c++-common/gomp/metadirective-7.c: New.
* c-c++-common/gomp/metadirective-8.c: New.
* c-c++-common/gomp/metadirective-construct.c: New.
* c-c++-common/gomp/metadirective-device.c: New.
* c-c++-common/gomp/metadirective-no-score.c: New.
* c-c++-common/gomp/metadirective-target-device.c: New.

libgomp/ChangeLog
* testsuite/libgomp.c-c++-common/metadirective-1.c: New.
* testsuite/libgomp.c-c++-common/metadirective-2.c: New.
* testsuite/libgomp.c-c++-common/metadirective-3.c: New.
* testsuite/libgomp.c-c++-common/metadirective-4.c: New.
* testsuite/libgomp.c-c++-common/metadirective-5.c: New.

Co-Authored-By: Kwok Cheung Yeung 
Co-Authored-By: Sandra Loosemore 
---
 .../c-c++-common/gomp/metadirective-1.c   |  52 +
 .../c-c++-common/gomp/metadirective-2.c   |  74 
 .../c-c++-common/gomp/metadirective-3.c   |  31 +++
 .../c-c++-common/gomp/metadirective-4.c   |  40 
 .../c-c++-common/gomp/metadirective-5.c   |  24 +++
 .../c-c++-common/gomp/metadirective-6.c   |  31 +++
 .../c-c++-common/gomp/metadirective-7.c   |  31 +++
 .../c-c++-common/gomp/metadirective-8.c   |  16 ++
 .../gomp/metadirective-construct.c| 177 ++
 .../c-c++-common/gomp/metadirective-device.c  | 147 +++
 .../gomp/metadirective-no-score.c |  95 ++
 .../gomp/metadirective-target-device.c| 147 +++
 .../libgomp.c-c++-common/metadirective-1.c|  35 
 .../libgomp.c-c++-common/metadirective-2.c|  41 
 .../libgomp.c-c++-common/metadirective-3.c|  34 
 .../libgomp.c-c++-common/metadirective-4.c|  52 +
 .../libgomp.c-c++-common/metadirective-5.c|  46 +
 17 files changed, 1073 insertions(+)
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-1.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-2.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-3.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-4.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-5.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-6.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-7.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-8.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-construct.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-device.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-no-score.c
 create mode 100644 
gcc/testsuite/c-c++-common/gomp/metadirective-target-device.c
 create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-1.c
 create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-2.c
 create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-3.c
 create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-4.c
 create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-5.c

diff --git a/gcc/testsuite/c-c++-common/gomp/metadirective-1.c 
b/gcc/testsuite/c-c++-common/gomp/metadirective-1.c
new file mode 100644
index 000..37b56237531
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/metadirective-1.c
@@ -0,0 +1,52 @@
+/* { dg-do compile } */
+
+#define N 100
+
+void f (int a[], int b[], int c[])
+{
+  int i;
+
+  #pragma omp metadirective \
+  default (teams loop) \
+  default (parallel loop) /* { dg-error "too many 'otherwise' or 'default' 
clauses in 'metadirective'" } */
+for (i = 0; i < N; i++) c[i] = a[i] * b[i];
+
+  #pragma omp metadirective \
+  otherwise (teams loop) \
+  default (parallel loop) /* { dg-error "too many 'otherwise' or 'default' 
clauses in 'metadirective'" } */
+for (i = 0; i < N; i++) c[i] = a[i] * b[i];
+
+  #pragma omp metadirective \
+  otherwise (teams loop) \
+  otherwise (parallel loop) /* { dg-error "too many 'otherwise' or 
'default' clauses in 'metadirective'" } */
+for (i = 0; i < N; i++) c[i] = a[i] * b[i];
+
+  #pragma omp metadirective \
+  default (bad_directive) /* { dg-error "unknown directive name before 
'\\)' token" } */
+for (i = 0; i < N; i++) c[i] = a[i] * b[i];
+
+  #pragma omp metadirective \
+  default (teams loop) \
+  where (device={arch("nvptx")}: parallel loop) /* { dg-error "'where' is 
not valid for 'metadirective'" } */
+for (i = 0; i < N; i++) c[i] = a[i] * b[i];
+
+  #pragma omp metadirective \
+  default (teams loop) \

[PATCH 08/12] OpenMP: Reject other properties with kind(any)

2024-05-04 Thread Sandra Loosemore
The OpenMP spec says:

"If trait-property any is specified in the kind trait-selector of the
device selector set or the target_device selector sets, no other
trait-property may be specified in the same selector set."

GCC was not previously enforcing this restriction and several testcases
included such valid constructs.  This patch fixes it.

gcc/ChangeLog
* omp-general.cc (omp_check_context_selector): Reject other
properties in the same selector set with kind(any).

gcc/testsuite/ChangeLog
* c-c++-common/gomp/declare-variant-10.c: Fix broken tests.
* c-c++-common/gomp/declare-variant-3.c: Likewise.
* c-c++-common/gomp/declare-variant-9.c: Likewise.
* c-c++-common/gomp/declare-variant-any.c: New.
* gfortran.dg/gomp/declare-variant-10.f90: Fix broken tests.
* gfortran.dg/gomp/declare-variant-3.f90: Likewise.
* gfortran.dg/gomp/declare-variant-9.f90: Likewise.
* gfortran.dg/gomp/declare-variant-any.f90: Likewise.
---
 gcc/omp-general.cc| 31 +++
 .../c-c++-common/gomp/declare-variant-10.c|  4 +--
 .../c-c++-common/gomp/declare-variant-3.c | 10 ++
 .../c-c++-common/gomp/declare-variant-9.c |  4 +--
 .../c-c++-common/gomp/declare-variant-any.c   | 10 ++
 .../gfortran.dg/gomp/declare-variant-10.f90   |  4 +--
 .../gfortran.dg/gomp/declare-variant-3.f90| 12 ++-
 .../gfortran.dg/gomp/declare-variant-9.f90|  2 +-
 .../gfortran.dg/gomp/declare-variant-any.f90  | 28 +
 9 files changed, 82 insertions(+), 23 deletions(-)
 create mode 100644 gcc/testsuite/c-c++-common/gomp/declare-variant-any.c
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/declare-variant-any.f90

diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc
index 6f36b5d163f..23072b10d75 100644
--- a/gcc/omp-general.cc
+++ b/gcc/omp-general.cc
@@ -1277,6 +1277,8 @@ omp_check_context_selector (location_t loc, tree ctx, 
bool metadirective_p)
   for (tree tss = ctx; tss; tss = TREE_CHAIN (tss))
 {
   enum omp_tss_code tss_code = OMP_TSS_CODE (tss);
+  bool saw_any_prop = false;
+  bool saw_other_prop = false;
 
   /* FIXME: not implemented yet.  */
   if (!metadirective_p && tss_code == OMP_TRAIT_SET_TARGET_DEVICE)
@@ -1314,6 +1316,27 @@ omp_check_context_selector (location_t loc, tree ctx, 
bool metadirective_p)
  else
ts_seen[ts_code] = true;
 
+
+ /* If trait-property "any" is specified in the "kind"
+trait-selector of the "device" selector set or the
+"target_device" selector sets, no other trait-property
+may be specified in the same selector set.  */
+ if (ts_code == OMP_TRAIT_DEVICE_KIND)
+   for (tree p = OMP_TS_PROPERTIES (ts); p; p = TREE_CHAIN (p))
+ {
+   const char *prop = omp_context_name_list_prop (p);
+   if (!prop)
+ continue;
+   else if (strcmp (prop, "any") == 0)
+ saw_any_prop = true;
+   else
+ saw_other_prop = true;
+ }
+   else if (ts_code == OMP_TRAIT_DEVICE_ARCH
+  || ts_code == OMP_TRAIT_DEVICE_ISA
+  || ts_code == OMP_TRAIT_DEVICE_NUM)
+   saw_other_prop = true;
+
  if (omp_ts_map[ts_code].valid_properties == NULL)
continue;
 
@@ -1366,6 +1389,14 @@ omp_check_context_selector (location_t loc, tree ctx, 
bool metadirective_p)
  break;
  }
}
+
+  if (saw_any_prop && saw_other_prop)
+   {
+ error_at (loc,
+   "no other trait-property may be specified "
+   "in the same selector set with %");
+ return error_mark_node;
+   }
 }
   return ctx;
 }
diff --git a/gcc/testsuite/c-c++-common/gomp/declare-variant-10.c 
b/gcc/testsuite/c-c++-common/gomp/declare-variant-10.c
index 2b8a39425b1..e77693430d1 100644
--- a/gcc/testsuite/c-c++-common/gomp/declare-variant-10.c
+++ b/gcc/testsuite/c-c++-common/gomp/declare-variant-10.c
@@ -7,7 +7,7 @@ void f01 (void);
 #pragma omp declare variant (f01) match (device={isa(avx512f,avx512bw)})
 void f02 (void);
 void f03 (void);
-#pragma omp declare variant (f03) match 
(device={kind("any"),arch(x86_64),isa(avx512f,avx512bw)})
+#pragma omp declare variant (f03) match 
(device={arch(x86_64),isa(avx512f,avx512bw)})
 void f04 (void);
 void f05 (void);
 #pragma omp declare variant (f05) match (device={kind(gpu)})
@@ -28,7 +28,7 @@ void f15 (void);
 #pragma omp declare variant (f15) match (device={isa(sse4,ssse3),arch(i386)})
 void f16 (void);
 void f17 (void);
-#pragma omp declare variant (f17) match (device={kind(any,fpga)})
+#pragma omp declare variant (f17) match (device={kind(fpga)})
 void f18 (void);
 
 #pragma omp declare target
diff --git a/gcc/testsuite/c-c++-common/gomp/declare-variant-3.c 
b/gcc/testsuite/c-c++-common/gomp/declare-variant-3.c
index 

[PATCH 04/12] OpenMP: C front end support for metadirectives

2024-05-04 Thread Sandra Loosemore
This patch adds support to the C front end to parse OpenMP metadirective
constructs.  It includes support for early parse-time resolution
of metadirectives (when possible) that will also be used by the C++ front
end.

Additional common C/C++ testcases are in a later patch in the series.

gcc/c-family/ChangeLog
* c-common.h (enum c_omp_directive_kind): Add C_OMP_DIR_META.
(c_omp_expand_metadirective): Declare.
* c-gimplify.cc: Include omp-general.h.
(genericize_omp_metadirective_stmt): New.
(c_genericize_control_stmt): Call it.
* c-omp.cc (c_omp_directives): Add "metadirective" and fix
commented-out stubs for the begin/end form.
(c_omp_expand_metadirective_r): New.
(c_omp_expand_metadirective): New.
* c-pragma.cc (omp_pragmas): Add "metadirective".
* c-pragma.h (enum pragma_kind): Add PRAGMA_OMP_METADIRECTIVE.

gcc/c/ChangeLog
* c-parser.cc (struct c_parser): Add new fields for metadirectives.
(c_parser_skip_to_end_of_block_or_statement):  Add metadirective_p
parameter; use it to control brace and parentheses behavior.
(mangle_metadirective_region_label): New.
(c_parser_label, c_parser_statement_after_labels): Use it.
(c_parser_pragma): Handle metadirective.
(c_parser_omp_context_selector): Add metadirective_p flag, use it
to gate support for non-constant user condition.
(c_parser_omp_context_selector_specification): Add metadirective_p
argument.
(c_parser_finish_omp_declare_variant): Adjust call to above.
(analyze_metadirective_body): New.
(c_parser_omp_metadirective): New.

gcc/testsuite/ChangeLog
* gcc.dg/gomp/metadirective-1.c: New.

Co-Authored-By: Kwok Cheung Yeung 
Co-Authored-By: Sandra Loosemore 
---
 gcc/c-family/c-common.h |   4 +-
 gcc/c-family/c-gimplify.cc  |  27 ++
 gcc/c-family/c-omp.cc   |  60 ++-
 gcc/c-family/c-pragma.cc|   1 +
 gcc/c-family/c-pragma.h |   1 +
 gcc/c/c-parser.cc   | 489 +++-
 gcc/testsuite/gcc.dg/gomp/metadirective-1.c |  15 +
 7 files changed, 577 insertions(+), 20 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/gomp/metadirective-1.c

diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 2d5f5399885..03f62571531 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -1391,7 +1391,8 @@ enum c_omp_directive_kind {
   C_OMP_DIR_CONSTRUCT,
   C_OMP_DIR_DECLARATIVE,
   C_OMP_DIR_UTILITY,
-  C_OMP_DIR_INFORMATIONAL
+  C_OMP_DIR_INFORMATIONAL,
+  C_OMP_DIR_META
 };
 
 struct c_omp_directive {
@@ -1405,6 +1406,7 @@ extern const struct c_omp_directive c_omp_directives[];
 extern const struct c_omp_directive *c_omp_categorize_directive (const char *,
 const char *,
 const char *);
+extern tree c_omp_expand_metadirective (vec &);
 
 /* Return next tree in the chain for chain_next walking of tree nodes.  */
 inline tree
diff --git a/gcc/c-family/c-gimplify.cc b/gcc/c-family/c-gimplify.cc
index 494da49791d..c53aca60bcf 100644
--- a/gcc/c-family/c-gimplify.cc
+++ b/gcc/c-family/c-gimplify.cc
@@ -43,6 +43,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "context.h"
 #include "tree-pass.h"
 #include "internal-fn.h"
+#include "omp-general.h"
 
 /*  The gimplification pass converts the language-dependent trees
 (ld-trees) emitted by the parser into language-independent trees
@@ -485,6 +486,27 @@ genericize_omp_for_stmt (tree *stmt_p, int *walk_subtrees, 
void *data,
   finish_bc_block (_FOR_BODY (stmt), bc_continue, clab);
 }
 
+/* Genericize a OMP_METADIRECTIVE node *STMT_P.  */
+
+static void
+genericize_omp_metadirective_stmt (tree *stmt_p, int *walk_subtrees,
+  void *data, walk_tree_fn func,
+  walk_tree_lh lh)
+{
+  tree stmt = *stmt_p;
+
+  for (tree variant = OMP_METADIRECTIVE_VARIANTS (stmt);
+   variant != NULL_TREE;
+   variant = TREE_CHAIN (variant))
+{
+  walk_tree_1 (_METADIRECTIVE_VARIANT_DIRECTIVE (variant),
+  func, data, NULL, lh);
+  walk_tree_1 (_METADIRECTIVE_VARIANT_BODY (variant),
+  func, data, NULL, lh);
+}
+
+  *walk_subtrees = 0;
+}
 
 /* Lower structured control flow tree nodes, such as loops.  The
STMT_P, WALK_SUBTREES, and DATA arguments are as for the walk_tree_fn
@@ -533,6 +555,11 @@ c_genericize_control_stmt (tree *stmt_p, int 
*walk_subtrees, void *data,
   genericize_omp_for_stmt (stmt_p, walk_subtrees, data, func, lh);
   break;
 
+case OMP_METADIRECTIVE:
+  genericize_omp_metadirective_stmt (stmt_p, walk_subtrees, data, func,
+  

[PATCH 12/12] OpenMP: Update documentation of metadirective implementation status.

2024-05-04 Thread Sandra Loosemore
libgomp/ChangeLog
* libgomp.texi (OpenMP 5.0): Mark metadirective and declare variant
as implemented.
(OpenMP 5.1): Mark target_device as supported.
Add changed interaction between declare target and OpenMP context
and dynamic selector support.
(OpenMP 5.2): Mark otherwise clause as supported, note that
default is also still accepted.
---
 libgomp/libgomp.texi | 21 ++---
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index 43048da4d6e..af7af63c504 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -192,9 +192,8 @@ The OpenMP 4.5 specification is fully supported.
 @item Array shaping @tab N @tab
 @item Array sections with non-unit strides in C and C++ @tab N @tab
 @item Iterators @tab Y @tab
-@item @code{metadirective} directive @tab N @tab
-@item @code{declare variant} directive
-  @tab P @tab @emph{simd} traits not handled correctly
+@item @code{metadirective} directive @tab Y @tab
+@item @code{declare variant} directive @tab Y @tab
 @item @var{target-offload-var} ICV and @code{OMP_TARGET_OFFLOAD}
   env variable @tab Y @tab
 @item Nested-parallel changes to @var{max-active-levels-var} ICV @tab Y @tab
@@ -289,8 +288,8 @@ The OpenMP 4.5 specification is fully supported.
 @headitem Description @tab Status @tab Comments
 @item OpenMP directive as C++ attribute specifiers @tab Y @tab
 @item @code{omp_all_memory} reserved locator @tab Y @tab
-@item @emph{target_device trait} in OpenMP Context @tab N @tab
-@item @code{target_device} selector set in context selectors @tab N @tab
+@item @emph{target_device trait} in OpenMP Context @tab Y
+@item @code{target_device} selector set in context selectors @tab Y @tab
 @item C/C++'s @code{declare variant} directive: elision support of
   preprocessed code @tab N @tab
 @item @code{declare variant}: new clauses @code{adjust_args} and
@@ -366,6 +365,12 @@ to address of matching mapped list item per 5.1, Sect. 
2.21.7.2 @tab N @tab
 @item @code{device_type(nohost)}/@code{device_type(host)} for variables @tab N 
@tab
 @item @code{present} modifier to the @code{map}, @code{to} and @code{from}
   clauses @tab Y @tab
+@item Changed interaction between @code{declare target} and OpenMP context
+  @tab Y @tab
+@item Dynamic selector support in @code{metadirective} @tab Y @tab
+@item Dynamic selector support in @code{declare variant} @tab P
+  @tab Fortran rejects non-constant expressions in dynamic selectors;
+  C/C++ reject expressions using argument variables.
 @end multitable
 
 
@@ -413,8 +418,10 @@ to address of matching mapped list item per 5.1, Sect. 
2.21.7.2 @tab N @tab
 @item Deprecation of traits array following the allocator_handle expression in
   @code{uses_allocators} @tab N @tab
 @item New @code{otherwise} clause as alias for @code{default} on metadirectives
-  @tab N @tab
-@item Deprecation of @code{default} clause on metadirectives @tab N @tab
+  @tab Y @tab
+@item Deprecation of @code{default} clause on metadirectives @tab N
+  @tab Both @code{otherwise} and @code{default} are accepted
+  without diagnostics.
 @item Deprecation of delimited form of @code{declare target} @tab N @tab
 @item Reproducible semantics changed for @code{order(concurrent)} @tab N @tab
 @item @code{allocate} and @code{firstprivate} clauses on @code{scope}
-- 
2.25.1



[PATCH 03/12] libgomp: runtime support for target_device selector

2024-05-04 Thread Sandra Loosemore
This patch implements the libgomp runtime support for the dynamic
target_device selector via the GOMP_evaluate_target_device function.

include/ChangeLog
* cuda/cuda.h (CUdevice_attribute): Add definitions for
CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR and
CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR.

libgomp/ChangeLog
* Makefile.am (libgomp_la_SOURCES): Add selector.c.
* Makefile.in: Regenerate.
* config/gcn/selector.c: New.
* config/linux/selector.c: New.
* config/linux/x86/selector.c: New.
* config/nvptx/selector.c: New.
* libgomp-plugin.h (GOMP_OFFLOAD_evaluate_device): New.
* libgomp.h (struct gomp_device_descr): Add evaluate_device_func field.
* libgomp.map (GOMP_5.1.3): New, add GOMP_evaluate_target_device.
* libgomp.texi (OpenMP Context Selectors): Document dynamic selector
matching of kind/arch/isa.
* libgomp_g.h (GOMP_evaluate_current_device): New.
(GOMP_evaluate_target_device): New.
* oacc-host.c (host_evaluate_device): New.
(host_openacc_exec): Initialize evaluate_device_func field to
host_evaluate_device.
* plugin/plugin-gcn.c (gomp_match_selectors): New.
(gomp_match_isa): New.
(GOMP_OFFLOAD_evaluate_device): New.
* plugin/plugin-nvptx.c (struct ptx_device): Add compute_major and
compute_minor fields.
(nvptx_open_device): Read compute capability information from device.
(gomp_match_selectors): New.
(gomp_match_selector): New.
(CHECK_ISA): New macro.
(GOMP_OFFLOAD_evaluate_device): New.
* selector.c: New.
* target.c (GOMP_evaluate_target_device): New.
(gomp_load_plugin_for_device): Load evaluate_device plugin function.

Co-Authored-By: Kwok Cheung Yeung 
Co-Authored-By: Sandra Loosemore 
---
 include/cuda/cuda.h |   2 +
 libgomp/Makefile.am |   2 +-
 libgomp/Makefile.in |   5 +-
 libgomp/config/gcn/selector.c   | 102 +++
 libgomp/config/linux/selector.c |  65 +
 libgomp/config/linux/x86/selector.c | 406 
 libgomp/config/nvptx/selector.c |  77 ++
 libgomp/libgomp-plugin.h|   2 +
 libgomp/libgomp.h   |   1 +
 libgomp/libgomp.map |   5 +
 libgomp/libgomp.texi|  18 +-
 libgomp/libgomp_g.h |   8 +
 libgomp/oacc-host.c |  11 +
 libgomp/plugin/plugin-gcn.c |  52 
 libgomp/plugin/plugin-nvptx.c   |  82 ++
 libgomp/selector.c  |  64 +
 libgomp/target.c|  40 +++
 17 files changed, 936 insertions(+), 6 deletions(-)
 create mode 100644 libgomp/config/gcn/selector.c
 create mode 100644 libgomp/config/linux/selector.c
 create mode 100644 libgomp/config/linux/x86/selector.c
 create mode 100644 libgomp/config/nvptx/selector.c
 create mode 100644 libgomp/selector.c

diff --git a/include/cuda/cuda.h b/include/cuda/cuda.h
index 0dca4b3a5c0..a775450df03 100644
--- a/include/cuda/cuda.h
+++ b/include/cuda/cuda.h
@@ -83,6 +83,8 @@ typedef enum {
   CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_MULTIPROCESSOR = 39,
   CU_DEVICE_ATTRIBUTE_ASYNC_ENGINE_COUNT = 40,
   CU_DEVICE_ATTRIBUTE_UNIFIED_ADDRESSING = 41,
+  CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR = 75,
+  CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR = 76,
   CU_DEVICE_ATTRIBUTE_MAX_REGISTERS_PER_MULTIPROCESSOR = 82
 } CUdevice_attribute;
 
diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index 1871590596d..87658da2d5d 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -72,7 +72,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c error.c \
target.c splay-tree.c libgomp-plugin.c oacc-parallel.c oacc-host.c \
oacc-init.c oacc-mem.c oacc-async.c oacc-plugin.c oacc-cuda.c \
priority_queue.c affinity-fmt.c teams.c allocator.c oacc-profiling.c \
-   oacc-target.c target-indirect.c
+   oacc-target.c target-indirect.c selector.c
 
 include $(top_srcdir)/plugin/Makefrag.am
 
diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index 11480d6a953..30e57571404 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -219,7 +219,7 @@ am_libgomp_la_OBJECTS = alloc.lo atomic.lo barrier.lo 
critical.lo \
oacc-parallel.lo oacc-host.lo oacc-init.lo oacc-mem.lo \
oacc-async.lo oacc-plugin.lo oacc-cuda.lo priority_queue.lo \
affinity-fmt.lo teams.lo allocator.lo oacc-profiling.lo \
-   oacc-target.lo target-indirect.lo $(am__objects_1)
+   oacc-target.lo target-indirect.lo selector.lo $(am__objects_1)
 libgomp_la_OBJECTS = $(am_libgomp_la_OBJECTS)
 AM_V_P = $(am__v_P_@AM_V@)
 am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
@@ -552,7 +552,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c \
oacc-parallel.c oacc-host.c oacc-init.c oacc-mem.c \
oacc-async.c

[PATCH 02/12] OpenMP: middle-end support for metadirectives

2024-05-04 Thread Sandra Loosemore
This patch adds middle-end support for OpenMP metadirectives.  Some
context selectors can be resolved during gimplification, but others need to
be deferred until the omp_device_lower pass, which requires that cgraph,
LTO streaming, inlining, etc all know about this construct as well.

gcc/ChangeLog
* cgraph.h (struct cgraph_node): Add has_metadirectives flag.
* cgraphclones.cc (cgraph_node::create_clone): Copy has_metadirectives
flag.
* doc/gimple.texi (Class hierarchy of GIMPLE statements): Document
gomp_metadirective and gomp_variant.
* gimple-low.cc (lower_omp_metadirective): New.
(lower_stmt): Call it.
* gimple-pretty-print.cc (dump_gimple_omp_metadirective): New.
(pp_gimple_stmt_1): Call it.
* gimple-streamer-in.cc (input_gimple_stmt): Handle
GIMPLE_OMP_METADIRECTIVE.
* gimple-streamer-out.cc (output_gimple_stmt): Likewise.
* gimple-walk.cc (walk_gimple_op): Likewise.
(walk_gimple_stmt): Likewise.
* gimple.cc (gimple_alloc_omp_metadirective): New.
(gimple_build_omp_metadirective): New.
(gimple_build_omp_variant): New.
* gimple.def (GIMPLE_OMP_METADIRECTIVE): New.
(GIMPLE_OMP_METADIRECTIVE_VARIANT): New.
* gimple.h (gomp_variant, gomp_metadirective): New.
(is_a_helper ::test): New.
(is_a_helper ::test): New.
(is_a_helper ::test): New.
(is_a_helper ::test): New.
(gimple_alloc_omp_metadirective): New.
(gimple_build_omp_metadirective): New.
(gimple_build_omp_variant): New.
(gimple_has_substatements): Handle GIMPLE_OMP_METADIRECTIVE.
(gimple_has_ops): Likewise.
(gimple_omp_metadirective_label): New.
(gimple_omp_metadirective_set_label): New.
(gimple_omp_variants): New.
(gimple_omp_metadirective_set_variants): New.
(gimple_return_set_retval): Handle GIMPLE_OMP_METADIRECTIVE.
* gimplify.cc (is_gimple_stmt): HANDLE OMP_METADIRECTIVE.
(expand_omp_metadirective): New.
(gimplify_omp_metadirective): New.
(gimplify_expr): Call it.
* gsstruct.def (GSS_OMP_METADIRECTIVE): New.
(GSS_OMP_METADIRECTIVE_VARIANT): New.
* lto-cgraph.cc (lto_output_node): Handle has_metadirectives flag.
(input_overwrite_node): Likewise.
* omp-expand.cc (expand_omp_target): Propagate has_metadirectives
flag.
(build_omp_regions_1): Handle GIMPLE_OMP_METADIRECTIVE.
(omp_make_gimple_edges): Likewise.
* omp-general.cc (omp_late_resolve_metadirective): New.
* omp-general.h (omp_late_resolve_metadirective): Declare.
* omp-low.cc (struct omp_context): Add next_clone field.
(new_omp_context): Handle next_clone field.
(clone_omp_context): New.
(delete_omp_context): Delete clones.
(create_omp_child_function): Propagate has_metadirectives bit.
(scan_omp_metadirective): New.
(scan_omp_1_stmt): Handle GIMPLE_OMP_METADIRECTIVE.
(lower_omp_metadirective): New.
(lower_omp_1): Handle GIMPLE_OMP_METADIRECTIVE.  Warn about
direct calls to offloadable functions containing metadirectives.
* omp-offload.cc: Include cfganal.h and cfghooks.h.
(omp_expand_metadirective): New.
(execute_omp_device_lower): Handle metadirectives.
(pass_omp_device_lower::gate):  Check has_metadirectives bit.
* omp-simd-clone.cc (simd_clone_create): Propagate has_metadirectives
flag.
* tree-cfg.cc (cleanup_dead_labels): Handle GIMPLE_OMP_METADIRECTIVE.
(gimple_redirect_edge_and_branch): Likewise.
* tree-inline.cc (remap_gimple_stmt): Handle GIMPLE_OMP_METADIRECTIVE.
(estimate_num_instructions): Likewise.
(expand_call_inline): Propagate has_metadirectives flag.
(tree_function_versioning): Likewise.
* tree-ssa-operands.cc: Include omp-general.h.
(operands_scanner::parse_ssa_operands): Handle
GIMPLE_OMP_METADIRECTIVE.

Co-Authored-By: Kwok Cheung Yeung 
Co-Authored-By: Sandra Loosemore 
Co-Authored-By: Marcel Vollweiler 
---
 gcc/cgraph.h   |   3 +
 gcc/cgraphclones.cc|   1 +
 gcc/doc/gimple.texi|   6 ++
 gcc/gimple-low.cc  |  36 
 gcc/gimple-pretty-print.cc |  64 +
 gcc/gimple-streamer-in.cc  |  10 ++
 gcc/gimple-streamer-out.cc |   6 ++
 gcc/gimple-walk.cc |  28 ++
 gcc/gimple.cc  |  35 +++
 gcc/gimple.def |   7 ++
 gcc/gimple.h   | 100 +++-
 gcc/gimplify.cc| 184 +
 gcc/gsstruct.def   |   2 +
 gcc/lto-cgraph.cc  |   2 +
 gcc/omp-expand.cc  |  30 ++
 gcc/omp-general.cc |  22 +
 gcc/omp-general.h  |   1 +
 gcc/omp-low.cc |  83 +
 gcc/omp-offload.cc | 105

[PATCH 01/12] OpenMP: metadirective tree data structures and front-end interfaces

2024-05-04 Thread Sandra Loosemore
This patch adds the OMP_METADIRECTIVE tree node and shared tree-level
support for manipulating metadirectives.  It defines/exposes
interfaces that will be used in subsequent patches that add front-end
and middle-end support, but nothing generates these nodes yet.

This patch also adds compile-time support for dynamic context
selectors (the target_device selector set and the condition selector
of the user selector set) for metadirectives only.  The "declare
variant" directive still supports only static selectors.

gcc/ChangeLog
* Makefile.in (GTFILES): Move omp-general.h earlier in the list.
* builtin-types.def (BT_FN_BOOL_INT_CONST_PTR_CONST_PTR_CONST_PTR):
New.
* doc/generic.texi (OpenMP): Document OMP_METADIRECTIVE and
context selector interfaces.
* omp-builtins.def (BUILT_IN_GOMP_EVALUATE_TARGET_DEVICE): New.
* omp-general.cc (omp_check_context_selector): Add metadirective_p
parameter, use it to conditionalize target_device support.
(make_omp_metadirective_variant): New.
(omp_context_selector_matches): Add metadirective_p and delay_p
parameters, use them to control things that can only be matched
late.  Handle OMP_TRAIT_SET_TARGET_DEVICE.
(score_wide_int): Move definition to omp-general.h.
(omp_encode_kind_arch_isa_props): New.
(omp_dynamic_cond): New.
(omp_context_compute_score): Handle OMP_TRAIT_SET_TARGET_DEVICE.
(omp_resolve_late_declare_variant, omp_resolve_declare_variant):
Adjust calls to omp_context_selector_matches.
(sort_variant): New.
(omp_get_dynamic_candidates): New.
(omp_early_resolve_metadirective): New.
* omp-general.h (score_wide_int): Moved here from omp-general.cc.
(struct omp_variant): New.
(OMP_METADIRECTIVE_VARIANT_SELECTOR): New.
(OMP_METADIRECTIVE_VARIANT_DIRECTIVE): New.
(OMP_METADIRECTIVE_VARIANT_BODY): New.
(make_omp_metadirective_variant): Declare.
(omp_check_context_selector): Adjust to match definition.
(omp_context_selector_matches): Likewise.
(omp_early_resolve_metadirective): New.
* tree-pretty-print.cc (dump_omp_context_selector): Remove
static qualifier.
(dump_generic_node): Handle OMP_METADIRECTIVE.
* tree-pretty-print.h (dump_omp_context_selector): Declare.
* tree.def (OMP_METADIRECTIVE): New.
* tree.h (OMP_METADIRECTIVE_VARIANTS): New.

gcc/c/ChangeLog
* c-parser.cc (c_finish_omp_declare_variant): Update calls to
omp_check_context_selector and omp_context_selector_matches.

gcc/cp/ChangeLog
* decl.cc (omp_declare_variant_finalize_one):  Update call to
omp_context_selector_matches to pass additional arguments.
* parser.cc (cp_finish_omp_declare_variant): Likewise for
omp_check_context_selector.

gcc/fortran/ChangeLog
* trans-openmp.cc (gfc_trans_omp_declare_variant):  Update calls to
omp_check_context_selector and omp_context_selector_matches.
* types.def (BT_FN_BOOL_INT_CONST_PTR_CONST_PTR_CONST_PTR): New.

Co-Authored-By: Kwok Cheung Yeung 
Co-Authored-By: Sandra Loosemore 
---
 gcc/Makefile.in |   2 +-
 gcc/builtin-types.def   |   2 +
 gcc/c/c-parser.cc   |   4 +-
 gcc/cp/decl.cc  |   2 +-
 gcc/cp/parser.cc|   2 +-
 gcc/doc/generic.texi|  32 
 gcc/fortran/trans-openmp.cc |   4 +-
 gcc/fortran/types.def   |   2 +
 gcc/omp-builtins.def|   3 +
 gcc/omp-general.cc  | 357 ++--
 gcc/omp-general.h   |  31 +++-
 gcc/tree-pretty-print.cc|  36 +++-
 gcc/tree-pretty-print.h |   2 +
 gcc/tree.def|   6 +
 gcc/tree.h  |   3 +
 15 files changed, 461 insertions(+), 27 deletions(-)

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index a74761b7ab3..65638c7b5d6 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -2868,6 +2868,7 @@ GTFILES = $(CPPLIB_H) $(srcdir)/input.h 
$(srcdir)/coretypes.h \
   $(srcdir)/tree-ssa-operands.h \
   $(srcdir)/tree-profile.cc $(srcdir)/tree-nested.cc \
   $(srcdir)/omp-offload.h \
+  $(srcdir)/omp-general.h \
   $(srcdir)/omp-general.cc \
   $(srcdir)/omp-low.cc \
   $(srcdir)/targhooks.cc $(out_file) $(srcdir)/passes.cc \
@@ -2894,7 +2895,6 @@ GTFILES = $(CPPLIB_H) $(srcdir)/input.h 
$(srcdir)/coretypes.h \
   $(srcdir)/ipa-strub.cc \
   $(srcdir)/internal-fn.h \
   $(srcdir)/calls.cc \
-  $(srcdir)/omp-general.h \
   $(srcdir)/analyzer/analyzer-language.cc \
   @all_gtfiles@
 
diff --git a/gcc/builtin-types.def b/gcc/builtin-types.def
index c97d6bad1de..605a38ab84d 100644
--- a/gcc/builtin-types.def
+++ b/gcc/builtin-types.def
@@ -878,6 +878,8 @@ DEF_FUNCTION_TYPE_4 (BT_FN_VOID_UINT_PTR_INT_PTR, BT_VOID, 
BT_INT, BT_PTR,
 BT_INT, BT_PTR)
 DEF_FUNCTION_TYPE_4 (BT_FN_BOOL_UINT_UINT

[PATCH 00/12] OpenMP: Metadirective support + "declare variant" improvements

2024-05-04 Thread Sandra Loosemore
n a timely manner
and reduce the burden of maintaining these patches out of tree.

-Sandra

Sandra Loosemore (12):
  OpenMP: metadirective tree data structures and front-end interfaces
  OpenMP: middle-end support for metadirectives
  libgomp: runtime support for target_device selector
  OpenMP: C front end support for metadirectives
  OpenMP: C++ front-end support for metadirectives
  OpenMP: common c/c++ testcases for metadirectives
  OpenMP: Fortran front-end support for metadirectives.
  OpenMP: Reject other properties with kind(any)
  OpenMP: Extend dynamic selector support to declare variant
  OpenMP: Remove dead code from declare variant reimplementation
  OpenMP: Update "declare target"/OpenMP context interaction
  OpenMP: Update documentation of metadirective implementation status.

 gcc/Makefile.in   |2 +-
 gcc/builtin-types.def |2 +
 gcc/c-family/c-attribs.cc |2 -
 gcc/c-family/c-common.h   |4 +-
 gcc/c-family/c-gimplify.cc|   27 +
 gcc/c-family/c-omp.cc |   60 +-
 gcc/c-family/c-pragma.cc  |1 +
 gcc/c-family/c-pragma.h   |1 +
 gcc/c/c-decl.cc   |8 +-
 gcc/c/c-parser.cc |  473 +++-
 gcc/cgraph.cc |2 -
 gcc/cgraph.h  |   12 +-
 gcc/cgraphclones.cc   |2 +-
 gcc/cp/cp-tree.h  |2 +
 gcc/cp/decl.cc|2 +-
 gcc/cp/decl2.cc   |9 +-
 gcc/cp/parser.cc  |  526 -
 gcc/cp/parser.h   |7 +
 gcc/cp/pt.cc  |  120 +
 gcc/cp/semantics.cc   |3 +-
 gcc/doc/generic.texi  |   32 +
 gcc/doc/gimple.texi   |6 +
 gcc/fortran/decl.cc   |   29 +
 gcc/fortran/dump-parse-tree.cc|   21 +
 gcc/fortran/gfortran.h|   20 +-
 gcc/fortran/io.cc |2 +-
 gcc/fortran/match.h   |2 +
 gcc/fortran/openmp.cc |  294 ++-
 gcc/fortran/parse.cc  |  571 +++--
 gcc/fortran/parse.h   |8 +-
 gcc/fortran/resolve.cc|6 +
 gcc/fortran/st.cc |4 +
 gcc/fortran/symbol.cc |   25 +-
 gcc/fortran/trans-decl.cc |5 +-
 gcc/fortran/trans-openmp.cc   |  238 +-
 gcc/fortran/trans-stmt.h  |1 +
 gcc/fortran/trans.cc  |1 +
 gcc/fortran/types.def |2 +
 gcc/gimple-low.cc |   36 +
 gcc/gimple-pretty-print.cc|   64 +
 gcc/gimple-streamer-in.cc |   13 +
 gcc/gimple-streamer-out.cc|   10 +
 gcc/gimple-walk.cc|   28 +
 gcc/gimple.cc |   36 +
 gcc/gimple.def|8 +
 gcc/gimple.h  |  122 +-
 gcc/gimplify.cc   |  574 +++--
 gcc/gimplify.h|2 +-
 gcc/gsstruct.def  |2 +
 gcc/ipa-free-lang-data.cc |2 +-
 gcc/ipa.cc|3 -
 gcc/lto-cgraph.cc |   12 +-
 gcc/lto-streamer-out.cc   |3 +-
 gcc/lto-streamer.h|6 -
 gcc/lto/lto-partition.cc  |5 +-
 gcc/omp-builtins.def  |3 +
 gcc/omp-expand.cc |   32 +-
 gcc/omp-general.cc| 2033 +
 gcc/omp-general.h |   50 +-
 gcc/omp-low.cc|   83 +
 gcc/omp-offload.cc|  117 +-
 gcc/omp-simd-clone.cc |3 +-
 gcc/passes.cc |3 +-
 gcc/symtab.cc |2 +-
 .../gomp/declare-target-indirect-2.c  |   10 +-
 .../c-c++-common/gomp/declare-variant-10.c|4 +-
 .../c-c++-common/gomp/declare-variant-12.c|   14 +-
 .../c-c++-common/gomp/declare-variant-13.c|6 +-
 .../c-c++-common/gomp/declare-variant-2.c |4 +-
 .../c-c++-common/gomp/declare-variant-3.c |   10 +-
 .../c-c++-common/gomp/declare-variant-8.c |4 +-
 .../c-c++-common/gomp/declare-variant-9.c |4 +-
 .../c-c++-common/gomp/declare-variant-any.c   |   10 +
 .../gomp/declare-variant-arg-exprs.c

[PATCH, obvious] Fix for ICE in tree-nested.cc

2024-05-03 Thread Sandra Loosemore
I'm planning to push the attached patch to mainline in a couple days, 
unless someone disputes that it's "obvious" or has some other objection. 
 I think it qualifies because the code immediately following the loop 
with the bad initializer is already conditionalized on GIMPLE_OMP_TARGET 
in the same way.


I think this patch is a candidate for backporting to the GCC 14 branch 
once it is unfrozen after the release, too.


-SandraFrom 001d166819525dcef43b980298c2f85af77cd8ad Mon Sep 17 00:00:00 2001
From: Sandra Loosemore 
Date: Mon, 22 Apr 2024 18:24:25 +
Subject: [PATCH, obvious] OpenMP: Fix for ICE in tree-nested.cc.

Use gimple_omp_target_clauses() instead of gimple_omp_taskreg_clauses()
when stmt is GIMPLE_OMP_TARGET, to avoid an as_a<> ICE.  The code
immediately following this is already conditionalized in the same way.

gcc/ChangeLog
	* tree-nested.cc (convert_tramp_reference_stmt): Use the correct
	accessor for GIMPLE_OMP_TARGET clauses.
---
 gcc/tree-nested.cc | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/gcc/tree-nested.cc b/gcc/tree-nested.cc
index 4e5f3be7676..fc0495d6443 100644
--- a/gcc/tree-nested.cc
+++ b/gcc/tree-nested.cc
@@ -2906,9 +2906,11 @@ convert_tramp_reference_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
 	  continue;
 	decl = i ? get_chain_decl (info) : info->frame_decl;
 	/* Don't add CHAIN.* or FRAME.* twice.  */
-	for (c = gimple_omp_taskreg_clauses (stmt);
-		 c;
-		 c = OMP_CLAUSE_CHAIN (c))
+	if (gimple_code (stmt) == GIMPLE_OMP_TARGET)
+	  c = gimple_omp_target_clauses (stmt);
+	else
+	  c = gimple_omp_taskreg_clauses (stmt);
+	for (; c; c = OMP_CLAUSE_CHAIN (c))
 	  if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
 		   || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED)
 		  && OMP_CLAUSE_DECL (c) == decl)
-- 
2.25.1



[committed, wwwdocs] gcc-14/changes.html: nios2 target is obsolete

2024-04-18 Thread Sandra Loosemore

I've committed the attached patch, per

https://gcc.gnu.org/pipermail/gcc/2024-April/243749.html

-SandraFrom a6afbd07ee3d669dc6ac396d68a99926a30818f9 Mon Sep 17 00:00:00 2001
From: Sandra Loosemore 
Date: Mon, 15 Apr 2024 17:17:35 +
Subject: [committed, wwwdocs] gcc-14/changes.html: nios2 target is obsolete

---
 htdocs/gcc-14/changes.html | 4 
 1 file changed, 4 insertions(+)

diff --git a/htdocs/gcc-14/changes.html b/htdocs/gcc-14/changes.html
index c98ebe5a..9509487c 100644
--- a/htdocs/gcc-14/changes.html
+++ b/htdocs/gcc-14/changes.html
@@ -49,6 +49,10 @@ a work-in-progress.
   unmaintained for quite a while has been declared obsolete in GCC 14.
   The next release of GCC will have their sources permanently removed.
   
+  Support for the nios2*-*- target ports has also been
+  declared obsolete in GCC 14, and the sources will also be removed
+  in the next release of GCC.
+  
   https://gcc.gnu.org/onlinedocs/gcc/Static-Analyzer-Options.html;>-fanalyzer
 is still only suitable for analyzing C code.
 In particular, using it on C++ is unlikely to give meaningful output.
-- 
2.25.1



[committed] Add nios2*-*-* to the list of obsolete targets

2024-04-18 Thread Sandra Loosemore

I've committed the attach patch, per

https://gcc.gnu.org/pipermail/gcc/2024-April/243749.html

-SandraFrom 71ba5a721749174815dec712d113f3afb251deda Mon Sep 17 00:00:00 2001
From: Sandra Loosemore 
Date: Mon, 8 Apr 2024 14:36:08 +
Subject: [committed] Add nios2*-*-* to the list of obsolete targets

This patch marks the nios2*-*-* targets obsolete in GCC 14.  Intel has
EOL'ed this architecture and the maintainers no longer have access to
hardware for testing.  While the port is still in reasonably good
shape at this time, no further testing or updates are planned.

gcc/
	* config.gcc: Add nios2*-*-* to the list of obsoleted targets.

contrib/
	* config-list.mk (LIST): --enable-obsolete for nios2*-*-*.
---
 contrib/config-list.mk | 3 ++-
 gcc/config.gcc | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/contrib/config-list.mk b/contrib/config-list.mk
index 16df66f0fc6..f282cd95c8d 100644
--- a/contrib/config-list.mk
+++ b/contrib/config-list.mk
@@ -78,7 +78,8 @@ LIST = \
   moxie-uclinux moxie-rtems \
   msp430-elf msp430-elfbare \
   nds32le-elf nds32be-elf \
-  nios2-elf nios2-linux-gnu nios2-rtems \
+  nios2-elfOPT-enable-obsolete nios2-linux-gnuOPT-enable-obsolete \
+  nios2-rtemsOPT-enable-obsolete \
   nvptx-none \
   or1k-elf or1k-linux-uclibc or1k-linux-musl or1k-rtems \
   pdp11-aout \
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 5df3c52f8e9..029ad1f1f08 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -274,6 +274,7 @@ esac
 case ${target}${target_min} in
 *-*-solaris2.11.[0-3]*		\
| ia64*-*-*\
+   | nios2*-*-*\
  )
 if test "x$enable_obsolete" != xyes; then
   echo "*** Configuration ${target}${target_min} is obsolete." >&2
-- 
2.25.1



Re: [PATCH] docs: Use @var{S} etc. in Spec File invoke.texi documentation

2024-03-27 Thread Sandra Loosemore

On 3/27/24 04:57, Jakub Jelinek wrote:

Hi!

We got internally a question about the Spec File syntax, misunderstanding
what is the literal syntax and what are the placeholder variables in
the syntax descriptions.
The following patch attempts to use @var{S} etc. instead of just S
to clarify it stands for any option (or start of option etc.) rather
than literal S, say in %{S:X}.  At least in HTML documentation it
then uses italics.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?


Looks good for me, as long as you visually inspected the changed text in 
the manual and didn't just make sure it still builds.  (I generally 
consider any markup/formatting changes "obvious" as long as they 
actually look OK.)


-Sandra


Re: [PATCH v7] C, ObjC: Add -Wunterminated-string-initialization

2024-03-05 Thread Sandra Loosemore

On 3/5/24 13:33, Alejandro Colomar wrote:

Warn about the following:

 char  s[3] = "foo";

Initializing a char array with a string literal of the same length as
the size of the array is usually a mistake.  Rarely is the case where
one wants to create a non-terminated character sequence from a string
literal.

In some cases, for writing faster code, one may want to use arrays
instead of pointers, since that removes the need for storing an array of
pointers apart from the strings themselves.

 char  *log_levels[]   = { "info", "warning", "err" };
vs.
 char  log_levels[][7] = { "info", "warning", "err" };

This forces the programmer to specify a size, which might change if a
new entry is later added.  Having no way to enforce null termination is
very dangerous, however, so it is useful to have a warning for this, so
that the compiler can make sure that the programmer didn't make any
mistakes.  This warning catches the bug above, so that the programmer
will be able to fix it and write:

 char  log_levels[][8] = { "info", "warning", "err" };

This warning already existed as part of -Wc++-compat, but this patch
allows enabling it separately.  It is also included in -Wextra, since
it may not always be desired (when unterminated character sequences are
wanted), but it's likely to be desired in most cases.

Since Wc++-compat now includes this warning, the test has to be modified
to expect the text of the new warning too, in .


The documentation parts of the patch are OK.

-Sandra



Re: [Patch] invoke.texi: Add note that -foffload= does not affect device detection

2024-03-03 Thread Sandra Loosemore

On 3/1/24 17:29, Sandra Loosemore wrote:

On 3/1/24 08:23, Tobias Burnus wrote:
Aside: Shouldn't all the HTML documents start with a  and  
before

the table of content? Currently, it has:
   Top (GNU libgomp)
and the body starts with
   Short Table of Contents


I think this is a bug in the version of texinfo used to produce the HTML 
content for the GCC web site.  Looking at a recent build of my own using 
Texinfo 6.7, I do see



GNU libgomp

The manual on the web site says it was produced by "GNU Texinfo 7.0dev".


I poked at this a little and apparently you need to fiddle with the 
SHOW_TITLE or NO_TOP_NODE_OUTPUT customization variables in recent 
versions of Texinfo in order to get the document title to show up in 
HTML output.


https://www.gnu.org/software/texinfo/manual/texinfo/texinfo.html#index-SHOW_005fTITLE

Probably this has to be controlled by a configure check since older 
Texinfo versions may barf on unknown options.


I'm not at a good point to fiddle with this myself right now (I'm deep 
inside more metadirective/declare variant hacking), also I have no idea 
how to re-do the HTML manuals linked from the GCC web site to tweak the 
formatting in this way.  I'd think that if we were going to do that, 
we'd also want to use an official release version of Texinfo instead of 
a "dev" snapshot.


-Sandra


Re: [Patch] invoke.texi: Add note that -foffload= does not affect device detection

2024-03-01 Thread Sandra Loosemore

On 3/1/24 08:23, Tobias Burnus wrote:

Not very often, but do I keep running into issues (fails, segfaults)
related to testing programs compiled with a GCC without offload
configured and then using the system libraries. - That's equivalent
to having the system compiler (or any offload compiler) and
compiling with -foffload=disable.

The problem is that while the program only contains host code,
the run-time library still initializes devices when an API
routine - such as omp_get_num_devices - is invoked. This can
lead to odd bugs as target regions, obviously, will use host
fallback (for any device number) but the API routines will
happily operate on the actual devices, which can lead to odd
errors.

(Likewise issue when compiling for one offload target type
and running on a system which has devices of an other type.)

I assume that that's not a very common problem, but it can be
rather confusing when hitting this issue.

Maybe the proposed wording will help others to avoid this pitfall.
(Or is this superfluous as -foffload= is not much used and, even if,
no one then remembers or finds this none?)

Thoughts?


Well, I spent a long time looking at this, and my only conclusion is 
that I don't really understand what the problem you're trying to solve 
is.  If it's problematical to have the runtime know about offload 
devices the compiled code isn't using, don't users also need to know how 
to restrict the runtime to a particular set of devices the same way 
-foffload= lets you do, and not just how to disable offloading in the 
runtime entirely?


It's pretty clearly documented already how -foffload affects the 
compiler's behavior, and the library's behavior is already documented in 
its own manual.  Maybe what we don't have is a tutorial on how to 
build/link/run programs using a specific offload device, or on the host?


Anyway, I don't really object to the text you want to add, but it makes 
me more confused instead of less so.  :-S




* * *

It was not clear to me how to refer to libgomp.texi
- Should it be 'libgomp' as in 'info libgomp' or the URL
   https://gcc.gnu.org/onlinedocs/libgomp/ (or filename of the PDF) 
implies?

- Or as  'GNU Offloading and Multi Processing Runtime Library Manual'
   as named linked to at https://gcc.gnu.org/onlinedocs or on the title 
page
   of the the PDF - but that name is not repeated in the info file or 
the HTML

   file.
- Or even 'GNU libgomp' to mirror a substring in the  of the HTML 
file.

I now ended up only implicitly referring that document.


The Texinfo input file has "@settitle GNU libgomp".

Aside: Shouldn't all the HTML documents start with a  and  
before

the table of content? Currently, it has:
   Top (GNU libgomp)
and the body starts with
   Short Table of Contents


I think this is a bug in the version of texinfo used to produce the HTML 
content for the GCC web site.  Looking at a recent build of my own using 
Texinfo 6.7, I do see



GNU libgomp

The manual on the web site says it was produced by "GNU Texinfo 7.0dev".

-Sandra



Re: [PATCH v5 RESEND] C, ObjC: Add -Wunterminated-string-initialization

2024-02-26 Thread Sandra Loosemore

On 2/26/24 09:19, Joseph Myers wrote:

On Mon, 26 Feb 2024, Alejandro Colomar wrote:


The idea seems reasonable, but the patch needs documentation for the new
option in invoke.texi.


Thanks!  Will do.

I don't see an obvious order in that file.  Where would you put the
option?  Do you want me to sort(1) it first, and then insert the new
option in alphabetic order?


Sandra might have a better idea of how the warning options ought to be
ordered in the manual.  (Obviously, don't mix reordering with any content
changes.)


Please don't blindly sort the options sections of the manual.  They've 
typically been organized to present general options first (things like 
-Wpedantic in the warning options section, or -g or -o in the debugging 
and optimization optimization sections), then more specialized flags for 
controlling specific individual behaviors.  We could do a better job of 
keeping the latter sublists alphabetized, but in some cases we have also 
grouped documentation for related options together even if they are not 
alphabetical, but that needs some manual review and decision-making and 
should not be mixed with adding new content.  We do try to keep the 
lists in the "Option Summary" section alphabetized except for the 
general options listed first, though.


As far as where to put documentation for new options, I'd say that you 
should put it in alphabetical order in the appropriate section, unless 
there is good reason to put it somewhere else, or the alphabetization of 
the whole section is so messed-up you can't figure out where it should 
go (putting it at the end is OK in that case, as opposed to some other 
random location in the list).  Remember to add the matching entry in the 
appropriate "Option Summary" list, and for this option IIUC you also 
need to add it to the lists of other options enabled by -Wextra and 
-Wc++-compat.


Are we still accepting patches to add new options in stage 4, or is this 
a stage 1 item?


-Sandra


Re: [PATCH v4 5/5] Add documentation for musttail attribute

2024-02-03 Thread Sandra Loosemore

On 2/2/24 02:09, Andi Kleen wrote:

gcc/ChangeLog:

* doc/extend.texi: Document [[musttail]]
---
  gcc/doc/extend.texi | 16 
  1 file changed, 16 insertions(+)

diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 142e41ab8fbf..866f6c4a9fed 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -9875,6 +9875,22 @@ foo (int x, int y)
  @code{y} is not actually incremented and the compiler can but does not
  have to optimize it to just @code{return 42 + 42;}.
  
+@cindex @code{musttail} statement attribute

+@item musttail
+
+The @code{gnu::musttail} or @code{clang::musttail} attribute
+can be applied to a return statement that returns the value
+of a call to indicate that the call must be a tail call
+that does not allocate extra stack space.


It took me about 3 attempts to parse this.  :-S  I think this might be a 
little better:


...can be applied to a @code{return} statement with a return-value 
expression that is a function call.  It asserts that the call must be a 
tail call that does not allocate extra stack space.



+
+@smallexample
+[[gnu::musttail]] return foo();
+@end smallexample
+
+If the compiler cannot generate a tail call it will generate


s/will generate/generates/

I'm a big fan of writing in the present tense.  ;-)


+an error. Tail calls generally require enabling optimization.
+On some targets they may not be supported.
+
  @end table
  
  @node Attribute Syntax


In addition to these changes, at the beginning of this section we have

@node Statement Attributes
@section Statement Attributes
@cindex Statement Attributes

GCC allows attributes to be set on null statements.  @xref{Attribute 
Syntax},

for details of the exact syntax for using attributes. [...]

Well, we now have an attribute that goes on a non-null statement, so we 
have to fix this.  The documentation for the other statement attributes 
is already explicit that they go on null statements so those already 
would be OK if we just removed the "null" restriction here.  OTOH, the 
Attribute Syntax section, in discussing GCC's traditional attribute 
syntax, says:


@subsubheading Statement Attributes
In GNU C, an attribute specifier list may appear as part of a null
statement.  The attribute goes before the semicolon.

If "musttail" is only supported in the standard attribute syntax, its 
new entry in the Statement Attributes node must say that, and the blurb 
at the top of the node quoted above must say something to the effect 
that the traditional syntax only allows statement attributes on null 
statements and attributes on non-null statements are only permitted in 
the new standard attribute form.


-Sandra



[Committed] MAINTAINERS: Update my e-mail address.

2024-02-01 Thread Sandra Loosemore
ChangeLog/
* MAINTAINERS: Update my e-mail address.
---
 MAINTAINERS | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 9d92be1f301..b47e0465852 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -100,7 +100,7 @@ msp430 port Nick Clifton

 nds32 port Chung-Ju Wu 
 nds32 port Shiva Chen  
 nios2 port Chung-Lin Tang  
-nios2 port Sandra Loosemore
+nios2 port Sandra Loosemore
 nvptx port Tom de Vries
 nvptx port Thomas Schwinge 
 or1k port  Stafford Horne  
@@ -228,7 +228,7 @@ build machinery (*.in)  Alexandre Oliva 

 build machinery (*.in) Ralf Wildenhues 
 docs co-maintainer Gerald Pfeifer  
 docs co-maintainer Joseph Myers
-docs co-maintainer Sandra Loosemore
+docs co-maintainer Sandra Loosemore
 docstring relicensing  Gerald Pfeifer  
 docstring relicensing  Joseph Myers
 predict.defJan Hubicka 
-- 
2.34.1



[COMMITTED, obvious] Sort warning options in c-family/c.opt.

2024-01-22 Thread Sandra Loosemore
In spite of the plea "Please try to keep this file in ASCII collating
order" at the top of the file, the sorting of the entries for the
various -Wfoo options had increased in entropy.  This made it hard to
correlate them against e.g. the list of options enabled by -Wall in
the manual (see PR90463).  This patch is at least a step in the right
direction to restore order to the file.

I confirmed that no lines were added or removed by these changes, and
that the output of "gcc -Q --help=warnings" is unchanged both with or
without -Wall added to the command.

gcc/c-family/ChangeLog
* c.opt: Improve sorting of warning options.
---
 gcc/c-family/c.opt | 488 ++---
 1 file changed, 244 insertions(+), 244 deletions(-)

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 314bd17004f..9c0a28092fc 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -303,6 +303,10 @@ Waddress
 C ObjC C++ ObjC++ Var(warn_address) Warning LangEnabledBy(C ObjC C++ 
ObjC++,Wall)
 Warn about suspicious uses of memory addresses.
 
+Waddress-of-packed-member
+C ObjC C++ ObjC++ Var(warn_address_of_packed_member) Init(1) Warning
+Warn when the address of packed member of struct or union is taken.
+
 Enum
 Name(warn_aligned_new_level) Type(int) UnknownError(argument %qs to 
%<-Waligned-new%> not recognized)
 
@@ -358,6 +362,10 @@ Wno-alloca-larger-than
 C ObjC C++ LTO ObjC++ Alias(Walloca-larger-than=,18446744073709551615EiB,none) 
Warning
 Disable Walloca-larger-than= warning.  Equivalent to 
Walloca-larger-than= or larger.
 
+Warith-conversion
+C ObjC C++ ObjC++ Var(warn_arith_conv) Warning
+Warn if conversion of the result of arithmetic might change the value even 
though converting the operands cannot.
+
 Warray-bounds=
 LangEnabledBy(C ObjC C++ LTO ObjC++,Wall,1,0)
 ; in common.opt
@@ -374,10 +382,6 @@ Warray-parameter=
 C ObjC C++ ObjC++ Joined RejectNegative UInteger Var(warn_array_parameter) 
IntegerRange(0, 2) LangEnabledBy(C ObjC C++ ObjC++,Wall, 2, 0) Warning
 Warn about mismatched declarations of array parameters and unsafe accesses to 
them.
 
-Wzero-length-bounds
-C ObjC C++ ObjC++ Var(warn_zero_length_bounds) Warning LangEnabledBy(C ObjC 
C++ ObjC++,Wall)
-Warn about accesses to interior zero-length array members.
-
 Wassign-intercept
 ObjC ObjC++ Var(warn_assign_intercept) Warning
 Warn whenever an Objective-C assignment is being intercepted by the garbage 
collector.
@@ -421,10 +425,6 @@ Wbool-operation
 C ObjC C++ ObjC++ Var(warn_bool_op) Warning LangEnabledBy(C ObjC C++ 
ObjC++,Wall)
 Warn about certain operations on boolean expressions.
 
-Wframe-address
-C ObjC C++ ObjC++ Var(warn_frame_address) Warning LangEnabledBy(C ObjC C++ 
ObjC++,Wall)
-Warn when __builtin_frame_address or __builtin_return_address is used unsafely.
-
 Wbuiltin-declaration-mismatch
 C ObjC C++ ObjC++ Var(warn_builtin_declaration_mismatch) Init(1) Warning
 Warn when a built-in function is declared with the wrong signature.
@@ -534,6 +534,14 @@ Wchkp
 C ObjC C++ ObjC++ Warning WarnRemoved
 Removed in GCC 9.  This switch has no effect.
 
+Wclass-conversion
+C++ ObjC++ Var(warn_class_conversion) Init(1) Warning
+Warn when a conversion function will never be called due to the type it 
converts to.
+
+Wclass-memaccess
+C++ ObjC++ Var(warn_class_memaccess) Warning LangEnabledBy(C++ ObjC++, Wall)
+Warn for unsafe raw memory writes to objects of class types.
+
 Wclobbered
 C ObjC C++ ObjC++ Var(warn_clobbered) Warning EnabledBy(Wextra)
 Warn about variables that might be changed by \"longjmp\" or \"vfork\".
@@ -650,6 +658,14 @@ Wdiv-by-zero
 C ObjC C++ ObjC++ Var(warn_div_by_zero) Init(1) Warning
 Warn about compile-time integer division by zero.
 
+Wdouble-promotion
+C ObjC C++ ObjC++ Var(warn_double_promotion) Warning
+Warn about implicit conversions from \"float\" to \"double\".
+
+Wduplicate-decl-specifier
+C ObjC Var(warn_duplicate_decl_specifier) Warning LangEnabledBy(C ObjC,Wall)
+Warn when a declaration has duplicate const, volatile, restrict or _Atomic 
specifier.
+
 Wduplicated-branches
 C ObjC C++ ObjC++ Var(warn_duplicated_branches) Init(0) Warning
 Warn about duplicated branches in if-else statements.
@@ -662,6 +678,10 @@ Weffc++
 C++ ObjC++ Var(warn_ecpp) Warning
 Warn about violations of Effective C++ style rules.
 
+Welaborated-enum-base
+C++ ObjC++ Var(warn_elaborated_enum_base) Warning Init(1)
+Warn if an additional enum-base is used in an elaborated-type-specifier.
+
 Wempty-body
 C ObjC C++ ObjC++ Var(warn_empty_body) Warning EnabledBy(Wextra)
 Warn about an empty body in an if or else statement.
@@ -694,6 +714,10 @@ Wexceptions
 C++ ObjC++ Var(warn_exceptions) Init(1) Warning
 Warn when an exception handler is shadowed by another handler.
 
+Wexpansion-to-defined
+C ObjC C++ ObjC++ CPP(warn_expansion_to_defined) 
CppReason(CPP_W_EXPANSION_TO_DEFINED) Var(cpp_warn_expansion_to_defined) 
Init(0) Warning EnabledBy(Wextra || Wpedantic)
+Warn if \"defined\" is used outside #if.
+
 

[COMMITTED] Correct lists of options enabled by -Wall and -Wextra [PR90463]

2024-01-22 Thread Sandra Loosemore
gcc/ChangeLog
PR c++/90463
* doc/invoke.texi (Warning Options): Correct lists of options
enabled by -Wall and -Wextra by checking against common.opt
and c-family/c.opt.
---
 gcc/doc/invoke.texi | 79 -
 1 file changed, 50 insertions(+), 29 deletions(-)

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 278c931b6a3..676e7ef03d1 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -6202,27 +6202,37 @@ Options} and @ref{Objective-C and Objective-C++ Dialect 
Options}.
 @option{-Wall} turns on the following warning flags:
 
 @gccoptlist{-Waddress
+-Waligned-new @r{(C++ and Objective-C++ only)}
 -Warray-bounds=1 @r{(only with} @option{-O2}@r{)}
 -Warray-compare
--Warray-parameter=2 @r{(C and Objective-C only)}
+-Warray-parameter=2
 -Wbool-compare
 -Wbool-operation
--Wc++11-compat  -Wc++14-compat
+-Wc++11-compat  -Wc++14-compat  -Wc++17compat  -Wc++20compat
 -Wcatch-value @r{(C++ and Objective-C++ only)}
 -Wchar-subscripts
+-Wclass-memaccess @r{(C++ and Objective-C++ only)}
 -Wcomment
+-Wdangling-else
 -Wdangling-pointer=2
+-Wdelete-non-virtual-dtor @r{(C++ and Objective-C++ only)}
 -Wduplicate-decl-specifier @r{(C and Objective-C only)}
 -Wenum-compare @r{(in C/ObjC; this is on by default in C++)}
 -Wenum-int-mismatch @r{(C and Objective-C only)}
--Wformat
--Wformat-overflow
--Wformat-truncation
--Wint-in-bool-context
+-Wformat=1
+-Wformat-contains-nul
+-Wformat-diag
+-Wformat-extra-args
+-Wformat-overflow=1
+-Wformat-truncation=1
+-Wformat-zero-length
+-Wframe-address
 -Wimplicit @r{(C and Objective-C only)}
--Wimplicit-int @r{(C and Objective-C only)}
 -Wimplicit-function-declaration @r{(C and Objective-C only)}
--Winit-self @r{(only for C++)}
+-Wimplicit-int @r{(C and Objective-C only)}
+-Winfinite-recursion
+-Winit-self @r{(C++ and Objective-C++ only)}
+-Wint-in-bool-context
 -Wlogical-not-parentheses
 -Wmain @r{(only for C/ObjC and unless} @option{-ffreestanding}@r{)}
 -Wmaybe-uninitialized
@@ -6230,24 +6240,26 @@ Options} and @ref{Objective-C and Objective-C++ Dialect 
Options}.
 -Wmemset-transposed-args
 -Wmisleading-indentation @r{(only for C/C++)}
 -Wmismatched-dealloc
--Wmismatched-new-delete @r{(only for C/C++)}
+-Wmismatched-new-delete @r{(C++ and Objective-C++ only)}
 -Wmissing-attributes
 -Wmissing-braces @r{(only for C/ObjC)}
 -Wmultistatement-macros
--Wnarrowing @r{(only for C++)}
+-Wnarrowing  @r{(C++ and Objective-C++ only)}
 -Wnonnull
 -Wnonnull-compare
--Wopenmp-simd
+-Wopenmp-simd @r{(C and C++ only)}
+-Woverloaded-virtual=1 @r{(C++ and Objective-C++ only)}
+-Wpacked-not-aligned
 -Wparentheses
--Wpessimizing-move @r{(only for C++)}
--Wpointer-sign
--Wrange-loop-construct @r{(only for C++)}
--Wreorder
+-Wpessimizing-move @r{(C++ and Objective-C++ only)}
+-Wpointer-sign @r{(only for C/ObjC)}
+-Wrange-loop-construct @r{(C++ and Objective-C++ only)}
+-Wreorder @r{(C++ and Objective-C++ only)}
 -Wrestrict
 -Wreturn-type
--Wself-move @r{(only for C++)}
+-Wself-move @r{(C++ and Objective-C++ only)}
 -Wsequence-point
--Wsign-compare @r{(only in C++)}
+-Wsign-compare @r{(C++ and Objective-C++ only)}
 -Wsizeof-array-div
 -Wsizeof-pointer-div
 -Wsizeof-pointer-memaccess
@@ -6258,12 +6270,16 @@ Options} and @ref{Objective-C and Objective-C++ Dialect 
Options}.
 -Wtrigraphs
 -Wuninitialized
 -Wunknown-pragmas
+-Wunused
+-Wunused-but-set-variable
+-Wunused-const-variable=1 @r{(only for C/ObjC)}
 -Wunused-function
 -Wunused-label
+-Wunused-local-typedefs
 -Wunused-value
 -Wunused-variable
 -Wuse-after-free=2
--Wvla-parameter @r{(C and Objective-C only)}
+-Wvla-parameter
 -Wvolatile-register-var
 -Wzero-length-bounds}
 
@@ -6283,27 +6299,32 @@ This enables some extra warning flags that are not 
enabled by
 @option{-Wall}. (This option used to be called @option{-W}.  The older
 name is still supported, but the newer name is more descriptive.)
 
-@gccoptlist{-Wclobbered
+@gccoptlist{-Wabsolute-value @r{(only for C/ObjC)}
+-Walloc-size
+-Wcalloc-transposed-args
 -Wcast-function-type
--Wdeprecated-copy @r{(C++ only)}
+-Wclobbered
+-Wdeprecated-copy @r{(C++ and Objective-C++ only)}
 -Wempty-body
--Wenum-conversion @r{(C only)}
--Wignored-qualifiers
+-Wenum-conversion @r{(only for C/ObjC)}
+-Wexpansion-to-defined
+-Wignored-qualifiers  @r{(only for C/C++)}
 -Wimplicit-fallthrough=3
+-Wmaybe-uninitialized
 -Wmissing-field-initializers
--Wmissing-parameter-type @r{(C only)}
--Wold-style-declaration @r{(C only)}
--Woverride-init
--Wsign-compare @r{(C only)}
+-Wmissing-parameter-type @r{(C/ObjC only)}
+-Wold-style-declaration @r{(C/ObjC only)}
+-Woverride-init @r{(C/ObjC only)}
+-Wredundant-move @r{(C++ and Objective-C++ only)}
+-Wshift-negative-value @r{(in C++11 to C++17 and in C99 and newer)}
+-Wsign-compare @r{(C++ and Objective-C++ only)}
+-Wsized-deallocation @r{(C++ and Objective-C++ only)}
 -Wstring-compare
--Wredundant-move @r{(only for C++)}
 -Wtype-limits
 -Wuninitialized
--Wshift-negative-value @r{(in C++11 to 

[COMMITTED] Make the manual clearer about what options -Wunused enables [PR90464]

2024-01-21 Thread Sandra Loosemore
gcc/ChangeLog
PR c++/90464
* doc/invoke.texi (Warning Options): Document that -Wunused-parameter
isn't enabled by -Wunused unless -Wextra is provided, and that
-Wunused does enable -Wunused-const-variable=1 for C.  Clarify that
-Wunused doesn't enable -Wunused-* options documented as behaving
otherwise, and list them explicitly.
---
 gcc/doc/invoke.texi | 28 ++--
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index f7a6e11d20e..278c931b6a3 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -7598,6 +7598,8 @@ This warning is enabled by @option{-Wall}.
 @opindex Wno-unused-parameter
 @item -Wunused-parameter
 Warn whenever a function parameter is unused aside from its declaration.
+This option is not enabled by @code{-Wunused} unless @code{-Wextra} is also
+specified.
 
 To suppress this warning use the @code{unused} attribute
 (@pxref{Variable Attributes}).
@@ -7624,25 +7626,26 @@ To suppress this warning use the @code{unused} attribute
 @item -Wunused-const-variable
 @itemx -Wunused-const-variable=@var{n}
 Warn whenever a constant static variable is unused aside from its declaration.
-@option{-Wunused-const-variable=1} is enabled by @option{-Wunused-variable}
-for C, but not for C++. In C this declares variable storage, but in C++ this
-is not an error since const variables take the place of @code{#define}s.
 
 To suppress this warning use the @code{unused} attribute
 (@pxref{Variable Attributes}).
 
 @table @gcctabopt
 @item -Wunused-const-variable=1
-This is the warning level that is enabled by @option{-Wunused-variable} for
-C.  It warns only about unused static const variables defined in the main
+Warn about unused static const variables defined in the main
 compilation unit, but not about static const variables declared in any
 header included.
 
+@option{-Wunused-const-variable=1} is enabled by either
+@option{-Wunused-variable} or @option{-Wunused} for C, but not for
+C++. In C this declares variable storage, but in C++ this is not an
+error since const variables take the place of @code{#define}s.
+
 @item -Wunused-const-variable=2
 This warning level also warns for unused constant static variables in
-headers (excluding system headers).  This is the warning level of
-@option{-Wunused-const-variable} and must be explicitly requested since
-in C++ this isn't an error and in C it might be harder to clean up all
+headers (excluding system headers).  It is equivalent to the short form
+@option{-Wunused-const-variable}.  This level must be explicitly
+requested in both C and C++ because it might be hard to clean up all
 headers included.
 @end table
 
@@ -7661,11 +7664,16 @@ This warning is enabled by @option{-Wall}.
 @opindex Wunused
 @opindex Wno-unused
 @item -Wunused
-All the above @option{-Wunused} options combined.
+All the above @option{-Wunused} options combined, except those documented
+as needing to be specified explicitly.
 
 In order to get a warning about an unused function parameter, you must
 either specify @option{-Wextra -Wunused} (note that @option{-Wall} implies
-@option{-Wunused}), or separately specify @option{-Wunused-parameter}.
+@option{-Wunused}), or separately specify @option{-Wunused-parameter} and/or
+@option{-Wunused-but-set-parameter}.
+
+@option{-Wunused} enables only @option{-Wunused-const-variable=1} rather than
+@option{-Wunused-const-variable}, and only for C, not C++.
 
 @opindex Wuse-after-free
 @opindex Wno-use-after-free
-- 
2.31.1



[COMMITTED] Clean up examples for -Wdangling-pointer [PR109708]

2024-01-20 Thread Sandra Loosemore
gcc/ChangeLog
PR c/109708
* doc/invoke.texi (Warning Options): Fix broken example and
clean up/reorganize the others.  Also describe what the short-form
options mean.
---
 gcc/doc/invoke.texi | 56 +++--
 1 file changed, 34 insertions(+), 22 deletions(-)

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 930c5dc7236..f7a6e11d20e 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -9423,51 +9423,63 @@ levels but may yield different results with 
optimization than without.
 
 @table @gcctabopt
 @item -Wdangling-pointer=1
-At level 1 the warning diagnoses only unconditional uses of dangling pointers.
-For example
+At level 1, the warning diagnoses only unconditional uses of dangling pointers.
+
+@item -Wdangling-pointer=2
+At level 2, in addition to unconditional uses the warning also diagnoses
+conditional uses of dangling pointers.
+@end table
+
+The short form @option{-Wdangling-pointer} is equivalent to
+@option{-Wdangling-pointer=2}, while @option{-Wno-dangling-pointer} and
+@option{-Wdangling-pointer=0} have the same effect of disabling the warnings.
+@option{-Wdangling-pointer=2} is included in @option{-Wall}.
+
+This example triggers the warning at level 1; the address of the unnamed
+temporary is unconditionally referenced outside of its scope.
+
 @smallexample
-int f (int c1, int c2, x)
+char f (char c1, char c2, char c3)
 @{
-  char *p = strchr ((char[])@{ c1, c2 @}, c3);
-  // warning: dangling pointer to a compound literal
-  return p ? *p : 'x';
+  char *p;
+  @{
+p = (char[]) @{ c1, c2, c3 @};
+  @}
+  // warning: using dangling pointer 'p' to an unnamed temporary
+  return *p;
 @}
 @end smallexample
+
 In the following function the store of the address of the local variable
-@code{x} in the escaped pointer @code{*p} also triggers the warning.
+@code{x} in the escaped pointer @code{*p} triggers the warning at
+level 1.
+
 @smallexample
 void g (int **p)
 @{
   int x = 7;
-  // warning: storing the address of a local variable in *p
+  // warning: storing the address of local variable 'x' in '*p'
   *p = 
 @}
 @end smallexample
 
-@item -Wdangling-pointer=2
-At level 2, in addition to unconditional uses the warning also diagnoses
-conditional uses of dangling pointers.
-
-For example, because the array @var{a} in the following function is out of
-scope when the pointer @var{s} that was set to point is used, the warning
-triggers at this level.
+In this example, the array @var{a} is out of
+scope when the pointer @var{s} is used.  Since the code that sets @code{s}
+is conditional, the warning triggers at level 2.
 
 @smallexample
-void f (char *s)
+extern void frob (const char *);
+void h (char *s)
 @{
   if (!s)
 @{
   char a[12] = "tmpname";
   s = a;
 @}
-  // warning: dangling pointer to a may be used
-  strcat (s, ".tmp");
-  ...
+  // warning: dangling pointer 's' to 'a' may be used
+  frob (s);
 @}
 @end smallexample
-@end table
-
-@option{-Wdangling-pointer=2} is included in @option{-Wall}.
 
 @opindex Wdate-time
 @opindex Wno-date-time
-- 
2.31.1



[COMMITTED] Correct documentation for -Warray-parameter [PR102998]

2024-01-20 Thread Sandra Loosemore
gcc/ChangeLog
PR c/102998
* doc/invoke.texi (Option Summary): Add -Warray-parameter.
(Warning Options): Correct/edit discussion of -Warray-parameter
to make the first example less confusing, and fill in missing info.
---
 gcc/doc/invoke.texi | 24 
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 313f363f5f2..930c5dc7236 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -332,6 +332,7 @@ Objective-C and Objective-C++ Dialects}.
 -Wno-aggressive-loop-optimizations
 -Warith-conversion
 -Warray-bounds  -Warray-bounds=@var{n}  -Warray-compare
+-Warray-parameter  -Warray-parameter=@var{n}
 -Wno-attributes  -Wattribute-alias=@var{n} -Wno-attribute-alias
 -Wno-attribute-warning
 -Wbidi-chars=@r{[}none@r{|}unpaired@r{|}any@r{|}ucn@r{]}
@@ -8467,25 +8468,28 @@ bool same = arr1 == arr2;
 @option{-Warray-compare} is enabled by @option{-Wall}.
 
 @opindex Wno-array-parameter
+@opindex Warray-parameter
 @item -Warray-parameter
 @itemx -Warray-parameter=@var{n}
-Warn about redeclarations of functions involving arguments of array or
+Warn about redeclarations of functions involving parameters of array or
 pointer types of inconsistent kinds or forms, and enable the detection
 of out-of-bounds accesses to such parameters by warnings such as
 @option{-Warray-bounds}.
 
-If the first function declaration uses the array form the bound specified
+If the first function declaration uses the array form for a parameter
+declaration, the bound specified
 in the array is assumed to be the minimum number of elements expected to
 be provided in calls to the function and the maximum number of elements
 accessed by it.  Failing to provide arguments of sufficient size or accessing
 more than the maximum number of elements may be diagnosed by warnings such
-as @option{-Warray-bounds}.  At level 1 the warning diagnoses inconsistencies
+as @option{-Warray-bounds} or @option{-Wstringop-overflow}.
+At level 1, the warning diagnoses inconsistencies
 involving array parameters declared using the @code{T[static N]} form.
 
-For example, the warning triggers for the following redeclarations because
-the first one allows an array of any size to be passed to @code{f} while
-the second one with the keyword @code{static} specifies that the array
-argument must have at least four elements.
+For example, the warning triggers for the second declaration of @code{f}
+because the first one with the keyword @code{static} specifies that
+the array argument must have at least four elements, while the second
+allows an array of any size to be passed to @code{f}.
 
 @smallexample
 void f (int[static 4]);
@@ -8493,7 +8497,7 @@ void f (int[]);   // warning (inconsistent array 
form)
 
 void g (void)
 @{
-  int *p = (int *)malloc (4);
+  int *p = (int *)malloc (1 * sizeof (int));
   f (p);  // warning (array too small)
   @dots{}
 @}
@@ -8514,6 +8518,10 @@ void g (int[8]);// warning (inconsistent array bound)
 @option{-Wvla-parameter} option triggers warnings for similar inconsistencies
 involving Variable Length Array arguments.
 
+The short form of the option @option{-Warray-parameter} is equivalent to
+@option{-Warray-parameter=2}.  The negative form @option{-Wno-array-parameter}
+is equivalent to @option{-Warray-parameter=0}.
+
 @opindex Wattribute-alias
 @opindex Wno-attribute-alias
 @item -Wattribute-alias=@var{n}
-- 
2.31.1



[COMMITTED] More precise documentation for cleanup attribute [PR110029]

2024-01-18 Thread Sandra Loosemore
gcc/ChangeLog
PR c/110029
* doc/extend.texi (Common Variable Attributes): Explain what
happens when multiple variables with cleanups are in the same scope.
---
 gcc/doc/extend.texi | 5 +
 1 file changed, 5 insertions(+)

diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 616e26d47dc..0bc586d120e 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -7782,6 +7782,11 @@ with static storage duration.  The function must take 
one parameter,
 a pointer to a type compatible with the variable.  The return value
 of the function (if any) is ignored.
 
+When multiple variables in the same scope have @code{cleanup}
+attributes, at exit from the scope their associated cleanup functions
+are run in reverse order of definition (last defined, first
+cleanup).
+
 If @option{-fexceptions} is enabled, then @var{cleanup_function}
 is run during the stack unwinding that happens during the
 processing of the exception.  Note that the @code{cleanup} attribute
-- 
2.31.1



[COMMITTED] Improve documentation of noinline and noipa attributes [PR108470]

2024-01-18 Thread Sandra Loosemore
gcc/ChangeLog
PR ipa/108470
* doc/extend.texi (Common Function Attributes): Document that
noinline also disables some interprocedural optimizations and
improve flow to the part about using inline asm instead to
disable calls from being optimized away completely.  Remove the
sentence that says noipa is mainly for internal compiler testing.
---
 gcc/doc/extend.texi | 17 ++---
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index d879ad544b5..616e26d47dc 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -3666,13 +3666,17 @@ propagation.
 @cindex @code{noinline} function attribute
 @item noinline
 This function attribute prevents a function from being considered for
-inlining.
+inlining.  It also disables some other interprocedural optimizations; it's
+preferable to use the more comprehensive @code{noipa} attribute instead
+if that is your goal.
+
 @c Don't enumerate the optimizations by name here; we try to be
 @c future-compatible with this mechanism.
-If the function does not have side effects, there are optimizations
-other than inlining that cause function calls to be optimized away,
-although the function call is live.  To keep such calls from being
-optimized away, put
+Even if a function is declared with the @code{noinline} attribute,
+there are optimizations other than inlining that can cause calls to be
+optimized away if it does not have side effects, although the function
+call is live.  To keep such calls from being optimized away, put
+
 @smallexample
 asm ("");
 @end smallexample
@@ -3691,8 +3695,7 @@ the body.  This attribute implies @code{noinline}, 
@code{noclone} and
 to a combination of other attributes, because its purpose is to suppress
 existing and future optimizations employing interprocedural analysis,
 including those that do not have an attribute suitable for disabling
-them individually.  This attribute is supported mainly for the purpose
-of testing the compiler.
+them individually.
 
 @cindex @code{nonnull} function attribute
 @cindex functions with non-null pointer arguments
-- 
2.31.1



Re: [PATCH] Remove remnant of removed Cygwin options from invoke.texi [PR108521]

2024-01-18 Thread Sandra Loosemore

On 1/18/24 12:41, Sandra Loosemore wrote:

From: Brian Inglis 

The -mcygwin option for x86 Windows was removed in 2010 by commit
3edeb30d044a4852881c34229e618b34f95b0d9e, but this reference was
overlooked.

gcc/ChangeLog
PR target/108521
* doc/invoke.texi (Option Summary): Remove -mcygwin and -mno-cygwin
from x86 Windows Options.


Oops, forgot to edit the tag in the patch before mailing.  This is committed 
now.

-Sandra


[PATCH] Remove remnant of removed Cygwin options from invoke.texi [PR108521]

2024-01-18 Thread Sandra Loosemore
From: Brian Inglis 

The -mcygwin option for x86 Windows was removed in 2010 by commit
3edeb30d044a4852881c34229e618b34f95b0d9e, but this reference was
overlooked.

gcc/ChangeLog
PR target/108521
* doc/invoke.texi (Option Summary): Remove -mcygwin and -mno-cygwin
from x86 Windows Options.
---
 gcc/doc/invoke.texi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 4d43dda9839..0ef2b894ea9 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -1490,7 +1490,7 @@ See RS/6000 and PowerPC Options.
 -munroll-only-small-loops -mlam=@var{choice}}
 
 @emph{x86 Windows Options}
-@gccoptlist{-mconsole  -mcrtdll=@var{library}  -mcygwin  -mno-cygwin  -mdll
+@gccoptlist{-mconsole  -mcrtdll=@var{library}  -mdll
 -mnop-fun-dllimport  -mthread
 -municode  -mwin32  -mwindows  -fno-set-stack-executable}
 
-- 
2.31.1



[COMMITTED] Restore documentation for const/volatile functions [PR107942]

2024-01-18 Thread Sandra Loosemore
In r5-7698-g8648c55f3b703a I accidentally removed the documentation of
GCC's special interpretation of const/volatile qualifiers on functions
from the function attributes section, thinking this was just a
bit-rotten leftover from old versions of GCC.  PR107942 points out
that this functionality is still present even though the docs are now gone.

I decided this material didn't really belong in the function
attributes discussion, but a new subsection in the general list of GCC
extensions to the C language.  And I agree with the comment in the
issue that we shouldn't really recommend this usage any more.

gcc/ChangeLog
PR c/107942
* doc/extend.texi (C Extensions): Add new section to menu.
(Function Attributes):  Move dangling index entries to
(Const and Volatile Functions): New section.
---
 gcc/doc/extend.texi | 37 +++--
 1 file changed, 35 insertions(+), 2 deletions(-)

diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index d1893ad860c..d879ad544b5 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -70,6 +70,7 @@ extensions, accepted by GCC in C90 mode and in C++.
 * Character Escapes::   @samp{\e} stands for the character @key{ESC}.
 * Alignment::   Determining the alignment of a function, type or 
variable.
 * Inline::  Defining inline functions (as fast as macros).
+* Const and Volatile Functions :: GCC interprets these specially in C.
 * Volatiles::   What constitutes an access to a volatile object.
 * Using Assembly Language with C:: Instructions and extensions for interfacing 
C with assembler.
 * Alternate Keywords::  @code{__const__}, @code{__asm__}, etc., for header 
files.
@@ -2522,8 +2523,6 @@ the enclosing block.
 @section Declaring Attributes of Functions
 @cindex function attributes
 @cindex declaring attributes of functions
-@cindex @code{volatile} applied to function
-@cindex @code{const} applied to function
 
 In GNU C and C++, you can use function attributes to specify certain
 function properties that may help the compiler optimize calls or
@@ -10397,6 +10396,40 @@ The definition in the header file causes most calls to 
the function
 to be inlined.  If any uses of the function remain, they refer to
 the single copy in the library.
 
+@node Const and Volatile Functions
+@section Const and Volatile Functions
+@cindex @code{const} applied to function
+@cindex @code{volatile} applied to function
+
+The C standard explicitly leaves the behavior of the @code{const} and
+@code{volatile} type qualifiers applied to functions undefined; these
+constructs can only arise through the use of @code{typedef}.  As an extension,
+GCC defines this use of the @code{const} qualifier to have the same meaning
+as the GCC @code{const} function attribute, and the @code{volatile} qualifier
+to be equivalent to the @code{noreturn} attribute.
+@xref{Common Function Attributes}, for more information.
+
+As examples of this usage,
+
+@smallexample
+
+/* @r{Equivalent to:}
+   void fatal () __attribute__ ((noreturn));  */
+typedef void voidfn ();
+volatile voidfn fatal;
+
+/* @r{Equivalent to:}
+   extern int square (int) __attribute__ ((const));  */
+typedef int intfn (int);
+extern const intfn square;
+@end smallexample
+
+In general, using function attributes instead is preferred, since the
+attributes make both the intent of the code and its reliance on a GNU
+extension explicit.  Additionally, using @code{const} and
+@code{volatile} in this way is specific to GNU C and does not work in
+GNU C++.
+
 @node Volatiles
 @section When is a Volatile Object Accessed?
 @cindex accessing volatiles
-- 
2.31.1



[COMMITTED] Document negative forms of -Wtsan and -Wxor-used-as-pow [PR110847]

2024-01-17 Thread Sandra Loosemore
These warnings are enabled by default, thus the manual should document the
-no form instead of the positive form.

gcc/ChangeLog
PR middle-end/110847
* doc/invoke.texi (Option Summary): Document negative forms of
-Wtsan and -Wxor-used-as-pow.
(Warning Options): Likewise.
---
 gcc/doc/invoke.texi | 22 +++---
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index a537be66736..4d43dda9839 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -410,7 +410,7 @@ Objective-C and Objective-C++ Dialects}.
 -Wswitch  -Wno-switch-bool  -Wswitch-default  -Wswitch-enum
 -Wno-switch-outside-range  -Wno-switch-unreachable  -Wsync-nand
 -Wsystem-headers  -Wtautological-compare  -Wtrampolines  -Wtrigraphs
--Wtrivial-auto-var-init -Wtsan -Wtype-limits  -Wundef
+-Wtrivial-auto-var-init  -Wno-tsan  -Wtype-limits  -Wundef
 -Wuninitialized  -Wunknown-pragmas
 -Wunsuffixed-float-constants  -Wunused
 -Wunused-but-set-parameter  -Wunused-but-set-variable
@@ -424,7 +424,7 @@ Objective-C and Objective-C++ Dialects}.
 -Wvector-operation-performance
 -Wvla  -Wvla-larger-than=@var{byte-size}  -Wno-vla-larger-than
 -Wvolatile-register-var  -Wwrite-strings
--Wxor-used-as-pow
+-Wno-xor-used-as-pow
 -Wzero-length-bounds}
 
 @item Static Analyzer Options
@@ -9090,14 +9090,13 @@ This warning is enabled by default.
 
 @opindex Wtsan
 @opindex Wno-tsan
-@item -Wtsan
-Warn about unsupported features in ThreadSanitizer.
+@item -Wno-tsan
+
+Disable warnings about unsupported features in ThreadSanitizer.
 
 ThreadSanitizer does not support @code{std::atomic_thread_fence} and
 can report false positives.
 
-This warning is enabled by default.
-
 @opindex Wtype-limits
 @opindex Wno-type-limits
 @item -Wtype-limits
@@ -10434,17 +10433,18 @@ and/or writes to register variables.  This warning is 
enabled by
 
 @opindex Wxor-used-as-pow
 @opindex Wno-xor-used-as-pow
-@item -Wxor-used-as-pow @r{(C, C++, Objective-C and Objective-C++ only)}
-Warn about uses of @code{^}, the exclusive or operator, where it appears
-the user meant exponentiation.  Specifically, the warning occurs when the
+@item -Wno-xor-used-as-pow @r{(C, C++, Objective-C and Objective-C++ only)}
+Disable warnings about uses of @code{^}, the exclusive or operator,
+where it appears the code meant exponentiation.
+Specifically, the warning occurs when the
 left-hand side is the decimal constant 2 or 10 and the right-hand side
 is also a decimal constant.
 
 In C and C++, @code{^} means exclusive or, whereas in some other languages
 (e.g. TeX and some versions of BASIC) it means exponentiation.
 
-This warning is enabled by default.  It can be silenced by converting one
-of the operands to hexadecimal.
+This warning can be silenced by converting one of the operands to
+hexadecimal as well as by compiling with @option{-Wno-xor-used-as-pow}.
 
 @opindex Wdisabled-optimization
 @opindex Wno-disabled-optimization
-- 
2.31.1



[COMMITTED] Re-alphabetize attribute tables in extend.texi.

2024-01-17 Thread Sandra Loosemore
These sections used to be alphabetized, but when I was working on the
fix for PR111659 I noticed documentation for some newer attributes had
been inserted at random places in the tables instead of maintaining
alphabetical order.  There's no change to content here, just moving
blocks of text around.

gcc/ChangeLog
* doc/extend.texi (Common Function Attributes): Re-alphabetize
the table.
(Common Variable Attributes): Likewise.
(Common Type Attributes): Likewise.
---
 gcc/doc/extend.texi | 857 ++--
 1 file changed, 430 insertions(+), 427 deletions(-)

diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 91f0b669b9e..d1893ad860c 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -3028,19 +3028,6 @@ types (@pxref{Variable Attributes}, @pxref{Type 
Attributes}.)
 The message attached to the attribute is affected by the setting of
 the @option{-fmessage-length} option.
 
-@cindex @code{unavailable} function attribute
-@item unavailable
-@itemx unavailable (@var{msg})
-The @code{unavailable} attribute results in an error if the function
-is used anywhere in the source file.  This is useful when identifying
-functions that have been removed from a particular variation of an
-interface.  Other than emitting an error rather than a warning, the
-@code{unavailable} attribute behaves in the same manner as
-@code{deprecated}.
-
-The @code{unavailable} attribute can also be used for variables and
-types (@pxref{Variable Attributes}, @pxref{Type Attributes}.)
-
 @cindex @code{error} function attribute
 @cindex @code{warning} function attribute
 @item error ("@var{message}")
@@ -3666,6 +3653,10 @@ This attribute locally overrides the 
@option{-fstack-limit-register}
 and @option{-fstack-limit-symbol} command-line options; it has the effect
 of disabling stack limit checking in the function it applies to.
 
+@cindex @code{no_stack_protector} function attribute
+@item no_stack_protector
+This attribute prevents stack protection code for the function.
+
 @cindex @code{noclone} function attribute
 @item noclone
 This function attribute prevents a function from being considered for
@@ -3761,63 +3752,6 @@ my_memcpy (void *dest, const void *src, size_t len)
 __attribute__((nonnull));
 @end smallexample
 
-@cindex @code{null_terminated_string_arg} function attribute
-@item null_terminated_string_arg
-@itemx null_terminated_string_arg (@var{N})
-The @code{null_terminated_string_arg} attribute may be applied to a
-function that takes a @code{char *} or @code{const char *} at
-referenced argument @var{N}.
-
-It indicates that the passed argument must be a C-style null-terminated
-string.  Specifically, the presence of the attribute implies that, if
-the pointer is non-null, the function may scan through the referenced
-buffer looking for the first zero byte.
-
-In particular, when the analyzer is enabled (via @option{-fanalyzer}),
-if the pointer is non-null, it will simulate scanning for the first
-zero byte in the referenced buffer, and potentially emit
-@option{-Wanalyzer-use-of-uninitialized-value}
-or @option{-Wanalyzer-out-of-bounds} on improperly terminated buffers.
-
-For example, given the following:
-
-@smallexample
-char *example_1 (const char *p)
-  __attribute__((null_terminated_string_arg (1)));
-@end smallexample
-
-the analyzer will check that any non-null pointers passed to the function
-are validly terminated.
-
-If the parameter must be non-null, it is appropriate to use both this
-attribute and the attribute @code{nonnull}, such as in:
-
-@smallexample
-extern char *example_2 (const char *p)
-  __attribute__((null_terminated_string_arg (1),
- nonnull (1)));
-@end smallexample
-
-See the @code{nonnull} attribute for more information and
-caveats.
-
-If the pointer argument is also referred to by an @code{access} attribute on 
the
-function with @var{access-mode} either @code{read_only} or @code{read_write}
-and the latter attribute has the optional @var{size-index} argument
-referring to a size argument, this expressses the maximum size of the access.
-For example, given:
-
-@smallexample
-extern char *example_fn (const char *p, size_t n)
-  __attribute__((null_terminated_string_arg (1),
- access (read_only, 1, 2),
- nonnull (1)));
-@end smallexample
-
-the analyzer will require the first parameter to be non-null, and either
-be validly null-terminated, or validly readable up to the size specified by
-the second parameter.
-
 @cindex @code{noplt} function attribute
 @item noplt
 The @code{noplt} attribute is the counterpart to option @option{-fno-plt}.
@@ -3896,6 +3830,63 @@ the standard C library can be guaranteed not to throw an 
exception
 with the notable exceptions of @code{qsort} and @code{bsearch} that
 take function pointer arguments.
 
+@cindex @code{null_terminated_string_arg} function attribute
+@item null_terminated_string_arg
+@itemx 

[COMMITTED] Clean up documentation for -Wstrict-flex-arrays [PR111659]

2024-01-17 Thread Sandra Loosemore
gcc/ChangeLog
PR middle-end/111659
* doc/extend.texi (Common Variable Attributes): Fix long lines
in documentation of strict_flex_array + other minor copy-editing.
Add a cross-reference to -Wstrict-flex-arrays.
* doc/invoke.texi (Option Summary): Fix whitespace in tables
before -fstrict-flex-arrays and -Wstrict-flex-arrays.
(C Dialect Options): Combine the docs for the two
-fstrict-flex-arrays forms into a single entry.  Note this option
is for C/C++ only.  Add a cross-reference to -Wstrict-flex-arrays.
(Warning Options): Note -Wstrict-flex-arrays is for C/C++ only.
Minor copy-editing.  Add cross references to the strict_flex_array
attribute and -fstrict-flex-arrays option.  Add note that this
option depends on -ftree-vrp.
---
 gcc/doc/extend.texi | 30 +++---
 gcc/doc/invoke.texi | 51 ++---
 2 files changed, 47 insertions(+), 34 deletions(-)

diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 89e823629e3..91f0b669b9e 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -7790,18 +7790,24 @@ are treated as flexible array members. @var{level}=3 is 
the strictest level,
 only when the trailing array is declared as a flexible array member per C99
 standard onwards (@samp{[]}), it is treated as a flexible array member.
 
-There are two more levels in between 0 and 3, which are provided to support
-older codes that use GCC zero-length array extension (@samp{[0]}) or 
one-element
-array as flexible array members (@samp{[1]}):
-When @var{level} is 1, the trailing array is treated as a flexible array member
-when it is declared as either @samp{[]}, @samp{[0]}, or @samp{[1]};
-When @var{level} is 2, the trailing array is treated as a flexible array member
-when it is declared as either @samp{[]}, or @samp{[0]}.
-
-This attribute can be used with or without the @option{-fstrict-flex-arrays}.
-When both the attribute and the option present at the same time, the level of
-the strictness for the specific trailing array field is determined by the
-attribute.
+There are two more levels in between 0 and 3, which are provided to
+support older codes that use GCC zero-length array extension
+(@samp{[0]}) or one-element array as flexible array members
+(@samp{[1]}).  When @var{level} is 1, the trailing array is treated as
+a flexible array member when it is declared as either @samp{[]},
+@samp{[0]}, or @samp{[1]}; When @var{level} is 2, the trailing array
+is treated as a flexible array member when it is declared as either
+@samp{[]}, or @samp{[0]}.
+
+This attribute can be used with or without the
+@option{-fstrict-flex-arrays} command-line option.  When both the
+attribute and the option are present at the same time, the level of
+the strictness for the specific trailing array field is determined by
+the attribute.
+
+The @code{strict_flex_array} attribute interacts with the
+@option{-Wstrict-flex-arrays} option.  @xref{Warning Options}, for more
+information.
 
 @cindex @code{alloc_size} variable attribute
 @item alloc_size (@var{position})
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 43fd3c3a3cd..a537be66736 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -207,7 +207,7 @@ in the following sections.
 -fopenmp  -fopenmp-simd  -fopenmp-target-simd-clone@r{[}=@var{device-type}@r{]}
 -fpermitted-flt-eval-methods=@var{standard}
 -fplan9-extensions  -fsigned-bitfields  -funsigned-bitfields
--fsigned-char  -funsigned-char -fstrict-flex-arrays[=@var{n}]
+-fsigned-char  -funsigned-char  -fstrict-flex-arrays[=@var{n}]
 -fsso-struct=@var{endianness}}
 
 @item C++ Language Options
@@ -405,7 +405,7 @@ Objective-C and Objective-C++ Dialects}.
 -Wstrict-aliasing=n  -Wstrict-overflow  -Wstrict-overflow=@var{n}
 -Wstring-compare
 -Wno-stringop-overflow -Wno-stringop-overread
--Wno-stringop-truncation -Wstrict-flex-arrays
+-Wno-stringop-truncation  -Wstrict-flex-arrays
 -Wsuggest-attribute=@r{[}pure@r{|}const@r{|}noreturn@r{|}format@r{|}malloc@r{]}
 -Wswitch  -Wno-switch-bool  -Wswitch-default  -Wswitch-enum
 -Wno-switch-outside-range  -Wno-switch-unreachable  -Wsync-nand
@@ -2945,22 +2945,22 @@ is always just like one of those two.
 
 @opindex fstrict-flex-arrays
 @opindex fno-strict-flex-arrays
-@item -fstrict-flex-arrays
-Control when to treat the trailing array of a structure as a flexible array
-member for the purpose of accessing the elements of such an array.
-The positive form is equivalent to @option{-fstrict-flex-arrays=3}, which is 
the
-strictest.  A trailing array is treated as a flexible array member only when it
-is declared as a flexible array member per C99 standard onwards.
-The negative form is equivalent to @option{-fstrict-flex-arrays=0}, which is 
the
-least strict.  All trailing arrays of structures are treated as flexible array
-members.
-
 @opindex fstrict-flex-arrays=@var{level}
-@item 

[COMMITTED] Move docs for -Wuse-after-free and -Wuseless-cast [PR111693]

2024-01-16 Thread Sandra Loosemore
These options were categorized as C++ options, but they apply to all
C-family languages.

gcc/ChangeLog
PR c/111693
* doc/invoke.texi (Option Summary): Move -Wuseless-cast
from C++ Language Options to Warning Options.  Add entry for
-Wuse-after-free.
(C++ Dialect Options): Move -Wuse-after-free and -Wuseless-cast
from here
(Warning Options): ...to here.  Minor copy-editing to fix typo
and grammar.
---
 gcc/doc/invoke.texi | 158 ++--
 1 file changed, 79 insertions(+), 79 deletions(-)

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 16e31a3c6db..43fd3c3a3cd 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -271,8 +271,7 @@ in the following sections.
 -Woverloaded-virtual  -Wno-pmf-conversions -Wself-move -Wsign-promo
 -Wsized-deallocation  -Wsuggest-final-methods
 -Wsuggest-final-types  -Wsuggest-override
--Wno-terminate  -Wuseless-cast  -Wno-vexing-parse
--Wvirtual-inheritance
+-Wno-terminate  -Wno-vexing-parse  -Wvirtual-inheritance
 -Wno-virtual-move-assign  -Wvolatile  -Wzero-as-null-pointer-constant}
 
 @item Objective-C and Objective-C++ Language Options
@@ -420,6 +419,7 @@ Objective-C and Objective-C++ Dialects}.
 -Wunused-macros
 -Wunused-parameter  -Wno-unused-result
 -Wunused-value  -Wunused-variable
+-Wuse-after-free  -Wuse-after-free=@var{n}  -Wuseless-cast
 -Wno-varargs  -Wvariadic-macros
 -Wvector-operation-performance
 -Wvla  -Wvla-larger-than=@var{byte-size}  -Wno-vla-larger-than
@@ -4814,83 +4814,6 @@ annotations.
 Warn about overriding virtual functions that are not marked with the
 @code{override} keyword.
 
-@opindex Wuse-after-free
-@opindex Wno-use-after-free
-@item -Wuse-after-free
-@itemx -Wuse-after-free=@var{n}
-Warn about uses of pointers to dynamically allocated objects that have
-been rendered indeterminate by a call to a deallocation function.
-The warning is enabled at all optimization levels but may yield different
-results with optimization than without.
-
-@table @gcctabopt
-@item -Wuse-after-free=1
-At level 1 the warning attempts to diagnose only unconditional uses
-of pointers made indeterminate by a deallocation call or a successful
-call to @code{realloc}, regardless of whether or not the call resulted
-in an actual reallocatio of memory.  This includes double-@code{free}
-calls as well as uses in arithmetic and relational expressions.  Although
-undefined, uses of indeterminate pointers in equality (or inequality)
-expressions are not diagnosed at this level.
-@item -Wuse-after-free=2
-At level 2, in addition to unconditional uses, the warning also diagnoses
-conditional uses of pointers made indeterminate by a deallocation call.
-As at level 2, uses in equality (or inequality) expressions are not
-diagnosed.  For example, the second call to @code{free} in the following
-function is diagnosed at this level:
-@smallexample
-struct A @{ int refcount; void *data; @};
-
-void release (struct A *p)
-@{
-  int refcount = --p->refcount;
-  free (p);
-  if (refcount == 0)
-free (p->data);   // warning: p may be used after free
-@}
-@end smallexample
-@item -Wuse-after-free=3
-At level 3, the warning also diagnoses uses of indeterminate pointers in
-equality expressions.  All uses of indeterminate pointers are undefined
-but equality tests sometimes appear after calls to @code{realloc} as
-an attempt to determine whether the call resulted in relocating the object
-to a different address.  They are diagnosed at a separate level to aid
-legacy code gradually transition to safe alternatives.  For example,
-the equality test in the function below is diagnosed at this level:
-@smallexample
-void adjust_pointers (int**, int);
-
-void grow (int **p, int n)
-@{
-  int **q = (int**)realloc (p, n *= 2);
-  if (q == p)
-return;
-  adjust_pointers ((int**)q, n);
-@}
-@end smallexample
-To avoid the warning at this level, store offsets into allocated memory
-instead of pointers.  This approach obviates needing to adjust the stored
-pointers after reallocation.
-@end table
-
-@option{-Wuse-after-free=2} is included in @option{-Wall}.
-
-@opindex Wuseless-cast
-@opindex Wno-useless-cast
-@item -Wuseless-cast @r{(C, Objective-C, C++ and Objective-C++ only)}
-Warn when an expression is cast to its own type.  This warning does not
-occur when a class object is converted to a non-reference type as that
-is a way to create a temporary:
-
-@smallexample
-struct S @{ @};
-void g (S&&);
-void f (S&& arg)
-@{
-  g (S(arg)); // make arg prvalue so that it can bind to S&&
-@}
-@end smallexample
-
 @opindex Wconversion-null
 @opindex Wno-conversion-null
 @item -Wno-conversion-null @r{(C++ and Objective-C++ only)}
@@ -7739,6 +7662,83 @@ In order to get a warning about an unused function 
parameter, you must
 either specify @option{-Wextra -Wunused} (note that @option{-Wall} implies
 @option{-Wunused}), or separately specify @option{-Wunused-parameter}.
 
+@opindex 

[COMITTED] Tidy documentation for BPF builtins [PR112973]

2024-01-16 Thread Sandra Loosemore
gcc/Changelog
PR target/112973
* doc/extend.texi (BPF Built-in Functions): Wrap long lines and
give the section a light copy-editing pass.
---
 gcc/doc/extend.texi | 38 --
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index b9129d1b464..89e823629e3 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -16832,19 +16832,27 @@ void __builtin_bfin_ssync (void);
 The following built-in functions are available for eBPF targets.
 
 @defbuiltin{{unsigned long long} __builtin_bpf_load_byte (unsigned long long 
@var{offset})}
-Load a byte from the @code{struct sk_buff} packet data pointed by the register 
@code{%r6} and return it.
+Load a byte from the @code{struct sk_buff} packet data pointed to by the
+register @code{%r6}, and return it.
 @enddefbuiltin
 
 @defbuiltin{{unsigned long long} __builtin_bpf_load_half (unsigned long long 
@var{offset})}
-Load 16 bits from the @code{struct sk_buff} packet data pointed by the 
register @code{%r6} and return it.
+Load 16 bits from the @code{struct sk_buff} packet data pointed to by the
+register @code{%r6}, and return it.
 @enddefbuiltin
 
 @defbuiltin{{unsigned long long} __builtin_bpf_load_word (unsigned long long 
@var{offset})}
-Load 32 bits from the @code{struct sk_buff} packet data pointed by the 
register @code{%r6} and return it.
+Load 32 bits from the @code{struct sk_buff} packet data pointed to by the
+register @code{%r6}, and return it.
 @enddefbuiltin
 
-@defbuiltin{{void *} __builtin_preserve_access_index (@var{expr})}
-BPF Compile Once-Run Everywhere (CO-RE) support. Instruct GCC to generate 
CO-RE relocation records for any accesses to aggregate data structures (struct, 
union, array types) in @var{expr}. This builtin is otherwise transparent, the 
return value is whatever @var{expr} evaluates to. It is also overloaded: 
@var{expr} may be of any type (not necessarily a pointer), the return type is 
the same. Has no effect if @code{-mco-re} is not in effect (either specified or 
implied).
+@defbuiltin{@var{type} __builtin_preserve_access_index (@var{type} @var{expr})}
+BPF Compile Once-Run Everywhere (CO-RE) support.  Instruct GCC to
+generate CO-RE relocation records for any accesses to aggregate
+data structures (struct, union, array types) in @var{expr}.  This builtin
+is otherwise transparent; @var{expr} may have any type and its value is
+returned.  This builtin has no effect if @code{-mco-re} is not in effect
+(either specified or implied).
 @enddefbuiltin
 
 @defbuiltin{{unsigned int} __builtin_preserve_field_info (@var{expr}, unsigned 
int @var{kind})}
@@ -16946,36 +16954,38 @@ The return value is the enum value in the target 
kernel.
 
 @defbuiltin{{unsigned int} __builtin_btf_type_id (@var{type}, unsigned int 
@var{kind})}
 BPF Compile Once-Run Everywhere (CO-RE) support. This builtin is used to get
-the BTF type ID of a specified type. Depending on the @var{kind} argument, it
-will either return the ID of the local BTF information, or the BTF type ID in
+the BTF type ID of a specified @var{type}.
+Depending on the @var{kind} argument, it
+either returns the ID of the local BTF information, or the BTF type ID in
 the target kernel.
 
 The following values are supported for @var{kind}:
 @table @code
 @item BTF_TYPE_ID_LOCAL = 0
-Return the local BTF type ID. Always succeeds.
+Return the local BTF type ID.  Always succeeds.
 
 @item BTF_TYPE_ID_TARGET = 1
-Return the target BTF type ID. If type does not exist in the target, returns 0.
+Return the target BTF type ID.  If @var{type} does not exist in the target,
+returns 0.
 @end table
 @enddefbuiltin
 
 @defbuiltin{{unsigned int} __builtin_preserve_type_info (@var{type}, unsigned 
int @var{kind})}
 BPF Compile Once-Run Everywhere (CO-RE) support. This builtin performs named
 type (struct/union/enum/typedef) verifications. The type of verification
-dependents on the @var{kind} argument provided.  This builtin will always
-return 0 if type does not exists in the target kernel.
+depends on the @var{kind} argument provided.  This builtin always
+returns 0 if @var{type} does not exist in the target kernel.
 
 The following values are supported for @var{kind}:
 @table @code
 @item BTF_TYPE_EXISTS = 0
-Checks if type exists in the target.
+Checks if @var{type} exists in the target.
 
 @item BTF_TYPE_MATCHES = 1
-Checks if type matches the local definition in the target kernel.
+Checks if @var{type} matches the local definition in the target kernel.
 
 @item BTF_TYPE_SIZE = 2
-Returns the size of the type within the target.
+Returns the size of the @var{type} within the target.
 @end table
 @enddefbuiltin
 
-- 
2.31.1



Re: [Patch] libgomp.texi: Document omp_pause_resource{,_all} and omp_target_memcpy* (was: [Patch] libgomp.texi: Document omp_pause_resource{,_all})

2024-01-14 Thread Sandra Loosemore

On 1/14/24 16:15, Tobias Burnus wrote:


+@node omp_target_memcpy
+@subsection @code{omp_target_memcpy} -- Copy data between devices
+@table @asis
+@item @emph{Description}:
+This routine tests copies @var{length} of bytes of data from the device
+identified by device number @var{src_device_num} to device 
@var{dst_device_num}.


Hmmm, I'm sure it's the train's fault :-) but "tests copies" makes no sense, 
and that's cut-and-pasted multiple times.  I think you just mean "copies" in 
all cases.



+@node omp_target_memcpy_rect
+@subsection @code{omp_target_memcpy_rect} -- Copy a subvolume of data between 
devices
+@table @asis
+@item @emph{Description}:
+This routine tests copies a subvolume of data from the device identified by
+device number @var{src_device_num} to device @var{dst_device_num}.  The
+subvolume of a multi-dimensional array of array dimension @var{num_dims} and
+each array element has a size of @var{element_size} bytes.  The @var{volume}


This is kind of garbled.  How about rephrasing that second sentence as

The array has @var{num_dims} and each array element has a size of 
@var{element_size} bytes.




+array specifies how many elements per dimension will be copied.  The full


s/will be/are/


+array in number of elements is given by the @var{dst_dimensions} and
+@var{src_dimensions} arguments for the array on the destination and source
+device, respectively.  The offset per dimension to the first element to


I think we can simplify that sentence, too, like

The full sizes of the destination and source arrays are given by the 
@var{dst_dimensions} and @var{src_dimensions} arguments, respectively.



+be copied is given by the @var{dst_offset} and @var{src_offset} arguments.
+The routine returns zero on success and non-zero otherwise.
+
+The OpenMP only requires that @var{num_dims} up to three is supported. In order


s/OpenMP/OpenMP specification/ ?


+to find implementation-specific maximally supported number of dimensions, the
+routine will return this value when invoked with a NULL pointer to both the


s/will return/returns/

either "null pointer" or "@code{NULL}" is preferable to "NULL pointer".


+@var{dst} and @var{src} arguments.  As GCC supports arbitrary dimensions, it
+will return INTMAX.


s/will return INTMAX/returns @code{INT_MAX}/


+
+The device-number arguments must be conforming device number, the @var{src} and


s/number,/numbers,/



+@var{dst} must be either both NULL or any of the following must be fulfilled:


same issue with "NULL" here, either "@code{NULL}" or "null pointers".

"any" seems unlikely to be useful.  Do you mean "all" of the following 
conditions?


+@var{element_size} and @var{num_dims} must be positive, the @var{volume}, 
offset
+and dimension arrays must have at least @var{num_dims} dimensions.
+Running this routine in a @code{target} region except on the initial device
+is not supported.


The part of the patch for omp_target_memcpy_rect_async has very similar 
problems and needs the same fixes.


-Sandra


Re: [Patch] libgomp.texi: Document omp_pause_resource{,_all}

2024-01-14 Thread Sandra Loosemore

On 1/14/24 07:26, Tobias Burnus wrote:
This documents two more OpenMP (5.0) routines, omp_pause_resource and 
omp_pause_resource_all.


Comments, remarks, suggestions - to the patch or the documentation in general?


I have some minor nits about typos and copy-editing.  I assume the formatting 
of the interface syntax

is consistent with how it's done elsewhere in the manual.


+@node Resource Relinquishing Routines
+@section Resource Relinquishing Routines
+
+Routines releasing resources used by the OpenMP runtime.
+They have C linkage and do not throw exceptions.
+
+@menu
+* omp_pause_resource:: Release OpenMP ressouces on a device
+* omp_pause_resource_all:: Release OpenMP ressouces on all devices


s/ressouces/resources/g (there are more instances below)


+@end menu
+
+
+
+@node omp_pause_resource
+@subsection @code{omp_pause_resource} -- Release OpenMP ressouces on a device
+@table @asis
+@item @emph{Description}:
+Free resources used by OpenMP programm and runtime library on and for the


s/OpenMP programm/an OpenMP program/g (same mistake below)


+device specified by @var{device_num}; on success, zero is returned and non-zero
+otherwise.
+
+The value of @var{device_num} must be valid device number.  The effect when


s/valid device number/a valid device number/


+invoked from within a @code{target} region is unspecified.
+
+@item @emph{C/C++}:
+@multitable @columnfractions .20 .80
+@item @emph{Prototype}: @tab @code{int omp_pause_resource(omp_pause_resource_t 
kind, int device_num);}
+@end multitable
+
+@item @emph{Fortran}:
+@multitable @columnfractions .20 .80
+@item @emph{Interface}: @tab @code{integer function omp_pause_resource(kind, 
device_num)}
+@item   @tab @code{integer (kind=omp_pause_resource_kind) kind}
+@item   @tab @code{integer device_num}
+@end multitable
+
+@item @emph{Reference}:
+@uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.43.
+@end table
+
+
+
+@node omp_pause_resource_all
+@subsection @code{omp_pause_resource_all} -- Release OpenMP ressouces on all 
devices
+@table @asis
+@item @emph{Description}:
+Free resources used by OpenMP programm and runtime library on all devices, 
including
+the host. On success, zero is returned and non-zero otherwise.
+
+The effect when invoked from within a @code{target} region is unspecified.
+
+@item @emph{C/C++}:
+@multitable @columnfractions .20 .80
+@item @emph{Prototype}: @tab @code{int omp_pause_resource(omp_pause_resource_t 
kind);}
+@end multitable
+
+@item @emph{Fortran}:
+@multitable @columnfractions .20 .80
+@item @emph{Interface}: @tab @code{integer function omp_pause_resource(kind)}
+@item   @tab @code{integer (kind=omp_pause_resource_kind) kind}
+@end multitable
+
+@item @emph{See also}:
+@ref{omp_pause_resource}
+
+@item @emph{Reference}:
+@uref{https://www.openmp.org, OpenMP specification v5.0}, Section 3.2.44.
+@end table
+
+


Re the content, I see no documentation for omp_pause_resource_t or the 
equivalent in Fortran, or any hint about what the kind argument is for.  I 
understand this is in the OpenMP spec but if you're going to make users read 
the spec anyway I wonder what the purpose of the GCC documentation is.  :-S  If 
it's to explain implementation-specific features, then it should at least be 
documenting whether GCC supports additional pause kinds as permitted by the spec.


-Sandra



Re: [PATCH v2]: gcc/doc/extend.texi: Update builtin example for __builtin_FILE, __builtin_LINE __builtin_FUNCTION

2024-01-13 Thread Sandra Loosemore

On 1/10/24 14:28, Jonny Grant wrote:
>
> 2024-01-10  Jonathan Grant  
> gcc/ChangeLog:
>* doc/extend.texi: Update builtin example for __builtin_FILE
>   __builtin_LINE __builtin_FUNCTION.
>
>
>
>>From 66290eb477dd1a99310ad9972c45391c2a87c1c7 Mon Sep 17 00:00:00 2001
> From: Jonathan Grant 
> Date: Wed, 29 Nov 2023 11:02:06 +
> Subject: [PATCH] gcc/doc: Update builtin example for __builtin_FILE
>   __builtin_LINE __builtin_FUNCTION
>
>
> Signed-off-by: Jonathan Grant 
> ---
>   gcc/doc/extend.texi | 14 --
>   1 file changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
> index 1ae589aeb29..f17a4b215de 100644
> --- a/gcc/doc/extend.texi
> +++ b/gcc/doc/extend.texi
> @@ -14660,20 +14660,22 @@ to @var{F} or the empty string if the call was not 
made at function

>   scope.
>
>   For example, in the following, each call to function @code{foo} will
> -print a line similar to @code{"file.c:123: foo: message"} with the name
> +print a line similar to @code{"file.c:5: foo: message"} with the name

Please also s/will print/prints/

>   of the file and the line number of the @code{printf} call, the name of
>   the function @code{foo}, followed by the word @code{message}.
>
>   @smallexample
> -const char*
> -function (const char *func = __builtin_FUNCTION ())
> +#include 
> +
> +void foo (void)
>   @{
> -  return func;
> +  printf ("%s:%i: %s: message\n", __builtin_FILE (), __builtin_LINE (), 
__builtin_FUNCTION ());
> +  printf ("%s:%i: %s: message\n", __builtin_FILE (), __builtin_LINE (), 
__builtin_FUNCTION ());


Is this duplicated code a mistake?  As you have it, each call to foo prints 
*two* lines, not "a line".  Maybe you mean to have more than one call to foo 
instead of more than one line printed per call?  If it's intentional, please 
correct the above descriptive text.


Also, I'm pretty sure this line of code is too long to format nicely in the PDF 
manual (it's well over 80 characters).  I'd put a line break after the call to 
__builtin_FILE ().


-Sandra




[Committed] libgcc, nios2: Fix exception handling on nios2 with -fpic

2024-01-11 Thread Sandra Loosemore
Exception handling on nios2-linux-gnu with -fpic has been broken since
revision 790854ea7670f11c14d431c102a49181d2915965, "Use _dl_find_object
in _Unwind_Find_FDE".  For whatever reason, this doesn't work on nios2.

Nios2 uses the GOT address as the base for DW_EH_PE_datarel
relocations in PIC; see my previous fix to make this work, revision
2d33dcfe9f0494c9b56a8d704c3d27c5a4329ebc, "Support for GOT-relative
DW_EH_PE_datarel encoding".  So this may be a horrible bug in the ABI
or in my interpretation of it or just glibc's implementation of
_dl_find_object for this target, but there's existing code out there
that does things this way; and realistically, nobody is going to
re-engineer this now that the vendor has EOL'ed the nios2
architecture.  So, just skip over the code trying to use
_dl_find_object on this target and fall back to the way that works.

I plan to backport this patch to the GCC 12 and GCC 13 branches as well.

libgcc/ChangeLog
* unwind-dw2-fde-dip.c (_Unwind_Find_FDE): Do not try to use
_dl_find_object on nios2; it doesn't work.
---
 libgcc/unwind-dw2-fde-dip.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libgcc/unwind-dw2-fde-dip.c b/libgcc/unwind-dw2-fde-dip.c
index 2f2ca35d549..57d0c8812b1 100644
--- a/libgcc/unwind-dw2-fde-dip.c
+++ b/libgcc/unwind-dw2-fde-dip.c
@@ -543,8 +543,9 @@ _Unwind_Find_FDE (void *pc, struct dwarf_eh_bases *bases)
 return ret;
 
   /* Use DLFO_STRUCT_HAS_EH_DBASE as a proxy for the existence of a glibc-style
- _dl_find_object function.  */
-#ifdef DLFO_STRUCT_HAS_EH_DBASE
+ _dl_find_object function.  However, do not use _dl_find_object on nios2,
+ which uses the GOT address as the base for DW_EH_PE_datarel instead.  */
+#if defined(DLFO_STRUCT_HAS_EH_DBASE) && !defined(__nios2__)
   {
 struct dl_find_object dlfo;
 if (_dl_find_object (pc, ) == 0 && dlfo.dlfo_eh_frame != NULL)
-- 
2.31.1



[PATCH 6/8] OpenMP: common c/c++ testcases for metadirectives

2024-01-06 Thread Sandra Loosemore
From: Kwok Cheung Yeung 

gcc/testsuite/ChangeLog
* c-c++-common/gomp/metadirective-1.c: New.
* c-c++-common/gomp/metadirective-2.c: New.
* c-c++-common/gomp/metadirective-3.c: New.
* c-c++-common/gomp/metadirective-4.c: New.
* c-c++-common/gomp/metadirective-5.c: New.
* c-c++-common/gomp/metadirective-6.c: New.
* c-c++-common/gomp/metadirective-7.c: New.
* c-c++-common/gomp/metadirective-8.c: New.
* c-c++-common/gomp/metadirective-construct.c: New.
* c-c++-common/gomp/metadirective-device.c: New.
* c-c++-common/gomp/metadirective-no-score.c: New.
* c-c++-common/gomp/metadirective-target-device.c: New.

libgomp/ChangeLog
* testsuite/libgomp.c-c++-common/metadirective-1.c: New.
* testsuite/libgomp.c-c++-common/metadirective-2.c: New.
* testsuite/libgomp.c-c++-common/metadirective-3.c: New.
* testsuite/libgomp.c-c++-common/metadirective-4.c: New.
* testsuite/libgomp.c-c++-common/metadirective-5.c: New.

Co-Authored-By: Sandra Loosemore 
---
 .../c-c++-common/gomp/metadirective-1.c   |  52 +
 .../c-c++-common/gomp/metadirective-2.c   |  74 
 .../c-c++-common/gomp/metadirective-3.c   |  31 +++
 .../c-c++-common/gomp/metadirective-4.c   |  40 
 .../c-c++-common/gomp/metadirective-5.c   |  24 +++
 .../c-c++-common/gomp/metadirective-6.c   |  31 +++
 .../c-c++-common/gomp/metadirective-7.c   |  31 +++
 .../c-c++-common/gomp/metadirective-8.c   |  16 ++
 .../gomp/metadirective-construct.c| 177 ++
 .../c-c++-common/gomp/metadirective-device.c  | 147 +++
 .../gomp/metadirective-no-score.c |  95 ++
 .../gomp/metadirective-target-device.c| 147 +++
 .../libgomp.c-c++-common/metadirective-1.c|  35 
 .../libgomp.c-c++-common/metadirective-2.c|  41 
 .../libgomp.c-c++-common/metadirective-3.c|  34 
 .../libgomp.c-c++-common/metadirective-4.c|  52 +
 .../libgomp.c-c++-common/metadirective-5.c|  46 +
 17 files changed, 1073 insertions(+)
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-1.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-2.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-3.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-4.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-5.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-6.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-7.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-8.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-construct.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-device.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/metadirective-no-score.c
 create mode 100644 
gcc/testsuite/c-c++-common/gomp/metadirective-target-device.c
 create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-1.c
 create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-2.c
 create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-3.c
 create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-4.c
 create mode 100644 libgomp/testsuite/libgomp.c-c++-common/metadirective-5.c

diff --git a/gcc/testsuite/c-c++-common/gomp/metadirective-1.c 
b/gcc/testsuite/c-c++-common/gomp/metadirective-1.c
new file mode 100644
index 000..37b56237531
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/metadirective-1.c
@@ -0,0 +1,52 @@
+/* { dg-do compile } */
+
+#define N 100
+
+void f (int a[], int b[], int c[])
+{
+  int i;
+
+  #pragma omp metadirective \
+  default (teams loop) \
+  default (parallel loop) /* { dg-error "too many 'otherwise' or 'default' 
clauses in 'metadirective'" } */
+for (i = 0; i < N; i++) c[i] = a[i] * b[i];
+
+  #pragma omp metadirective \
+  otherwise (teams loop) \
+  default (parallel loop) /* { dg-error "too many 'otherwise' or 'default' 
clauses in 'metadirective'" } */
+for (i = 0; i < N; i++) c[i] = a[i] * b[i];
+
+  #pragma omp metadirective \
+  otherwise (teams loop) \
+  otherwise (parallel loop) /* { dg-error "too many 'otherwise' or 
'default' clauses in 'metadirective'" } */
+for (i = 0; i < N; i++) c[i] = a[i] * b[i];
+
+  #pragma omp metadirective \
+  default (bad_directive) /* { dg-error "unknown directive name before 
'\\)' token" } */
+for (i = 0; i < N; i++) c[i] = a[i] * b[i];
+
+  #pragma omp metadirective \
+  default (teams loop) \
+  where (device={arch("nvptx")}: parallel loop) /* { dg-error "'where' is 
not valid for 'metadirective'" } */
+for (i = 0; i < N; i++) c[i] = a[i] * b[i];
+
+  #pragma omp metadirective \
+  default (teams loop) \

[PATCH 8/8] OpenMP: Update documentation of metadirective implementation status.

2024-01-06 Thread Sandra Loosemore
libgomp/ChangeLog
* libgomp.texi (OpenMP 5.0): Mark metadirective as implemented.
(OpenMP 5.1): Mark target_device as partially supported.
(OpenMP 5.2): Mark otherwise clause as supported, note that
default is also still accepted.
---
 libgomp/libgomp.texi | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index c727850397d..8ef22086653 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -192,7 +192,7 @@ The OpenMP 4.5 specification is fully supported.
 @item Array shaping @tab N @tab
 @item Array sections with non-unit strides in C and C++ @tab N @tab
 @item Iterators @tab Y @tab
-@item @code{metadirective} directive @tab N @tab
+@item @code{metadirective} directive @tab Y @tab
 @item @code{declare variant} directive
   @tab P @tab @emph{simd} traits not handled correctly
 @item @var{target-offload-var} ICV and @code{OMP_TARGET_OFFLOAD}
@@ -289,8 +289,11 @@ The OpenMP 4.5 specification is fully supported.
 @headitem Description @tab Status @tab Comments
 @item OpenMP directive as C++ attribute specifiers @tab Y @tab
 @item @code{omp_all_memory} reserved locator @tab Y @tab
-@item @emph{target_device trait} in OpenMP Context @tab N @tab
-@item @code{target_device} selector set in context selectors @tab N @tab
+@item @emph{target_device trait} in OpenMP Context @tab Y
+@item @code{target_device} selector set in context selectors @tab P
+  @tab Supported only for @code{metadirective}.  
+  The @code{declare variant} construct does not yet support dynamic
+  selectors.
 @item C/C++'s @code{declare variant} directive: elision support of
   preprocessed code @tab N @tab
 @item @code{declare variant}: new clauses @code{adjust_args} and
@@ -413,8 +416,10 @@ to address of matching mapped list item per 5.1, Sect. 
2.21.7.2 @tab N @tab
 @item Deprecation of traits array following the allocator_handle expression in
   @code{uses_allocators} @tab N @tab
 @item New @code{otherwise} clause as alias for @code{default} on metadirectives
-  @tab N @tab
-@item Deprecation of @code{default} clause on metadirectives @tab N @tab
+  @tab Y @tab
+@item Deprecation of @code{default} clause on metadirectives @tab N
+  @tab Both @code{otherwise} and @code{default} are accepted
+  without diagnostics.
 @item Deprecation of delimited form of @code{declare target} @tab N @tab
 @item Reproducible semantics changed for @code{order(concurrent)} @tab N @tab
 @item @code{allocate} and @code{firstprivate} clauses on @code{scope}
-- 
2.31.1



[PATCH 4/8] OpenMP: C front end support for metadirectives

2024-01-06 Thread Sandra Loosemore
From: Kwok Cheung Yeung 

This patch adds support to the C front end to parse OpenMP metadirective
constructs.  It includes support for early parse-time resolution
of metadirectives (when possible) that will also be used by the C++ front
end.

Additional common C/C++ testcases are in a later patch in the series.

gcc/c-family/ChangeLog
* c-common.h (enum c_omp_directive_kind): Add C_OMP_DIR_META.
(c_omp_expand_metadirective): Declare.
* c-gimplify.cc: Include omp-general.h.
(genericize_omp_metadirective_stmt): New.
(c_genericize_control_stmt): Call it.
* c-omp.cc (c_omp_directives): Add "metadirective" and fix
commented-out stubs for the begin/end form.
(c_omp_expand_metadirective_r): New.
(c_omp_expand_metadirective): New.
* c-pragma.cc (omp_pragmas): Add "metadirective".
* c-pragma.h (enum pragma_kind): Add PRAGMA_OMP_METADIRECTIVE.

gcc/c/ChangeLog
* c-parser.cc (struct c_parser): Add new fields for metadirectives.
(c_parser_skip_to_end_of_block_or_statement):  Add metadirective_p
parameter; use it to control brace and parentheses behavior.
(mangle_metadirective_region_label): New.
(c_parser_label, c_parser_statement_after_labels): Use it.
(c_parser_pragma): Handle metadirective.
(c_parser_omp_context_selector): Add metadirective_p flag, use it
to gate support for non-constant user condition.
(c_parser_omp_context_selector_specification): Add metadirective_p
flag.
(c_parser_finish_omp_declare_variant): Adjust call.
(analyze_metadirective_body): New.
(c_parser_omp_metadirective): New.

gcc/testsuite/ChangeLog
* gcc.dg/gomp/metadirective-1.c: New.

Co-Authored-By: Sandra Loosemore 
---
 gcc/c-family/c-common.h |   4 +-
 gcc/c-family/c-gimplify.cc  |  27 ++
 gcc/c-family/c-omp.cc   |  60 ++-
 gcc/c-family/c-pragma.cc|   1 +
 gcc/c-family/c-pragma.h |   1 +
 gcc/c/c-parser.cc   | 489 +++-
 gcc/testsuite/gcc.dg/gomp/metadirective-1.c |  15 +
 7 files changed, 577 insertions(+), 20 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/gomp/metadirective-1.c

diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 3c2d75a0027..bad12c8119f 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -1391,7 +1391,8 @@ enum c_omp_directive_kind {
   C_OMP_DIR_CONSTRUCT,
   C_OMP_DIR_DECLARATIVE,
   C_OMP_DIR_UTILITY,
-  C_OMP_DIR_INFORMATIONAL
+  C_OMP_DIR_INFORMATIONAL,
+  C_OMP_DIR_META
 };
 
 struct c_omp_directive {
@@ -1405,6 +1406,7 @@ extern const struct c_omp_directive c_omp_directives[];
 extern const struct c_omp_directive *c_omp_categorize_directive (const char *,
 const char *,
 const char *);
+extern tree c_omp_expand_metadirective (vec 
&);
 
 /* Return next tree in the chain for chain_next walking of tree nodes.  */
 inline tree
diff --git a/gcc/c-family/c-gimplify.cc b/gcc/c-family/c-gimplify.cc
index 494da49791d..c53aca60bcf 100644
--- a/gcc/c-family/c-gimplify.cc
+++ b/gcc/c-family/c-gimplify.cc
@@ -43,6 +43,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "context.h"
 #include "tree-pass.h"
 #include "internal-fn.h"
+#include "omp-general.h"
 
 /*  The gimplification pass converts the language-dependent trees
 (ld-trees) emitted by the parser into language-independent trees
@@ -485,6 +486,27 @@ genericize_omp_for_stmt (tree *stmt_p, int *walk_subtrees, 
void *data,
   finish_bc_block (_FOR_BODY (stmt), bc_continue, clab);
 }
 
+/* Genericize a OMP_METADIRECTIVE node *STMT_P.  */
+
+static void
+genericize_omp_metadirective_stmt (tree *stmt_p, int *walk_subtrees,
+  void *data, walk_tree_fn func,
+  walk_tree_lh lh)
+{
+  tree stmt = *stmt_p;
+
+  for (tree variant = OMP_METADIRECTIVE_VARIANTS (stmt);
+   variant != NULL_TREE;
+   variant = TREE_CHAIN (variant))
+{
+  walk_tree_1 (_METADIRECTIVE_VARIANT_DIRECTIVE (variant),
+  func, data, NULL, lh);
+  walk_tree_1 (_METADIRECTIVE_VARIANT_BODY (variant),
+  func, data, NULL, lh);
+}
+
+  *walk_subtrees = 0;
+}
 
 /* Lower structured control flow tree nodes, such as loops.  The
STMT_P, WALK_SUBTREES, and DATA arguments are as for the walk_tree_fn
@@ -533,6 +555,11 @@ c_genericize_control_stmt (tree *stmt_p, int 
*walk_subtrees, void *data,
   genericize_omp_for_stmt (stmt_p, walk_subtrees, data, func, lh);
   break;
 
+case OMP_METADIRECTIVE:
+  genericize_omp_metadirective_stmt (stmt_p, walk_subtrees, data, func,
+ 

[PATCH 5/8] OpenMP: C++ front-end support for metadirectives

2024-01-06 Thread Sandra Loosemore
From: Kwok Cheung Yeung 

This patch adds C++ support for metadirectives.  It uses the
c-family support committed with the corresponding C front end patch
to do early parse-time metadirective resolution when possible.

Additional C/C++ common testcases are provided in a subsequent
patch in the series.

gcc/cp/ChangeLog
* parser.cc (cp_parser_skip_to_end_of_block_or_statement): Add
metadirective_p parameter, use it to control brace/parentheses
behavior for metadirectives.
(mangle_metadirective_region_label): New.
(cp_parser_label_for_labeled_statement): Use it.
(cp_parser_jump_statement): Likewise.
(cp_parser_omp_context_selector): Add metadirective_p
parameter, use it to control error behavior for non-constant exprs
properties.
(cp_parser_omp_context_selector_specification): Add metadirective_p
parameter, use it for cp_parser_omp_context_selector call.
(cp_finish_omp_declare_variant): Adjust call to
cp_parser_omp_context_selector_specification.
(analyze_metadirective_body): New.
(cp_parser_omp_metadirective): New.
(cp_parser_pragma): Handle PRAGMA_OMP_METADIRECTIVE.
* parser.h (struct cp_parser): Add fields for metadirective parsing
state.
* pt.cc (tsubst_omp_context_selector): New.
(tsubst_stmt): Handle OMP_METADIRECTIVE.

gcc/testsuite/ChangeLog
* g++.dg/gomp/attrs-metadirective-1.C: New.
* g++.dg/gomp/attrs-metadirective-2.C: New.
* g++.dg/gomp/attrs-metadirective-3.C: New.
* g++.dg/gomp/attrs-metadirective-4.C: New.
* g++.dg/gomp/attrs-metadirective-5.C: New.
* g++.dg/gomp/attrs-metadirective-6.C: New.
* g++.dg/gomp/attrs-metadirective-7.C: New.
* g++.dg/gomp/attrs-metadirective-8.C: New.

libgomp/ChangeLog
* testsuite/libgomp.c++/metadirective-template-1.C: New.
* testsuite/libgomp.c++/metadirective-template-2.C: New.
* testsuite/libgomp.c++/metadirective-template-3.C: New.

Co-Authored-By: Sandra Loosemore 
---
 gcc/cp/parser.cc  | 524 +-
 gcc/cp/parser.h   |   7 +
 gcc/cp/pt.cc  | 118 
 .../g++.dg/gomp/attrs-metadirective-1.C   |  40 ++
 .../g++.dg/gomp/attrs-metadirective-2.C   |  74 +++
 .../g++.dg/gomp/attrs-metadirective-3.C   |  31 ++
 .../g++.dg/gomp/attrs-metadirective-4.C   |  41 ++
 .../g++.dg/gomp/attrs-metadirective-5.C   |  24 +
 .../g++.dg/gomp/attrs-metadirective-6.C   |  31 ++
 .../g++.dg/gomp/attrs-metadirective-7.C   |  31 ++
 .../g++.dg/gomp/attrs-metadirective-8.C   |  16 +
 .../libgomp.c++/metadirective-template-1.C|  37 ++
 .../libgomp.c++/metadirective-template-2.C|  41 ++
 .../libgomp.c++/metadirective-template-3.C|  41 ++
 14 files changed, 1043 insertions(+), 13 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-1.C
 create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-2.C
 create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-3.C
 create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-4.C
 create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-5.C
 create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-6.C
 create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-7.C
 create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-metadirective-8.C
 create mode 100644 libgomp/testsuite/libgomp.c++/metadirective-template-1.C
 create mode 100644 libgomp/testsuite/libgomp.c++/metadirective-template-2.C
 create mode 100644 libgomp/testsuite/libgomp.c++/metadirective-template-3.C

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index b864a9b5275..4ec4ed8a01c 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -2998,7 +2998,7 @@ static void cp_parser_skip_to_end_of_statement
 static void cp_parser_consume_semicolon_at_end_of_statement
   (cp_parser *);
 static void cp_parser_skip_to_end_of_block_or_statement
-  (cp_parser *);
+  (cp_parser *, bool = false);
 static bool cp_parser_skip_to_closing_brace
   (cp_parser *);
 static bool cp_parser_skip_entire_template_parameter_list
@@ -4174,9 +4174,11 @@ cp_parser_consume_semicolon_at_end_of_statement 
(cp_parser *parser)
have consumed a non-nested `;'.  */
 
 static void
-cp_parser_skip_to_end_of_block_or_statement (cp_parser* parser)
+cp_parser_skip_to_end_of_block_or_statement (cp_parser* parser,
+bool metadirective_p)
 {
   int nesting_depth = 0;
+  int bracket_depth = 0;
 
   /* Unwind generic function template scope if necessary.  */
   if (parser->fully_implicit_function_template_p)
@@ -4198,7 +4200,7 @@ cp_parser_skip_to_end_of_block_or_statement (cp_parser* 
parser)
 
case CPP_SEMICOLON:
  /* Stop if this is an unnes

[PATCH 7/8] OpenMP: Fortran front-end support for metadirectives.

2024-01-06 Thread Sandra Loosemore
uct.f90: New.
* gfortran.dg/gomp/metadirective-no-score.f90: New.
* gfortran.dg/gomp/pure-1.f90: Add metadirective test.
* gfortran.dg/gomp/pure-2.f90: Remove metadirective test.

libgomp/ChangeLog
* testsuite/libgomp.fortran/metadirective-1.f90: New.
* testsuite/libgomp.fortran/metadirective-2.f90: New.
* testsuite/libgomp.fortran/metadirective-3.f90: New.
* testsuite/libgomp.fortran/metadirective-4.f90: New.
* testsuite/libgomp.fortran/metadirective-5.f90: New.
* testsuite/libgomp.fortran/metadirective-6.f90: New.

Co-Authored-By: Sandra Loosemore 
Co-Authored-By: Tobias Burnus 
Co-Authored-By: Paul-Antoine Arras 
---
 gcc/fortran/decl.cc   |  29 +
 gcc/fortran/dump-parse-tree.cc|  21 +
 gcc/fortran/gfortran.h|  24 +-
 gcc/fortran/io.cc |   2 +-
 gcc/fortran/match.h   |   2 +
 gcc/fortran/openmp.cc | 265 +++-
 gcc/fortran/parse.cc  | 571 +++---
 gcc/fortran/parse.h   |   8 +-
 gcc/fortran/resolve.cc|   6 +
 gcc/fortran/st.cc |   4 +
 gcc/fortran/symbol.cc |  25 +-
 gcc/fortran/trans-decl.cc |   5 +-
 gcc/fortran/trans-openmp.cc   | 239 +---
 gcc/fortran/trans-stmt.h  |   1 +
 gcc/fortran/trans.cc  |   1 +
 .../gfortran.dg/gomp/metadirective-1.f90  |  55 ++
 .../gfortran.dg/gomp/metadirective-10.f90 |  40 ++
 .../gfortran.dg/gomp/metadirective-11.f90 |  33 +
 .../gfortran.dg/gomp/metadirective-2.f90  |  62 ++
 .../gfortran.dg/gomp/metadirective-3.f90  |  34 ++
 .../gfortran.dg/gomp/metadirective-4.f90  |  39 ++
 .../gfortran.dg/gomp/metadirective-5.f90  |  30 +
 .../gfortran.dg/gomp/metadirective-6.f90  |  31 +
 .../gfortran.dg/gomp/metadirective-7.f90  |  36 ++
 .../gfortran.dg/gomp/metadirective-8.f90  |  22 +
 .../gfortran.dg/gomp/metadirective-9.f90  |  30 +
 .../gomp/metadirective-construct.f90  | 260 
 .../gomp/metadirective-no-score.f90   | 122 
 gcc/testsuite/gfortran.dg/gomp/pure-1.f90 |   7 +
 gcc/testsuite/gfortran.dg/gomp/pure-2.f90 |   8 -
 .../libgomp.fortran/metadirective-1.f90   |  61 ++
 .../libgomp.fortran/metadirective-2.f90   |  40 ++
 .../libgomp.fortran/metadirective-3.f90   |  29 +
 .../libgomp.fortran/metadirective-4.f90   |  46 ++
 .../libgomp.fortran/metadirective-5.f90   |  44 ++
 .../libgomp.fortran/metadirective-6.f90   |  58 ++
 36 files changed, 1937 insertions(+), 353 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-1.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-10.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-11.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-2.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-3.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-4.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-5.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-6.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-7.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-8.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-9.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-construct.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/metadirective-no-score.f90
 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-1.f90
 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-2.f90
 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-3.f90
 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-4.f90
 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-5.f90
 create mode 100644 libgomp/testsuite/libgomp.fortran/metadirective-6.f90

diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index 503ecb8d9b5..0ab2e710e78 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -8404,6 +8404,7 @@ gfc_match_end (gfc_statement *st)
 
 case COMP_CONTAINS:
 case COMP_DERIVED_CONTAINS:
+case COMP_OMP_BEGIN_METADIRECTIVE:
   state = gfc_state_stack->previous->state;
   block_name = gfc_state_stack->previous->sym == NULL
 ? NULL : gfc_state_stack->previous->sym->name;
@@ -8411,6 +8412,28 @@ gfc_match_end (gfc_statement *st)
&& gfc_state_stack->previous->sym->abr_modproc_decl;
   break;
 
+case COMP_OMP_METADIRECTIVE:
+  {
+   /* Metadirectives can be nested, so we need to drill down to the
+  first state that is not COMP_OMP_METADIR

[PATCH 3/8] libgomp: runtime support for target_device selector

2024-01-06 Thread Sandra Loosemore
From: Kwok Cheung Yeung 

This patch implements the libgomp runtime support for the dynamic
target_device selector via the GOMP_evaluate_target_device function.

include/ChangeLog
* cuda/cuda.h (CUdevice_attribute): Add definitions for
CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR and
CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR.

libgomp/ChangeLog
* Makefile.am (libgomp_la_SOURCES): Add selector.c.
* Makefile.am: Regenerate.
* config/gcn/selector.c: New.
* config/linux/selector.c: New.
* config/linux/x86/selector.c: New.
* config/nvptx/selector.c: New.
* libgomp-plugin.h (GOMP_OFFLOAD_evaluate_device): New.
* libgomp.h (struct gomp_device_descr): Add evaluate_device_func field.
* libgomp.map (GOMP_5.1): Add GOMP_evaluate_target_device.
* libgomp_g.h (GOMP_evaluate_current_device): New.
(GOMP_evaluate_target_device): New.
* oacc-host.c (host_evaluate_device): New.
(host_openacc_exec): Initialize evaluate_device_func field to
host_evaluate_device.
* plugin/plugin-gcn.c (GOMP_OFFLOAD_evaluate_device): New.
* plugin/plugin-nvptx.c (struct ptx_device): Add compute_major and
compute_minor fields.
(nvptx_open_device): Read compute capability information from device.
(CHECK_ISA): New macro.
(GOMP_OFFLOAD_evaluate_device): New.
* selector.c: New.
* target.c (GOMP_evaluate_target_device): New.
(gomp_load_plugin_for_device): Load evaluate_device plugin function.
---
 include/cuda/cuda.h |   2 +
 libgomp/Makefile.am |   2 +-
 libgomp/Makefile.in |   5 +-
 libgomp/config/gcn/selector.c   |  57 +
 libgomp/config/linux/selector.c |  43 
 libgomp/config/linux/x86/selector.c | 325 
 libgomp/config/nvptx/selector.c |  65 ++
 libgomp/libgomp-plugin.h|   2 +
 libgomp/libgomp.h   |   1 +
 libgomp/libgomp.map |   1 +
 libgomp/libgomp_g.h |   8 +
 libgomp/oacc-host.c |  11 +
 libgomp/plugin/plugin-gcn.c |  14 ++
 libgomp/plugin/plugin-nvptx.c   |  45 
 libgomp/selector.c  |  36 +++
 libgomp/target.c|  38 
 16 files changed, 652 insertions(+), 3 deletions(-)
 create mode 100644 libgomp/config/gcn/selector.c
 create mode 100644 libgomp/config/linux/selector.c
 create mode 100644 libgomp/config/linux/x86/selector.c
 create mode 100644 libgomp/config/nvptx/selector.c
 create mode 100644 libgomp/selector.c

diff --git a/include/cuda/cuda.h b/include/cuda/cuda.h
index 114aba4e074..0d57bdd68e9 100644
--- a/include/cuda/cuda.h
+++ b/include/cuda/cuda.h
@@ -82,6 +82,8 @@ typedef enum {
   CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_MULTIPROCESSOR = 39,
   CU_DEVICE_ATTRIBUTE_ASYNC_ENGINE_COUNT = 40,
   CU_DEVICE_ATTRIBUTE_UNIFIED_ADDRESSING = 41,
+  CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR = 75,
+  CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR = 76,
   CU_DEVICE_ATTRIBUTE_MAX_REGISTERS_PER_MULTIPROCESSOR = 82
 } CUdevice_attribute;
 
diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am
index 1871590596d..87658da2d5d 100644
--- a/libgomp/Makefile.am
+++ b/libgomp/Makefile.am
@@ -72,7 +72,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c error.c \
target.c splay-tree.c libgomp-plugin.c oacc-parallel.c oacc-host.c \
oacc-init.c oacc-mem.c oacc-async.c oacc-plugin.c oacc-cuda.c \
priority_queue.c affinity-fmt.c teams.c allocator.c oacc-profiling.c \
-   oacc-target.c target-indirect.c
+   oacc-target.c target-indirect.c selector.c
 
 include $(top_srcdir)/plugin/Makefrag.am
 
diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
index 56a6beab867..81de2ddb943 100644
--- a/libgomp/Makefile.in
+++ b/libgomp/Makefile.in
@@ -219,7 +219,7 @@ am_libgomp_la_OBJECTS = alloc.lo atomic.lo barrier.lo 
critical.lo \
oacc-parallel.lo oacc-host.lo oacc-init.lo oacc-mem.lo \
oacc-async.lo oacc-plugin.lo oacc-cuda.lo priority_queue.lo \
affinity-fmt.lo teams.lo allocator.lo oacc-profiling.lo \
-   oacc-target.lo target-indirect.lo $(am__objects_1)
+   oacc-target.lo target-indirect.lo selector.lo $(am__objects_1)
 libgomp_la_OBJECTS = $(am_libgomp_la_OBJECTS)
 AM_V_P = $(am__v_P_@AM_V@)
 am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
@@ -552,7 +552,7 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c 
env.c \
oacc-parallel.c oacc-host.c oacc-init.c oacc-mem.c \
oacc-async.c oacc-plugin.c oacc-cuda.c priority_queue.c \
affinity-fmt.c teams.c allocator.c oacc-profiling.c \
-   oacc-target.c target-indirect.c $(am__append_3)
+   oacc-target.c target-indirect.c selector.c $(am__append_3)
 
 # Nvidia PTX OpenACC plugin.
 @PLUGIN_NVPTX_TRUE@libgomp_plugin_nvptx_version_info = -version-info 
$(libtool_VERSION)
@@ 

[PATCH 2/8] OpenMP: middle-end support for metadirectives

2024-01-06 Thread Sandra Loosemore
From: Kwok Cheung Yeung 

This patch adds middle-end support for OpenMP metadirectives.  Some
context selectors can be resolved during gimplification, but others need to
be deferred until the omp_device_lower pass, which requires that cgraph,
LTO streaming, inlining, etc all know about this construct as well.

gcc/ChangeLog
* cgraph.h (struct cgraph_node): Add has_metadirectives flag.
* cgraphclones.cc (cgraph_node::create_clone): Copy has_metadirectives
flag.
* gimple-low.cc (lower_omp_metadirective): New.
(lower_stmt): Call it.
* gimple-pretty-print.cc (dump_gimple_omp_metadirective): New.
(pp_gimple_stmt_1): Call it.
* gimple-streamer-in.cc (input_gimple_stmt): Handle
GIMPLE_OMP_METADIRECTIVE.
* gimple-streamer-out.cc (output_gimple_stmt): Likewise.
* gimple-walk.cc (walk_gimple_op): Likewise.
(walk_gimple_stmt): Likewise.
* gimple.cc (gimple_alloc_omp_metadirective): New.
(gimple_build_omp_metadirective): New.
(gimple_build_omp_metadirective_variant): New.
* gimple.def (GIMPLE_OMP_METADIRECTIVE): New.
(GIMPLE_OMP_METADIRECTIVE_VARIANT): New.
* gimple.h (gomp_metadirective_variant, gomp_metadirective): New.
(is_a_helper ::test): New.
(is_a_helper ::test): New.
(is_a_helper ::test): New.
(is_a_helper ::test): New.
(gimple_alloc_omp_metadirective): New.
(gimple_build_omp_metadirective): New.
(gimple_build_omp_metadirective_variant): New.
(gimple_has_substatements): Handle GIMPLE_OMP_METADIRECTIVE.
(gimple_has_ops): Likewise.
(gimple_omp_metadirective_label): New.
(gimple_omp_metadirective_set_label): New.
(gimple_omp_metadirective_variants): New.
(gimple_omp_metadirective_set_variants): New.
(gimple_return_set_retval): Handle GIMPLE_OMP_METADIRECTIVE.
* gimplify.cc (is_gimple_stmt): HANDLE OMP_METADIRECTIVE.
(expand_omp_metadirective): New.
(gimplify_omp_metadirective): New.
(gimplify_expr): Call it.
* gsstruct.def (GSS_OMP_METADIRECTIVE): New.
(GSS_OMP_METADIRECTIVE_VARIANT): New.
* lto-cgraph.cc (lto_output_node): Handle has_metadirectives flag.
(input_overwrite_node): Likewise.
* omp-expand.cc (expand_omp_target): Propagate has_metadirectives
flag.
(build_omp_regions_1): Handle GIMPLE_OMP_METADIRECTIVE.
(omp_make_gimple_edges): Likewise.
* omp-general.cc (make_omp_metadirective_variant): New.
* omp-general.h (make_omp_metadirective_variant): Declare.
* omp-low.cc (struct omp_context): Add next_clone field.
(new_omp_context): Handle next_clone field.
(clone_omp_context): New.
(delete_omp_context): Delete clones.
(scan_omp_metadirective): New.
(scan_omp_1_stmt): Handle GIMPLE_OMP_METADIRECTIVE.
(lower_omp_metadirective): New.
(lower_omp_1): Handle GIMPLE_OMP_METADIRECTIVE.  Warn about
direct calls to offloadable functions containing metadirectives.
* omp-offload.cc: Include cfganal.h and cfghooks.h.
(omp_expand_metadirective): New.
(execute_omp_device_lower): Handle metadirectives.
(pass_omp_device_lower::gate):  Handle metadirectives.
* omp-simd-clone.cc (simd_clone_create): Propagate has_metadirectives
flag.
* tree-cfg.cc (cleanup_dead_labels): Handle GIMPLE_OMP_METADIRECTIVE.
(gimple_redirect_edge_and_branch): Likewise.
* tree-inline.cc (remap_gimple_stmt): Handle GIMPLE_OMP_METADIRECTIVE.
(estimate_num_instructions): Likewise.
(expand_call_inline): Propagate has_metadirectives flag.
(tree_function_versioning): Likewise.
* tree-ssa-operands.cc: Include omp-general.h.
(operands_scanner::parse_ssa_operands): Handle
GIMPLE_OMP_METADIRECTIVE.

Co-Authored-By: Sandra Loosemore 
Co-Authored-By: Marcel Vollweiler 
---
 gcc/cgraph.h   |   3 +
 gcc/cgraphclones.cc|   1 +
 gcc/gimple-low.cc  |  36 
 gcc/gimple-pretty-print.cc |  64 +
 gcc/gimple-streamer-in.cc  |  10 ++
 gcc/gimple-streamer-out.cc |   6 ++
 gcc/gimple-walk.cc |  28 ++
 gcc/gimple.cc  |  35 +++
 gcc/gimple.def |   7 ++
 gcc/gimple.h   | 100 +++-
 gcc/gimplify.cc| 184 +
 gcc/gsstruct.def   |   2 +
 gcc/lto-cgraph.cc  |   2 +
 gcc/omp-expand.cc  |  30 ++
 gcc/omp-general.cc |  22 +
 gcc/omp-general.h  |   1 +
 gcc/omp-low.cc |  80 
 gcc/omp-offload.cc | 105 -
 gcc/omp-simd-clone.cc  |   1 +
 gcc/tree-cfg.cc|  24 +
 gcc/tree-inline.cc |  39 
 gcc/tree-ssa-operands.cc   |  17 
 22 files changed

[PATCH 1/8] OpenMP: metadirective tree data structures and front-end interfaces

2024-01-06 Thread Sandra Loosemore
From: Kwok Cheung Yeung 

This patch adds the OMP_METADIRECTIVE tree node and shared tree-level
support for manipulating metadirectives.  It defines/exposes
interfaces that will be used in subsequent patches that add front-end
and middle-end support, but nothing generates these nodes yet.

This patch also adds compile-time support for dynamic context
selectors (the target_device selector set and the condition selector
of the user selector set) for metadirectives only.  The "declare
variant" directive still supports only static selectors.

gcc/ChangeLog
* Makefile.in (GTFILES): Move omp-general.h earlier in the list.
* builtin-types.def (BT_FN_BOOL_INT_CONST_PTR_CONST_PTR_CONST_PTR):
New.
* doc/generic.texi (OpenMP): Document OMP_METADIRECTIVE and
context selector interfaces.
* omp-builtins.def (BUILT_IN_GOMP_EVALUATE_TARGET_DEVICE): New.
* omp-general.cc (omp_check_context_selector): Add metadirective_p
parameter, use it to conditionalize target_device support.
(make_omp_metadirective_variant): New.
(omp_context_selector_matches): Add metadirective_p and delay_p
parameters, use them to control things that can only be matched
late.  Handle OMP_TRAIT_SET_TARGET_DEVICE.
(score_wide_int): Move definition to omp-general.h.
(omp_dynamic_cond): New.
(omp_context_compute_score): Handle OMP_TRAIT_SET_TARGET_DEVICE.
(omp_resolve_late_declare_variant, omp_resolve_declare_variant):
Adjust calls to omp_context_selector_matches.
(sort_variant): New.
(omp_get_dynamic_candidates): New.
(omp_resolve_metadirective): New.
* omp-general.h (score_wide_int): Moved here from omp-general.cc.
(struct omp_metadirective_variant): New.
(OMP_METADIRECTIVE_VARIANT_SELECTOR): New.
(OMP_METADIRECTIVE_VARIANT_DIRECTIVE): New.
(OMP_METADIRECTIVE_VARIANT_BODY): New.
(make_omp_metadirective_variant): Declare.
(omp_check_context_selector): Adjust to match definition.
(omp_context_selector_matches): Likewise.
(omp_resolve_metadirective): New.
* tree-pretty-print.cc (dump_omp_context_selector): Remove
static qualifier.
(dump_generic_node): Handle OMP_METADIRECTIVE.
* tree-pretty-print.h (dump_omp_context_selector): Declare.
* tree.def (OMP_METADIRECTIVE): New.
* tree.h (OMP_METADIRECTIVE_VARIANTS): New.

gcc/c/ChangeLog
* c-parser.cc (c_finish_omp_declare_variant): Update calls to
omp_context_selector_patches to pass additional arguments.

gcc/cp/ChangeLog
* decl.cc (omp_declare_variant_finalize_one):  Update call to
omp_context_selector_patches to pass additional arguments.
* parser.cc (cp_finish_omp_declare_variant): Likewise.

gcc/fortran/ChangeLog
* trans-openmp.cc (gfc_trans_omp_declare_variant):  Update calls to
omp_context_selector_patches to pass additional arguments.
* types.def (BT_FN_BOOL_INT_CONST_PTR_CONST_PTR_CONST_PTR): New.

Co-Authored-By: Sandra Loosemore 
---
 gcc/Makefile.in |   2 +-
 gcc/builtin-types.def   |   2 +
 gcc/c/c-parser.cc   |   4 +-
 gcc/cp/decl.cc  |   2 +-
 gcc/cp/parser.cc|   2 +-
 gcc/doc/generic.texi|  32 
 gcc/fortran/trans-openmp.cc |   4 +-
 gcc/fortran/types.def   |   2 +
 gcc/omp-builtins.def|   3 +
 gcc/omp-general.cc  | 337 ++--
 gcc/omp-general.h   |  31 +++-
 gcc/tree-pretty-print.cc|  36 +++-
 gcc/tree-pretty-print.h |   2 +
 gcc/tree.def|   6 +
 gcc/tree.h  |   3 +
 15 files changed, 441 insertions(+), 27 deletions(-)

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index deb12e17d25..06134e61a3d 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -2868,6 +2868,7 @@ GTFILES = $(CPPLIB_H) $(srcdir)/input.h 
$(srcdir)/coretypes.h \
   $(srcdir)/tree-ssa-operands.h \
   $(srcdir)/tree-profile.cc $(srcdir)/tree-nested.cc \
   $(srcdir)/omp-offload.h \
+  $(srcdir)/omp-general.h \
   $(srcdir)/omp-general.cc \
   $(srcdir)/omp-low.cc \
   $(srcdir)/targhooks.cc $(out_file) $(srcdir)/passes.cc \
@@ -2894,7 +2895,6 @@ GTFILES = $(CPPLIB_H) $(srcdir)/input.h 
$(srcdir)/coretypes.h \
   $(srcdir)/ipa-strub.cc \
   $(srcdir)/internal-fn.h \
   $(srcdir)/calls.cc \
-  $(srcdir)/omp-general.h \
   $(srcdir)/analyzer/analyzer-language.cc \
   @all_gtfiles@
 
diff --git a/gcc/builtin-types.def b/gcc/builtin-types.def
index c97d6bad1de..605a38ab84d 100644
--- a/gcc/builtin-types.def
+++ b/gcc/builtin-types.def
@@ -878,6 +878,8 @@ DEF_FUNCTION_TYPE_4 (BT_FN_VOID_UINT_PTR_INT_PTR, BT_VOID, 
BT_INT, BT_PTR,
 BT_INT, BT_PTR)
 DEF_FUNCTION_TYPE_4 (BT_FN_BOOL_UINT_UINT_UINT_BOOL,
 BT_BOOL, BT_UINT, BT_UINT, BT_UINT, BT_BOOL)
+DEF_FUNCT

[PATCH 0/8] OpenMP: Implement metadirective support

2024-01-06 Thread Sandra Loosemore
This patch set adds support for metadirectives and dynamic selectors
in metadirectives.  To give credit where it's due, this is primarily
Kwok's work, originally posted 2+ years ago (and WIP for some time
before that):

https://gcc.gnu.org/pipermail/gcc-patches/2021-December/586600.html

There's also currently an improved version of those patches on the
OG13 branch, along with several followup bug fixes contributed by
others.

My contributions have been collecting, rebasing, and refactoring all
the patches, adding the missing attribute syntax and template support
to the C++ front end, fixing more bugs, adding documentation, and
making some improvements to the internal engineering aspect of the
code.

Although the original patches were posted long ago, I suspect it is
now too late in the release cycle for this feature to make it into GCC
14, although it would certainly make users happy if it could be
squeezed in.  Another concern is that I'm facing some short-term
disruptions in my ability to continue work on this and I need to at
least publish the current patches so they don't get lost in the
shuffle.  Plus, if this patch set doesn't make it into GCC 14, it will
still be useful as a better starting point for OG14 than the patch set
currently on OG13.

In terms of what is still missing:

- Dynamic context selectors are currently supported only by
  metadirective and not declare variant.
- The C and C++ front ends attempt to do early resolution of
  metadirectives at parse time, but the Fortran front end does not do
  that yet.
- IIUC the construct selector set is supposed to allow you to specify
  the name of any OpenMP construct, but it only recognizes a small subset.
- Needs more test cases.  (Everything always needs more test cases.)
- Other unimplemented features beyond what was specified in OpenMP 5.1???

BTW, I'm aware that there are some open Bugzilla issues relating to
the OG13 implementation of metadirectives, at least PRs 112779,
107067, and 106730, although I haven't investigated or worked on any
of those directly.  I do know that at least items (a) and (h) from PR
112779 have been fixed in this patch set, though.

Anyway, I think it would be reasonable to do the missing features and
bug fixes and follow-up patches rather than continuing to sit on the
entire patch set until it's complete and perfect in every way.  :-)

-Sandra


Kwok Cheung Yeung (7):
  OpenMP: metadirective tree data structures and front-end interfaces
  OpenMP: middle-end support for metadirectives
  libgomp: runtime support for target_device selector
  OpenMP: C front end support for metadirectives
  OpenMP: C++ front-end support for metadirectives
  OpenMP: common c/c++ testcases for metadirectives
  OpenMP: Fortran front-end support for metadirectives.

Sandra Loosemore (1):
  OpenMP: Update documentation of metadirective implementation status.

 gcc/Makefile.in   |   2 +-
 gcc/builtin-types.def |   2 +
 gcc/c-family/c-common.h   |   4 +-
 gcc/c-family/c-gimplify.cc|  27 +
 gcc/c-family/c-omp.cc |  60 +-
 gcc/c-family/c-pragma.cc  |   1 +
 gcc/c-family/c-pragma.h   |   1 +
 gcc/c/c-parser.cc | 493 ++-
 gcc/cgraph.h  |   3 +
 gcc/cgraphclones.cc   |   1 +
 gcc/cp/decl.cc|   2 +-
 gcc/cp/parser.cc  | 526 +++-
 gcc/cp/parser.h   |   7 +
 gcc/cp/pt.cc  | 118 
 gcc/doc/generic.texi  |  32 +
 gcc/fortran/decl.cc   |  29 +
 gcc/fortran/dump-parse-tree.cc|  21 +
 gcc/fortran/gfortran.h|  24 +-
 gcc/fortran/io.cc |   2 +-
 gcc/fortran/match.h   |   2 +
 gcc/fortran/openmp.cc | 265 +++-
 gcc/fortran/parse.cc  | 571 +++---
 gcc/fortran/parse.h   |   8 +-
 gcc/fortran/resolve.cc|   6 +
 gcc/fortran/st.cc |   4 +
 gcc/fortran/symbol.cc |  25 +-
 gcc/fortran/trans-decl.cc |   5 +-
 gcc/fortran/trans-openmp.cc   | 243 +---
 gcc/fortran/trans-stmt.h  |   1 +
 gcc/fortran/trans.cc  |   1 +
 gcc/fortran/types.def |   2 +
 gcc/gimple-low.cc |  36 ++
 gcc/gimple-pretty-print.cc|  64 ++
 gcc/gimple-streamer-in.cc |  10 +
 gcc/gimple-streamer-out.cc|   6 +
 gcc/gimple-walk.cc|  28 +
 gcc/gimple.cc |  35 ++
 gcc

[committed, obvious] OpenMP: trivial cleanups to omp-general.cc

2024-01-03 Thread Sandra Loosemore
gcc/ChangeLog
* omp-general.cc: Fix comment typos and misplaced/confusing
comments.  Delete redundant include of omp-general.h.
---
 gcc/omp-general.cc | 21 +
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc
index 264fbc01b78..bd4648f196f 100644
--- a/gcc/omp-general.cc
+++ b/gcc/omp-general.cc
@@ -1,5 +1,5 @@
-/* General types and functions that are uselful for processing of OpenMP,
-   OpenACC and similar directivers at various stages of compilation.
+/* General types and functions that are useful for processing of OpenMP,
+   OpenACC and similar directives at various stages of compilation.
 
Copyright (C) 2005-2024 Free Software Foundation, Inc.
 
@@ -19,8 +19,6 @@ You should have received a copy of the GNU General Public 
License
 along with GCC; see the file COPYING3.  If not see
 .  */
 
-/* Find an OMP clause of type KIND within CLAUSES.  */
-
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
@@ -45,11 +43,11 @@ along with GCC; see the file COPYING3.  If not see
 #include "data-streamer.h"
 #include "streamer-hooks.h"
 #include "opts.h"
-#include "omp-general.h"
 #include "tree-pretty-print.h"
 
 enum omp_requires omp_requires_mask;
 
+/* Find an OMP clause of type KIND within CLAUSES.  */
 tree
 omp_find_clause (tree clauses, enum omp_clause_code kind)
 {
@@ -2874,9 +2872,8 @@ oacc_launch_pack (unsigned code, tree device, unsigned op)
   return res;
 }
 
-/* FIXME: What is the following comment for? */
-/* Look for compute grid dimension clauses and convert to an attribute
-   attached to FN.  This permits the target-side code to (a) massage
+/* Openacc compute grid dimension clauses are converted to an attribute
+   attached to the function.  This permits the target-side code to (a) massage
the dimensions, (b) emit that data and (c) optimize.  Non-constant
dimensions are pushed onto ARGS.
 
@@ -2890,9 +2887,8 @@ oacc_launch_pack (unsigned code, tree device, unsigned op)
dimensions, keyed by the device type.  The first entry will be the
default.  Well, that's the plan.  */
 
-/* Replace any existing oacc fn attribute with updated dimensions.  */
-
-/* Variant working on a list of attributes.  */
+/* Replace any existing oacc fn attribute in ATTRIBS with updated
+   dimensions.  */
 
 tree
 oacc_replace_fn_attrib_attr (tree attribs, tree dims)
@@ -2905,7 +2901,8 @@ oacc_replace_fn_attrib_attr (tree attribs, tree dims)
   return tree_cons (ident, dims, attribs);
 }
 
-/* Variant working on a function decl.  */
+/* Replace any existing oacc fn attribute on FN with updated
+   dimensions.  */
 
 void
 oacc_replace_fn_attrib (tree fn, tree dims)
-- 
2.31.1



Re: [patch] libgomp.texi: Document omp_display_env

2024-01-03 Thread Sandra Loosemore

On 1/3/24 11:31, Tobias Burnus wrote:
Another small step in my side project of documenting all OpenMP routines in 
libgomp.texi
Here, only 'omp_display_env' is added. (New since OpenMP 5.1 but since a long 
time in GCC,
some fineprint in both the implementation and in the documentation is based on 
TR11.)


* * *

RFC - regarding printing the values (env.c not the documentation):

I am wondering whether to change "OMP_VAR = 'val'" to "OMP_VAR='val'", i.e. to 
remove

the spaces around the equal sign.

Pro: The latter is friendlier when using the env var with POSIX shells / Bash 
as those do not
permit spaces. (While 'setenv' in the cshell requires a space instead of an 
equal size.)
Since OpenMP has the '[device] ' prevfix which is used by many implementations, 
including GCC,

copy'n'paste is now harder and the benefit of removing the space is lower.

Additionally, the OpenMP document has "format NAME ’=’ VALUE" which also 
implies no spaces

and LLVM's runtime library also prints it without spaces.

Thoughts?  (The attached patch documents the current implementation.)


I'm not sure about the usability issues, except I think it's generally easier 
to change an undocumented interface.  :-)



Comments or suggestions to the .texi patch itself?




libgomp.texi: Document omp_display_env

libgomp/ChangeLog:

* libgomp.texi (Environment Display Routine): Uncomment and
add omp_display_env description.
(OMP_DISPLAY_ENV): Update wording, add 'see also'.

 libgomp/libgomp.texi | 109 ---
 1 file changed, 94 insertions(+), 15 deletions(-)

diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index c727850397d..686f712 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -570,7 +570,7 @@ specification in version 5.2.
 @c * Interoperability Routines::
 * Memory Management Routines::
 @c * Tool Control Routine::
-@c * Environment Display Routine::
+* Environment Display Routine::
 @end menu
 
 
@@ -2919,18 +2919,93 @@ was already deallocated or when the used allocator has already been destroyed.
 
 
 @c @node Tool Control Routine

+@c @section Tool Control Routine
 @c
 @c FIXME
 
-@c @node Environment Display Routine

-@c @section Environment Display Routine
-@c
-@c Routine to display the OpenMP number and the initial value of ICVs.
-@c It has C linkage and do not throw exceptions.
-@c
-@c menu
-@c * omp_display_env:: 
-@c end menu
+@node Environment Display Routine
+@section Environment Display Routine
+
+Routine to display the OpenMP number and the initial value of ICVs.


I'm not sure what an "OpenMP number is".  Below it says "GCC version number" 
and "OpenMP version" in different places; does it print both, or is one of 
those incorrect?  IIUC GCC does not implement specific OpenMP versions or have 
any way to control which OpenMP version you get; it's just whatever we've 
gotten around to implementing so far.



+It has C linkage and do not throw exceptions.


s/do/does/


+
+@menu
+* omp_display_env:: print the initial ICV values
+@end menu
+
+@node omp_display_env
+@subsection @code{omp_display_env} -- print the initial ICV values


The right markup for an em dash in Texinfo would be
s/ -- /---/


+@table @asis
+@item @emph{Description}:
+Each time this routine is invoked, the GCC version number and initial value of
+internal control variables (ICVs) is shown on @code{stderr}.  Initial value
+denotes the value at startup after evaluating the environment variables, such
+that later calls to API routines or clauses used in enclosing constructs do not
+affect the @emph{displayed} values.


I'd rephrase this a bit:

...is printed on @code{stderr}.  The displayed values are those at startup
after evaluating the environment variables; later calls to API routines
or clauses used in enclosing constructs do not affect the output.


+
+If the @var{verbose} argument is @code{false}, only the OpenMP version and
+standard OpenMP ICVs are shown; if it is @code{true}, additionally, the
+GCC-specific ICVs are shown.
+
+The output consists of multiple lines and starts with
+@samp{OPENMP DISPLAY ENVIRONMENT BEGIN} followed by the name-value lines and
+ends with @samp{OPENMP DISPLAY ENVIRONMENT END}. The name-value lines are
+(usually and in GCC) indented by two spaces; the @var{name} is followed by an
+equal sign and the @var{value} is enclosed in single quotes; in GCC, the equal
+sign is preceded and followed by a single space.


This is the documentation for the GCC implementation, so it's not necessary to 
say "in GCC" or
"usually" to imply that other implementations may do something different.  Just 
document what GCC does, unless you think the format is likely to change.



+
+The first line has as @var{name} either (usually and in GCC) @samp{_OPENMP} or
+@samp{openmp_version} and shows as value the OpenMP version number
+(4-digit year, 2-digit month) of the implementation, matching the value of
+the @code{_OPENMP} macro and, in 

[Committed, obvious] Testsuite: Fix failures in g++.dg/analyzer/placement-new-size.C

2023-12-21 Thread Sandra Loosemore
This testcase was failing on uses of int8_t, int64_t, etc without
including .

gcc/testsuite/ChangeLog
* g++.dg/analyzer/placement-new-size.C: Include .  Also
add missing newline to end of file.
---
 gcc/testsuite/g++.dg/analyzer/placement-new-size.C | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.dg/analyzer/placement-new-size.C 
b/gcc/testsuite/g++.dg/analyzer/placement-new-size.C
index 75a5a159282..f6c7bd4de5f 100644
--- a/gcc/testsuite/g++.dg/analyzer/placement-new-size.C
+++ b/gcc/testsuite/g++.dg/analyzer/placement-new-size.C
@@ -2,6 +2,7 @@
 
 #include 
 #include 
+#include 
 
 extern int get_buf_size ();
 
@@ -34,4 +35,4 @@ void test_binop ()
   int32_t *i = ::new (p + 1) int32_t; /* { dg-warning "heap-based buffer 
overflow" } */
   *i = 42; /* { dg-warning "heap-based buffer overflow" } */
   free (p);
-}
\ No newline at end of file
+}
-- 
2.31.1



Re: [PATCH v26 00/23] Optimize type traits compilation performance

2023-12-19 Thread Sandra Loosemore

On 12/6/23 22:11, Ken Matsui wrote:

This patch series optimizes type traits compilation performance by
implementing built-in type traits and using them in libstdc++.


I'm finding that all the new g++.dg/ext/is_*.C testcases added by this patch 
series are failing due
to the "#include ".  If that is supposed to refer to the file 
of that name in the libstdc++ testcase, there's no gcc option being passed to 
add that location to the include search path.  That .h file includes other 
header files from the libstdc++ testsuite so just copying it into the same 
directory as the new g++ tests doesn't work.  Can you fix this, somehow?


Target is nios2-elf, if that matters.

-Sandra


[PATCH 5/5] OpenMP: Add prettyprinter support for context selectors.

2023-12-17 Thread Sandra Loosemore
With the change to use enumerators instead of strings to represent
context selector and selector-set names, the default tree-list output
for dumping selectors is less helpful for debugging and harder to use
in test cases.  This patch adds support for dumping context selectors
using syntax similar to that used for input to the compiler.

gcc/ChangeLog
* omp-general.cc (omp_context_name_list_prop): Remove static qualifer.
* omp-general.h (omp_context_name_list_prop): Declare.
* tree-cfg.cc (dump_function_to_file): Intercept
"omp declare variant base" attribute for special handling.
* tree-pretty-print.cc: Include omp-general.h.
(dump_omp_context_selector): New.
(print_omp_context_selector): New.
* tree-pretty-print.h (dump_omp_context_selector): Declare.
(print_omp_context_selector): Declare.
---
 gcc/omp-general.cc   |  2 +-
 gcc/omp-general.h|  1 +
 gcc/tree-cfg.cc  |  9 +
 gcc/tree-pretty-print.cc | 75 
 gcc/tree-pretty-print.h  |  3 ++
 5 files changed, 89 insertions(+), 1 deletion(-)

diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc
index 233f235d81e..65990df1238 100644
--- a/gcc/omp-general.cc
+++ b/gcc/omp-general.cc
@@ -1234,7 +1234,7 @@ struct omp_ts_info omp_ts_map[] =
 /* Return a name from PROP, a property in selectors accepting
name lists.  */
 
-static const char *
+const char *
 omp_context_name_list_prop (tree prop)
 {
   gcc_assert (OMP_TP_NAME (prop) == OMP_TP_NAMELIST_NODE);
diff --git a/gcc/omp-general.h b/gcc/omp-general.h
index 66ed4903513..3c2b221b226 100644
--- a/gcc/omp-general.h
+++ b/gcc/omp-general.h
@@ -164,6 +164,7 @@ extern gimple *omp_build_barrier (tree lhs);
 extern tree find_combined_omp_for (tree *, int *, void *);
 extern poly_uint64 omp_max_vf (void);
 extern int omp_max_simt_vf (void);
+extern const char *omp_context_name_list_prop (tree);
 extern void omp_construct_traits_to_codes (tree, int, enum tree_code *);
 extern tree omp_check_context_selector (location_t loc, tree ctx);
 extern void omp_mark_declare_variant (location_t loc, tree variant,
diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc
index d784b911532..1ab18fa6b0f 100644
--- a/gcc/tree-cfg.cc
+++ b/gcc/tree-cfg.cc
@@ -8291,6 +8291,15 @@ dump_function_to_file (tree fndecl, FILE *file, 
dump_flags_t flags)
 
  if (strstr (IDENTIFIER_POINTER (name), "no_sanitize"))
print_no_sanitize_attr_value (file, TREE_VALUE (chain));
+ else if (!strcmp (IDENTIFIER_POINTER (name),
+   "omp declare variant base"))
+   {
+ tree a = TREE_VALUE (chain);
+ print_generic_expr (file, TREE_PURPOSE (a), dump_flags);
+ fprintf (file, " match ");
+ print_omp_context_selector (file, TREE_VALUE (a),
+ dump_flags);
+   }
  else
print_generic_expr (file, TREE_VALUE (chain), dump_flags);
  fprintf (file, ")");
diff --git a/gcc/tree-pretty-print.cc b/gcc/tree-pretty-print.cc
index 68857ae1cdf..fd61d28faff 100644
--- a/gcc/tree-pretty-print.cc
+++ b/gcc/tree-pretty-print.cc
@@ -35,6 +35,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "gomp-constants.h"
 #include "gimple.h"
 #include "fold-const.h"
+#include "omp-general.h"
 
 /* Routines in this file get invoked via the default tree printer
used by diagnostics and thus they are called from pp_printf which
@@ -1497,6 +1498,80 @@ dump_omp_clauses (pretty_printer *pp, tree clause, int 
spc, dump_flags_t flags,
 }
 }
 
+/* Dump an OpenMP context selector CTX to PP.  */
+void
+dump_omp_context_selector (pretty_printer *pp, tree ctx, int spc,
+  dump_flags_t flags)
+{
+  for (tree set = ctx; set && set != error_mark_node; set = TREE_CHAIN (set))
+{
+  pp_string (pp, OMP_TSS_NAME (set));
+  pp_string (pp, " = {");
+  for (tree sel = OMP_TSS_TRAIT_SELECTORS (set);
+  sel && sel != error_mark_node; sel = TREE_CHAIN (sel))
+   {
+ if (OMP_TS_CODE (sel) == OMP_TRAIT_INVALID)
+   pp_string (pp, "");
+ else
+   pp_string (pp, OMP_TS_NAME (sel));
+ tree score = OMP_TS_SCORE (sel);
+ tree props = OMP_TS_PROPERTIES (sel);
+ if (props)
+   {
+ pp_string (pp, " (");
+ if (score)
+   {
+ pp_string (pp, "score(");
+ dump_generic_node (pp, score, spc + 4, flags, false);
+ pp_string (pp, "): ");
+   }
+ for (tree prop = props; prop; prop = TREE_CHAIN (prop))
+   {
+ if (OMP_TP_NAME (prop) == OMP_TP_NAMELIST_NODE)
+   {
+ const char *str = omp_context_name_list_prop (prop);
+ pp_string (pp, "\"");
+   

[PATCH V4 3/5] OpenMP: Use enumerators for names of trait-sets and traits

2023-12-17 Thread Sandra Loosemore
This patch introduces enumerators to represent trait-set names and
trait names, which makes it easier to use tables to control other
behavior and for switch statements to dispatch on the tags.  The tags
are stored in the same place in the TREE_LIST structure (OMP_TSS_ID or
OMP_TS_ID) and are encoded there as integer constants.

gcc/ChangeLog
* omp-selectors.h: New file.
* omp-general.h: Include omp-selectors.h.
(OMP_TSS_CODE, OMP_TSS_NAME): New.
(OMP_TS_CODE, OMP_TS_NAME): New.
(make_trait_set_selector, make_trait_selector): Adjust declarations.
(omp_construct_traits_to_codes): Likewise.
(omp_context_selector_set_compare): Likewise.
(omp_get_context_selector): Likewise.
(omp_get_context_selector_list): New.
* omp-general.cc (omp_construct_traits_to_codes): Pass length in
as argument instead of returning it.  Make it table-driven.
(omp_tss_map): New.
(kind_properties, vendor_properties, extension_properties): New.
(atomic_default_mem_order_properties): New.
(omp_ts_map): New.
(omp_check_context_selector): Simplify lookup and dispatch logic.
(omp_mark_declare_variant): Ignore variants with unknown construct
selectors.  Adjust for new representation.
(make_trait_set_selector, make_trait_selector): Adjust for new
representations.
(omp_context_selector_matches): Simplify dispatch logic.  Avoid
fixed-sized buffers and adjust call to omp_construct_traits_to_codes.
(omp_context_selector_props_compare): Adjust for new representations
and simplify dispatch logic.
(omp_context_selector_set_compare): Likewise.
(omp_context_selector_compare): Likewise.
(omp_get_context_selector): Adjust for new representations, and split
out...
(omp_get_context_selector_list): New function.
(omp_lookup_tss_code): New.
(omp_lookup_ts_code): New.
(omp_context_compute_score): Adjust for new representations.  Avoid
fixed-sized buffers and magic numbers.  Adjust call to
omp_construct_traits_to_codes.
* gimplify.cc (omp_construct_selector_matches): Avoid use of
fixed-size buffer.  Adjust call to omp_construct_traits_to_codes.

gcc/c/ChangeLog
* c-parser.cc (omp_construct_selectors): Delete.
(omp_device_selectors): Delete.
(omp_implementation_selectors): Delete.
(omp_user_selectors): Delete.
(c_parser_omp_context_selector): Adjust for new representations
and simplify dispatch logic.  Uniformly warn instead of sometimes
error when an unknown selector is found.
(c_parser_omp_context_selector_specification): Likewise.
(c_finish_omp_declare_variant): Adjust for new representations.

gcc/cp/ChangeLog
* decl.cc (omp_declare_variant_finalize_one): Adjust for new
representations.
* parser.cc (omp_construct_selectors): Delete.
(omp_device_selectors): Delete.
(omp_implementation_selectors): Delete.
(omp_user_selectors): Delete.
(cp_parser_omp_context_selector): Adjust for new representations
and simplify dispatch logic.  Uniformly warn instead of sometimes
error when an unknown selector is found.
(cp_parser_omp_context_selector_specification): Likewise.
* pt.cc (tsubst_attribute): Adjust for new representations.

gcc/fortran/ChangeLog
* gfortran.h: Include omp-selectors.h.
(enum gfc_omp_trait_property_kind): Delete, and replace all
references with equivalent omp_tp_type enumerators.
(struct gfc_omp_trait_property): Update for omp_tp_type.
(struct gfc_omp_selector): Replace string name with new enumerator.
(struct gfc_omp_set_selector): Likewise.
* openmp.cc (gfc_free_omp_trait_property_list): Update for
omp_tp_type.
(omp_construct_selectors): Delete.
(omp_device_selectors): Delete.
(omp_implementation_selectors): Delete.
(omp_user_selectors): Delete.
(gfc_ignore_trait_property_extension): New.
(gfc_ignore_trait_property_extension_list): New.
(gfc_match_omp_selector): Adjust for new representations and simplify
dispatch logic.  Uniformly warn instead of sometimes error when an
unknown selector is found.
(gfc_match_omp_context_selector): Adjust for new representations.
(gfc_match_omp_context_selector_specification): Likewise.
* trans-openmp.cc (gfc_trans_omp_declare_variant): Adjust for
new representations.

gcc/testsuite/
* c-c++-common/gomp/declare-variant-1.c: Expect warning on
unknown selectors.
* c-c++-common/gomp/declare-variant-2.c: Likewise.
* gfortran.dg/gomp/declare-variant-1.f90: Likewise.
* gfortran.dg/gomp/declare-variant-2.f90: Likewise.
---
 gcc/c/c-parser.cc | 234 

Re: [PATCH V3 3/4] OpenMP: Use enumerators for names of trait-sets and traits

2023-12-17 Thread Sandra Loosemore

On 12/12/23 05:05, Tobias Burnus wrote:

Hi Sandra,

On 07.12.23 16:52, Sandra Loosemore wrote:

This patch introduces enumerators to represent trait-set names and
trait names, which makes it easier to use tables to control other
behavior and for switch statements to dispatch on the tags.  The tags
are stored in the same place in the TREE_LIST structure (OMP_TSS_ID or
OMP_TS_ID) and are encoded there as integer constants.


Thanks - that looks like a huge improvement.

* * *

I think it is useful to prepare for 'target_device'. However, it is currently 
not yet implemented

on mainline - contrary to OG13.

Can you add some kind of error diagnostic for it? On mainline, the current 
result is:


error: expected ‘construct’, ‘device’, ‘implementation’ or ‘user’ before 
‘target_device’

    13 | #pragma omp declare variant (f05) match (target_device={kind(gpu)})
   |  ^

But with your patch, it is silently accepted, which is bad.

(That's a modified version of 
gcc/testsuite/c-c++-common/gomp/declare-variant-10.c:13)


I think you have two options:

* Either fail with the same error message as above

* Or update the error message to list 'target_device' (for C/C++/Fortran)
   and handle 'target_device' separately with a sorry.

To whatever you think makes more sense for know, knowing that we do want to add 
'target_device'

in the not to far future.

(I am slightly preferring the updated-error message + sorry variant as it 
avoids touching

the messages later again, but either is fine.)


OK.  I had a FIXME in the code noting that listing all the valid selector-set 
keywords in the error message was prone to bit-rot anyway, so I have replaced 
it with something more generic, and added a sorry for the missing 
"target_device" support.


Also in V4 of the patch I have added a sorry for the missing "requires" 
selector support so it does that rather than ICE, as Julian discovered.


Finally, I improved the error handling for including a trait-score on selectors 
that don't permit it -- it now says explicitly that a score isn't permitted 
there, instead of a cascade of more more obscure errors.  I have a test case 
for that coming later with the metadirectives patches, which are not ready for 
GCC 14.


And  I have a new part 5 for this series coming along too, with 
prettyprinter support for the new selector representation.  I realize we're 
long past the end of stage 1 but I think this is still reasonable to consider 
for GCC 14.  It's only for internal debugging purposes, and I think it'll be 
useful for Julian's work and implementing missing 5.1/5.2/TR11 selector 
features for declare variant as well as my current hackery on finishing 
metadirectives.  There aren't any "declare variant" test cases that examine the 
attribute on the base function in dump files, BTW, but I did inspect the output 
by hand and also do some further testing with metadirective.



Otherwise, the patch LGTM.

As written before, 1/4, 2/4 and 4/4 are LGTM as posted.


Thanks.  I'll push parts 1-4 when part 3 is approved, and part 5 too if/when 
that's approved.


-Sandra


Re: [PATCH] extend.texi: Mark builtin arguments with @var{...}

2023-12-10 Thread Sandra Loosemore

On 12/4/23 00:36, Jakub Jelinek wrote:

On Fri, Dec 01, 2023 at 10:43:57AM -0700, Sandra Loosemore wrote:

On 12/1/23 10:33, Jakub Jelinek wrote:

Shall we tweak that somehow?  If the argument names are unimportant, perhaps
it is fine to leave that out, but shouldn't we always use @var{...} around
the parameter names when specified?


Yup.  The Texinfo manual says:  "When using @deftypefn command and
variations, you should mark parameter names with @var to distinguish these
from data type names, keywords, and other parts of the literal syntax of the
programming language."


Here is a patch which does that (but not adding types to where they were
missing, that will be harder to search for).

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?


This is mostly OK, but I noticed some things you missed:


@@ -12946,13 +12946,13 @@ and @code{__ATOMIC_CONSUME}.
  
  @enddefbuiltin
  
-@defbuiltin{void __atomic_load (@var{type} *ptr, @var{type} *ret, int memorder)}

+@defbuiltin{void __atomic_load (@var{type} *@var{ptr}, @var{type} *ret, int 
@var{memorder})}


@var markup on "ret" here.


-@defbuiltin{void __atomic_store_n (@var{type} *ptr, @var{type} val, int 
memorder)}
+@defbuiltin{void __atomic_store_n (@var{type} *@var{ptr}, @var{type} val, int 
@var{memorder})}


And on "val" here...


-@defbuiltin{void __atomic_store (@var{type} *ptr, @var{type} *val, int 
memorder)}
+@defbuiltin{void __atomic_store (@var{type} *@var{ptr}, @var{type} *val, int 
@var{memorder})}


...and here...


-@defbuiltin{@var{type} __atomic_exchange_n (@var{type} *ptr, @var{type} val, 
int memorder)}
+@defbuiltin{@var{type} __atomic_exchange_n (@var{type} *@var{ptr}, @var{type} 
val, int @var{memorder})}


...and here.


-@defbuiltin{void __atomic_exchange (@var{type} *ptr, @var{type} *val, 
@var{type} *ret, int memorder)}
+@defbuiltin{void __atomic_exchange (@var{type} *@var{ptr}, @var{type} *val, 
@var{type} *ret, int @var{memorder})}


And both "val" and "ret" here.

OK with those things fixed.

-Sandra




[PATCH V3 3/4] OpenMP: Use enumerators for names of trait-sets and traits

2023-12-07 Thread Sandra Loosemore
This patch introduces enumerators to represent trait-set names and
trait names, which makes it easier to use tables to control other
behavior and for switch statements to dispatch on the tags.  The tags
are stored in the same place in the TREE_LIST structure (OMP_TSS_ID or
OMP_TS_ID) and are encoded there as integer constants.

gcc/ChangeLog
* omp-selectors.h: New file.
* omp-general.h: Include omp-selectors.h.
(OMP_TSS_CODE, OMP_TSS_NAME): New.
(OMP_TS_CODE, OMP_TS_NAME): New.
(make_trait_set_selector, make_trait_selector): Adjust declarations.
(omp_construct_traits_to_codes): Likewise.
(omp_context_selector_set_compare): Likewise.
(omp_get_context_selector): Likewise.
(omp_get_context_selector_list): New.
* omp-general.cc (omp_construct_traits_to_codes): Pass length in
as argument instead of returning it.  Make it table-driven.
(omp_tss_map): New.
(kind_properties, vendor_properties, extension_properties): New.
(atomic_default_mem_order_properties): New.
(omp_ts_map): New.
(omp_check_context_selector): Simplify lookup and dispatch logic.
(omp_mark_declare_variant): Ignore variants with unknown construct
selectors.  Adjust for new representation.
(make_trait_set_selector, make_trait_selector): Adjust for new
representations.
(omp_context_selector_matches): Simplify dispatch logic.  Avoid
fixed-sized buffers and adjust call to omp_construct_traits_to_codes.
(omp_context_selector_props_compare): Adjust for new representations
and simplify dispatch logic.
(omp_context_selector_set_compare): Likewise.
(omp_context_selector_compare): Likewise.
(omp_get_context_selector): Adjust for new representations, and split
out...
(omp_get_context_selector_list): New function.
(omp_lookup_tss_code): New.
(omp_lookup_ts_code): New.
(omp_context_compute_score): Adjust for new representations.  Avoid
fixed-sized buffers and magic numbers.  Adjust call to
omp_construct_traits_to_codes.
* gimplify.cc (omp_construct_selector_matches): Avoid use of
fixed-size buffer.  Adjust call to omp_construct_traits_to_codes.

gcc/c/ChangeLog
* c-parser.cc (omp_construct_selectors): Delete.
(omp_device_selectors): Delete.
(omp_implementation_selectors): Delete.
(omp_user_selectors): Delete.
(c_parser_omp_context_selector): Adjust for new representations
and simplify dispatch logic.  Uniformly warn instead of sometimes
error when an unknown selector is found.
(c_parser_omp_context_selector_specification): Likewise.
(c_finish_omp_declare_variant): Adjust for new representations.

gcc/cp/ChangeLog
* decl.cc (omp_declare_variant_finalize_one): Adjust for new
representations.
* parser.cc (omp_construct_selectors): Delete.
(omp_device_selectors): Delete.
(omp_implementation_selectors): Delete.
(omp_user_selectors): Delete.
(cp_parser_omp_context_selector): Adjust for new representations
and simplify dispatch logic.  Uniformly warn instead of sometimes
error when an unknown selector is found.
(cp_parser_omp_context_selector_specification): Likewise.
* pt.cc (tsubst_attribute): Adjust for new representations.

gcc/fortran/ChangeLog
* gfortran.h: Include omp-selectors.h.
(enum gfc_omp_trait_property_kind): Delete, and replace all
references with equivalent omp_tp_type enumerators.
(struct gfc_omp_trait_property): Update for omp_tp_type.
(struct gfc_omp_selector): Replace string name with new enumerator.
(struct gfc_omp_set_selector): Likewise.
* openmp.cc (gfc_free_omp_trait_property_list): Update for
omp_tp_type.
(omp_construct_selectors): Delete.
(omp_device_selectors): Delete.
(omp_implementation_selectors): Delete.
(omp_user_selectors): Delete.
(gfc_ignore_trait_property_extension): New.
(gfc_ignore_trait_property_extension_list): New.
(gfc_match_omp_selector): Adjust for new representations and simplify
dispatch logic.  Uniformly warn instead of sometimes error when an
unknown selector is found.
(gfc_match_omp_context_selector): Adjust for new representations.
(gfc_match_omp_context_selector_specification): Likewise.
* trans-openmp.cc (gfc_trans_omp_declare_variant): Adjust for
new representations.

gcc/testsuite/
* c-c++-common/gomp/declare-variant-1.c: Expect warning on
unknown selectors.
* c-c++-common/gomp/declare-variant-2.c: Likewise.
* gfortran.dg/gomp/declare-variant-1.f90: Likewise.
* gfortran.dg/gomp/declare-variant-2.f90: Likewise.
---
 gcc/c/c-parser.cc | 185 

[PATCH V3 4/4] OpenMP: Permit additional selector properties

2023-12-07 Thread Sandra Loosemore
This patch adds "hpe" to the known properties for the "vendor" selector,
and support for "acquire" and "release" for "atomic_default_mem_order".

gcc/ChangeLog
* omp-general.cc (vendor_properties): Add "hpe".
(atomic_default_mem_order_properties): Add "acquire" and "release".
(omp_context_selector_matches): Handle "acquire" and "release".

gcc/testsuite/ChangeLog
* c-c++-common/gomp/declare-variant-2.c: Don't expect error on
"acquire" and "release".
* gfortran.dg/gomp/declare-variant-2a.f90: Likewise.
---
 gcc/omp-general.cc| 10 --
 gcc/testsuite/c-c++-common/gomp/declare-variant-2.c   |  4 ++--
 gcc/testsuite/gfortran.dg/gomp/declare-variant-2a.f90 |  4 ++--
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc
index 5f0cb041ffa..4f7c83fbd2c 100644
--- a/gcc/omp-general.cc
+++ b/gcc/omp-general.cc
@@ -1126,12 +1126,12 @@ const char *omp_tss_map[] =
 static const char *const kind_properties[] =
   { "host", "nohost", "cpu", "gpu", "fpga", "any", NULL };
 static const char *const vendor_properties[] =
-  { "amd", "arm", "bsc", "cray", "fujitsu", "gnu", "ibm", "intel",
+  { "amd", "arm", "bsc", "cray", "fujitsu", "gnu", "hpe", "ibm", "intel",
 "llvm", "nvidia", "pgi", "ti", "unknown", NULL };
 static const char *const extension_properties[] =
   { NULL };
 static const char *const atomic_default_mem_order_properties[] =
-  { "seq_cst", "relaxed", "acq_rel", NULL };
+  { "seq_cst", "relaxed", "acq_rel", "acquire", "release", NULL };
 
 struct omp_ts_info omp_ts_map[] =
   {
@@ -1551,6 +1551,12 @@ omp_context_selector_matches (tree ctx)
  else if (!strcmp (prop, "acq_rel")
   && omo != OMP_MEMORY_ORDER_ACQ_REL)
return 0;
+ else if (!strcmp (prop, "acquire")
+  && omo != OMP_MEMORY_ORDER_ACQUIRE)
+   return 0;
+ else if (!strcmp (prop, "release")
+  && omo != OMP_MEMORY_ORDER_RELEASE)
+   return 0;
}
  break;
case OMP_TRAIT_DEVICE_ARCH:
diff --git a/gcc/testsuite/c-c++-common/gomp/declare-variant-2.c 
b/gcc/testsuite/c-c++-common/gomp/declare-variant-2.c
index 97285fa3b74..bc3f443379f 100644
--- a/gcc/testsuite/c-c++-common/gomp/declare-variant-2.c
+++ b/gcc/testsuite/c-c++-common/gomp/declare-variant-2.c
@@ -105,9 +105,9 @@ void f50 (void);
/* { dg-error "expected '\\\}' before '\\(' token" "" {
 void f51 (void);   
/* { dg-error "expected '\\\}' before '\\(' token" "" { target c } .-1 } */
 #pragma omp declare variant (f1) 
match(implementation={atomic_default_mem_order})  /* { dg-error "expected 
'\\(' before '\\\}' token" } */
 void f52 (void);
-#pragma omp declare variant (f1) 
match(implementation={atomic_default_mem_order(acquire)}) /* { dg-error 
"incorrect property 'acquire' of 'atomic_default_mem_order' selector" } */
+#pragma omp declare variant (f1) 
match(implementation={atomic_default_mem_order(acquire)})
 void f53 (void);
-#pragma omp declare variant (f1) 
match(implementation={atomic_default_mem_order(release)}) /* { dg-error 
"incorrect property 'release' of 'atomic_default_mem_order' selector" } */
+#pragma omp declare variant (f1) 
match(implementation={atomic_default_mem_order(release)})
 void f54 (void);
 #pragma omp declare variant (f1) 
match(implementation={atomic_default_mem_order(foobar)})  /* { dg-error 
"incorrect property 'foobar' of 'atomic_default_mem_order' selector" } */
 void f55 (void);
diff --git a/gcc/testsuite/gfortran.dg/gomp/declare-variant-2a.f90 
b/gcc/testsuite/gfortran.dg/gomp/declare-variant-2a.f90
index 56de1177789..edc9b27f884 100644
--- a/gcc/testsuite/gfortran.dg/gomp/declare-variant-2a.f90
+++ b/gcc/testsuite/gfortran.dg/gomp/declare-variant-2a.f90
@@ -29,10 +29,10 @@ contains
 !$omp declare variant (f1) match(implementation={vendor("foobar")}) ! { 
dg-warning "unknown property '.foobar.' of 'vendor' selector" }
   end subroutine
   subroutine f53 ()
-!$omp declare variant (f1) 
match(implementation={atomic_default_mem_order(acquire)})  ! { dg-error 
"incorrect property 'acquire' of 'atomic_default_mem_order' selector" }
+!$omp declare variant (f1) 
match(implementation={atomic_default_mem_order(acquire)})
   end subroutine
   subroutine f54 ()
-!$omp declare variant (f1) 
match(implementation={atomic_default_mem_order(release)})  ! { dg-error 
"incorrect property 'release' of 'atomic_default_mem_order' selector" }
+!$omp declare variant (f1) 
match(implementation={atomic_default_mem_order(release)})
   end subroutine
   subroutine f55 ()
 !$omp declare variant (f1) 
match(implementation={atomic_default_mem_order(foobar)}) ! { dg-error 
"incorrect 

[PATCH V3 1/4] OpenMP: Introduce accessor macros and constructors for context selectors.

2023-12-07 Thread Sandra Loosemore
This patch hides the underlying nested TREE_LIST structure of context
selectors behind accessor macros that have more meaningful names than
the generic TREE_PURPOSE/TREE_VALUE accessors.  There is a slight
change to the representation in that the score expression in
trait-selectors has a distinguished tag and is separated from the
ordinary properties, although internally it is still represented as
the first item in the TREE_VALUE of the selector.  This patch also renames
some local variables with slightly more descriptive names so it is easier
to track whether something is a selector-set, selector, or property.

gcc/ChangeLog
* omp-general.h (OMP_TS_SCORE_NODE): New.
(OMP_TSS_ID, OMP_TSS_TRAIT_SELECTORS): New.
(OMP_TS_ID, OMP_TS_SCORE, OMP_TS_PROPERTIES): New.
(OMP_TP_NAME, OMP_TP_VALUE): New.
(make_trait_set_selector): Declare.
(make_trait_selector): Declare.
(make_trait_property): Declare.
(omp_constructor_traits_to_codes): Rename to
omp_construct_traits_to_codes.
* omp-general.cc (omp_constructor_traits_to_codes): Rename
to omp_construct_traits_to_codes.  Use new accessors.
(omp_check_context_selector): Use new accessors.
(make_trait_set_selector): New.
(make_trait_selector): New.
(make_trait_property): New.
(omp_context_name_list_prop): Use new accessors.
(omp_context_selector_matches): Use new accessors.
(omp_context_selector_props_compare): Use new accessors.
(omp_context_selector_set_compare): Use new accessors.
(omp_get_context_selector): Use new accessors.
(omp_context_compute_score): Use new accessors.
* gimplify.cc (omp_construct_selector_matches): Adjust for renaming
of omp_constructor_traits_to_codes.

gcc/c/ChangeLog
* c-parser.cc (c_parser_omp_context_selector): Use new constructors.

gcc/cp/ChangeLog
* parser.cc (cp_parser_omp_context_selector): Use new constructors.
* pt.cc: Include omp-general.h.
(tsubst_attribute): Use new context selector accessors and
 constructors.

gcc/fortran/ChangeLog
* trans-openmp.cc (gfc_trans_omp_declare_variant): Use new
constructors.
---
 gcc/c/c-parser.cc   |  27 ++--
 gcc/cp/parser.cc|  30 ++--
 gcc/cp/pt.cc|  82 ++
 gcc/fortran/trans-openmp.cc |  27 ++--
 gcc/gimplify.cc |   4 +-
 gcc/omp-general.cc  | 293 ++--
 gcc/omp-general.h   |  48 +-
 7 files changed, 297 insertions(+), 214 deletions(-)

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index df9a07928b5..9a17a8c5760 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -24353,7 +24353,10 @@ static const char *const omp_user_selectors[] = {
  trait-selector-name[([trait-score:]trait-property[,trait-property[,...]])]
 
trait-score:
- score(score-expression)  */
+ score(score-expression)
+
+   Note that this function returns a list of trait selectors for the
+   trait-selector-set SET.  */
 
 static tree
 c_parser_omp_context_selector (c_parser *parser, tree set, tree parms)
@@ -24372,6 +24375,7 @@ c_parser_omp_context_selector (c_parser *parser, tree 
set, tree parms)
}
 
   tree properties = NULL_TREE;
+  tree scoreval = NULL_TREE;
   const char *const *selectors = NULL;
   bool allow_score = true;
   bool allow_user = false;
@@ -24478,8 +24482,7 @@ c_parser_omp_context_selector (c_parser *parser, tree 
set, tree parms)
error_at (token->location, "score argument must be "
  "non-negative");
  else
-   properties = tree_cons (get_identifier (" score"),
-   score, properties);
+   scoreval = score;
}
  token = c_parser_peek_token (parser);
}
@@ -24492,7 +24495,8 @@ c_parser_omp_context_selector (c_parser *parser, tree 
set, tree parms)
{
  t = c_parser_expr_no_commas (parser, NULL).value;
  if (TREE_CODE (t) == STRING_CST)
-   properties = tree_cons (NULL_TREE, t, properties);
+   properties = make_trait_property (NULL_TREE, t,
+ properties);
  else if (t != error_mark_node)
{
  mark_exp_read (t);
@@ -24503,7 +24507,8 @@ c_parser_omp_context_selector (c_parser *parser, tree 
set, tree parms)
  "constant integer expression or string "
  "literal");
  else
-   properties = tree_cons (NULL_TREE, t, properties);
+   properties = make_trait_property (NULL_TREE, t,
+ properties);

[PATCH V3 2/4] OpenMP: Unify representation of name-list properties.

2023-12-07 Thread Sandra Loosemore
Previously, name-list properties specified as identifiers were stored
in the TREE_PURPOSE/OMP_TP_NAME slot, while those specified as strings
were stored in the TREE_VALUE/OMP_TP_VALUE slot.  This patch puts both
representations in OMP_TP_VALUE with a magic cookie in OMP_TP_NAME.

gcc/ChangeLog
* omp-general.h (OMP_TP_NAMELIST_NODE): New.
* omp-general.cc (omp_context_name_list_prop): Move earlier
in the file, and adjust for new representation.
(omp_check_context_selector): Adjust this too.
(omp_context_selector_props_compare): Likewise.

gcc/c/ChangeLog
* c-parser.cc (c_parser_omp_context_selector): Adjust for new
namelist property representation.

gcc/cp/ChangeLog
* parser.cc (cp_parser_omp_context_selector): Adjust for new
namelist property representation.
* pt.cc (tsubst_attribute): Likewise.

gcc/fortran/ChangeLog
* trans-openmp.cc (gfc_trans_omp_declare_varaint): Adjust for
new namelist property representation.
---
 gcc/c/c-parser.cc   |  5 ++-
 gcc/cp/parser.cc|  5 ++-
 gcc/cp/pt.cc|  4 +-
 gcc/fortran/trans-openmp.cc |  5 ++-
 gcc/omp-general.cc  | 84 +
 gcc/omp-general.h   |  1 +
 6 files changed, 61 insertions(+), 43 deletions(-)

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index 9a17a8c5760..7fe449dc54a 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -24538,11 +24538,12 @@ c_parser_omp_context_selector (c_parser *parser, tree 
set, tree parms)
case CTX_PROPERTY_NAME_LIST:
  do
{
- tree prop = NULL_TREE, value = NULL_TREE;
+ tree prop = OMP_TP_NAMELIST_NODE;
+ tree value = NULL_TREE;
  if (c_parser_next_token_is (parser, CPP_KEYWORD)
  || c_parser_next_token_is (parser, CPP_NAME))
{
- prop = c_parser_peek_token (parser)->value;
+ value = c_parser_peek_token (parser)->value;
  c_parser_consume_token (parser);
}
  else if (c_parser_next_token_is (parser, CPP_STRING))
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 9d4ae9726e5..eb1b0f26003 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -47539,11 +47539,12 @@ cp_parser_omp_context_selector (cp_parser *parser, 
tree set, bool has_parms_p)
case CTX_PROPERTY_NAME_LIST:
  do
{
- tree prop = NULL_TREE, value = NULL_TREE;
+ tree prop = OMP_TP_NAMELIST_NODE;
+ tree value = NULL_TREE;
  if (cp_lexer_next_token_is (parser->lexer, CPP_KEYWORD)
  || cp_lexer_next_token_is (parser->lexer, CPP_NAME))
{
- prop = cp_lexer_peek_token (parser->lexer)->u.value;
+ value = cp_lexer_peek_token (parser->lexer)->u.value;
  cp_lexer_consume_token (parser->lexer);
}
  else if (cp_lexer_next_token_is (parser->lexer, CPP_STRING))
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 2541ad95cc1..ca4975dcd6f 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -11869,7 +11869,9 @@ tsubst_attribute (tree t, tree *decl_p, tree args,
}
  properties = copy_list (OMP_TS_PROPERTIES (ts));
  for (tree p = properties; p; p = TREE_CHAIN (p))
-   if (OMP_TP_VALUE (p))
+   if (OMP_TP_NAME (p) == OMP_TP_NAMELIST_NODE)
+ continue;
+   else if (OMP_TP_VALUE (p))
  {
bool allow_string
  = (OMP_TS_ID (ts) != condition || set[0] != 'u');
diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc
index fe8044a57cd..60154ff3751 100644
--- a/gcc/fortran/trans-openmp.cc
+++ b/gcc/fortran/trans-openmp.cc
@@ -8235,9 +8235,10 @@ gfc_trans_omp_declare_variant (gfc_namespace *ns)
  break;
case CTX_PROPERTY_NAME_LIST:
  {
-   tree prop = NULL_TREE, value = NULL_TREE;
+   tree prop = OMP_TP_NAMELIST_NODE;
+   tree value = NULL_TREE;
if (otp->is_name)
- prop = get_identifier (otp->name);
+ value = get_identifier (otp->name);
else
  value = gfc_conv_constant_to_tree (otp->expr);
 
diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc
index 75980fcf4da..156508eabb5 100644
--- a/gcc/omp-general.cc
+++ b/gcc/omp-general.cc
@@ -1114,6 +1114,30 @@ omp_maybe_offloaded (void)
   return false;
 }
 
+/* Return a name from PROP, a property in selectors accepting
+   name lists.  */
+
+static const char *

[PATCH V3 0/4] OpenMP: Improve data abstractions for context selectors

2023-12-07 Thread Sandra Loosemore
Here is a new version of my context selector implementation cleanup
patch set, incorporating comments from Tobias on V2 of part 3.  Parts
1 and 2 are unchanged from V1 except that I rebased them so they
should apply cleanly to mainline head now.  There's a new part 4 that
adds new functionality, handling the additional properties Tobias asked
for.

The part 3 changes from V2 are primarily in making the front ends pass
through a marker for unknown selectors to later processing, instead of
ignoring them completely; anything that contains these unknown
selectors then fails to match.  As Tobias suggested, I also changed
the front ends to uniformly warn about any unknown selector;
previously it either gave no diagnostic at all or gave an error,
depending on the selector set.  To get this to work in the Fortran
front end, I moved the mapping from strings to the new enums to the
parse phase instead of the translate phase, where I'd had it before.
I think this is a cleaner design anyway as it allows getting rid of the
duplicate set of allowed names in the Fortran front end and sharing the
same tables used everywhere else.

-Sandra


Sandra Loosemore (4):
  OpenMP: Introduce accessor macros and constructors for context
selectors.
  OpenMP: Unify representation of name-list properties.
  OpenMP: Use enumerators for names of trait-sets and traits
  OpenMP: Permit additional selector properties

 gcc/c/c-parser.cc | 205 ++---
 gcc/cp/decl.cc|   8 +-
 gcc/cp/parser.cc  | 205 ++---
 gcc/cp/pt.cc  |  93 ++-
 gcc/fortran/gfortran.h|  20 +-
 gcc/fortran/openmp.cc | 189 ++---
 gcc/fortran/trans-openmp.cc   |  66 +-
 gcc/gimplify.cc   |  17 +-
 gcc/omp-general.cc| 778 +++---
 gcc/omp-general.h |  66 +-
 gcc/omp-selectors.h   |  93 +++
 .../c-c++-common/gomp/declare-variant-1.c |   1 +
 .../c-c++-common/gomp/declare-variant-2.c |  44 +-
 .../gfortran.dg/gomp/declare-variant-1.f90|   1 +
 .../gfortran.dg/gomp/declare-variant-2.f90|  34 +-
 .../gfortran.dg/gomp/declare-variant-2a.f90   |   4 +-
 16 files changed, 1015 insertions(+), 809 deletions(-)
 create mode 100644 gcc/omp-selectors.h

-- 
2.31.1



Re: [PATCH] extend.texi: Fix up defbuiltin* with spaces in return type

2023-12-01 Thread Sandra Loosemore

On 12/1/23 10:33, Jakub Jelinek wrote:

On Fri, Dec 01, 2023 at 10:04:38AM -0700, Sandra Loosemore wrote:

Thanks, this looks good to me.  I think I also noticed this weird formatting
in passing recently when I was looking for something else and did not have
time to track it down myself.


There is another question.  In many cases we just specify types for the
builtin arguments, in other cases types and names with @var{name} syntax,
and in other case with just name.

@defbuiltin{int __builtin_fpclassify (int, int, int, int, int, ...)}
vs.
@defbuiltin{size_t __builtin_object_size (const void * @var{ptr}, int 
@var{type})}
vs.
@defbuiltinx{bool __builtin_umull_overflow (unsigned long int a, unsigned long 
int b, unsigned long int *res)}
and in some cases even just name the arguments and don't specify type:
@defbuiltin{void __builtin_clear_padding (@var{ptr})}
@defbuiltin{@var{type} __builtin_choose_expr (@var{const_exp}, @var{exp1}, 
@var{exp2})}

Shall we tweak that somehow?  If the argument names are unimportant, perhaps
it is fine to leave that out, but shouldn't we always use @var{...} around
the parameter names when specified?


Yup.  The Texinfo manual says:  "When using @deftypefn command and variations, 
you should mark parameter names with @var to distinguish these from data type 
names, keywords, and other parts of the literal syntax of the programming 
language."



And avoid leaving out the types, use something like
__builtin_clear_padding (@var{type} *@var{ptr})
or
__builtin_choose_expr (@var{type1} @var{const_exp}, @var{type2} @var{exp1}, 
@var{type3} @var{exp2})
?


That would probably be good too.

-Sandra





Re: [PATCH] extend.texi: Fix up defbuiltin* with spaces in return type

2023-12-01 Thread Sandra Loosemore

On 12/1/23 03:26, Jakub Jelinek wrote:

Hi!

In 
https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#index-_005f_005fbuiltin_005fstdc_005fbit_005ffloor>>
 I've noticed that while e.g. __builtin_stdc_bit_floor builtin is properly
rendered in bold and bigger size, for the __builtin_stdc_bit_width builtin
it is not the builtin name which is marked like that, but the keyword int
before it.  Also, seems such builtins are missing from the index.

I've read the texinfo docs and they seem to suggest in
https://www.gnu.org/software/texinfo/manual/texinfo/html_node/Line-Macros.html>>
 that return types of functions with spaces in the return type should be
wrapped with {}s and we already use that e.g. in
@defbuiltin{{void *} __builtin_thread_pointer (void)}

The following patch adjusts builtins I found which contained one or two
spaces in the return type name (plus two spots which used 2 spaces after
single keyword return type instead of 1 which triggered my search regex as
well).

Tested on x86_64-linux, ok for trunk?


Thanks, this looks good to me.  I think I also noticed this weird formatting in 
passing recently when I was looking for something else and did not have time to 
track it down myself.


-Sandra




[PATCH V2 3/3] OpenMP: Use enumerators for names of trait-sets and traits

2023-11-22 Thread Sandra Loosemore
This patch introduces enumerators to represent trait-set names and
trait names, which makes it easier to use tables to control other
behavior and for switch statements to dispatch on the tags.  The tags
are stored in the same place in the TREE_LIST structure (OMP_TSS_ID or
OMP_TS_ID) and are encoded there as integer constants.

gcc/ChangeLog
* omp-general.h (enum omp_tss_code): New.
(enum omp_ts_code): New.
(enum omp_tp_type): New.
(omp_tss_map): New.
(struct omp_ts_info): New.
(omp_ts_map): New.
(OMP_TSS_CODE, OMP_TSS_NAME): New.
(OMP_TS_CODE, OMP_TS_NAME): New.
(make_trait_set_selector, make_trait_selector): Adjust declarations.
(omp_construct_traits_to_codes): Likewise.
(omp_context_selector_set_compare): Likewise.
(omp_get_context_selector): Likewise.
(omp_get_context_selector_list): New.
(omp_lookup_tss_code): New.
(omp_lookup_ts_code): New.
* omp-general.cc (omp_construct_traits_to_codes): Pass length in
as argument instead of returning it.  Make it table-driven.
(omp_tss_map): New.
(kind_properties, vendor_properties, extension_properties): New.
(atomic_default_mem_order_properties): New.
(omp_ts_map): New.
(omp_check_context_selector): Simplify lookup and dispatch logic.
(omp_mark_declare_variant): Adjust for new representation.
(make_trait_set_selector, make_trait_selector): Adjust for new
representations.
(omp_context_selector_matches): Simplify dispatch logic.  Avoid
fixed-sized buffers and adjust call to omp_construct_traits_to_codes.
(omp_context_selector_props_compare): Adjust for new representations
and simplify dispatch logic.
(omp_context_selector_set_compare): Likewise.
(omp_context_selector_compare): Likewise.
(omp_get_context_selector): Adjust for new representations, and split
out...
(omp_get_context_selector_list): New function.
(omp_lookup_tss_code): New.
(omp_lookup_ts_code): New.
(omp_context_compute_score): Adjust for new representations.  Avoid
fixed-sized buffers and magic numbers.  Adjust call to
omp_construct_traits_to_codes.
* gimplify.cc (omp_construct_selector_matches): Avoid use of
fixed-size buffer.  Adjust call to omp_construct_traits_to_codes.

gcc/c/ChangeLog
* c-parser.cc (omp_construct_selectors): Delete.
(omp_device_selectors): Delete.
(omp_implementation_selectors): Delete.
(omp_user_selectors): Delete.
(c_parser_omp_context_selector): Adjust for new representations
and simplify dispatch logic.
(c_parser_omp_context_selector_specification): Likewise.
(c_finish_omp_declare_variant): Adjust for new representations.

gcc/cp/ChangeLog
* decl.cc (omp_declare_variant_finalize_one): Adjust for new
representations.
* parser.cc (omp_construct_selectors): Delete.
(omp_device_selectors): Delete.
(omp_implementation_selectors): Delete.
(omp_user_selectors): Delete.
(cp_parser_omp_context_selector): Adjust for new representations
and simplify dispatch logic.
(cp_parser_omp_context_selector_specification): Likewise.
* pt.cc (tsubst_attribute): Adjust for new representations.

gcc/fortran/ChangeLog
* trans-openmp.cc (gfc_trans_omp_declare_variant): Adjust for
new representations.
---
 gcc/c/c-parser.cc   | 192 -
 gcc/cp/decl.cc  |   8 +-
 gcc/cp/parser.cc| 189 -
 gcc/cp/pt.cc|  15 +-
 gcc/fortran/trans-openmp.cc |  41 ++-
 gcc/gimplify.cc |  17 +-
 gcc/omp-general.cc  | 530 +++-
 gcc/omp-general.h   |  89 +-
 8 files changed, 590 insertions(+), 491 deletions(-)

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index a2ff381e0c1..70c0e1828ca 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -24016,16 +24016,6 @@ c_parser_omp_declare_simd (c_parser *parser, enum 
pragma_context context)
 }
 }
 
-static const char *const omp_construct_selectors[] = {
-  "simd", "target", "teams", "parallel", "for", NULL };
-static const char *const omp_device_selectors[] = {
-  "kind", "isa", "arch", NULL };
-static const char *const omp_implementation_selectors[] = {
-  "vendor", "extension", "atomic_default_mem_order", "unified_address",
-  "unified_shared_memory", "dynamic_allocators", "reverse_offload", NULL };
-static const char *const omp_user_selectors[] = {
-  "condition", NULL };
-
 /* OpenMP 5.0:
 
trait-selector:
@@ -24038,7 +24028,8 @@ static const char *const omp_user_selectors[] = {
trait-selector-set SET.  */
 
 static tree
-c_parser_omp_context_selector (c_parser *parser, tree set, tree parms)
+c_parser_omp_context_selector (c_parser *parser, enum 

Re: [PATCH 3/3] OpenMP: Use enumerators for names of trait-sets and traits

2023-11-21 Thread Sandra Loosemore

On 11/19/23 02:21, Sandra Loosemore wrote:

This patch introduces enumerators to represent trait-set names and
trait names, which makes it easier to use tables to control other
behavior and for switch statements to dispatch on the tags.  The tags
are stored in the same place in the TREE_LIST structure (OMP_TSS_ID or
OMP_TS_ID) and are encoded there as integer constants.

This patch has only been lightly tested and still has at least one bug
that causes an ICE.  :-(


Update: I've tracked down the ICE to me having introduced an incorrect variable 
initialization in omp_context_compute_score.  I'm now looking at fixing 
interfaces to avoid the separate bug in omp_mark_declare_variant that Julian 
reported, and I'll post a revised part 3 in the next day or two.


-Sandra


[PATCH 3/3] OpenMP: Use enumerators for names of trait-sets and traits

2023-11-19 Thread Sandra Loosemore
This patch introduces enumerators to represent trait-set names and
trait names, which makes it easier to use tables to control other
behavior and for switch statements to dispatch on the tags.  The tags
are stored in the same place in the TREE_LIST structure (OMP_TSS_ID or
OMP_TS_ID) and are encoded there as integer constants.

This patch has only been lightly tested and still has at least one bug
that causes an ICE.  :-(

gcc/ChangeLog
* omp-general.h (enum omp_tss_code): New.
(enum omp_ts_code): New.
(enum omp_tp_type): New.
(omp_tss_map): New.
(struct omp_ts_info): New.
(omp_ts_map): New.
(OMP_TSS_CODE, OMP_TSS_NAME): New.
(OMP_TS_CODE, OMP_TS_NAME): New.
(make_trait_set_selector, make_trait_selector): Adjust declarations.
(omp_context_selector_set_compare): Likewise.
(omp_get_context_selector): Likewise.
(omp_get_context_selector_list): New.
(omp_lookup_tss_code): New.
(omp_lookup_ts_code): New.
* omp-general.cc (omp_construct_traits_to_codes): Make it
table-driven.
(omp_tss_map): New.
(kind_properties, vendor_properties, extension_properties): New.
(atomic_default_mem_order_properties): New.
(omp_ts_map): New.
(omp_check_context_selector): Simplify lookup and dispatch logic.
(omp_mark_declare_variant): Adjust for new representation.
(make_trait_set_selector, make_trait_selector): Adjust for new
representations.
(omp_context_selector_matches): Simplify dispatch logic, also
avoid fix-sized buffers.
(omp_context_selector_props_compare): Adjust for new representations
and simplify dispatch logic.
(omp_context_selector_set_compare): Likewise.
(omp_context_selector_compare): Likewise.
(omp_get_context_selector): Adjust for new representations, and split
out...
(omp_get_context_selector_list): New function.
(omp_lookup_tss_code): New.
(omp_lookup_ts_code): New.
(omp_context_compute_score): Adjust for new representations.  Avoid
fixed-sized buffers and magic numbers.

gcc/c/ChangeLog
* c-parser.cc (omp_construct_selectors): Delete.
(omp_device_selectors): Delete.
(omp_implementation_selectors): Delete.
(omp_user_selectors): Delete.
(c_parser_omp_context_selector): Adjust for new representations
and simplify dispatch logic.
(c_parser_omp_context_selector_specification): Likewise.
(c_finish_omp_declare_variant): Adjust for new representations.

gcc/cp/ChangeLog
* decl.cc (omp_declare_variant_finalize_one): Adjust for new
representations.
* parser.cc (omp_construct_selectors): Delete.
(omp_device_selectors): Delete.
(omp_implementation_selectors): Delete.
(omp_user_selectors): Delete.
(cp_parser_omp_context_selector): Adjust for new representations
and simplify dispatch logic.
(cp_parser_omp_context_selector_specification): Likewise.
* pt.cc (tsubst_attribute): Adjust for new representations.

gcc/fortran/ChangeLog
* trans-openmp.cc (gfc_trans_omp_declare_variant): Adjust for
new representations.
---
 gcc/c/c-parser.cc   | 192 --
 gcc/cp/decl.cc  |   8 +-
 gcc/cp/parser.cc| 189 --
 gcc/cp/pt.cc|  15 +-
 gcc/fortran/trans-openmp.cc |  41 ++-
 gcc/omp-general.cc  | 496 +++-
 gcc/omp-general.h   |  87 ++-
 7 files changed, 555 insertions(+), 473 deletions(-)

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index a2ff381e0c1..70c0e1828ca 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -24016,16 +24016,6 @@ c_parser_omp_declare_simd (c_parser *parser, enum 
pragma_context context)
 }
 }
 
-static const char *const omp_construct_selectors[] = {
-  "simd", "target", "teams", "parallel", "for", NULL };
-static const char *const omp_device_selectors[] = {
-  "kind", "isa", "arch", NULL };
-static const char *const omp_implementation_selectors[] = {
-  "vendor", "extension", "atomic_default_mem_order", "unified_address",
-  "unified_shared_memory", "dynamic_allocators", "reverse_offload", NULL };
-static const char *const omp_user_selectors[] = {
-  "condition", NULL };
-
 /* OpenMP 5.0:
 
trait-selector:
@@ -24038,7 +24028,8 @@ static const char *const omp_user_selectors[] = {
trait-selector-set SET.  */
 
 static tree
-c_parser_omp_context_selector (c_parser *parser, tree set, tree parms)
+c_parser_omp_context_selector (c_parser *parser, enum omp_tss_code set,
+  tree parms)
 {
   tree ret = NULL_TREE;
   do
@@ -24052,80 +24043,52 @@ c_parser_omp_context_selector (c_parser *parser, tree 
set, tree parms)
  c_parser_error (parser, "expected trait selector name");
  return 

[PATCH 0/3] OpenMP: Improve data abstractions for context selectors

2023-11-19 Thread Sandra Loosemore
While trying to track down some bugs in the metadirective patches
(currently on the OG13 branch), I found that I was getting totally
lost in the undocumented data structures for context selectors; the
multiple levels of TREE_PURPOSE and TREE_VALUE that don't hint at what
kind of object is being accessed, generic variable names like "t1" and
"t2" likewise.  Similarly the inconsistent and undocumented
representation of different properties, switch statements over the
first character of the trait selector set name, etc added to my
confusion.  It's not surprising that adding new features made this
foundation pretty creaky and I think that adding the additional
selector features in OMP 5.2 and 6.* is going to cause it to fall over
completely.

This series of patches adds a layer of data abstraction, using at
least slightly more descriptive names, and then tries to address some
of the representation and coding issues.

Part 1 introduces some macros (e.g., OMP_TSS_ID instead of
TREE_PURPOSE to get the name of a selector) and renames a bunch of
variables (e.g., tss for a trait-set selector, ts for a trait
selector, tp for a trait property).  Those changes were relatively
mechanical.  I also added some abstraction for the trait-score so that
it need not be handled explicitly when processing property lists.

Part 2 changes the representation of name-list properties so that both
the string and identifier forms store the name in the same place.

Part 3 is a more radical change: it replaces the string names of
trait-set and trait selectors with enumerators, which allows clean-up
of those funky switch statements.  I also made things more
table-driven.  Alas, this part is still WIP; there's an ICE in one of
the test cases I haven't been able to track down yet.

I can continue to work on this patch set in the next couple of weeks
if the general direction is seen as a good thing.  I believe there is
a little more latitude re the end of stage 1 with OpenMP (as there is
with target-specific patches) since it is not enabled by default; in any
case I'd like to get feedback on the general direction before continuing too
much farther with this, and adapting the metadirective patches to match it.

-Sandra

Sandra Loosemore (3):
  OpenMP: Introduce accessor macros and constructors for context
selectors.
  OpenMP: Unify representation of name-list properties.
  OpenMP: Use enumerators for names of trait-sets and traits

 gcc/c/c-parser.cc   | 212 ---
 gcc/cp/decl.cc  |   8 +-
 gcc/cp/parser.cc| 212 ---
 gcc/cp/pt.cc|  93 +++--
 gcc/fortran/trans-openmp.cc |  65 +++-
 gcc/gimplify.cc |   4 +-
 gcc/omp-general.cc  | 713 ++--
 gcc/omp-general.h   | 132 ++-
 8 files changed, 811 insertions(+), 628 deletions(-)

-- 
2.31.1



[PATCH 1/3] OpenMP: Introduce accessor macros and constructors for context selectors.

2023-11-19 Thread Sandra Loosemore
This patch hides the underlying nested TREE_LIST structure of context
selectors behind accessor macros that have more meaningful names than
the generic TREE_PURPOSE/TREE_VALUE accessors.  There is a slight
change to the representation in that the score expression in
trait-selectors has a distinguished tag and is separated from the
ordinary properties, although internally it is still represented as
the first item in the TREE_VALUE of the selector.  This patch also renames
some local variables with slightly more descriptive names so it is easier
to track whether something is a selector-set, selector, or property.

gcc/ChangeLog
* omp-general.h (OMP_TS_SCORE_NODE): New.
(OMP_TSS_ID, OMP_TSS_TRAIT_SELECTORS): New.
(OMP_TS_ID, OMP_TS_SCORE, OMP_TS_PROPERTIES): New.
(OMP_TP_NAME, OMP_TP_VALUE): New.
(make_trait_set_selector): Declare.
(make_trait_selector): Declare.
(make_trait_property): Declare.
(omp_constructor_traits_to_codes): Rename to
omp_construct_traits_to_codes.
* omp-general.cc (omp_constructor_traits_to_codes): Rename
to omp_construct_traits_to_codes.  Use new accessors.
(omp_check_context_selector): Use new accessors.
(make_trait_set_selector): New.
(make_trait_selector): New.
(make_trait_property): New.
(omp_context_name_list_prop): Use new accessors.
(omp_context_selector_matches): Use new accessors.
(omp_context_selector_props_compare): Use new accessors.
(omp_context_selector_set_compare): Use new accessors.
(omp_get_context_selector): Use new accessors.
(omp_context_compute_score): Use new accessors.
* gimplify.cc (omp_construct_selector_matches): Adjust for renaming
of omp_constructor_traits_to_codes.

gcc/c/ChangeLog
* c-parser.cc (c_parser_omp_context_selector): Use new constructors.

gcc/cp/ChangeLog
* parser.cc (cp_parser_omp_context_selector): Use new constructors.
* pt.cc: Include omp-general.h.
(tsubst_attribute): Use new context selector accessors and
 constructors.

gcc/fortran/ChangeLog
* trans-openmp.cc (gfc_trans_omp_declare_variant): Use new
constructors.
---
 gcc/c/c-parser.cc   |  27 ++--
 gcc/cp/parser.cc|  30 ++--
 gcc/cp/pt.cc|  82 ++
 gcc/fortran/trans-openmp.cc |  27 ++--
 gcc/gimplify.cc |   4 +-
 gcc/omp-general.cc  | 293 ++--
 gcc/omp-general.h   |  48 +-
 7 files changed, 297 insertions(+), 214 deletions(-)

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index 703f9570dbc..fcbacd461c7 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -24032,7 +24032,10 @@ static const char *const omp_user_selectors[] = {
  trait-selector-name[([trait-score:]trait-property[,trait-property[,...]])]
 
trait-score:
- score(score-expression)  */
+ score(score-expression)
+
+   Note that this function returns a list of trait selectors for the
+   trait-selector-set SET.  */
 
 static tree
 c_parser_omp_context_selector (c_parser *parser, tree set, tree parms)
@@ -24051,6 +24054,7 @@ c_parser_omp_context_selector (c_parser *parser, tree 
set, tree parms)
}
 
   tree properties = NULL_TREE;
+  tree scoreval = NULL_TREE;
   const char *const *selectors = NULL;
   bool allow_score = true;
   bool allow_user = false;
@@ -24157,8 +24161,7 @@ c_parser_omp_context_selector (c_parser *parser, tree 
set, tree parms)
error_at (token->location, "score argument must be "
  "non-negative");
  else
-   properties = tree_cons (get_identifier (" score"),
-   score, properties);
+   scoreval = score;
}
  token = c_parser_peek_token (parser);
}
@@ -24171,7 +24174,8 @@ c_parser_omp_context_selector (c_parser *parser, tree 
set, tree parms)
{
  t = c_parser_expr_no_commas (parser, NULL).value;
  if (TREE_CODE (t) == STRING_CST)
-   properties = tree_cons (NULL_TREE, t, properties);
+   properties = make_trait_property (NULL_TREE, t,
+ properties);
  else if (t != error_mark_node)
{
  mark_exp_read (t);
@@ -24182,7 +24186,8 @@ c_parser_omp_context_selector (c_parser *parser, tree 
set, tree parms)
  "constant integer expression or string "
  "literal");
  else
-   properties = tree_cons (NULL_TREE, t, properties);
+   properties = make_trait_property (NULL_TREE, t,
+ properties);

[PATCH 2/3] OpenMP: Unify representation of name-list properties.

2023-11-19 Thread Sandra Loosemore
Previously, name-list properties specified as identifiers were stored
in the TREE_PURPOSE/OMP_TP_NAME slot, while those specified as strings
were stored in the TREE_VALUE/OMP_TP_VALUE slot.  This patch puts both
representations in OMP_TP_VALUE with a magic cookie in OMP_TP_NAME.

gcc/ChangeLog
* omp-general.h (OMP_TP_NAMELIST_NODE): New.
* omp-general.cc (omp_context_name_list_prop): Move earlier
in the file, and adjust for new representation.
(omp_check_context_selector): Adjust this too.
(omp_context_selector_props_compare): Likewise.

gcc/c/ChangeLog
* c-parser.cc (c_parser_omp_context_selector): Adjust for new
namelist property representation.

gcc/cp/ChangeLog
* parser.cc (cp_parser_omp_context_selector): Adjust for new
namelist property representation.
* pt.cc (tsubst_attribute): Likewise.

gcc/fortran/ChangeLog
* trans-openmp.cc (gfc_trans_omp_declare_varaint): Adjust for
new namelist property representation.
---
 gcc/c/c-parser.cc   |  5 ++-
 gcc/cp/parser.cc|  5 ++-
 gcc/cp/pt.cc|  4 +-
 gcc/fortran/trans-openmp.cc |  5 ++-
 gcc/omp-general.cc  | 84 +
 gcc/omp-general.h   |  1 +
 6 files changed, 61 insertions(+), 43 deletions(-)

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index fcbacd461c7..a2ff381e0c1 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -24217,11 +24217,12 @@ c_parser_omp_context_selector (c_parser *parser, tree 
set, tree parms)
case CTX_PROPERTY_NAME_LIST:
  do
{
- tree prop = NULL_TREE, value = NULL_TREE;
+ tree prop = OMP_TP_NAMELIST_NODE;
+ tree value = NULL_TREE;
  if (c_parser_next_token_is (parser, CPP_KEYWORD)
  || c_parser_next_token_is (parser, CPP_NAME))
{
- prop = c_parser_peek_token (parser)->value;
+ value = c_parser_peek_token (parser)->value;
  c_parser_consume_token (parser);
}
  else if (c_parser_next_token_is (parser, CPP_STRING))
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index dd773570981..9030365644d 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -47469,11 +47469,12 @@ cp_parser_omp_context_selector (cp_parser *parser, 
tree set, bool has_parms_p)
case CTX_PROPERTY_NAME_LIST:
  do
{
- tree prop = NULL_TREE, value = NULL_TREE;
+ tree prop = OMP_TP_NAMELIST_NODE;
+ tree value = NULL_TREE;
  if (cp_lexer_next_token_is (parser->lexer, CPP_KEYWORD)
  || cp_lexer_next_token_is (parser->lexer, CPP_NAME))
{
- prop = cp_lexer_peek_token (parser->lexer)->u.value;
+ value = cp_lexer_peek_token (parser->lexer)->u.value;
  cp_lexer_consume_token (parser->lexer);
}
  else if (cp_lexer_next_token_is (parser->lexer, CPP_STRING))
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 3af793dfe20..c3815733651 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -11892,7 +11892,9 @@ tsubst_attribute (tree t, tree *decl_p, tree args,
}
  properties = copy_list (OMP_TS_PROPERTIES (ts));
  for (tree p = properties; p; p = TREE_CHAIN (p))
-   if (OMP_TP_VALUE (p))
+   if (OMP_TP_NAME (p) == OMP_TP_NAMELIST_NODE)
+ continue;
+   else if (OMP_TP_VALUE (p))
  {
bool allow_string
  = (OMP_TS_ID (ts) != condition || set[0] != 'u');
diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc
index fe8044a57cd..60154ff3751 100644
--- a/gcc/fortran/trans-openmp.cc
+++ b/gcc/fortran/trans-openmp.cc
@@ -8235,9 +8235,10 @@ gfc_trans_omp_declare_variant (gfc_namespace *ns)
  break;
case CTX_PROPERTY_NAME_LIST:
  {
-   tree prop = NULL_TREE, value = NULL_TREE;
+   tree prop = OMP_TP_NAMELIST_NODE;
+   tree value = NULL_TREE;
if (otp->is_name)
- prop = get_identifier (otp->name);
+ value = get_identifier (otp->name);
else
  value = gfc_conv_constant_to_tree (otp->expr);
 
diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc
index 4ea0d971273..e4e3890449e 100644
--- a/gcc/omp-general.cc
+++ b/gcc/omp-general.cc
@@ -1114,6 +1114,30 @@ omp_maybe_offloaded (void)
   return false;
 }
 
+/* Return a name from PROP, a property in selectors accepting
+   name lists.  */
+
+static const char *

Re: [patch] libgomp.texi: Update "Enabling OpenMP" + OpenACC / invoke.texi: -fopenacc/-fopenmp update (was: Re: [patch] libgomp.texi: Update "Enabling OpenMP")

2023-10-15 Thread Sandra Loosemore

On 10/15/23 04:42, Tobias Burnus wrote:


Updated patch attached.


This version looks OK to me.

-Sandra


Re: [patch] libgomp.texi: Improve "OpenACC Environment Variables"

2023-10-15 Thread Sandra Loosemore

On 10/15/23 04:40, Tobias Burnus wrote:

Hi Sandra,

thanks for the comments.

On 15.10.23 00:46, Sandra Loosemore wrote:

+Semicolon separated list of dynamic libraries to be loaded as
profiling library.


s/Semicolon separated/Semicolon-separated/

There's also a semantic issue with "list of dynamic libraries"
(plural) and "profiling library" (singular).  Are they all separately
profiling libraries, or does the entire list constitute a single
logical profiling library and its dependencies?


No, each library works as separate "profiling library", everything else
does not make much sense.

Updated patch attached - I hope it is now clearer.


Yup, this version is fine to commit.

-Sandra



Re: [patch] libgomp.texi: Use present not future tense (was: [Patch] libgomp.texi: Clarify OMP_TARGET_OFFLOAD=mandatory)

2023-10-15 Thread Sandra Loosemore

On 10/15/23 04:39, Tobias Burnus wrote:


@@ -905,8 +905,8 @@ For @code{omp_sched_auto} the @var{chunk_size} argument is 
ignored.
 @subsection @code{omp_get_schedule} -- Obtain the runtime scheduling method
 @table @asis
 @item @emph{Description}:
-Obtain the runtime scheduling method.  The @var{kind} argument will be
-set to the value @code{omp_sched_static}, @code{omp_sched_dynamic},
+Obtain the runtime scheduling method.  The @var{kind} argument is set to
+to @code{omp_sched_static}, @code{omp_sched_dynamic},


You've introduced an extra "to" here.


@@ -3029,7 +3029,7 @@ 
OMP_ALLOCATOR=omp_low_lat_mem_space:pinned=true,partition=nearest
 Sets the format string used when displaying OpenMP thread affinity information.
 Special values are output using @code{%} followed by an optional size
 specification and then either the single-character field type or its long
-name enclosed in curly braces; using @code{%%} will display a literal percent.
+name enclosed in curly braces; using @code{%%} displays a literal percent.
 The size specification consists of an optional @code{0.} or @code{.} followed
 by a positive integer, specifying the minimal width of the output.  With
 @code{0.} and numerical values, the output is padded with zeros on the left;


I think all the @code markups here ought to be @samp, but let's not do that in 
this patch.



-If set to @code{DISABLED}, then offloading is disabled and all code will run on
-the host. If set to @code{DEFAULT}, the program will try offloading to the
+If set to @code{DISABLED}, then offloading is disabled and all code runs on
+the host. If set to @code{DEFAULT}, the program tries offloading to the
 device first, then fall back to running code on the host if it cannot.


Missed one here; s/[will] fall back/falls back/.


@@ -3559,7 +3559,7 @@ Binds threads to specific CPUs.  The variable should 
contain a space-separated
 or comma-separated list of CPUs.  This list may contain different kinds of 
 entries: either single CPU numbers in any order, a range of CPUs (M-N) 
 or a range with some stride (M-N:S).  CPU numbers are zero based.  For example,

-@code{GOMP_CPU_AFFINITY="0 3 1-2 4-15:2"} will bind the initial thread
+@code{GOMP_CPU_AFFINITY="0 3 1-2 4-15:2"} binds the initial thread
 to CPU 0, the second to CPU 3, the third to CPU 1, the fourth to 
 CPU 2, the fifth to CPU 4, the sixth through tenth to CPUs 6, 8, 10, 12,

 and 14 respectively and then start assigning back from the beginning of


Similarly, s/[will] start/starts/.


 @item @emph{C/C++}:
@@ -3983,8 +3983,8 @@ but might be removed in a future version of GCC.
 @table @asis
 @item @emph{Description}
 This function tests for completion of the asynchronous operation specified
-in @var{arg}. In C/C++, a non-zero value will be returned to indicate
-the specified asynchronous operation has completed. While Fortran will return
+in @var{arg}. In C/C++, a non-zero value is returned to indicate
+the specified asynchronous operation has completed. While Fortran returns
 a @code{true}. If the asynchronous operation has not completed, C/C++ returns
 a zero and Fortran returns a @code{false}.


H.  How about s/, While/while/ here.  And it sounds odd to me to say "a 
true" or a "a zero"; I'd suggest deleting the indefinite article from all those 
uses.



@@ -4012,8 +4012,8 @@ a zero and Fortran returns a @code{false}.
 @table @asis
 @item @emph{Description}
 This function tests for completion of all asynchronous operations.
-In C/C++, a non-zero value will be returned to indicate all asynchronous
-operations have completed. While Fortran will return a @code{true}. If
+In C/C++, a non-zero value is returned to indicate all asynchronous
+operations have completed. While Fortran returns a @code{true}. If
 any asynchronous operation has not completed, C/C++ returns a zero and
 Fortran returns a @code{false}.


Ditto here.

 
@@ -4196,9 +4196,9 @@ This function shuts down the runtime for the device type specified in

 This function returns whether the program is executing on a particular
 device specified in @var{devicetype}. In C/C++ a non-zero value is
 returned to indicate the device is executing on the specified device type.
-In Fortran, @code{true} will be returned. If the program is not executing
-on the specified device type C/C++ will return a zero, while Fortran will
-return @code{false}.
+In Fortran, @code{true} is returned. If the program is not executing
+on the specified device type C/C++ will return a zero, while Fortran


You missed a "will return" here, and same issues with "a zero".


@@ -5178,7 +5178,7 @@ subsequent to the calls to @code{acc_copyin()}.
 As seen in the previous use case, a call to @code{cublasCreate()}
 initializes the CUBLAS library and allocates the hardware resources on the
 host and the device.  However, since the device has already been allocated,
-@code{cublasCreate()} will only initialize the CUBLAS library and allocate
+@code{cublasCreate()} only initializes the CUBLAS 

Re: [patch] libgomp.texi: Improve "OpenACC Environment Variables"

2023-10-14 Thread Sandra Loosemore

On 10/14/23 13:51, Tobias Burnus wrote:


@@ -5003,6 +5001,17 @@ The variable @env{GCC_ACC_NOTIFY} is used for diagnostic 
purposes.
 @node ACC_DEVICE_TYPE
 @section @code{ACC_DEVICE_TYPE}
 @table @asis
+@item @emph{Description}:
+Control the default device type to use when executing compute regions.
+If unset, the code can be run on any device type, favoring a non-host
+device type.
+
+Supported value in GCC (if compiled in) are


s/value/values/


+@itemize
+@item @code{host}
+@item @code{nvidia}
+@item @code{radeon}
+@end itemize
 @item @emph{Reference}:
 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
 4.1.
@@ -5013,6 +5022,10 @@ The variable @env{GCC_ACC_NOTIFY} is used for diagnostic 
purposes.
 @node ACC_DEVICE_NUM
 @section @code{ACC_DEVICE_NUM}
 @table @asis
+@item @emph{Description}:
+Control which device, identified by device number, is the default device.
+The number must be a nonnegative integer number less that the number of


Ummm, too many "number"s!

How about rephrasing that as
The value must be a nonnegative integer less than the number of


+devices.  If unset, device number zero is used.
 @item @emph{Reference}:
 @uref{https://www.openacc.org, OpenACC specification v2.6}, section
 4.2.
@@ -5023,6 +5036,11 @@ The variable @env{GCC_ACC_NOTIFY} is used for diagnostic 
purposes.
 @node ACC_PROFLIB
 @section @code{ACC_PROFLIB}
 @table @asis
+@item @emph{Description}:
+Semicolon separated list of dynamic libraries to be loaded as profiling 
library.


s/Semicolon separated/Semicolon-separated/

There's also a semantic issue with "list of dynamic libraries" (plural) and 
"profiling library" (singular).  Are they all separately profiling libraries, 
or does the entire list constitute a single logical profiling library and its 
dependencies?



+The library file is found as described by the documentation of @code{dlopen} of


Probably s/The/Each/?


+your operating system.  Each library must implement at least the routine
+@code{acc_register_library} routine.


Again, I'm not sure if this applies to every library in the list, or just that 
some library in the list must provide this routine.


-Sandra


Re: [patch] libgomp.texi: Update "Enabling OpenMP"

2023-10-14 Thread Sandra Loosemore

On 10/14/23 13:43, Tobias Burnus wrote:

When browsing libgomp doc, I came across
https://gcc.gnu.org/onlinedocs/libgomp/Enabling-OpenMP.html>> 
First, I found especially the Fortran part difficult to read. Secondly,

it missed the C++ attribute syntax. And I also missed a reference to
-fopenmp-simd.

The attached patch tries to improve this. Note that it talks about C and
C++ attributes, even though C23's [[omp::]] support has not yet landed.
(But is expected very soon.)


Is somebody actively working on implementing that, and expecting to get it in 
before Stage 1 closes?  I don't think we should document features that don't 
exist yet.  This syntax for C also isn't even in the draft OpenMP 6.0 document 
so at this point it's just a hypothetical extension.  To me it seems a better 
use of resources to finish implementing things that are actually in earlier 
versions of the OpenMP standard, and to fill in documentation for features that 
are actually implemented.


Other than that...


diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index 526d1be2955..d8126f96fe4 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -136,15 +136,22 @@ changed to GNU Offloading and Multi Processing Runtime 
Library.
 @node Enabling OpenMP
 @chapter Enabling OpenMP
 
-To activate the OpenMP extensions for C/C++ and Fortran, the compile-time 
-flag @command{-fopenmp} must be specified.  This enables the OpenMP directive
-@code{#pragma omp} in C/C++ and @code{!$omp} directives in free form, 
-@code{c$omp}, @code{*$omp} and @code{!$omp} directives in fixed form, 
-@code{!$} conditional compilation sentinels in free form and @code{c$},

-@code{*$} and @code{!$} sentinels in fixed form, for Fortran.  The flag also
-arranges for automatic linking of the OpenMP runtime library 
+To activate the OpenMP extensions for C/C++ and Fortran, the compile-time

+flag @command{-fopenmp} must be specified.  For C and C++, this enables


Use @option markup on options, not @command.


+the handling of the OpenMP directives using @code{#pragma omp} and the
+@code{[[omp::directive(...)]]}, @code{[[omp::sequence(...)]]} and
+@code{[[omp::decl(...)]]} attributes.  For Fortran, it enables for
+free source form the @code{!$omp} sentinel for directives and the
+@code{!$} conditional compilation sentinel and for fixed source form the
+@code{c$omp}, @code{*$omp} and @code{!$omp} sentinels for directives and
+the @code{c$}, @code{*$} and @code{!$} conditional compilation sentinels.
+The flag also arranges for automatic linking of the OpenMP runtime library
 (@ref{Runtime Library Routines}).


And I think all those @code markups should be @samp instead, or you could just 
replace this whole blurb with something like "This flag enables recognition of 
the directive syntax documented in the OpenMP specification, and also arranges 
for automatic linking..."



+The @command{-fopenmp-simd} flag can be used to enable a subset of


This should be @option too.


+OpenMP directives, which do not require the linking of neither the


s/, which/ that/
s/neither/either/


+OpenMP runtime library nor the POSIX threads library.
+
 A complete description of all OpenMP directives may be found in the
 @uref{https://www.openmp.org, OpenMP Application Program Interface} manuals.
 See also @ref{OpenMP Implementation Status}.


-Sandra


Re: [Patch] libgomp.texi: Clarify OMP_TARGET_OFFLOAD=mandatory

2023-10-14 Thread Sandra Loosemore

On 10/12/23 10:37, Tobias Burnus wrote:

@@ -3133,15 +3134,25 @@ variable can be set to one of three values - 
@code{MANDATORY}, @code{DISABLED}
 or @code{DEFAULT}.
 
 If set to @code{MANDATORY}, the program will terminate with an error if

-the offload device is not present or is not supported.  If set to
-@code{DISABLED}, then offloading is disabled and all code will run on the
-host. If set to @code{DEFAULT}, the program will try offloading to the
+any device construct or device memory routine uses a device that is unavailable
+or not supported by the implementation, or uses a non-conforming device number.
+If set to @code{DISABLED}, then offloading is disabled and all code will run on
+the host. If set to @code{DEFAULT}, the program will try offloading to the
 device first, then fall back to running code on the host if it cannot.
 
 If undefined, then the program will behave as if @code{DEFAULT} was set.
 
+Note: Even with @code{MANDATORY}, there will be no run-time termination when

+the device number in a @code{device} clause or argument to a device memory
+routine is for host, which includes using the device number in the
+@var{default-device-var} ICV.  However, the initial value of
+the @var{default-device-var} ICV is affected by @code{MANDATORY}.


Can we please rewrite this whole section in the present tense?  E.g.

s/will terminate/terminates/
s/will run/runs/
s/will try ... fall back/tries ... falls back/
s/will behave/behaves/
s/will be/is/

-Sandra




Re: [Patch] libgomp.texi: Note to 'Memory allocation' sect and missing mem-memory routines

2023-10-14 Thread Sandra Loosemore

On 10/12/23 04:53, Tobias Burnus wrote:


libgomp.texi: Note to 'Memory allocation' sect and missing mem-memory routines

This commit completes the documentation of the OpenMP memory-management
routines, except for the unimplemented TR11 additions.  It also makes clear
in the 'Memory allocation' section of the 'OpenMP-Implementation Specifics'
chapter under which condition OpenMP managed memory/allocators are used.

libgomp/ChangeLog:

* libgomp.texi: Fix some typos.
(Memory Management Routines): Document remaining 5.x routines.
(Memory allocation): Make clear when the section applies.

 libgomp/libgomp.texi | 382 +--
 1 file changed, 367 insertions(+), 15 deletions(-)

diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index 0d965f96d48..3fc9c7dea23 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -1917,7 +1917,7 @@ is not supported.
 @item @emph{Description}:
 If the device number is refers to the initial device or to a device with


s/is refers/refers/


 memory accessible from the host (shared memory), the @code{omp_get_mapped_ptr}
-routines returnes the value of the passed @var{ptr}.  Otherwise, if associated
+routines returns the value of the passed @var{ptr}.  Otherwise, if associated
 storage to the passed host pointer @var{ptr} exists on device associated with


s/on device/on the device/ (or maybe /on a device/?)


+@node omp_alloc
+@subsection @code{omp_alloc} -- Memory allocation with an allocator
+@table @asis
+@item @emph{Description}:
+Allocate memory with the specified allocator, which can either be a predefined
+allocator, an allocator handle or @code{omp_null_allocator}.  If the allocators
+is @code{omp_null_allocator}, the allocator specified by the


Minimally, s/allocators is/allocator is/, or maybe something like /allocator 
argument is/, and/or add appropriate markup on allocator here to indicate that 
it is an argument.



+@var{def-allocator-var} ICV is used.  @var{size} must be a nonnegative number
+denoting the number of bytes to be allocated; if @var{size} is zero,
+@code{omp_alloc} will return a null pointer.  If successful, a pointer to the


s/will return/returns/


+allocated memory is returned, otherwise the @code{fallback} trait of the
+allocator determines the behavior.  The content of the allocated memory is
+unspecified.
+
+In @code{target} regions, either the @code{dynamic_allocators} clause must
+appear on a @code{requires} directive in the same compilation unit -- or the


s/ -- or/, or/


+@var{allocator} argument may only be a constant expression with the value of


s/may only be/must be/


+@node omp_aligned_alloc
+@subsection @code{omp_aligned_alloc} -- Memory allocation with an allocator 
and alignment
+@table @asis
+@item @emph{Description}:
+Allocate memory with the specified allocator, which can either be a predefined
+allocator, an allocator handle or @code{omp_null_allocator}.  If the allocators
+is @code{omp_null_allocator}, the allocator specified by the


Ditto above comments re "allocators is".


+@var{def-allocator-var} ICV is used.  @var{alignment} must be a positive power
+of two and @var{size} must be a nonnegative number that is a multiple of the
+alignment and denotes the number of bytes to be allocated; if @var{size} is
+zero, @code{omp_aligned_alloc} will return a null pointer.  The alignment will
+be at least the maximal value required by @code{alignment} trait of the


s/will return/return/

"The alignment will be" needs to be rewritten to avoid future tense too, but 
I'm not sure what you're trying to say here.  Is this a requirement on the 
alignment argument or a statement about the actual alignment of the allocated 
memory?



+allocator and the value of the  passed @var{alignment} argument.  If 
successful,
+a pointer to the allocated memory is returned, otherwise the @code{fallback}
+trait of the allocator determines the behavior.  The content of the allocated
+memory is unspecified.
+
+In @code{target} regions, either the @code{dynamic_allocators} clause must
+appear on a @code{requires} directive in the same compilation unit -- or the
+@var{allocator} argument may only be a constant expression with the value of
+one of the predefined allocators and may not be @code{omp_null_allocator}.


Ditto above comments re using comma and "must".


+@node omp_free
+@subsection @code{omp_free} -- Freeing memory allocated with OpenMP routines
+@table @asis
+@item @emph{Description}:
+The @code{omp_free} routine deallocates memory previously allocated by an
+OpenMP memory-management routine. The @var{ptr} argument must point to such
+memory or be a null pointer; if it is a null pointer, no operation is
+performed.  If specified, the @var{allocator} argument must be either the
+memory allocator that was used for the allocation or @code{omp_null_allocator};
+if it is @code{omp_null_allocator}, the implementation will determine the value


s/will 

[COMMITTED] Docs: Minimally document standard C/C++ attribute syntax.

2023-10-06 Thread Sandra Loosemore
gcc/ChangeLog:

* doc/extend.texi (Function Attributes): Mention standard attribute
syntax.
(Variable Attributes): Likewise.
(Type Attributes): Likewise.
(Attribute Syntax): Likewise.
---
 gcc/doc/extend.texi | 74 +++--
 1 file changed, 52 insertions(+), 22 deletions(-)

diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index b4770f1a149..e1129a4fb95 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -2537,13 +2537,14 @@ for each target.  However, a considerable number of 
attributes are
 supported by most, if not all targets.  Those are described in
 the @ref{Common Function Attributes} section.
 
-Function attributes are introduced by the @code{__attribute__} keyword
-in the declaration of a function, followed by an attribute specification
-enclosed in double parentheses.  You can specify multiple attributes in
-a declaration by separating them by commas within the double parentheses
-or by immediately following one attribute specification with another.
-@xref{Attribute Syntax}, for the exact rules on attribute syntax and
-placement.  Compatible attribute specifications on distinct declarations
+GCC provides two different ways to specify attributes: the traditional
+GNU syntax using @samp{__attribute__ ((...))} annotations, and the
+newer standard C and C++ syntax using @samp{[[...]]} with the
+@samp{gnu::} prefix on attribute names.  Note that the exact rules for
+placement of attributes in your source code are different depending on
+which syntax you use.  @xref{Attribute Syntax}, for details.
+
+Compatible attribute specifications on distinct declarations
 of the same function are merged.  An attribute specification that is not
 compatible with attributes already applied to a declaration of the same
 function is ignored with a warning.
@@ -7433,10 +7434,9 @@ when this attribute is present.
 @cindex attribute of variables
 @cindex variable attributes
 
-The keyword @code{__attribute__} allows you to specify special properties
+You can use attributes to specify special properties
 of variables, function parameters, or structure, union, and, in C++, class
-members.  This @code{__attribute__} keyword is followed by an attribute
-specification enclosed in double parentheses.  Some attributes are currently
+members.  Some attributes are currently
 defined generically for variables.  Other attributes are defined for
 variables on particular target systems.  Other attributes are available
 for functions (@pxref{Function Attributes}), labels (@pxref{Label Attributes}),
@@ -7445,8 +7445,12 @@ enumerators (@pxref{Enumerator Attributes}), statements
 Other front ends might define more attributes
 (@pxref{C++ Extensions,,Extensions to the C++ Language}).
 
-@xref{Attribute Syntax}, for details of the exact syntax for using
-attributes.
+GCC provides two different ways to specify attributes: the traditional
+GNU syntax using @samp{__attribute__ ((...))} annotations, and the
+newer standard C and C++ syntax using @samp{[[...]]} with the
+@samp{gnu::} prefix on attribute names.  Note that the exact rules for
+placement of attributes in your source code are different depending on
+which syntax you use.  @xref{Attribute Syntax}, for details.
 
 @menu
 * Common Variable Attributes::
@@ -8508,7 +8512,7 @@ placed in either the @code{.bss_below100} section or the
 @cindex attribute of types
 @cindex type attributes
 
-The keyword @code{__attribute__} allows you to specify various special
+You can use attributes to specify various special
 properties of types.  Some type attributes apply only to structure and
 union types, and in C++, also class types, while others can apply to
 any type defined via a @code{typedef} declaration.  Unless otherwise
@@ -8521,19 +8525,20 @@ labels (@pxref{Label  Attributes}), enumerators 
(@pxref{Enumerator
 Attributes}), statements (@pxref{Statement Attributes}), and for variables
 (@pxref{Variable Attributes}).
 
-The @code{__attribute__} keyword is followed by an attribute specification
-enclosed in double parentheses.
+GCC provides two different ways to specify attributes: the traditional
+GNU syntax using @samp{__attribute__ ((...))} annotations, and the
+newer standard C and C++ syntax using @samp{[[...]]} with the
+@samp{gnu::} prefix on attribute names.  Note that the exact rules for
+placement of attributes in your source code are different depending on
+which syntax you use.  @xref{Attribute Syntax}, for details.
 
 You may specify type attributes in an enum, struct or union type
 declaration or definition by placing them immediately after the
 @code{struct}, @code{union} or @code{enum} keyword.  You can also place
 them just past the closing curly brace of the definition, but this is less
 preferred because logically the type should be fully defined at 
-the closing brace.
-
-You can also include type attributes in a @code{typedef} declaration.
-@xref{Attribute Syntax}, for details of the 

Re: RFC: attributes documentation

2023-10-03 Thread Sandra Loosemore

On 10/3/23 08:19, Joseph Myers wrote:

On Mon, 2 Oct 2023, Sandra Loosemore wrote:


Going beyond that, though, I think we should also document that the standard
syntax is now the preferred way to do it, and change the examples (except for
the parts documenting the old syntax) to use the new standard syntax.  It's
been accepted by the default -std= setting for both C and C++ since GCC 10,
and my understanding is that C2x will be official by the time GCC 14 is
released (so supporting the new syntax won't be just another GNU extension any
more). Does this sound OK to everybody?


If you're documenting attributes in the [[]] form, you need to be a lot
more careful to distinguish between an attribute on a declaration and one
on the type of that declaration, for example, because those need to go in
different places in the standard syntax (the laxity applied with
__attribute__ that tries to guess what was meant and e.g. move an
attribute from a declaration to its type doesn't apply with the standard
syntax, which has precise rules in the standard for what entity an
attribute in a given syntactic position appertains to).  In some cases
this means that the [[]] attribute needs to go in a different position
from __attribute__ in examples [snip]


Right, I was aware I couldn't just do a simple text substitution here without 
at least hand-checking that the examples still have the intended effect!  I'm 
estimating this as a medium-sized documentation project of the kind I typically 
do around the end of the year when we are in stage 3, although since life is 
uncertain I'd like to get in the more minimal fix (to at least mention the 
C/C++ standard attribute syntax) sooner.  My question was more about whether 
there was objection in principle to doing the rewrite.  I recall that for a 
very long time we were telling people to use __attribute__ instead of pragmas, 
and basically telling people to avoid #pragma entirely, for example.  Is 
__attribute__ also considered more powerful than the standard [[]] syntax, 
enough to recommend it over writing standard-conforming code?


-Sandra


RFC: attributes documentation

2023-10-02 Thread Sandra Loosemore
When I was working on something else recently, I realized that the GCC manual 
had nothing in its attributes section saying that you could use the various 
documented GCC extension attributes with C/C++ standard attribute syntax too, 
or how (you have to use the "gnu::" prefix); I ended up finding this 
information in the release notes for GCC 10 instead.  :-(  So, minimally, I am 
going to address that.


Going beyond that, though, I think we should also document that the standard 
syntax is now the preferred way to do it, and change the examples (except for 
the parts documenting the old syntax) to use the new standard syntax.  It's 
been accepted by the default -std= setting for both C and C++ since GCC 10, and 
my understanding is that C2x will be official by the time GCC 14 is released 
(so supporting the new syntax won't be just another GNU extension any more). 
Does this sound OK to everybody?


-Sandra


[WIP 2/4] OpenMP: Language-independent parts of loop transform support.

2023-10-01 Thread Sandra Loosemore
From: Frederik Harwath 

This patch adds support for the OMP_LOOP_TRANS tree node, internal
OpenMP clauses representing loop transformations, and the
omp_transform_loops pass to lower them.

gcc/ChangeLog:

* Makefile.in (OBJS): Add omp-transform-loops.o.
* gimple-pretty-print.cc (dump_gimple_omp_for): Handle
GF_OMP_FOR_KIND_TRANSFORM_LOOP.
* gimple.h (enum gf_mask): Add GF_FOR_KIND_TRANSFORM_LOOP.
* gimplify.cc (is_gimple_stmt): Add OMP_LOOP_TRANS.
(gimplify_scan_omp_clauses): Handle loop transform clauses.
(gimplify_adjust_omp_clauses): Likewise.
(omp_for_drop_tile_clauses): New function.
(gimplify_omp_for): Call omp_for_drop_tile_clauses.  Handle
OMP_LOOP_TRANS and loop transform clauses.
(gimplify_omp_loop): Handle loop transform clauses.
(gimplify_expr): Handle OMP_LOOP_TRANS.
* omp-general.cc (omp_loop_transform_clause_p): New function.
* omp-general.h (omp_loop_transform_clause_p): Declare.
* omp-transform-loops.cc: New file.
* params.opt (omp-unroll-full-max-iterations): New.
(omp-unroll-default-factor): New.
* passes.def: Add pass_omp_transform_loops before pass_lower_omp.
* tree-core.h (enum omp_clause_code): Add OMP_CLAUSE_UNROLL_FULL,
OMP_CLAUSE_UNROLL_NONE, OMP_CLAUSE_UNROLL_PARTIAL, and
OMP_CLAUSE_TILE.
* tree-nested.cc (convert_nonlocal_omp_clauses): Add support
for loop transform clauses.
(convert_local_omp_clauses): Likewise.
* tree-pass.h (make_pass_omp_transform_loops): Declare.
* tree-pretty-print.cc (dump_omp_clause): Add support for loop
transform clauses.
(dump_generic_node): Handle OMP_LOOP_TRANS.
* tree.cc (omp_clause_num_ops): Add entries for loop transforms.
(omp_clause_code_name): Likewise.
* tree.def (OMP_LOOP_TRANS): New.
* tree.h (OMP_CLAUSE_TRANSFORM_LEVEL): New.
(OMP_CLAUSE_UNROLL_PARTIAL_EXPR): New.
(OMP_CLAUSE_TILE_SIZES): New.
* doc/invoke.texi (Optimize Options): Document the new parameters.

Co-Authored-By: Sandra Loosemore 
---
 gcc/Makefile.in|1 +
 gcc/doc/invoke.texi|9 +
 gcc/gimple-pretty-print.cc |6 +
 gcc/gimple.h   |1 +
 gcc/gimplify.cc|   65 +-
 gcc/omp-general.cc |   14 +
 gcc/omp-general.h  |1 +
 gcc/omp-transform-loops.cc | 1815 
 gcc/params.opt |8 +
 gcc/passes.def |1 +
 gcc/tree-core.h|   12 +
 gcc/tree-nested.cc |   14 +
 gcc/tree-pass.h|1 +
 gcc/tree-pretty-print.cc   |   52 ++
 gcc/tree.cc|8 +
 gcc/tree.def   |6 +
 gcc/tree.h |   11 +
 17 files changed, 2024 insertions(+), 1 deletion(-)
 create mode 100644 gcc/omp-transform-loops.cc

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 9cc16268abf..767823e223b 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1582,6 +1582,7 @@ OBJS = \
omp-expand.o \
omp-general.o \
omp-low.o \
+   omp-transform-loops.o \
omp-oacc-kernels-decompose.o \
omp-oacc-neuter-broadcast.o \
omp-simd-clone.o \
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 4085fc90907..e904dc4b3c4 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -16470,6 +16470,15 @@ With @option{--param=openacc-privatization=quiet}, 
don't diagnose.
 This is the current default.
 With @option{--param=openacc-privatization=noisy}, do diagnose.
 
+@item omp-unroll-full-max-iterations
+The maximum number of iterations of a loop for which an OpenMP @samp{omp 
unroll}
+directive on the loop without a clause is turned into an
+@samp{omp unroll full}.
+
+@item omp-unroll-default-factor
+The unroll factor used for loops that have an OpenMP @samp{omp unroll partial}
+directive without an explicit unroll factor.
+
 @end table
 
 The following choices of @var{name} are available on AArch64 targets:
diff --git a/gcc/gimple-pretty-print.cc b/gcc/gimple-pretty-print.cc
index 320df9197b4..1548feea092 100644
--- a/gcc/gimple-pretty-print.cc
+++ b/gcc/gimple-pretty-print.cc
@@ -1474,6 +1474,9 @@ dump_gimple_omp_for (pretty_printer *buffer, const 
gomp_for *gs, int spc,
case GF_OMP_FOR_KIND_SIMD:
  kind = " simd";
  break;
+   case GF_OMP_FOR_KIND_TRANSFORM_LOOP:
+ kind = " unroll";
+ break;
default:
  gcc_unreachable ();
}
@@ -1511,6 +1514,9 @@ dump_gimple_omp_for (pretty_printer *buffer, const 
gomp_for *gs, int spc,
case GF_OMP_FOR_KIND_SIMD:
  pp_string (buffer, "#pragma omp simd");
  break;
+   case GF_OMP_FOR_KIND_TRANSFORM_LOOP:
+ pp_string (buffer, "#pragma omp loop_transform");
+ break;
default:
  gcc_unreachable (

[WIP 0/4] OpenMP: support for loop transformations

2023-10-01 Thread Sandra Loosemore
This series of patches is an update of Frederik's previous loop
transformation patch set, previously posted here:

https://gcc.gnu.org/pipermail/gcc-patches/2023-March/614564.html

that has been updated to resolve conflicts with my set of
imperfectly-nested loops patches and other changes on mainline since
March.  It does not address Jakub's code review concerns that these
patches are lowering the transformations too late, and that this needs
to be done in the front ends instead; the purpose of this iteration of
the patch set is to provide a baseline for doing that rewrite.

I used the version of Frederik's patches that were committed
to the OG13 branch as the basis for this work, along with several
follow-up bug fixes, some glue and additional test cases I had added
on OG13 with my own imperfectly-nested loops patches there, the
support for C++ attribute syntax that I had later put on OG13 (which
required resolving some conflicts with different changes on mainline),
etc.  The specific OG13 commits that were on my merge list were:

ea770a4a9f6 openmp: Add Fortran support for "omp unroll" directive
c17983cd052 openmp: Add C/C++ support for "omp unroll" directive
5e11b7ffc84 openacc: Rename OMP_CLAUSE_TILE to OMP_CLAUSE_OACC_TILE
c6f772b089d openmp: Add Fortran support for "omp tile"
5b9c9f10892 openmp: Add C/C++ support for "omp tile"
5c71451f714 openmp: Add Fortran support for loop transformations on inner loops
3baddf440b7 openmp: Add C/C++ support for loop transformations on inner loops
c89addc938d openmp: Fix loop transformation tests
94a75fb12e6 openmp: Fix initialization for 'unroll full'
8adfa43a19e openmp: Fix diagnostic message for "omp unroll"
e59a5a62eb5 openmp: Fix number of iterations computation for "omp unroll full"
62e64a55d3f OpenMP: Handle loop transformation clauses in nested functions
09623de2186 OpenMP: C support for imperfectly-nested loops
546b3460346 OpenMP: C++ support for imperfectly-nested loops
bf38eb98eaf OpenMP: New c/c++ testcases for imperfectly-nested loops
4b17c1a010b OpenMP: Refactor and tidy Fortran front-end code for loop 
transformations
e10b1be8777 OpenMP: Fortran support for imperfectly nested loops
ff563b2c8dd OpenMP: C++ attribute syntax fixes/testcases for loop 
transformations

Because there were so many incremental changes I've reorganized
Frederik's patch set into a smaller set of consolidated changes, and
written new changelogs.

-Sandra

Frederik Harwath (4):
  openacc: Rename OMP_CLAUSE_TILE to OMP_CLAUSE_OACC_TILE
  OpenMP: Language-independent parts of loop transform support.
  OpenMP: Fortran front-end support for loop transforms.
  OpenMP: C and C++ front-end support for loop transforms.

 gcc/Makefile.in   |1 +
 gcc/c-family/c-gimplify.cc|1 +
 gcc/c-family/c-omp.cc |   12 +-
 gcc/c-family/c-pragma.cc  |2 +
 gcc/c-family/c-pragma.h   |7 +-
 gcc/c/c-parser.cc |  527 -
 gcc/c/c-typeck.cc |   10 +-
 gcc/cp/cp-gimplify.cc |3 +
 gcc/cp/parser.cc  |  541 -
 gcc/cp/pt.cc  |   15 +-
 gcc/cp/semantics.cc   |  103 +-
 gcc/doc/invoke.texi   |9 +
 gcc/fortran/dump-parse-tree.cc|   28 +
 gcc/fortran/gfortran.h|   12 +-
 gcc/fortran/match.h   |2 +
 gcc/fortran/openmp.cc |  736 +--
 gcc/fortran/parse.cc  |   48 +
 gcc/fortran/resolve.cc|6 +
 gcc/fortran/st.cc |2 +
 gcc/fortran/trans-openmp.cc   |  186 +-
 gcc/fortran/trans.cc  |2 +
 gcc/gimple-pretty-print.cc|6 +
 gcc/gimple.h  |1 +
 gcc/gimplify.cc   |   73 +-
 gcc/omp-general.cc|   22 +-
 gcc/omp-general.h |1 +
 gcc/omp-low.cc|6 +-
 gcc/omp-transform-loops.cc| 1815 +
 gcc/params.opt|8 +
 gcc/passes.def|1 +
 .../c-c++-common/gomp/imperfect-attributes.c  |   18 +-
 .../loop-transforms/imperfect-loop-nest.c |   11 +
 .../gomp/loop-transforms/tile-1.c |  160 ++
 .../gomp/loop-transforms/tile-2.c |  179 ++
 .../gomp/loop-transforms/tile-3.c |  109 +
 .../gomp/loop-transforms/tile-4.c |  322 +++
 .../gomp/loop-transforms/tile-5.c |  150 ++
 .../gomp/loop-transforms/tile-6.c |   34 +
 .../gomp/loop-transforms/tile-7.c |   31 +
 .../gomp/loop-transforms/tile-8.c |   40 +
 

[WIP 1/4] openacc: Rename OMP_CLAUSE_TILE to OMP_CLAUSE_OACC_TILE

2023-10-01 Thread Sandra Loosemore
From: Frederik Harwath 

OMP_CLAUSE_TILE will be used for the OpenMP 5.1 loop transformation
construct "omp tile".

gcc/ChangeLog:

* tree-core.h (enum omp_clause_code): Rename OMP_CLAUSE_TILE.
* tree.h (OMP_CLAUSE_TILE_LIST): Rename to ...
(OMP_CLAUSE_OACC_TILE_LIST): ... this.
(OMP_CLAUSE_TILE_ITERVAR): Rename to ...
(OMP_CLAUSE_OACC_TILE_ITERVAR): ... this.
(OMP_CLAUSE_TILE_COUNT): Rename to ...
(OMP_CLAUSE_OACC_TILE_COUNT): this.
* gimplify.cc (gimplify_scan_omp_clauses): Adjust to renamings.
(gimplify_adjust_omp_clauses): Likewise.
(gimplify_omp_for): Likewise.
* omp-general.cc (omp_extract_for_data): Likewise.
* omp-low.cc (scan_sharing_clauses): Likewise.
(lower_oacc_head_mark): Likewise.
* tree-nested.cc (convert_nonlocal_omp_clauses): Likewise.
(convert_local_omp_clauses): Likewise.
* tree-pretty-print.cc (dump_omp_clause): Likewise.
* tree.cc: Likewise.

gcc/c-family/ChangeLog:

* c-omp.cc (c_oacc_split_loop_clauses): Adjust to renamings.

gcc/c/ChangeLog:

* c-parser.cc (c_parser_omp_clause_collapse): Adjust to renamings.
(c_parser_oacc_clause_tile): Likewise.
(c_parser_omp_for_loop): Likewise.
* c-typeck.cc (c_finish_omp_clauses): Likewise.

gcc/cp/ChangeLog:

* parser.cc (cp_parser_oacc_clause_tile): Adjust to renamings.
(cp_parser_omp_clause_collapse): Likewise.
(cp_parser_omp_for_loop): Likewise.
* pt.cc (tsubst_omp_clauses): Likewise.
* semantics.cc (finish_omp_clauses): Likewise.
(finish_omp_for): Likewise.

gcc/fortran/ChangeLog:

* openmp.cc (enum omp_mask2): Adjust to renamings.
(gfc_match_omp_clauses): Likewise.
* trans-openmp.cc (gfc_trans_omp_clauses): Likewise.
---
 gcc/c-family/c-omp.cc   |  2 +-
 gcc/c/c-parser.cc   | 12 ++--
 gcc/c/c-typeck.cc   |  2 +-
 gcc/cp/parser.cc| 12 ++--
 gcc/cp/pt.cc|  2 +-
 gcc/cp/semantics.cc |  8 
 gcc/fortran/openmp.cc   |  6 +++---
 gcc/fortran/trans-openmp.cc |  4 ++--
 gcc/gimplify.cc |  8 
 gcc/omp-general.cc  |  8 
 gcc/omp-low.cc  |  6 +++---
 gcc/tree-core.h |  2 +-
 gcc/tree-nested.cc  |  4 ++--
 gcc/tree-pretty-print.cc|  4 ++--
 gcc/tree.cc |  2 +-
 gcc/tree.h  | 12 ++--
 16 files changed, 47 insertions(+), 47 deletions(-)

diff --git a/gcc/c-family/c-omp.cc b/gcc/c-family/c-omp.cc
index 95b6c1e623f..5de3b77c450 100644
--- a/gcc/c-family/c-omp.cc
+++ b/gcc/c-family/c-omp.cc
@@ -1899,7 +1899,7 @@ c_oacc_split_loop_clauses (tree clauses, tree 
*not_loop_clauses,
 {
  /* Loop clauses.  */
case OMP_CLAUSE_COLLAPSE:
-   case OMP_CLAUSE_TILE:
+   case OMP_CLAUSE_OACC_TILE:
case OMP_CLAUSE_GANG:
case OMP_CLAUSE_WORKER:
case OMP_CLAUSE_VECTOR:
diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index 0d468b86bd8..e6342d2188d 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -14658,7 +14658,7 @@ c_parser_omp_clause_collapse (c_parser *parser, tree 
list)
   location_t loc;
 
   check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
-  check_no_duplicate_clause (list, OMP_CLAUSE_TILE, "tile");
+  check_no_duplicate_clause (list, OMP_CLAUSE_OACC_TILE, "tile");
 
   loc = c_parser_peek_token (parser)->location;
   matching_parens parens;
@@ -15842,7 +15842,7 @@ c_parser_oacc_clause_tile (c_parser *parser, tree list)
   location_t loc;
   tree tile = NULL_TREE;
 
-  check_no_duplicate_clause (list, OMP_CLAUSE_TILE, "tile");
+  check_no_duplicate_clause (list, OMP_CLAUSE_OACC_TILE, "tile");
   check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
 
   loc = c_parser_peek_token (parser)->location;
@@ -15894,9 +15894,9 @@ c_parser_oacc_clause_tile (c_parser *parser, tree list)
   /* Consume the trailing ')'.  */
   c_parser_consume_token (parser);
 
-  c = build_omp_clause (loc, OMP_CLAUSE_TILE);
+  c = build_omp_clause (loc, OMP_CLAUSE_OACC_TILE);
   tile = nreverse (tile);
-  OMP_CLAUSE_TILE_LIST (c) = tile;
+  OMP_CLAUSE_OACC_TILE_LIST (c) = tile;
   OMP_CLAUSE_CHAIN (c) = list;
   return c;
 }
@@ -21137,10 +21137,10 @@ c_parser_omp_for_loop (location_t loc, c_parser 
*parser, enum tree_code code,
   for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
 if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
   collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl));
-else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_TILE)
+else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_OACC_TILE)
   {
tiling = true;
-   collapse = list_length (OMP_CLAUSE_TILE_LIST (cl));
+   collapse = list_length (OMP_CLAUSE_OACC_TILE_LIST (cl));
   }
 else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_ORDERED
 && 

[PATCH, obvious] OpenMP: GIMPLE_OMP_STRUCTURED_BLOCK bug fix

2023-09-26 Thread Sandra Loosemore
I'm planning to push the attached 1-liner bug fix to mainline tomorrow, when 
testing has completed.  I think this qualifies as "obvious".  There's no test 
case because I discovered it while testing the updated loop transformation 
patches, which are still a work in progress; it fixed an ICE in the newly-added 
tests for that.  This is clearly just a bug in existing code unrelated to the 
new functionality, though.


-Sandra
commit 4c3db8cf0611fa99886d698b62102ba15058776f
Author: Sandra Loosemore 
Date:   Wed Sep 27 03:21:43 2023 +

OpenMP: GIMPLE_OMP_STRUCTURED_BLOCK bug fix

This is a bug fix for commit a62c8324e7e31ae6614f549bdf9d8a653233f8fc,
which added GIMPLE_OMP_STRUCTURED_BLOCK.  I found a big switch statement
over gimple codes that needs to know about this new node, but didn't.

gcc/ChangeLog
* gimple.cc (gimple_copy): Add case GIMPLE_OMP_STRUCTURED_BLOCK.

diff --git a/gcc/gimple.cc b/gcc/gimple.cc
index d5a4f634416..46f28784e07 100644
--- a/gcc/gimple.cc
+++ b/gcc/gimple.cc
@@ -2163,6 +2163,7 @@ gimple_copy (gimple *stmt)
 
 	case GIMPLE_OMP_SECTION:
 	case GIMPLE_OMP_MASTER:
+	case GIMPLE_OMP_STRUCTURED_BLOCK:
 	copy_omp_body:
 	  new_seq = gimple_seq_copy (gimple_omp_body (stmt));
 	  gimple_omp_set_body (copy, new_seq);


Re: [Patch] libgomp.texi: Fix ICV var name, document some memory management routines

2023-09-07 Thread Sandra Loosemore

On 9/7/23 02:56, Tobias Burnus wrote:

Main reason was to fix an ICV value; as collateral change, I also added
documentation for some of the memory-management functions.

Comments, suggestions? If not, I will commit it soon.


I only have one nit:


+@node omp_destroy_allocator
+@subsection @code{omp_destroy_allocator} -- Destroy an allocator
+@table @asis
+@item @emph{Description}:
+Releases all resources used by a memory allocator, which must not represent
+a predefined memory allocator.  Accessing memory after its allocator has been
+destroyed has unspecified behavior.  Passing @code{omp_null_allocator} to the
+routine is permitted but will have no effect.


s/will have/has/

I didn't build this to see how the formatting comes out, I assume you have done 
that and it is consistent with the way other functions are documented.


-Sandra



[PATCH] OpenMP: Fix ICE in fixup_blocks_walker [PR111274]

2023-09-07 Thread Sandra Loosemore
This ICE was caused by an invalid assumption that all BIND_EXPRs have
a non-null BIND_EXPR_BLOCK.  In C++ these do exist and are used for
temporaries introduced in expressions that are not full-expressions.
Since they have no block to fix up, the traversal can just ignore
these tree nodes.

gcc/cp/ChangeLog
* parser.cc (fixup_blocks_walker): Check for null BIND_EXPR_BLOCK.

gcc/testsuite/ChangeLog
* g++.dg/gomp/pr111274.C: New test case
---
 gcc/cp/parser.cc |  5 -
 gcc/testsuite/g++.dg/gomp/pr111274.C | 15 +++
 2 files changed, 19 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/gomp/pr111274.C

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 7811d582b07..15a98019a4a 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -44485,7 +44485,10 @@ fixup_blocks_walker (tree *tp, int *walk_subtrees, 
void *dp)
 {
   tree superblock = *(tree *)dp;
 
-  if (TREE_CODE (*tp) == BIND_EXPR)
+  /* BIND_EXPR_BLOCK may be null if the expression is not a
+ full-expression; if there's no block, no patching is necessary
+ for this node.  */
+  if (TREE_CODE (*tp) == BIND_EXPR && BIND_EXPR_BLOCK (*tp))
 {
   tree block = BIND_EXPR_BLOCK (*tp);
   if (superblock)
diff --git a/gcc/testsuite/g++.dg/gomp/pr111274.C 
b/gcc/testsuite/g++.dg/gomp/pr111274.C
new file mode 100644
index 000..6d3414fc82c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/gomp/pr111274.C
@@ -0,0 +1,15 @@
+// { dg-do "compile" }
+
+// This example used to ICE in fixup_blocks_walker due to a BIND_EXPR with
+// null BIND_EXPR_BLOCK.
+
+struct _Vector_base {
+  ~_Vector_base();
+};
+int ColumnSmallestLastOrdering_OMP_i_MaxNumThreads,
+ColumnSmallestLastOrdering_OMP_i_MaxDegree;
+void ColumnSmallestLastOrdering_OMP() {
+#pragma omp for
+  for (int i = 0; i < ColumnSmallestLastOrdering_OMP_i_MaxNumThreads; i++)
+new _Vector_base[ColumnSmallestLastOrdering_OMP_i_MaxDegree];
+}
-- 
2.31.1



Re: [PATCH] Darwin: homogenize spelling of macOS

2023-08-31 Thread Sandra Loosemore

On 8/31/23 05:27, Iain Sandoe wrote:

Hi FX,

+Sandra


On 31 Aug 2023, at 12:13, FX Coudert  wrote:

This patch homogenizes to some extent the use of “Mac OS X” or “OS X” or “Mac 
OS” in the gcc/ folder to “macOS”, which is the modern way of writing it. It is 
not a global replacement though, and each use was audited.

- When referring to specific versions that used the “OS X” or “Mac OS” as their 
name, it was kept.
- All uses referring to powerpc*-apple-darwin* were kept as-is, because those 
versions all predate the change to “macOS”.
- I did not touch Ada or D
- I did not touch testsuite comments

Tested by building on x86_64-apple-darwin, and generating the docs.
OK to push?


I think this is useful for user (or configurer)-facing documentation and help 
strings.

Being picky, there is one change where the reference is to 10.9 and earlier 
which are all Mac OS X (but that’s in a code comment so no need to change it).

OK from the Darwin perspective (for the code changes),
please wait for any comments from Sandra on the documentation changes.


I can't claim any particular knowledge of macOS or its correct historical 
naming, so I'm happy to defer to experts on that.  I did look over the patch 
and didn't spot anything that looked scary, at least.


-Sandra


[COMMITTED V3 5/6] OpenMP: Fortran support for imperfectly-nested loops

2023-08-25 Thread Sandra Loosemore
OpenMP 5.0 removed the restriction that multiple collapsed loops must
be perfectly nested, allowing "intervening code" (including nested
BLOCKs) before or after each nested loop.  In GCC this code is moved
into the inner loop body by the respective front ends.

In the Fortran front end, most of the semantic processing happens during
the translation phase, so the parse phase just collects the intervening
statements, checks them for errors, and splices them around the loop body.

gcc/fortran/ChangeLog
* gfortran.h (struct gfc_namespace): Add omp_structured_block bit.
* openmp.cc: Include omp-api.h.
(resolve_omp_clauses): Consolidate inscan reduction clause conflict
checking here.
(find_nested_loop_in_chain): New.
(find_nested_loop_in_block): New.
(gfc_resolve_omp_do_blocks): Set omp_current_do_collapse properly.
Handle imperfectly-nested loops when looking for nested omp scan.
Refactor to move inscan reduction clause conflict checking to
resolve_omp_clauses.
(gfc_resolve_do_iterator): Handle imperfectly-nested loops.
(struct icode_error_state): New.
(icode_code_error_callback): New.
(icode_expr_error_callback): New.
(diagnose_intervening_code_errors_1): New.
(diagnose_intervening_code_errors): New.
(make_structured_block): New.
(restructure_intervening_code): New.
(is_outer_iteration_variable): Do not assume loops are perfectly
nested.
(check_nested_loop_in_chain): New.
(check_nested_loop_in_block_state): New.
(check_nested_loop_in_block_symbol): New.
(check_nested_loop_in_block): New.
(expr_uses_intervening_var): New.
(is_intervening_var): New.
(expr_is_invariant): Do not assume loops are perfectly nested.
(resolve_omp_do): Handle imperfectly-nested loops.
* trans-stmt.cc (gfc_trans_block_construct): Generate
OMP_STRUCTURED_BLOCK if magic bit is set on block namespace.

gcc/testsuite/ChangeLog
* gfortran.dg/gomp/collapse1.f90: Adjust expected errors.
* gfortran.dg/gomp/collapse2.f90: Likewise.
* gfortran.dg/gomp/imperfect-gotos.f90: New.
* gfortran.dg/gomp/imperfect-invalid-scope.f90: New.
* gfortran.dg/gomp/imperfect1.f90: New.
* gfortran.dg/gomp/imperfect2.f90: New.
* gfortran.dg/gomp/imperfect3.f90: New.
* gfortran.dg/gomp/imperfect4.f90: New.
* gfortran.dg/gomp/imperfect5.f90: New.

libgomp/ChangeLog
* testsuite/libgomp.fortran/imperfect-destructor.f90: New.
* testsuite/libgomp.fortran/imperfect1.f90: New.
* testsuite/libgomp.fortran/imperfect2.f90: New.
* testsuite/libgomp.fortran/imperfect3.f90: New.
* testsuite/libgomp.fortran/imperfect4.f90: New.
* testsuite/libgomp.fortran/target-imperfect1.f90: New.
* testsuite/libgomp.fortran/target-imperfect2.f90: New.
* testsuite/libgomp.fortran/target-imperfect3.f90: New.
* testsuite/libgomp.fortran/target-imperfect4.f90: New.
---
 gcc/fortran/gfortran.h|   3 +
 gcc/fortran/openmp.cc | 763 +++---
 gcc/fortran/trans-stmt.cc |   7 +-
 gcc/testsuite/gfortran.dg/gomp/collapse1.f90  |   6 +-
 gcc/testsuite/gfortran.dg/gomp/collapse2.f90  |  10 +-
 .../gfortran.dg/gomp/imperfect-gotos.f90  |  69 ++
 .../gomp/imperfect-invalid-scope.f90  |  81 ++
 gcc/testsuite/gfortran.dg/gomp/imperfect1.f90 |  39 +
 gcc/testsuite/gfortran.dg/gomp/imperfect2.f90 |  56 ++
 gcc/testsuite/gfortran.dg/gomp/imperfect3.f90 |  45 ++
 gcc/testsuite/gfortran.dg/gomp/imperfect4.f90 |  36 +
 gcc/testsuite/gfortran.dg/gomp/imperfect5.f90 |  85 ++
 .../libgomp.fortran/imperfect-destructor.f90  | 142 
 .../testsuite/libgomp.fortran/imperfect1.f90  |  67 ++
 .../testsuite/libgomp.fortran/imperfect2.f90  | 102 +++
 .../testsuite/libgomp.fortran/imperfect3.f90  | 110 +++
 .../testsuite/libgomp.fortran/imperfect4.f90  | 121 +++
 .../libgomp.fortran/target-imperfect1.f90 |  72 ++
 .../libgomp.fortran/target-imperfect2.f90 | 110 +++
 .../libgomp.fortran/target-imperfect3.f90 | 116 +++
 .../libgomp.fortran/target-imperfect4.f90 | 126 +++
 21 files changed, 2058 insertions(+), 108 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/imperfect-gotos.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/imperfect-invalid-scope.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/imperfect1.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/imperfect2.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/imperfect3.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/imperfect4.f90
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/imperfect5.f90
 create mode 100644 libgomp/testsuite/libgomp.fortran/imperfect-destructor.f90
 create mode 100644 libgomp/testsuite/libgomp.fortran/imperfect1.f90
 create 

[COMMITTED V3 4/6] OpenMP: New C/C++ testcases for imperfectly nested loops.

2023-08-25 Thread Sandra Loosemore
gcc/testsuite/ChangeLog
* c-c++-common/gomp/imperfect-attributes.c: New.
* c-c++-common/gomp/imperfect-badloops.c: New.
* c-c++-common/gomp/imperfect-blocks.c: New.
* c-c++-common/gomp/imperfect-extension.c: New.
* c-c++-common/gomp/imperfect-gotos.c: New.
* c-c++-common/gomp/imperfect-invalid-scope.c: New.
* c-c++-common/gomp/imperfect-labels.c: New.
* c-c++-common/gomp/imperfect-legacy-syntax.c: New.
* c-c++-common/gomp/imperfect-pragmas.c: New.
* c-c++-common/gomp/imperfect1.c: New.
* c-c++-common/gomp/imperfect2.c: New.
* c-c++-common/gomp/imperfect3.c: New.
* c-c++-common/gomp/imperfect4.c: New.
* c-c++-common/gomp/imperfect5.c: New.

libgomp/ChangeLog
* testsuite/libgomp.c-c++-common/imperfect1.c: New.
* testsuite/libgomp.c-c++-common/imperfect2.c: New.
* testsuite/libgomp.c-c++-common/imperfect3.c: New.
* testsuite/libgomp.c-c++-common/imperfect4.c: New.
* testsuite/libgomp.c-c++-common/imperfect5.c: New.
* testsuite/libgomp.c-c++-common/imperfect6.c: New.
* testsuite/libgomp.c-c++-common/target-imperfect1.c: New.
* testsuite/libgomp.c-c++-common/target-imperfect2.c: New.
* testsuite/libgomp.c-c++-common/target-imperfect3.c: New.
* testsuite/libgomp.c-c++-common/target-imperfect4.c: New.
---
 .../c-c++-common/gomp/imperfect-attributes.c  |  81 
 .../c-c++-common/gomp/imperfect-badloops.c|  50 +
 .../c-c++-common/gomp/imperfect-blocks.c  |  75 
 .../c-c++-common/gomp/imperfect-extension.c   |  55 ++
 .../c-c++-common/gomp/imperfect-gotos.c   | 174 ++
 .../gomp/imperfect-invalid-scope.c|  77 
 .../c-c++-common/gomp/imperfect-labels.c  |  85 +
 .../gomp/imperfect-legacy-syntax.c|  44 +
 .../c-c++-common/gomp/imperfect-pragmas.c |  85 +
 gcc/testsuite/c-c++-common/gomp/imperfect1.c  |  38 
 gcc/testsuite/c-c++-common/gomp/imperfect2.c  |  34 
 gcc/testsuite/c-c++-common/gomp/imperfect3.c  |  52 ++
 gcc/testsuite/c-c++-common/gomp/imperfect4.c  |  33 
 gcc/testsuite/c-c++-common/gomp/imperfect5.c  |  95 ++
 .../libgomp.c-c++-common/imperfect1.c |  76 
 .../libgomp.c-c++-common/imperfect2.c | 114 
 .../libgomp.c-c++-common/imperfect3.c | 119 
 .../libgomp.c-c++-common/imperfect4.c | 117 
 .../libgomp.c-c++-common/imperfect5.c |  49 +
 .../libgomp.c-c++-common/imperfect6.c | 115 
 .../libgomp.c-c++-common/target-imperfect1.c  |  81 
 .../libgomp.c-c++-common/target-imperfect2.c  | 122 
 .../libgomp.c-c++-common/target-imperfect3.c  | 125 +
 .../libgomp.c-c++-common/target-imperfect4.c  | 122 
 24 files changed, 2018 insertions(+)
 create mode 100644 gcc/testsuite/c-c++-common/gomp/imperfect-attributes.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/imperfect-badloops.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/imperfect-blocks.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/imperfect-extension.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/imperfect-gotos.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/imperfect-invalid-scope.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/imperfect-labels.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/imperfect-legacy-syntax.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/imperfect-pragmas.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/imperfect1.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/imperfect2.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/imperfect3.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/imperfect4.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/imperfect5.c
 create mode 100644 libgomp/testsuite/libgomp.c-c++-common/imperfect1.c
 create mode 100644 libgomp/testsuite/libgomp.c-c++-common/imperfect2.c
 create mode 100644 libgomp/testsuite/libgomp.c-c++-common/imperfect3.c
 create mode 100644 libgomp/testsuite/libgomp.c-c++-common/imperfect4.c
 create mode 100644 libgomp/testsuite/libgomp.c-c++-common/imperfect5.c
 create mode 100644 libgomp/testsuite/libgomp.c-c++-common/imperfect6.c
 create mode 100644 libgomp/testsuite/libgomp.c-c++-common/target-imperfect1.c
 create mode 100644 libgomp/testsuite/libgomp.c-c++-common/target-imperfect2.c
 create mode 100644 libgomp/testsuite/libgomp.c-c++-common/target-imperfect3.c
 create mode 100644 libgomp/testsuite/libgomp.c-c++-common/target-imperfect4.c

diff --git a/gcc/testsuite/c-c++-common/gomp/imperfect-attributes.c 
b/gcc/testsuite/c-c++-common/gomp/imperfect-attributes.c
new file mode 100644
index 000..776295ce22a
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/imperfect-attributes.c
@@ -0,0 +1,81 @@
+/* { dg-do compile { target { c || 

[COMMITTED V3 2/6] OpenMP: C front end support for imperfectly-nested loops

2023-08-25 Thread Sandra Loosemore
OpenMP 5.0 removed the restriction that multiple collapsed loops must
be perfectly nested, allowing "intervening code" (including nested
BLOCKs) before or after each nested loop.  In GCC this code is moved
into the inner loop body by the respective front ends.

This patch changes the C front end to use recursive descent parsing
on nested loops within an "omp for" construct, rather than an iterative
approach, in order to preserve proper nesting of compound statements.

New common C/C++ testcases are in a separate patch.

gcc/c-family/ChangeLog
* c-common.h (c_omp_check_loop_binding_exprs): Declare.
* c-omp.cc: Include tree-iterator.h.
(find_binding_in_body): New.
(check_loop_binding_expr_r): New.
(LOCATION_OR): New.
(check_looop_binding_expr): New.
(c_omp_check_loop_binding_exprs): New.

gcc/c/ChangeLog
* c-parser.cc (struct c_parser): Add omp_for_parse_state field.
(struct omp_for_parse_data): New.
(check_omp_intervening_code): New.
(add_structured_block_stmt): New.
(c_parser_compound_statement_nostart): Recognize intervening code,
nested loops, and other things that need special handling in
OpenMP loop constructs.
(c_parser_while_statement): Error on loop in intervening code.
(c_parser_do_statement): Likewise.
(c_parser_for_statement): Likewise.
(c_parser_postfix_expression_after_primary): Error on calls to
the OpenMP runtime in intervening code.
(c_parser_pragma): Error on OpenMP pragmas in intervening code.
(c_parser_omp_loop_nest): New.
(c_parser_omp_for_loop): Rewrite to use recursive descent, calling
c_parser_omp_loop_nest to do the heavy lifting.

gcc/ChangeLog
* omp-api.h: New.
* omp-general.cc (omp_runtime_api_procname): New.
(omp_runtime_api_call): Moved here from omp-low.cc, and make
non-static.
* omp-general.h: Include omp-api.h.
* omp-low.cc (omp_runtime_api_call): Delete this copy.

gcc/testsuite/ChangeLog
* c-c++-common/goacc/collapse-1.c: Update for new C error behavior.
* c-c++-common/goacc/tile-2.c: Likewise.
* gcc.dg/gomp/collapse-1.c: Likewise.
---
 gcc/c-family/c-common.h   |   1 +
 gcc/c-family/c-omp.cc | 151 +++
 gcc/c/c-parser.cc | 860 +-
 gcc/omp-api.h |  32 +
 gcc/omp-general.cc| 134 +++
 gcc/omp-general.h |   1 +
 gcc/omp-low.cc| 129 ---
 gcc/testsuite/c-c++-common/goacc/collapse-1.c |  16 +-
 gcc/testsuite/c-c++-common/goacc/tile-2.c |   4 +-
 gcc/testsuite/gcc.dg/gomp/collapse-1.c|  10 +-
 10 files changed, 942 insertions(+), 396 deletions(-)
 create mode 100644 gcc/omp-api.h

diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 78fc5248ba6..732cb4eff64 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -1299,6 +1299,7 @@ extern tree c_finish_omp_for (location_t, enum tree_code, 
tree, tree, tree,
 extern bool c_omp_check_loop_iv (tree, tree, walk_tree_lh);
 extern bool c_omp_check_loop_iv_exprs (location_t, enum tree_code, tree, int,
   tree, tree, tree, walk_tree_lh);
+extern bool c_omp_check_loop_binding_exprs (tree, vec *);
 extern tree c_finish_oacc_wait (location_t, tree, tree);
 extern tree c_oacc_split_loop_clauses (tree, tree *, bool);
 extern void c_omp_split_clauses (location_t, enum tree_code, omp_clause_mask,
diff --git a/gcc/c-family/c-omp.cc b/gcc/c-family/c-omp.cc
index 4faddb00bbc..9b7d7f789e3 100644
--- a/gcc/c-family/c-omp.cc
+++ b/gcc/c-family/c-omp.cc
@@ -36,6 +36,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimplify.h"
 #include "langhooks.h"
 #include "bitmap.h"
+#include "tree-iterator.h"
 
 
 /* Complete a #pragma oacc wait construct.  LOC is the location of
@@ -1728,6 +1729,156 @@ c_omp_check_loop_iv_exprs (location_t stmt_loc, enum 
tree_code code,
   return !data.fail;
 }
 
+
+/* Helper function for c_omp_check_loop_binding_exprs: look for a binding
+   of DECL in BODY.  Only traverse things that might be containers for
+   intervening code in an OMP loop.  Returns the BIND_EXPR or DECL_EXPR
+   if found, otherwise null.  */
+
+static tree
+find_binding_in_body (tree decl, tree body)
+{
+  if (!body)
+return NULL_TREE;
+
+  switch (TREE_CODE (body))
+{
+case BIND_EXPR:
+  for (tree b = BIND_EXPR_VARS (body); b; b = DECL_CHAIN (b))
+   if (b == decl)
+ return body;
+  return find_binding_in_body (decl, BIND_EXPR_BODY (body));
+
+case DECL_EXPR:
+  if (DECL_EXPR_DECL (body) == decl)
+   return body;
+  return NULL_TREE;
+
+case STATEMENT_LIST:
+  for (tree_stmt_iterator si = tsi_start (body); !tsi_end_p (si);
+  tsi_next ())
+ 

[COMMITTED V3 6/6] OpenMP: Document support for imperfectly-nested loops.

2023-08-25 Thread Sandra Loosemore
libgomp/ChangeLog
* libgomp.texi (OpenMP 5.0):  Imperfectly-nested loops are done.
---
 libgomp/libgomp.texi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libgomp/libgomp.texi b/libgomp/libgomp.texi
index 5c91163893f..4aad8cc52f4 100644
--- a/libgomp/libgomp.texi
+++ b/libgomp/libgomp.texi
@@ -200,7 +200,7 @@ The OpenMP 4.5 specification is fully supported.
 @item @code{!=} as relational-op in canonical loop form for C/C++ @tab Y @tab
 @item @code{nonmonotonic} as default loop schedule modifier for 
worksharing-loop
   constructs @tab Y @tab
-@item Collapse of associated loops that are imperfectly nested loops @tab N 
@tab
+@item Collapse of associated loops that are imperfectly nested loops @tab Y 
@tab
 @item Clauses @code{if}, @code{nontemporal} and @code{order(concurrent)} in
   @code{simd} construct @tab Y @tab
 @item @code{atomic} constructs in @code{simd} @tab Y @tab
-- 
2.31.1



[COMMITTED V3 3/6] OpenMP: C++ support for imperfectly-nested loops

2023-08-25 Thread Sandra Loosemore
OpenMP 5.0 removed the restriction that multiple collapsed loops must
be perfectly nested, allowing "intervening code" (including nested
BLOCKs) before or after each nested loop.  In GCC this code is moved
into the inner loop body by the respective front ends.

This patch changes the C++ front end to use recursive descent parsing
on nested loops within an "omp for" construct, rather than an
iterative approach, in order to preserve proper nesting of compound
statements.  Preserving cleanups (destructors) for class objects
declared in intervening code and loop initializers complicates moving
the former into the body of the loop; this is handled by parsing the
entire construct before reassembling any of it.

gcc/cp/ChangeLog
* cp-tree.h (cp_convert_omp_range_for): Adjust declaration.
* parser.cc (struct omp_for_parse_data): New.
(cp_parser_postfix_expression): Diagnose calls to OpenMP runtime
in intervening code.
(check_omp_intervening_code): New.
(cp_parser_statement_seq_opt): Special-case nested loops, blocks,
and other constructs for OpenMP loops.
(cp_parser_iteration_statement): Reject loops in intervening code.
(cp_parser_omp_for_loop_init): Expand comments and tweak the
interface slightly to better distinguish input/output parameters.
(cp_convert_omp_range_for): Likewise.
(cp_parser_omp_loop_nest): New, split from cp_parser_omp_for_loop
and largely rewritten.  Add more comments.
(insert_structured_blocks): New.
(find_structured_blocks): New.
(struct sit_data, substitute_in_tree_walker, substitute_in_tree):
New.
(fixup_blocks_walker): New.
(cp_parser_omp_for_loop): Rewrite to use recursive descent instead
of a loop.  Add logic to reshuffle the bits of code collected
during parsing so intervening code gets moved to the loop body.
(cp_parser_omp_loop): Remove call to finish_omp_for_block, which
is now redundant.
(cp_parser_omp_simd): Likewise.
(cp_parser_omp_for): Likewise.
(cp_parser_omp_distribute): Likewise.
(cp_parser_oacc_loop): Likewise.
(cp_parser_omp_taskloop): Likewise.
(cp_parser_pragma): Reject OpenMP pragmas in intervening code.
* parser.h (struct cp_parser): Add omp_for_parse_state field.
* pt.cc (tsubst_omp_for_iterator): Adjust call to
cp_convert_omp_range_for.
* semantics.cc (finish_omp_for): Try harder to preserve location
of loop variable init expression for use in diagnostics.
(struct fofb_data, finish_omp_for_block_walker): New.
(finish_omp_for_block): Allow variables to be bound in a BIND_EXPR
nested inside BIND instead of directly in BIND itself.

gcc/testsuite/ChangeLog
* c-c++-common/goacc/tile-2.c: Adjust expected error patterns.
* g++.dg/gomp/attrs-imperfect1.C: New test.
* g++.dg/gomp/attrs-imperfect2.C: New test.
* g++.dg/gomp/attrs-imperfect3.C: New test.
* g++.dg/gomp/attrs-imperfect4.C: New test.
* g++.dg/gomp/attrs-imperfect5.C: New test.
* g++.dg/gomp/pr41967.C: Adjust expected error patterns.
* g++.dg/gomp/tpl-imperfect-gotos.C: New test.
* g++.dg/gomp/tpl-imperfect-invalid-scope.C: New test.

libgomp/ChangeLog
* testsuite/libgomp.c++/attrs-imperfect1.C: New test.
* testsuite/libgomp.c++/attrs-imperfect2.C: New test.
* testsuite/libgomp.c++/attrs-imperfect3.C: New test.
* testsuite/libgomp.c++/attrs-imperfect4.C: New test.
* testsuite/libgomp.c++/attrs-imperfect5.C: New test.
* testsuite/libgomp.c++/attrs-imperfect6.C: New test.
* testsuite/libgomp.c++/imperfect-class-1.C: New test.
* testsuite/libgomp.c++/imperfect-class-2.C: New test.
* testsuite/libgomp.c++/imperfect-class-3.C: New test.
* testsuite/libgomp.c++/imperfect-destructor.C: New test.
* testsuite/libgomp.c++/imperfect-template-1.C: New test.
* testsuite/libgomp.c++/imperfect-template-2.C: New test.
* testsuite/libgomp.c++/imperfect-template-3.C: New test.
---
 gcc/cp/cp-tree.h  |2 +-
 gcc/cp/parser.cc  | 1315 -
 gcc/cp/parser.h   |3 +
 gcc/cp/pt.cc  |3 +-
 gcc/cp/semantics.cc   |  117 +-
 gcc/testsuite/c-c++-common/goacc/tile-2.c |4 +-
 gcc/testsuite/g++.dg/gomp/attrs-imperfect1.C  |   38 +
 gcc/testsuite/g++.dg/gomp/attrs-imperfect2.C  |   34 +
 gcc/testsuite/g++.dg/gomp/attrs-imperfect3.C  |   33 +
 gcc/testsuite/g++.dg/gomp/attrs-imperfect4.C  |   33 +
 gcc/testsuite/g++.dg/gomp/attrs-imperfect5.C  |   57 +
 gcc/testsuite/g++.dg/gomp/pr41967.C   |2 +-
 .../g++.dg/gomp/tpl-imperfect-gotos.C |  161 ++
 .../g++.dg/gomp/tpl-imperfect-invalid-scope.C |   

[COMMITTED V3 1/6] OpenMP: Add OMP_STRUCTURED_BLOCK and GIMPLE_OMP_STRUCTURED_BLOCK.

2023-08-25 Thread Sandra Loosemore
In order to detect invalid jumps in and out of intervening code in
imperfectly-nested loops, the front ends need to insert some sort of
marker to identify the structured block sequences that they push into
the inner body of the loop.  The error checking happens in the
diagnose_omp_blocks pass, between gimplification and OMP lowering, so
we need both GENERIC and GIMPLE representations of these markers.
They are removed in OMP lowering so no subsequent passes need to know
about them.

This patch doesn't include any front-end changes to generate the new
data structures.

gcc/cp/ChangeLog
* constexpr.cc (cxx_eval_constant_expression): Handle
OMP_STRUCTURED_BLOCK.
* pt.cc (tsubst_expr): Likewise.

gcc/ChangeLog
* doc/generic.texi (OpenMP): Document OMP_STRUCTURED_BLOCK.
* doc/gimple.texi (GIMPLE instruction set): Add
GIMPLE_OMP_STRUCTURED_BLOCK.
(GIMPLE_OMP_STRUCTURED_BLOCK): New subsection.
* gimple-low.cc (lower_stmt): Error on GIMPLE_OMP_STRUCTURED_BLOCK.
* gimple-pretty-print.cc (dump_gimple_omp_block): Handle
GIMPLE_OMP_STRUCTURED_BLOCK.
(pp_gimple_stmt_1): Likewise.
* gimple-walk.cc (walk_gimple_stmt): Likewise.
* gimple.cc (gimple_build_omp_structured_block): New.
* gimple.def (GIMPLE_OMP_STRUCTURED_BLOCK): New.
* gimple.h (gimple_build_omp_structured_block): Declare.
(gimple_has_substatements): Handle GIMPLE_OMP_STRUCTURED_BLOCK.
(CASE_GIMPLE_OMP): Likewise.
* gimplify.cc (is_gimple_stmt): Handle OMP_STRUCTURED_BLOCK.
(gimplify_expr): Likewise.
* omp-expand.cc (GIMPLE_OMP_STRUCTURED_BLOCK): Error on
GIMPLE_OMP_STRUCTURED_BLOCK.
* omp-low.cc (scan_omp_1_stmt): Handle GIMPLE_OMP_STRUCTURED_BLOCK.
(lower_omp_1): Likewise.
(diagnose_sb_1): Likewise.
(diagnose_sb_2): Likewise.
* tree-inline.cc (remap_gimple_stmt): Handle
GIMPLE_OMP_STRUCTURED_BLOCK.
(estimate_num_insns): Likewise.
* tree-nested.cc (convert_nonlocal_reference_stmt): Likewise.
(convert_local_reference_stmt): Likewise.
(convert_gimple_call): Likewise.
* tree-pretty-print.cc (dump_generic_node): Handle
OMP_STRUCTURED_BLOCK.
* tree.def (OMP_STRUCTURED_BLOCK): New.
* tree.h (OMP_STRUCTURED_BLOCK_BODY): New.
---
 gcc/cp/constexpr.cc|  1 +
 gcc/cp/pt.cc   |  1 +
 gcc/doc/generic.texi   | 14 ++
 gcc/doc/gimple.texi| 19 +++
 gcc/gimple-low.cc  |  4 
 gcc/gimple-pretty-print.cc |  6 +-
 gcc/gimple-walk.cc |  1 +
 gcc/gimple.cc  | 15 +++
 gcc/gimple.def |  5 +
 gcc/gimple.h   |  3 +++
 gcc/gimplify.cc|  6 ++
 gcc/omp-expand.cc  |  4 
 gcc/omp-low.cc | 11 +++
 gcc/tree-inline.cc |  6 ++
 gcc/tree-nested.cc |  3 +++
 gcc/tree-pretty-print.cc   |  4 
 gcc/tree.def   |  9 +
 gcc/tree.h |  3 +++
 18 files changed, 114 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index da2c3116810..8bd5c4a47f8 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -8155,6 +8155,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, 
tree t,
 case OMP_SCAN:
 case OMP_SCOPE:
 case OMP_SECTION:
+case OMP_STRUCTURED_BLOCK:
 case OMP_MASTER:
 case OMP_MASKED:
 case OMP_TASKGROUP:
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index a4809f034dc..e06d11fcb75 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -19741,6 +19741,7 @@ tsubst_expr (tree t, tree args, tsubst_flags_t 
complain, tree in_decl)
   break;
 
 case OMP_MASTER:
+case OMP_STRUCTURED_BLOCK:
   omp_parallel_combined_clauses = NULL;
   /* FALLTHRU */
 case OMP_SECTION:
diff --git a/gcc/doc/generic.texi b/gcc/doc/generic.texi
index 3f9bddd7eae..c8d6ef062f6 100644
--- a/gcc/doc/generic.texi
+++ b/gcc/doc/generic.texi
@@ -2488,6 +2488,20 @@ In some cases, @code{OMP_CONTINUE} is placed right before
 occur right after the looping body, it will be emitted between
 @code{OMP_CONTINUE} and @code{OMP_RETURN}.
 
+@item OMP_STRUCTURED_BLOCK
+
+This is another statement that doesn't correspond to an OpenMP directive.
+It is used to mark sections of code in another directive that must
+be structured block sequences, in particular for sequences of intervening code
+in the body of an @code{OMP_FOR}.  It is not necessary to use this when the
+entire body of a directive is required to be a structured block sequence,
+since that is implicit in the representation of the corresponding node.
+
+This tree node is used only to allow error checking transfers of control
+in/out of the structured block sequence after gimplification.
+It has a single operand (@code{OMP_STRUCTURED_BLOCK_BODY}) that is
+the code within the structured 

[COMMITTED V3 0/6] Support for imperfectly-nested loops

2023-08-25 Thread Sandra Loosemore
V2 of these patches were previously approved with a few small changes
requested.  For the archives, here is the version I've pushed.

Parts 1 and 2 are unchanged since V2.  In part 3 (C++) I had to fix a
merge problem by hand.  In parts 4 and 5, I hacked up a couple tests
as requested by Jakub.  Part 5 (Fortran) also includes the whitespace
fix Tobias pointed out, and part 6 (documentation) is new.

-Sandra

Sandra Loosemore (6):
  OpenMP: Add OMP_STRUCTURED_BLOCK and GIMPLE_OMP_STRUCTURED_BLOCK.
  OpenMP: C front end support for imperfectly-nested loops
  OpenMP: C++ support for imperfectly-nested loops
  OpenMP: New C/C++ testcases for imperfectly nested loops.
  OpenMP: Fortran support for imperfectly-nested loops
  OpenMP: Document support for imperfectly-nested loops.

 gcc/c-family/c-common.h   |1 +
 gcc/c-family/c-omp.cc |  151 ++
 gcc/c/c-parser.cc |  860 +++
 gcc/cp/constexpr.cc   |1 +
 gcc/cp/cp-tree.h  |2 +-
 gcc/cp/parser.cc  | 1315 -
 gcc/cp/parser.h   |3 +
 gcc/cp/pt.cc  |4 +-
 gcc/cp/semantics.cc   |  117 +-
 gcc/doc/generic.texi  |   14 +
 gcc/doc/gimple.texi   |   19 +
 gcc/fortran/gfortran.h|3 +
 gcc/fortran/openmp.cc |  763 --
 gcc/fortran/trans-stmt.cc |7 +-
 gcc/gimple-low.cc |4 +
 gcc/gimple-pretty-print.cc|6 +-
 gcc/gimple-walk.cc|1 +
 gcc/gimple.cc |   15 +
 gcc/gimple.def|5 +
 gcc/gimple.h  |3 +
 gcc/gimplify.cc   |6 +
 gcc/omp-api.h |   32 +
 gcc/omp-expand.cc |4 +
 gcc/omp-general.cc|  134 ++
 gcc/omp-general.h |1 +
 gcc/omp-low.cc|  140 +-
 gcc/testsuite/c-c++-common/goacc/collapse-1.c |   16 +-
 gcc/testsuite/c-c++-common/goacc/tile-2.c |4 +-
 .../c-c++-common/gomp/imperfect-attributes.c  |   81 +
 .../c-c++-common/gomp/imperfect-badloops.c|   50 +
 .../c-c++-common/gomp/imperfect-blocks.c  |   75 +
 .../c-c++-common/gomp/imperfect-extension.c   |   55 +
 .../c-c++-common/gomp/imperfect-gotos.c   |  174 +++
 .../gomp/imperfect-invalid-scope.c|   77 +
 .../c-c++-common/gomp/imperfect-labels.c  |   85 ++
 .../gomp/imperfect-legacy-syntax.c|   44 +
 .../c-c++-common/gomp/imperfect-pragmas.c |   85 ++
 gcc/testsuite/c-c++-common/gomp/imperfect1.c  |   38 +
 gcc/testsuite/c-c++-common/gomp/imperfect2.c  |   34 +
 gcc/testsuite/c-c++-common/gomp/imperfect3.c  |   52 +
 gcc/testsuite/c-c++-common/gomp/imperfect4.c  |   33 +
 gcc/testsuite/c-c++-common/gomp/imperfect5.c  |   95 ++
 gcc/testsuite/g++.dg/gomp/attrs-imperfect1.C  |   38 +
 gcc/testsuite/g++.dg/gomp/attrs-imperfect2.C  |   34 +
 gcc/testsuite/g++.dg/gomp/attrs-imperfect3.C  |   33 +
 gcc/testsuite/g++.dg/gomp/attrs-imperfect4.C  |   33 +
 gcc/testsuite/g++.dg/gomp/attrs-imperfect5.C  |   57 +
 gcc/testsuite/g++.dg/gomp/pr41967.C   |2 +-
 .../g++.dg/gomp/tpl-imperfect-gotos.C |  161 ++
 .../g++.dg/gomp/tpl-imperfect-invalid-scope.C |   94 ++
 gcc/testsuite/gcc.dg/gomp/collapse-1.c|   10 +-
 gcc/testsuite/gfortran.dg/gomp/collapse1.f90  |6 +-
 gcc/testsuite/gfortran.dg/gomp/collapse2.f90  |   10 +-
 .../gfortran.dg/gomp/imperfect-gotos.f90  |   69 +
 .../gomp/imperfect-invalid-scope.f90  |   81 +
 gcc/testsuite/gfortran.dg/gomp/imperfect1.f90 |   39 +
 gcc/testsuite/gfortran.dg/gomp/imperfect2.f90 |   56 +
 gcc/testsuite/gfortran.dg/gomp/imperfect3.f90 |   45 +
 gcc/testsuite/gfortran.dg/gomp/imperfect4.f90 |   36 +
 gcc/testsuite/gfortran.dg/gomp/imperfect5.f90 |   85 ++
 gcc/tree-inline.cc|6 +
 gcc/tree-nested.cc|3 +
 gcc/tree-pretty-print.cc  |4 +
 gcc/tree.def  |9 +
 gcc/tree.h|3 +
 libgomp/libgomp.texi  |2 +-
 .../testsuite/libgomp.c++/attrs-imperfect1.C  |   76 +
 .../testsuite/libgomp.c++/attrs-imperfect2.C  |  114 ++
 .../testsuite/libgomp.c++/attrs-imperfect3.C  |  119 ++
 .../testsuite/libgomp.c++/attrs-imperfect4.C  |  117 ++
 .../testsuite/libgomp.c++/attrs-imperfect5.C  |   49 +
 .../testsuite/libgomp.c++/attrs-imperfect6.C  |  115 ++
 .../testsuite/libgomp.c++/imperfect-class-1.C |  169 +++
 .../testsuite/libgomp.c++/imperfect-class-2.C |  167

Re: [PATCH V2 2/5] OpenMP: C front end support for imperfectly-nested loops

2023-08-22 Thread Sandra Loosemore via Gcc-patches

On 8/22/23 07:23, Jakub Jelinek wrote:



diff --git a/gcc/testsuite/c-c++-common/goacc/collapse-1.c 
b/gcc/testsuite/c-c++-common/goacc/collapse-1.c
index 11b14383983..0feac8f8ddb 100644
--- a/gcc/testsuite/c-c++-common/goacc/collapse-1.c
+++ b/gcc/testsuite/c-c++-common/goacc/collapse-1.c
@@ -8,8 +8,8 @@ f1 (void)
  {
#pragma acc parallel
#pragma acc loop collapse (2)
-  for (i = 0; i < 5; i++)
-;  /* { dg-error "not enough perfectly 
nested" } */
+  for (i = 0; i < 5; i++)   /* { dg-error "not enough nested loops" } */
+;
{
  for (j = 0; j < 5; j++)
;


All these c-c++-common testsuite changes will now FAIL after the C patch but
before the C++.  It is nice to have the new c-c++-common tests in a separate
patch, but these tweaks which can't be just avoided need the temporary
{ target c } vs. { target c++} hacks undone later in the C++ patch.


In spite of being in the c-c++-common subdirectory, this particular testcase is 
presently run only for C:


/* { dg-skip-if "not yet" { c++ } } */

I did previously do incremental testing between applying the the C and C++ 
parts of the series to confirm that there were no regressions.


BTW, thanks for your previous detailed review of the original version of this 
patch, and pointing out many things I'd overlooked; I feel that V2 is much more 
robust and correct as a result.  :-)


-Sandra


[OG13, committed 2/3] OpenMP: C++ attribute syntax fixes/testcases for "declare mapper"

2023-08-18 Thread Sandra Loosemore
gcc/c-family/ChangeLog
* c-omp.cc (c_omp_directives): Uncomment "declare mapper" entry.

gcc/cp/ChangeLog
* parser.cc (cp_parser_omp_declare_mapper): Allow commas between
clauses.

gcc/testsuite/ChangeLog
* g++.dg/gomp/attrs-declare-mapper-3.C: New file.
* g++.dg/gomp/attrs-declare-mapper-4.C: New file.
* g++.dg/gomp/attrs-declare-mapper-5.C: New file.
* g++.dg/gomp/attrs-declare-mapper-6.C: New file.
---
 gcc/c-family/ChangeLog.omp|  4 +
 gcc/c-family/c-omp.cc |  4 +-
 gcc/cp/ChangeLog.omp  |  5 ++
 gcc/cp/parser.cc  |  2 +
 gcc/testsuite/ChangeLog.omp   |  7 ++
 .../g++.dg/gomp/attrs-declare-mapper-3.C  | 31 
 .../g++.dg/gomp/attrs-declare-mapper-4.C  | 74 +++
 .../g++.dg/gomp/attrs-declare-mapper-5.C  | 26 +++
 .../g++.dg/gomp/attrs-declare-mapper-6.C  | 22 ++
 9 files changed, 173 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-declare-mapper-3.C
 create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-declare-mapper-4.C
 create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-declare-mapper-5.C
 create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-declare-mapper-6.C

diff --git a/gcc/c-family/ChangeLog.omp b/gcc/c-family/ChangeLog.omp
index 60f5c29276f..40cb8e811e5 100644
--- a/gcc/c-family/ChangeLog.omp
+++ b/gcc/c-family/ChangeLog.omp
@@ -1,3 +1,7 @@
+2023-08-18  Sandra Loosemore  
+
+   * c-omp.cc (c_omp_directives): Uncomment "declare mapper" entry.
+
 2023-08-10  Julian Brown  
 
* c-common.h (c_omp_region_type): Add C_ORT_UPDATE and C_ORT_OMP_UPDATE
diff --git a/gcc/c-family/c-omp.cc b/gcc/c-family/c-omp.cc
index 9ff09b59bc6..7bc69e9e2da 100644
--- a/gcc/c-family/c-omp.cc
+++ b/gcc/c-family/c-omp.cc
@@ -5500,8 +5500,8 @@ const struct c_omp_directive c_omp_directives[] = {
 C_OMP_DIR_STANDALONE, false },
   { "critical", nullptr, nullptr, PRAGMA_OMP_CRITICAL,
 C_OMP_DIR_CONSTRUCT, false },
-  /* { "declare", "mapper", nullptr, PRAGMA_OMP_DECLARE,
-C_OMP_DIR_DECLARATIVE, false },  */
+  { "declare", "mapper", nullptr, PRAGMA_OMP_DECLARE,
+C_OMP_DIR_DECLARATIVE, false },
   { "declare", "reduction", nullptr, PRAGMA_OMP_DECLARE,
 C_OMP_DIR_DECLARATIVE, true },
   { "declare", "simd", nullptr, PRAGMA_OMP_DECLARE,
diff --git a/gcc/cp/ChangeLog.omp b/gcc/cp/ChangeLog.omp
index 6e154ea3426..1b2d71422d8 100644
--- a/gcc/cp/ChangeLog.omp
+++ b/gcc/cp/ChangeLog.omp
@@ -1,3 +1,8 @@
+2023-08-18  Sandra Loosemore  
+
+   * parser.cc (cp_parser_omp_declare_mapper): Allow commas between
+   clauses.
+
 2023-08-18  Sandra Loosemore  
 
* parser.cc (analyze_metadirective_body): Handle CPP_PRAGMA and
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 84ec0de6c69..0ce2a7be608 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -50358,6 +50358,8 @@ cp_parser_omp_declare_mapper (cp_parser *parser, 
cp_token *pragma_tok,
 
   while (cp_lexer_next_token_is_not (parser->lexer, CPP_PRAGMA_EOL))
 {
+  if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
+   cp_lexer_consume_token (parser->lexer);
   pragma_omp_clause c_kind = cp_parser_omp_clause_name (parser);
   if (c_kind != PRAGMA_OMP_CLAUSE_MAP)
{
diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index a9b4ac3d0a7..a7d11777988 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -1,3 +1,10 @@
+2023-08-18  Sandra Loosemore  
+
+   * g++.dg/gomp/attrs-declare-mapper-3.C: New file.
+   * g++.dg/gomp/attrs-declare-mapper-4.C: New file.
+   * g++.dg/gomp/attrs-declare-mapper-5.C: New file.
+   * g++.dg/gomp/attrs-declare-mapper-6.C: New file.
+
 2023-08-18  Sandra Loosemore  
 
* g++.dg/gomp/attrs-metadirective-1.C: New file.
diff --git a/gcc/testsuite/g++.dg/gomp/attrs-declare-mapper-3.C 
b/gcc/testsuite/g++.dg/gomp/attrs-declare-mapper-3.C
new file mode 100644
index 000..36345fe0dc2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/gomp/attrs-declare-mapper-3.C
@@ -0,0 +1,31 @@
+// { dg-do compile { target c++11 } } 
+// { dg-additional-options "-fdump-tree-gimple" }
+
+#include 
+
+// Test named mapper invocation.
+
+struct S {
+  int *ptr;
+  int size;
+};
+
+int main (int argc, char *argv[])
+{
+  int N = 1024;
+  [[omp::directive (declare mapper (mapN:struct S s)
+   map(to:s.ptr, s.size)
+   map(s.ptr[:N]))]];
+
+  struct S s;
+  s.ptr = (int *) malloc (sizeof (int) * N);
+
+  [[omp::directive (target map(mapper(mapN), tofrom: s))]]
+// { dg-final { scan-tree-dump {map\(struct:s \[len: 2\]\) map\(alloc:s\.ptr 
\[len: [0-9]+\]\) map\(to:s\.size \[len: [0-9]+\]\) map\(tofrom:\*_[0-9]+ 
\[len: _[0-9]+\]\) map\(attach:s\

[OG13, committed 3/3] OpenMP: C++ attribute syntax fixes/testcases for loop transformations

2023-08-18 Thread Sandra Loosemore
gcc/cp/ChangeLog
* parser.cc (cp_parser_omp_all_clauses): Allow comma before first
clause.
(cp_parser_see_omp_loop_nest): Accept C++ standard attributes
before RID_FOR.
(cp_parser_omp_loop_nest): Process C++ standard attributes like
pragmas.  Improve error handling for bad pragmas/attributes.
Use cp_parser_see_omp_loop_nest instead of duplicating what it
does.
(cp_parser_omp_tile_sizes): Permit comma before the clause.
(cp_parser_omp_tile): Assert that this isn't called for inner
directive.
(cp_parser_omp_unroll): Likewise.

gcc/testsuite/ChangeLog
* g++.dg/gomp/loop-transforms/attrs-tile-1.C: New file.
* g++.dg/gomp/loop-transforms/attrs-tile-2.C: New file.
* g++.dg/gomp/loop-transforms/attrs-tile-3.C: New file.
* g++.dg/gomp/loop-transforms/attrs-unroll-1.C: New file.
* g++.dg/gomp/loop-transforms/attrs-unroll-2.C: New file.
* g++.dg/gomp/loop-transforms/attrs-unroll-3.C: New file.
* g++.dg/gomp/loop-transforms/attrs-unroll-inner-1.C: New file.
* g++.dg/gomp/loop-transforms/attrs-unroll-inner-2.C: New file.
* g++.dg/gomp/loop-transforms/attrs-unroll-inner-3.C: New file.
---
 gcc/cp/ChangeLog.omp  |  15 ++
 gcc/cp/parser.cc  |  69 ---
 gcc/testsuite/ChangeLog.omp   |  12 ++
 .../gomp/loop-transforms/attrs-tile-1.C   | 164 +
 .../gomp/loop-transforms/attrs-tile-2.C   | 174 ++
 .../gomp/loop-transforms/attrs-tile-3.C   | 111 +++
 .../gomp/loop-transforms/attrs-unroll-1.C | 135 ++
 .../gomp/loop-transforms/attrs-unroll-2.C |  81 
 .../gomp/loop-transforms/attrs-unroll-3.C |  20 ++
 .../loop-transforms/attrs-unroll-inner-1.C|  15 ++
 .../loop-transforms/attrs-unroll-inner-2.C|  29 +++
 .../loop-transforms/attrs-unroll-inner-3.C|  71 +++
 12 files changed, 872 insertions(+), 24 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/gomp/loop-transforms/attrs-tile-1.C
 create mode 100644 gcc/testsuite/g++.dg/gomp/loop-transforms/attrs-tile-2.C
 create mode 100644 gcc/testsuite/g++.dg/gomp/loop-transforms/attrs-tile-3.C
 create mode 100644 gcc/testsuite/g++.dg/gomp/loop-transforms/attrs-unroll-1.C
 create mode 100644 gcc/testsuite/g++.dg/gomp/loop-transforms/attrs-unroll-2.C
 create mode 100644 gcc/testsuite/g++.dg/gomp/loop-transforms/attrs-unroll-3.C
 create mode 100644 
gcc/testsuite/g++.dg/gomp/loop-transforms/attrs-unroll-inner-1.C
 create mode 100644 
gcc/testsuite/g++.dg/gomp/loop-transforms/attrs-unroll-inner-2.C
 create mode 100644 
gcc/testsuite/g++.dg/gomp/loop-transforms/attrs-unroll-inner-3.C

diff --git a/gcc/cp/ChangeLog.omp b/gcc/cp/ChangeLog.omp
index 1b2d71422d8..fe5ef67a7ad 100644
--- a/gcc/cp/ChangeLog.omp
+++ b/gcc/cp/ChangeLog.omp
@@ -1,3 +1,18 @@
+2023-08-18  Sandra Loosemore  
+
+   * parser.cc (cp_parser_omp_all_clauses): Allow comma before first
+   clause.
+   (cp_parser_see_omp_loop_nest): Accept C++ standard attributes
+   before RID_FOR.
+   (cp_parser_omp_loop_nest): Process C++ standard attributes like
+   pragmas.  Improve error handling for bad pragmas/attributes.
+   Use cp_parser_see_omp_loop_nest instead of duplicating what it
+   does.
+   (cp_parser_omp_tile_sizes): Permit comma before the clause.
+   (cp_parser_omp_tile): Assert that this isn't called for inner
+   directive.
+   (cp_parser_omp_unroll): Likewise.
+
 2023-08-18  Sandra Loosemore  
 
* parser.cc (cp_parser_omp_declare_mapper): Allow commas between
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 0ce2a7be608..4871f4511a9 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -42240,15 +42240,12 @@ cp_parser_omp_all_clauses (cp_parser *parser, 
omp_clause_mask mask,
   if (nested && cp_lexer_next_token_is (parser->lexer, CPP_CLOSE_PAREN))
break;
 
-  if (!first || nested != 2)
-   {
- if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
-   cp_lexer_consume_token (parser->lexer);
- else if (nested == 2)
-   error_at (cp_lexer_peek_token (parser->lexer)->location,
- "clauses in % trait should be separated "
-  "by %<,%>");
-   }
+  if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
+   cp_lexer_consume_token (parser->lexer);
+  else if (!first && nested == 2)
+   error_at (cp_lexer_peek_token (parser->lexer)->location,
+ "clauses in % trait should be separated "
+ "by %<,%>");
 
   token = cp_lexer_peek_token (parser->lexer);
   c_kind = cp_parser_omp_clause_name (parser);
@@ -44803,6 +44800,11 @@ cp_parser_see_omp_loop_nest (cp_parser *par

  1   2   3   4   5   6   7   8   9   10   >