aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Burnus <tburnus@baylibre.com>2025-11-05 12:51:37 +0100
committerTobias Burnus <tburnus@baylibre.com>2025-11-05 12:51:37 +0100
commitdd62c97f1227d36770ff2e18411038f147e0bb5f (patch)
tree25058549dfa0bb5a9f17ec103dfcbf5ff7dcfffc
parent470411f44f51d9ef85bfcf3a8f9cb25344dd243f (diff)
downloadgcc-dd62c97f1227d36770ff2e18411038f147e0bb5f.zip
gcc-dd62c97f1227d36770ff2e18411038f147e0bb5f.tar.gz
gcc-dd62c97f1227d36770ff2e18411038f147e0bb5f.tar.bz2
OpenMP/Fortran: Fix skipping unmatchable metadirectives [PR122570]
Fix a bug in the removal code of always false variants in metadirectives. PR fortran/122570 gcc/fortran/ChangeLog: * openmp.cc (resolve_omp_metadirective): Fix 'skip' of never matchable metadirective variants. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/pr122570.f: New test.
-rw-r--r--gcc/fortran/openmp.cc13
-rw-r--r--gcc/testsuite/gfortran.dg/gomp/pr122570.f29
2 files changed, 38 insertions, 4 deletions
diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index f5db9a8..770bc5b 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -12320,6 +12320,7 @@ static void
resolve_omp_metadirective (gfc_code *code, gfc_namespace *ns)
{
gfc_omp_variant *variant = code->ext.omp_variants;
+ gfc_omp_variant *prev_variant = variant;
while (variant)
{
@@ -12333,15 +12334,19 @@ resolve_omp_metadirective (gfc_code *code, gfc_namespace *ns)
as the 'otherwise' clause should always match. */
if (variant == code->ext.omp_variants && !variant->next)
break;
- if (variant == code->ext.omp_variants)
- code->ext.omp_variants = variant->next;
gfc_omp_variant *tmp = variant;
- variant = variant->next;
+ if (variant == code->ext.omp_variants)
+ variant = prev_variant = code->ext.omp_variants = variant->next;
+ else
+ variant = prev_variant->next = variant->next;
gfc_free_omp_set_selector_list (tmp->selectors);
free (tmp);
}
else
- variant = variant->next;
+ {
+ prev_variant = variant;
+ variant = variant->next;
+ }
}
/* Replace metadirective by its body if only 'nothing' remains. */
if (!code->ext.omp_variants->next && code->ext.omp_variants->stmt == ST_NONE)
diff --git a/gcc/testsuite/gfortran.dg/gomp/pr122570.f b/gcc/testsuite/gfortran.dg/gomp/pr122570.f
new file mode 100644
index 0000000..9897cc6
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/gomp/pr122570.f
@@ -0,0 +1,29 @@
+! { dg-do compile }
+! { dg-additional-options "-Wall" }
+
+! PR fortran/122570
+
+ SUBROUTINE INITAL
+ implicit none (type, external)
+ integer :: j, n
+ n = 5
+!$omp metadirective &
+!$omp& when(user={condition(.true.)}: target teams &
+!$omp& distribute parallel do) &
+!$omp& when(user={condition(.false.)}: target teams &
+!$omp& distribute parallel do)
+ DO J=1,N
+ END DO
+ END SUBROUTINE
+
+ SUBROUTINE CALC3
+ implicit none (type, external)
+ integer :: i, m
+ m = 99
+!$omp metadirective
+!$omp& when(user={condition(.false.)}:
+!$omp& simd)
+ DO 301 I=1,M
+ 301 CONTINUE
+ 300 CONTINUE ! { dg-warning "Label 300 at .1. defined but not used \\\[-Wunused-label\\\]" }
+ END SUBROUTINE