public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-9534] openmp: Make c_omp_check_loop_binding_exprs diagnostics translatable [PR114364]
@ 2024-03-19  8:13 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2024-03-19  8:13 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:8959ab63f1881a8a4b1921b946d4ea3986bf1063

commit r14-9534-g8959ab63f1881a8a4b1921b946d4ea3986bf1063
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Mar 19 09:10:26 2024 +0100

    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.

Diff:
---
 gcc/c-family/c-omp.cc | 51 +++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 39 insertions(+), 12 deletions(-)

diff --git a/gcc/c-family/c-omp.cc b/gcc/c-family/c-omp.cc
index 5117022e330..c0e02aa422f 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;
 	}
     }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-03-19  8:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-19  8:13 [gcc r14-9534] openmp: Make c_omp_check_loop_binding_exprs diagnostics translatable [PR114364] Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).