aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2024-03-19 09:10:26 +0100
committerJakub Jelinek <jakub@redhat.com>2024-03-19 09:10:26 +0100
commit8959ab63f1881a8a4b1921b946d4ea3986bf1063 (patch)
treebf3a4ccf40a9608ef84efba8cdf1bcb8baa5150e /gcc
parent94c3508c5a14d1948fe3bffa9e16c6f3d9c2836a (diff)
downloadgcc-8959ab63f1881a8a4b1921b946d4ea3986bf1063.zip
gcc-8959ab63f1881a8a4b1921b946d4ea3986bf1063.tar.gz
gcc-8959ab63f1881a8a4b1921b946d4ea3986bf1063.tar.bz2
openmp: Make c_omp_check_loop_binding_exprs diagnostics translatable [PR114364]
c_omp_check_loop_binding_exprs with check_loop_binding_expr was composing diagnostics from a format string with %s that provided additional words (but not keywords). That is a big no no for translations, both because the translator can't choose a different word order and because the %s part wasn't translated at all (would need to use _("...") to get translated), so this patch rewrites it such that the whole messages are in the format strings. 2024-03-19 Jakub Jelinek <jakub@redhat.com> PR c/114364 * c-omp.cc (enum check_loop_binding_expr_ctx): New type. (check_loop_binding_expr): Remove context argument, add ctx argument with check_loop_binding_expr_ctx type at the end. Don't create diagnostic message from multiple pieces. (c_omp_check_loop_binding_exprs): Adjust callers.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/c-family/c-omp.cc51
1 files changed, 39 insertions, 12 deletions
diff --git a/gcc/c-family/c-omp.cc b/gcc/c-family/c-omp.cc
index 5117022..c0e02aa 100644
--- a/gcc/c-family/c-omp.cc
+++ b/gcc/c-family/c-omp.cc
@@ -1793,22 +1793,46 @@ check_loop_binding_expr_r (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED,
#define LOCATION_OR(loc1, loc2) \
((loc1) != UNKNOWN_LOCATION ? (loc1) : (loc2))
+enum check_loop_binding_expr_ctx {
+ CHECK_LOOP_BINDING_EXPR_CTX_LOOP_VAR,
+ CHECK_LOOP_BINDING_EXPR_CTX_IN_INIT,
+ CHECK_LOOP_BINDING_EXPR_CTX_END_TEST,
+ CHECK_LOOP_BINDING_EXPR_CTX_INCR
+};
+
/* Check a single expression EXPR for references to variables bound in
intervening code in BODY. Return true if ok, otherwise give an error
referencing CONTEXT and return false. Use LOC for the error message
if EXPR doesn't have one. */
static bool
-check_loop_binding_expr (tree expr, tree body, const char *context,
- location_t loc)
+check_loop_binding_expr (tree expr, tree body, location_t loc,
+ check_loop_binding_expr_ctx ctx)
{
tree bad = walk_tree (&expr, check_loop_binding_expr_r, (void *)&body, NULL);
if (bad)
{
location_t eloc = EXPR_LOCATION (expr);
- error_at (LOCATION_OR (eloc, loc),
- "variable %qD used %s is bound "
- "in intervening code", bad, context);
+ eloc = LOCATION_OR (eloc, loc);
+ switch (ctx)
+ {
+ case CHECK_LOOP_BINDING_EXPR_CTX_LOOP_VAR:
+ error_at (eloc, "variable %qD used as loop variable is bound "
+ "in intervening code", bad);
+ break;
+ case CHECK_LOOP_BINDING_EXPR_CTX_IN_INIT:
+ error_at (eloc, "variable %qD used in initializer is bound "
+ "in intervening code", bad);
+ break;
+ case CHECK_LOOP_BINDING_EXPR_CTX_END_TEST:
+ error_at (eloc, "variable %qD used in end test is bound "
+ "in intervening code", bad);
+ break;
+ case CHECK_LOOP_BINDING_EXPR_CTX_INCR:
+ error_at (eloc, "variable %qD used in increment expression is bound "
+ "in intervening code", bad);
+ break;
+ }
return false;
}
return true;
@@ -1839,13 +1863,15 @@ c_omp_check_loop_binding_exprs (tree stmt, vec<tree> *orig_inits)
e = TREE_OPERAND (init, 1);
eloc = LOCATION_OR (EXPR_LOCATION (init), loc);
- if (!check_loop_binding_expr (decl, body, "as loop variable", eloc))
+ if (!check_loop_binding_expr (decl, body, eloc,
+ CHECK_LOOP_BINDING_EXPR_CTX_LOOP_VAR))
ok = false;
- if (!check_loop_binding_expr (e, body, "in initializer", eloc))
+ if (!check_loop_binding_expr (e, body, eloc,
+ CHECK_LOOP_BINDING_EXPR_CTX_IN_INIT))
ok = false;
if (orig_init
- && !check_loop_binding_expr (orig_init, body,
- "in initializer", eloc))
+ && !check_loop_binding_expr (orig_init, body, eloc,
+ CHECK_LOOP_BINDING_EXPR_CTX_IN_INIT))
ok = false;
/* INCR and/or COND may be null if this is a template with a
@@ -1859,7 +1885,8 @@ c_omp_check_loop_binding_exprs (tree stmt, vec<tree> *orig_inits)
e = TREE_OPERAND (cond, 0);
else
e = cond;
- if (!check_loop_binding_expr (e, body, "in end test", eloc))
+ if (!check_loop_binding_expr (e, body, eloc,
+ CHECK_LOOP_BINDING_EXPR_CTX_END_TEST))
ok = false;
}
@@ -1870,8 +1897,8 @@ c_omp_check_loop_binding_exprs (tree stmt, vec<tree> *orig_inits)
increment/decrement. We don't have to check the latter
since there are no operands besides the iteration variable. */
if (TREE_CODE (incr) == MODIFY_EXPR
- && !check_loop_binding_expr (TREE_OPERAND (incr, 1), body,
- "in increment expression", eloc))
+ && !check_loop_binding_expr (TREE_OPERAND (incr, 1), body, eloc,
+ CHECK_LOOP_BINDING_EXPR_CTX_INCR))
ok = false;
}
}