From patchwork Tue Mar 19 08:16:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 87340 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DE2983858418 for ; Tue, 19 Mar 2024 08:17:48 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 14DCD3858CD1 for ; Tue, 19 Mar 2024 08:17:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 14DCD3858CD1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 14DCD3858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710836225; cv=none; b=v5TYqc7CLJRlGczBPZseAYf/ROjDqT+IajTSVIydaIax1pBDd+ss1AqHyHWHOe+JFEaRaJxHMRLiQoNqeNKbF7tEvrof2ocAUgBlCFP0i6yPoUSCpVP6Z64mCLk4x3Igar7MdvUKMUj4Eq7C5XmqQ3QEDrVCMrxBtJijnTpdmik= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710836225; c=relaxed/simple; bh=Nc1mumX1TqXauaTFUHlsO+AifswW1wNQLO8Vg24LhH8=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=IjuXWdp2vrqeXaCwdPaAuId8ORktLz8hrOEuZur/WUkDMf9aQfYN6SRtOCXmTyFoQF1tV6eCZ7dZJ3sr72F7IJysIeB3lNVSP0LU6bE9LIrXlwfUgh57EQwrYAr73t5jxqYSBf3hdPiK2A4I1CrYRXrPGmGa/DKnGKT067zofWQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710836222; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=4LwaDqQV1Buva+EbNtcWEM0+nSTNzwGP+dgXNxy9+JI=; b=UitD7N9Lut0HY6/L6uW6jP43by3ET0VX2UvS22OmxNo1tLpePdaKNVFG/YMShDJwTqzyIl KRZ0ePJ1vzDiRdbQJFO5oYo8+5Pfg6s45UITfwkWQvloa/akQR0qX+Kk5drK9URjiahKo1 jIQTaKN4nivF+7xawCXAkuGoUsnyd1Y= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-310-1A5lHybCMxiKvZQtC8k_tg-1; Tue, 19 Mar 2024 04:16:59 -0400 X-MC-Unique: 1A5lHybCMxiKvZQtC8k_tg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 05EFC28B6AA3; Tue, 19 Mar 2024 08:16:59 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A883D1121312; Tue, 19 Mar 2024 08:16:58 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 42J8Gqhs683598 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 19 Mar 2024 09:16:52 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 42J8GprP683597; Tue, 19 Mar 2024 09:16:51 +0100 Date: Tue, 19 Mar 2024 09:16:51 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Cc: Tobias Burnus Subject: [committed] openmp: Make c_omp_check_loop_binding_exprs diagnostics translatable [PR114364] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Hi! 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. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 2024-03-19 Jakub Jelinek 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. Jakub --- gcc/c-family/c-omp.cc.jj 2024-01-09 13:47:23.132687124 +0100 +++ gcc/c-family/c-omp.cc 2024-03-16 16:51:54.158702954 +0100 @@ -1793,22 +1793,46 @@ check_loop_binding_expr_r (tree *tp, int #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 stm 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 stm 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 stm 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; } }