Some janitorial fixes found by UBSAN and cppcheck and silencing a bogus declare-variant' selector error for C++ until it is properly fixed.
Committed as r17-5411-g8d5bc2c194466b. Tobias
commit 8d5bc2c194466bfc90bc93b88a26081cb1e4d677 Author: Tobias Burnus <[email protected]> Date: Tue Oct 20 15:41:37 2026 +0200 OpenMP simd's 'scaled': Fortran - janitorial fixes | gomp/declare-variant-7.c: Add xfail for C++ [PR128032/127995/127734] Silence UBSAN warning for uninitalized memory that is only written to but is also passed around (for the unreachable reading mode path) by '{}' initializing the gfc_typespec variable in fortran/module.cc. Fix safelen >= simdlen checking by correctly checking both expressions for const-scalar-int-ness in fortran/openmp.cc. As for gomp/declare-variant-5.c in commit r17-5124-g36d99b4873e675, do the same for ...-7.c: Commit r17-5084-g9759f4fa7d0177 fixed some issues related to the simd trait, which in turn causes this testcase to fail with C++. This commit silents those with dg-bogus + xfail until properly fixed, cf. PR. gcc/fortran/ChangeLog: PR fortran/128032 PR fortran/127995 * module.cc (mio_omp_declare_simd_clauses): {} initialize a var. * openmp.cc (resolve_omp_clauses): Fix safelen >= simdlen const-scalar-int-ness check. gcc/testsuite/ChangeLog: PR c++/127734 * c-c++-common/gomp/declare-variant-7.c: Add dg-bogus + xfail to silence C++ fails. --- gcc/fortran/module.cc | 2 +- gcc/fortran/openmp.cc | 5 +++-- gcc/testsuite/c-c++-common/gomp/declare-variant-7.c | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/gcc/fortran/module.cc b/gcc/fortran/module.cc index ea86a091f69..70d231dcf6a 100644 --- a/gcc/fortran/module.cc +++ b/gcc/fortran/module.cc @@ -4486,7 +4486,7 @@ mio_omp_declare_simd_clauses (gfc_omp_clauses **clausesp) break; case 6: { - gfc_typespec ts; + gfc_typespec ts = {}; mio_typespec (&ts); clauses->simdlen_type.type = ts.type; clauses->simdlen_type.kind = ts.kind; diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc index 98adc8e0a84..ba7f3c5ea24 100644 --- a/gcc/fortran/openmp.cc +++ b/gcc/fortran/openmp.cc @@ -11823,10 +11823,11 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses *omp_clauses, we need to repeat some const check as the program still continues after the error diagnostic above. */ if (omp_clauses->safelen_expr && omp_clauses->simdlen_expr - && omp_clauses->safelen_expr->expr_type == EXPR_CONSTANT - && omp_clauses->simdlen_expr->ts.type == BT_INTEGER && omp_clauses->simdlen_expr->expr_type == EXPR_CONSTANT + && omp_clauses->safelen_expr->rank == 0 + && omp_clauses->simdlen_expr->rank == 0 + && omp_clauses->safelen_expr->ts.type == BT_INTEGER && omp_clauses->simdlen_expr->ts.type == BT_INTEGER && mpz_cmp (omp_clauses->safelen_expr->value.integer, omp_clauses->simdlen_expr->value.integer) < 0) diff --git a/gcc/testsuite/c-c++-common/gomp/declare-variant-7.c b/gcc/testsuite/c-c++-common/gomp/declare-variant-7.c index 4eebcbcd1d2..53e69de1158 100644 --- a/gcc/testsuite/c-c++-common/gomp/declare-variant-7.c +++ b/gcc/testsuite/c-c++-common/gomp/declare-variant-7.c @@ -35,3 +35,20 @@ int f14 (int x, int q); int f15 (int x, int q); #pragma omp declare variant (f3) match (construct={simd(inbranch, simdlen (5-1) linear (q:4-3))}) /* { dg-error "clauses in 'simd' trait should be separated by ','" } */ int f16 (int x, int q); + +// See PR middle-end/127850 for several issues related to handling simdlen clauses in the context selector, +// those below are only the tip of the iceberg: + +// { dg-bogus "cannot convert 'float' to '__v4sf' {aka '__vector\\(4\\) float'}" "" { xfail c++ } 12 } +// { dg-bogus "cannot convert 'float' to '__v4sf' {aka '__vector\\(4\\) float'}" "" { xfail c++ } 14 } +// { dg-bogus "cannot convert 'float' to '__v4sf' {aka '__vector\\(4\\) float'}" "" { xfail c++ } 16 } +// { dg-bogus "cannot convert 'float' to '__v4sf' {aka '__vector\\(4\\) float'}" "" { xfail c++ } 18 } +// { dg-bogus "cannot convert 'float' to '__v4sf' {aka '__vector\\(4\\) float'}" "" { xfail c++ } 20 } +// { dg-bogus "cannot convert 'float' to '__v8sf' {aka '__vector\\(8\\) float'}" "" { xfail c++ } 22 } +// { dg-bogus "cannot convert 'float' to '__v8sf' {aka '__vector\\(8\\) float'}" "" { xfail c++ } 24 } +// { dg-bogus "cannot convert 'float' to '__v8sf' {aka '__vector\\(8\\) float'}" "" { xfail c++ } 26 } +// { dg-bogus "cannot convert 'int' to '__v4si' {aka '__vector\\(4\\) int'}" "" { xfail c++ } 28 } +// { dg-bogus "cannot convert 'int' to '__v4si' {aka '__vector\\(4\\) int'}" "" { xfail c++ } 30 } +// { dg-bogus "cannot convert 'int' to '__v4si' {aka '__vector\\(4\\) int'}" "" { xfail c++ } 32 } +// { dg-bogus "cannot convert 'int' to '__v4si' {aka '__vector\\(4\\) int'}" "" { xfail c++ } 34 } +// { dg-bogus "cannot convert 'int' to '__v4si' {aka '__vector\\(4\\) int'}" "" { xfail c++ } 36 }
