From patchwork Tue Aug 6 19:52:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerry D X-Patchwork-Id: 1969667 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=hSJm9vXJ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WdkW24Xpbz1ydt for ; Wed, 7 Aug 2024 05:53:00 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9E4BD385C6CD for ; Tue, 6 Aug 2024 19:52:58 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 235063858414; Tue, 6 Aug 2024 19:52:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 235063858414 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 235063858414 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::436 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722973954; cv=none; b=YQ5UbGjv5aJ1RM5mhwNVrUKIBssoyhprinr97Yuv+/PE8aT/X9BsdpxY5C7Pt6z0Lh4X6Z8bfPuyZ0XZSL4u/gO3df4o/gCp/JVxe7EmgqoB0/wpKkcLw7B4kzOJF9zHggNsqeRmhGcq9Ip/7FMLn60z9OfCQB7rlDKDuvRUC0s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722973954; c=relaxed/simple; bh=59anuSgBVtSLFL98XuT1xbxZQK7JAF+rZmBJAw4fW44=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=FMqw8f73mulSlHhLqGbsbWWljm0bNLam1sJEJYoC/8spTLWRirXAoaNLB0HjyYaZ9RiC/idN9u3PTwN1FbUOZhjq6fiNGQcMgFVApVVhavJdSzMyJTIR4XMPZALUMpx+2bI9E52s/U23eRGDqJ7/xMpTrxA9rUX7LT1P18uyIsE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-70d22b6dab0so154891b3a.1; Tue, 06 Aug 2024 12:52:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722973950; x=1723578750; darn=gcc.gnu.org; h=autocrypt:subject:from:cc:to:content-language:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=oudxVZj+DnSZ1oDe7PZ3/zouvocYcHohUxuiOLHKuvo=; b=hSJm9vXJyTKi2fKb1PiUWPJQJ01QyMDk92NY38J+60op8CB5k+FDYISIlPrsWwCjJQ tKOtA7xi4rIiZVofAXP0NKsD+ETtYzPup+WXaMAKYCKMWmMAFL5L3pXg84P+bG65pULX Bq7dEYHfbkO1SQFUjY6hIVgd50XwWSAvIB8EPbbCw09v+jKPcW8hyb2PZ/rGrfiw8Jnl sczaln9twzx3IMNt+aG3rK1YIqWkKPFYMCStPKeJRs6e7y2oFPihwwZqWCSUNhYEvjP0 y5+qa8guB7KtI6nfZR2ldCBF5ar1kwZAKw2q+apAuC+UC6DDoMrS3b+nrJTeYlUqyN4l thZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722973950; x=1723578750; h=autocrypt:subject:from:cc:to:content-language:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=oudxVZj+DnSZ1oDe7PZ3/zouvocYcHohUxuiOLHKuvo=; b=anTGFZbZjBbBFzzIKokrM9ttn8lvBMrSUL+FzDo3paKNpCuxfB0ndQ0i4MMhuzOkxe 23OCxHDhS4kwqBjsVKYA/qXxiZMNqfm8bn+x8YM4qQ0XvlaI3lizGVgDmvIKOcrnS6kz By/8RY3g5I6Wpe/lG1j7p8+vd4w9VsWR58Ap8gpE9Q7KfOdxIOYP1jS13kvZm2cRYl4x nZfXVJhaeq3awgWflLtl57585etT/9Xdiimp3egbeLy2Eii+nylSNEVyvWdUnwsF5slf gOwoaD3a61EN25YHF2lUHix9J6qE39UZQTlsl0XxqrzFpkJHdAkGdeomS6PPhVCH8+Xq ge3g== X-Gm-Message-State: AOJu0YwqS/dVQMcI1jkxJ+FaSk31ACicdCVTGTaxFMQBChpQgBzO4JnL r4ZMR5MCnBGp1G4XR/4IKPEwGUcLNgJ0N6nQzFAwmgkf4CF8i9sibkEtFQ== X-Google-Smtp-Source: AGHT+IEiHTF0zlDCqnsQ94n9lBCojZBj2Ejw9vq7V55e55CwtJA6mFJl1xbC5O6IfXJphJBIWFqnLw== X-Received: by 2002:a05:6a00:1490:b0:70e:acd0:d8b6 with SMTP id d2e1a72fcca58-7106cdde3bbmr12617253b3a.0.1722973950130; Tue, 06 Aug 2024 12:52:30 -0700 (PDT) Received: from [192.168.1.140] ([50.37.177.113]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ecdfffasm7206914b3a.124.2024.08.06.12.52.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 06 Aug 2024 12:52:29 -0700 (PDT) Message-ID: <472e38e3-4106-4b97-aae3-aea2e826d3a0@gmail.com> Date: Tue, 6 Aug 2024 12:52:28 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: gfortran Cc: gcc-patches , Jerry D From: Jerry D Subject: [Patch, Fortran] Bug 109105 - Error-prone format string building in resolve.cc Autocrypt: addr=jvdelisle2@gmail.com; keydata= xjMEY5TlkxYJKwYBBAHaRw8BAQdAyrkRDhmJhSTTlV/50gJLlvliU6/Lm5C9ViKV8T9y1GnN HkplcnJ5IEQgPGp2ZGVsaXNsZTJAZ21haWwuY29tPsKJBBMWCAAxFiEEOFR0TS0390uh8dRV uWXAJaWpwWoFAmOU5ZMCGwMECwkIBwUVCAkKCwUWAgMBAAAKCRC5ZcAlpanBalsJAP4wdCiH 2Of9oZv1QWgZ/AVdbWFM3Fv47/WZQHOXfoZ9HgD6AkXrKeJ+6usST7PEaDJjptaViT1fLiYY V/6XaOKSsgLOOARjlOWTEgorBgEEAZdVAQUBAQdAdA7PczYnl07vnOT9oP/wvvMDd4HP09Zl g3LzwXQJWT8DAQgHwngEGBYIACAWIQQ4VHRNLTf3S6Hx1FW5ZcAlpanBagUCY5TlkwIbDAAK CRC5ZcAlpanBasF/AQCa5WjlsVpLsEiggZyT18MOJNAdeRd7wkGDUrwedHrvawD/cE1H+/Ms L1ZwvQiLfGdx8crigQqWTQyos4kH8Wx82wc= X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Hi all, The attached patch changes all the snprintf calls to regular gfc_error calls to cleanup translation. I introduced a simple macro to facilitate doing the checks that were being done in the bad_op code section. From the description for the call to gfc_extend_expr interfaces are mentioned so I used the CHECK_INTERFACES name for the macro. Regression tested on linux-x86_64. No new test cases. OK for mainline? Backport? Regards, Jerry Author: Jerry DeLisle Date: Tue Aug 6 12:47:30 2024 -0700 Fortran: Eliminate error prone translations. PR fortran/109105 gcc/fortran/ChangeLog: * resolve.cc (CHECK_INTERFACES): New helper macro. (resolve_operator): Replace use of snprintf with gfc_error. diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index 503029364c1..eb3085a05ca 100644 --- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -4137,15 +4137,23 @@ convert_to_numeric (gfc_expr *a, gfc_expr *b) } /* Resolve an operator expression node. This can involve replacing the - operation with a user defined function call. */ + operation with a user defined function call. CHECK_INTERFACES is a + helper macro. */ + +#define CHECK_INTERFACES \ + { \ + match m = gfc_extend_expr (e); \ + if (m == MATCH_YES) \ + return true; \ + if (m == MATCH_ERROR) \ + return false; \ + } static bool resolve_operator (gfc_expr *e) { gfc_expr *op1, *op2; /* One error uses 3 names; additional space for wording (also via gettext). */ - char msg[3*GFC_MAX_SYMBOL_LEN + 1 + 50]; - bool dual_locus_error; bool t = true; /* Reduce stacked parentheses to single pair */ @@ -4195,8 +4203,6 @@ resolve_operator (gfc_expr *e) if (t == false) return false; - dual_locus_error = false; - /* op1 and op2 cannot both be BOZ. */ if (op1 && op1->ts.type == BT_BOZ && op2 && op2->ts.type == BT_BOZ) @@ -4210,9 +4216,9 @@ resolve_operator (gfc_expr *e) if ((op1 && op1->expr_type == EXPR_NULL) || (op2 && op2->expr_type == EXPR_NULL)) { - snprintf (msg, sizeof (msg), - _("Invalid context for NULL() pointer at %%L")); - goto bad_op; + CHECK_INTERFACES + gfc_error ("Invalid context for NULL() pointer at %L", &e->where); + return false; } switch (e->value.op.op) @@ -4227,10 +4233,10 @@ resolve_operator (gfc_expr *e) break; } - snprintf (msg, sizeof (msg), - _("Operand of unary numeric operator %%<%s%%> at %%L is %s"), - gfc_op2string (e->value.op.op), gfc_typename (e)); - goto bad_op; + CHECK_INTERFACES + gfc_error ("Operand of unary numeric operator %<%s%> at %L is %s", + gfc_op2string (e->value.op.op), &e->where, gfc_typename (e)); + return false; case INTRINSIC_PLUS: case INTRINSIC_MINUS: @@ -4244,10 +4250,10 @@ resolve_operator (gfc_expr *e) Defer to a possibly overloading user-defined operator. */ if (!gfc_op_rank_conformable (op1, op2)) { - dual_locus_error = true; - snprintf (msg, sizeof (msg), - _("Inconsistent ranks for operator at %%L and %%L")); - goto bad_op; + CHECK_INTERFACES + gfc_error ("Inconsistent ranks for operator at %L and %L", + &op1->where, &op2->where); + return false; } gfc_type_convert_binary (e, 1); @@ -4255,16 +4261,21 @@ resolve_operator (gfc_expr *e) } if (op1->ts.type == BT_DERIVED || op2->ts.type == BT_DERIVED) - snprintf (msg, sizeof (msg), - _("Unexpected derived-type entities in binary intrinsic " - "numeric operator %%<%s%%> at %%L"), - gfc_op2string (e->value.op.op)); + { + CHECK_INTERFACES + gfc_error ("Unexpected derived-type entities in binary intrinsic " + "numeric operator %<%s%> at %L", + gfc_op2string (e->value.op.op), &e->where); + return false; + } else - snprintf (msg, sizeof(msg), - _("Operands of binary numeric operator %%<%s%%> at %%L are %s/%s"), - gfc_op2string (e->value.op.op), gfc_typename (op1), - gfc_typename (op2)); - goto bad_op; + { + CHECK_INTERFACES + gfc_error ("Operands of binary numeric operator %<%s%> at %L are %s/%s", + gfc_op2string (e->value.op.op), &e->where, gfc_typename (op1), + gfc_typename (op2)); + return false; + } case INTRINSIC_CONCAT: if (op1->ts.type == BT_CHARACTER && op2->ts.type == BT_CHARACTER @@ -4275,10 +4286,10 @@ resolve_operator (gfc_expr *e) break; } - snprintf (msg, sizeof (msg), - _("Operands of string concatenation operator at %%L are %s/%s"), - gfc_typename (op1), gfc_typename (op2)); - goto bad_op; + CHECK_INTERFACES + gfc_error ("Operands of string concatenation operator at %L are %s/%s", + &e->where, gfc_typename (op1), gfc_typename (op2)); + return false; case INTRINSIC_AND: case INTRINSIC_OR: @@ -4318,12 +4329,11 @@ resolve_operator (gfc_expr *e) goto simplify_op; } - snprintf (msg, sizeof (msg), - _("Operands of logical operator %%<%s%%> at %%L are %s/%s"), - gfc_op2string (e->value.op.op), gfc_typename (op1), - gfc_typename (op2)); - - goto bad_op; + CHECK_INTERFACES + gfc_error ("Operands of logical operator %<%s%> at %L are %s/%s", + gfc_op2string (e->value.op.op), &e->where, gfc_typename (op1), + gfc_typename (op2)); + return false; case INTRINSIC_NOT: /* Logical ops on integers become bitwise ops with -fdec. */ @@ -4342,9 +4352,10 @@ resolve_operator (gfc_expr *e) break; } - snprintf (msg, sizeof (msg), _("Operand of .not. operator at %%L is %s"), - gfc_typename (op1)); - goto bad_op; + CHECK_INTERFACES + gfc_error ("Operand of .not. operator at %L is %s", &e->where, + gfc_typename (op1)); + return false; case INTRINSIC_GT: case INTRINSIC_GT_OS: @@ -4356,8 +4367,9 @@ resolve_operator (gfc_expr *e) case INTRINSIC_LE_OS: if (op1->ts.type == BT_COMPLEX || op2->ts.type == BT_COMPLEX) { - strcpy (msg, _("COMPLEX quantities cannot be compared at %L")); - goto bad_op; + CHECK_INTERFACES + gfc_error ("COMPLEX quantities cannot be compared at %L", &e->where); + return false; } /* Fall through. */ @@ -4427,10 +4439,10 @@ resolve_operator (gfc_expr *e) Defer to a possibly overloading user-defined operator. */ if (!gfc_op_rank_conformable (op1, op2)) { - dual_locus_error = true; - snprintf (msg, sizeof (msg), - _("Inconsistent ranks for operator at %%L and %%L")); - goto bad_op; + CHECK_INTERFACES + gfc_error ("Inconsistent ranks for operator at %L and %L", + &op1->where, &op2->where); + return false; } gfc_type_convert_binary (e, 1); @@ -4464,18 +4476,22 @@ resolve_operator (gfc_expr *e) } if (op1->ts.type == BT_LOGICAL && op2->ts.type == BT_LOGICAL) - snprintf (msg, sizeof (msg), - _("Logicals at %%L must be compared with %s instead of %s"), - (e->value.op.op == INTRINSIC_EQ - || e->value.op.op == INTRINSIC_EQ_OS) - ? ".eqv." : ".neqv.", gfc_op2string (e->value.op.op)); + { + CHECK_INTERFACES + gfc_error ("Logicals at %L must be compared with %s instead of %s", + &e->where, + (e->value.op.op == INTRINSIC_EQ || e->value.op.op == INTRINSIC_EQ_OS) + ? ".eqv." : ".neqv.", gfc_op2string (e->value.op.op)); + } else - snprintf (msg, sizeof (msg), - _("Operands of comparison operator %%<%s%%> at %%L are %s/%s"), - gfc_op2string (e->value.op.op), gfc_typename (op1), - gfc_typename (op2)); + { + CHECK_INTERFACES + gfc_error ("Operands of comparison operator %<%s%> at %L are %s/%s", + gfc_op2string (e->value.op.op), &e->where, gfc_typename (op1), + gfc_typename (op2)); + } - goto bad_op; + return false; case INTRINSIC_USER: if (e->value.op.uop->op == NULL) @@ -4483,28 +4499,29 @@ resolve_operator (gfc_expr *e) const char *name = e->value.op.uop->name; const char *guessed; guessed = lookup_uop_fuzzy (name, e->value.op.uop->ns->uop_root); + CHECK_INTERFACES if (guessed) - snprintf (msg, sizeof (msg), - _("Unknown operator %%<%s%%> at %%L; did you mean " - "%%<%s%%>?"), name, guessed); + gfc_error ("Unknown operator %<%s%> at %L; did you mean " + "%<%s%>?", name, &e->where, guessed); else - snprintf (msg, sizeof (msg), _("Unknown operator %%<%s%%> at %%L"), - name); + gfc_error ("Unknown operator %<%s%> at %L", name, &e->where); } else if (op2 == NULL) - snprintf (msg, sizeof (msg), - _("Operand of user operator %%<%s%%> at %%L is %s"), - e->value.op.uop->name, gfc_typename (op1)); + { + CHECK_INTERFACES + gfc_error ("Operand of user operator %<%s%> at %L is %s", + e->value.op.uop->name, &e->where, gfc_typename (op1)); + } else { - snprintf (msg, sizeof (msg), - _("Operands of user operator %%<%s%%> at %%L are %s/%s"), - e->value.op.uop->name, gfc_typename (op1), - gfc_typename (op2)); e->value.op.uop->op->sym->attr.referenced = 1; + CHECK_INTERFACES + gfc_error ("Operands of user operator %<%s%> at %L are %s/%s", + e->value.op.uop->name, &e->where, gfc_typename (op1), + gfc_typename (op2)); } - goto bad_op; + return false; case INTRINSIC_PARENTHESES: e->ts = op1->ts; @@ -4582,10 +4599,10 @@ resolve_operator (gfc_expr *e) e->rank = 0; /* Try user-defined operators, and otherwise throw an error. */ - dual_locus_error = true; - snprintf (msg, sizeof (msg), - _("Inconsistent ranks for operator at %%L and %%L")); - goto bad_op; + CHECK_INTERFACES + gfc_error ("Inconsistent ranks for operator at %L and %L", + &op1->where, &op2->where); + return false; } } @@ -4620,23 +4637,6 @@ simplify_op: t = true; } return t; - -bad_op: - - { - match m = gfc_extend_expr (e); - if (m == MATCH_YES) - return true; - if (m == MATCH_ERROR) - return false; - } - - if (dual_locus_error) - gfc_error (msg, &op1->where, &op2->where); - else - gfc_error (msg, &e->where); - - return false; }