Jakub Jelinek wrote:
Isn't all this caused just by the missing check that condition trait has a
constant expression?
IMHO that is the way to handle it in GCC 14.
Concur – how about the following patch?
Tobias
PS: See PR113904 for follow up tasks. / Instead of '.AND.' etc. I could
have also used some more '==', '<' etc. expressions in the modified
examples (as should have Sandra in the initial version), but,
fortunately, there is at least one '=='.
OpenMP: Reject non-const 'condition' trait in Fortran
OpenMP 5.0 only permits constant expressions for the 'condition' trait
in context selectors; this is relaxed in 5.2 but not implemented. In order
to avoid wrong code, it is now rejected.
Additionally, in Fortran, 'condition' should not accept an integer
expression, which is now ensured. Additionally, as 'device_num' should be
a conforming device number, there is now a check on the value.
PR middle-end/113904
gcc/c/ChangeLog:
* c-parser.cc (c_parser_omp_context_selector): Handle splitting of
OMP_TRAIT_PROPERTY_EXPR into OMP_TRAIT_PROPERTY_{DEV_NUM,BOOL}_EXPR.
gcc/cp/ChangeLog:
* parser.cc (cp_parser_omp_context_selector): Handle splitting of
OMP_TRAIT_PROPERTY_EXPR into OMP_TRAIT_PROPERTY_{DEV_NUM,BOOL}_EXPR.
gcc/fortran/ChangeLog:
* openmp.cc (gfc_match_omp_context_selector):
* trans-openmp.cc (gfc_trans_omp_declare_variant): Handle splitting of
OMP_TRAIT_PROPERTY_EXPR into OMP_TRAIT_PROPERTY_{DEV_NUM,BOOL}_EXPR.
gcc/ChangeLog:
* omp-general.cc (struct omp_ts_info): Update for splitting of
OMP_TRAIT_PROPERTY_EXPR into OMP_TRAIT_PROPERTYDEV_NUM,BOOL}_EXPR.
* omp-selectors.h (enum omp_tp_type): Replace
OMP_TRAIT_PROPERTY_EXPR by OMP_TRAIT_PROPERTY_{DEV_NUM,BOOL}_EXPR.
gcc/testsuite/ChangeLog:
* gfortran.dg/gomp/declare-variant-1.f90: Change 'condition' trait's
argument from integer to a logical expression.
* gfortran.dg/gomp/declare-variant-11.f90: Likewise.
* gfortran.dg/gomp/declare-variant-12.f90: Likewise.
* gfortran.dg/gomp/declare-variant-13.f90: Likewise.
* gfortran.dg/gomp/declare-variant-2.f90: Likewise.
* gfortran.dg/gomp/declare-variant-2a.f90: Likewise.
* gfortran.dg/gomp/declare-variant-3.f90: Likewise.
* gfortran.dg/gomp/declare-variant-4.f90: Likewise.
* gfortran.dg/gomp/declare-variant-6.f90: Likewise.
* gfortran.dg/gomp/declare-variant-8.f90: Likewise.
* gfortran.dg/gomp/declare-variant-20.f90: New test.
gcc/c/c-parser.cc | 3 +-
gcc/cp/parser.cc | 3 +-
gcc/fortran/openmp.cc | 30 ++---
gcc/fortran/trans-openmp.cc| 3 +-
gcc/omp-general.cc | 4 +-
gcc/omp-selectors.h| 3 +-
.../gfortran.dg/gomp/declare-variant-1.f90 | 4 +-
.../gfortran.dg/gomp/declare-variant-11.f90| 4 +-
.../gfortran.dg/gomp/declare-variant-12.f90| 12 ++---
.../gfortran.dg/gomp/declare-variant-13.f90| 2 +-
.../gfortran.dg/gomp/declare-variant-2.f90 | 8 ++--
.../gfortran.dg/gomp/declare-variant-20.f90| 51 ++
.../gfortran.dg/gomp/declare-variant-2a.f90| 4 +-
.../gfortran.dg/gomp/declare-variant-3.f90 | 8 ++--
.../gfortran.dg/gomp/declare-variant-4.f90 | 8 ++--
.../gfortran.dg/gomp/declare-variant-6.f90 | 14 +++---
.../gfortran.dg/gomp/declare-variant-8.f90 | 2 +-
17 files changed, 119 insertions(+), 44 deletions(-)
diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index c31349dae2f..3be91d666a5 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -24656,7 +24656,8 @@ c_parser_omp_context_selector (c_parser *parser, enum omp_tss_code set,
}
while (1);
break;
- case OMP_TRAIT_PROPERTY_EXPR:
+ case OMP_TRAIT_PROPERTY_DEV_NUM_EXPR:
+ case OMP_TRAIT_PROPERTY_BOOL_EXPR:
t = c_parser_expr_no_commas (parser, NULL).value;
if (t != error_mark_node)
{
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index f0c8f9c4005..68ab74d70b9 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -47984,7 +47984,8 @@ cp_parser_omp_context_selector (cp_parser *parser, enum omp_tss_code set,
}
while (1);
break;
- case OMP_TRAIT_PROPERTY_EXPR:
+ case OMP_TRAIT_PROPERTY_DEV_NUM_EXPR:
+ case OMP_TRAIT_PROPERTY_BOOL_EXPR:
/* FIXME: this is bogus, the expression need
not be constant. */
t = cp_parser_constant_expression (parser);
diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index 0af80d54fad..d8cce6922b0 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -5790,19 +5790,39 @@ gfc_match_omp_context_selector (gfc_omp_set_selector *oss)
}
while (1);
break;
- case OMP_TRAIT_PROPERTY_EXPR:
+ case OMP_TRAIT_PROPERTY_DEV_NUM_EXPR:
+ case OMP_TRAIT_PROPERTY_BOOL_EXPR:
if (gfc_match_expr (&otp->expr) != MATCH_YES)
{
gfc