Hi! Most of gimple_build_cond_empty callers call just build2 to prepare condition which is put into GIMPLE_COND, but this one spot has been using incorrectly fold_build2. Now the arguments of the *build2 were already gimplified, but the folding of some conditions can turn say unsigned_var > INT_MAX into (int) unsigned_var < 0 etc. and thus turn the condition into something invalid in gimple, because we only try to regimplify the operands if they refer to some decl which needs to be regimplified (has DECL_VALUE_EXPR on it).
Fixed by also using build2 instead of fold_build2, bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk so far. 2025-11-25 Jakub Jelinek <[email protected]> PR middle-end/120564 * omp-expand.cc (extract_omp_for_update_vars): Use build2 instead of fold_build2 to build argument for gimple_build_cond_empty. * c-c++-common/gomp/pr120564.c: New test. --- gcc/omp-expand.cc.jj 2025-08-26 00:28:03.333960307 +0200 +++ gcc/omp-expand.cc 2025-11-24 14:54:50.425228234 +0100 @@ -3299,7 +3299,7 @@ extract_omp_for_update_vars (struct omp_ if (DECL_P (v) && TREE_ADDRESSABLE (v)) v = force_gimple_operand_gsi (&gsi, v, true, NULL_TREE, false, GSI_CONTINUE_LINKING); - t = fold_build2 (fd->loops[i].cond_code, boolean_type_node, v, t); + t = build2 (fd->loops[i].cond_code, boolean_type_node, v, t); stmt = gimple_build_cond_empty (t); gsi_insert_after (&gsi, stmt, GSI_CONTINUE_LINKING); if (walk_tree (gimple_cond_lhs_ptr (as_a <gcond *> (stmt)), --- gcc/testsuite/c-c++-common/gomp/pr120564.c.jj 2025-11-24 14:56:58.520996923 +0100 +++ gcc/testsuite/c-c++-common/gomp/pr120564.c 2025-11-24 14:56:38.977337354 +0100 @@ -0,0 +1,15 @@ +/* PR middle-end/120564 */ +/* { dg-do compile } */ + +void bar (unsigned long long, unsigned long long, unsigned long long); + +void +foo (void) +{ + unsigned long long v1, v2, v3; +#pragma omp parallel for schedule(static, 32) collapse(3) + for (v1 = 0; v1 < 20; v1 += 2) + for (v2 = __LONG_LONG_MAX__; v2 > __LONG_LONG_MAX__; v2 -= 3) + for (v3 = 10; v3 > 0; v3--) + bar (v1, v2, v3); +} Jakub
