From patchwork Fri Nov 4 13:44:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lewis Hyatt X-Patchwork-Id: 15526 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp412255wru; Fri, 4 Nov 2022 06:47:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6I6sPq0xPab4d7thKNriGo+gFgnX3YJlr104UQfNJa+wJ7cCnxn+aOBQDy144jAZxkSHft X-Received: by 2002:a05:6402:530d:b0:463:b0cb:50e5 with SMTP id eo13-20020a056402530d00b00463b0cb50e5mr19896533edb.45.1667569636699; Fri, 04 Nov 2022 06:47:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667569636; cv=none; d=google.com; s=arc-20160816; b=bIQ6IvuNlvcyJuX4TkN2pz+Ws9OlDtMl/b9L+K3jhkMi6gs13Gwe3UT6AC7mBhNmkt BcniVAMovVY4BQTAWdHxbid32XtUSeU8XRwLjYIDV4Ja+Do88VatBfldOR7DFsryvhM/ OTsviRJ6+E+F827xHpOSZAL2w4/hm3Zqlaoort1NEhOTBrpHr5xZN0TaURVsmYmDQ1PK sWszHlbEWM9SbOUNdMH4QEUf/YAbJuIFYszZKk4r8xoYTUXm7DakG5cUktYeJLHWuUem ozRkpUYcjIUkNX1l9casxaFnlaCpzcNlSknAHffhfwWjw8xOfF1AtzEwo/W32YjEJo+Y QmPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=EvvRB9QW4440AE+ZhZb6QXiqc9HCdhzhjJeV9OLjNIw=; b=XCBMTHhGRXdELDI44VZMEZl7GO8Ic94Z8AbXHUxCGtr3bK/yDSMfYVJCEB/7ivrsml ynBmDzZwkAVGXqro5CQYZmQkgXxjexFHatCLXlngFazzALURyY2d60oTpjZmyQIzbeP+ CmXo/r48zXQ/SBcO352qQTSpLQg7oeo9AAxkOIpr4LnENbuhxVr2nxEU0rDL7OCfVSD7 UIbzuHqfIN3WIhVL82rmo8lTAK5KIiV6DzLUUOCSZ06vnWNs9J7DeWO1gP9WtdfTvZMy uo0YNVVyooYuQE1x2qeD+B01lGRpLejDWfbFkekF9i4trTCo3qUH2eiuSq5X3eQKn06S CRHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FpC6j3tY; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id dd11-20020a1709069b8b00b0079e1916c11asi5642955ejc.703.2022.11.04.06.47.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 06:47:16 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FpC6j3tY; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1835A3857359 for ; Fri, 4 Nov 2022 13:46:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1835A3857359 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667569587; bh=EvvRB9QW4440AE+ZhZb6QXiqc9HCdhzhjJeV9OLjNIw=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=FpC6j3tY1nkaPa522D5j6staf9O1eNkc0g89sorN5iW/Vs3V2qzjNDcHCmtnl96Vt 0BXEiMkSfhnchUZXkPKkRIWYq0TgvvT0z4wOJxCPHSwrZOHU4TeD1MOExdlnw2nrQk UCSJm3O639Xmrvpo/aAE+I0qObtdbj8lWpek8cR8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qt1-x831.google.com (mail-qt1-x831.google.com [IPv6:2607:f8b0:4864:20::831]) by sourceware.org (Postfix) with ESMTPS id 3AAF73858428 for ; Fri, 4 Nov 2022 13:44:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3AAF73858428 Received: by mail-qt1-x831.google.com with SMTP id h21so3035521qtu.2 for ; Fri, 04 Nov 2022 06:44:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EvvRB9QW4440AE+ZhZb6QXiqc9HCdhzhjJeV9OLjNIw=; b=B4fSpgnnIV9qthVDa/CF8WXIEeoUK5Dbp3AyLC6QvzVmUe37QexxYD3Ufq0he72qjq 3mSPNPT+bhsIShrPpqp97OprAxM/kKwNyf8T2vXRY/ZbSu08FS4RR9K/oCH9qXSP0QQy ERccm24ZJHpGcvdJIFlhq10PYaJaL/ikd55uJoiQ/6WGSZwBRw0WReJPjcpFsaDGT3OU wFqrly3k6fhKumrFC7/n8M22mGBlgCezFqcovQ9uXHrrk6h0Pgk4+hw06W6Idem/XJwM TrF/tzE5r0xlENDaF7sbReElThXo5arMBvYp/wjIXNGwPVpwQy+Yz7ME+ikjDLu0b6y9 m64Q== X-Gm-Message-State: ACrzQf3u6dzS9EI6YEmC0+PExqvVkOo3TFqLT3Sf06PIYupwD2Na0IZC 2TXKXLP1TxWOqaox8+/68kRXVuKifDU= X-Received: by 2002:ac8:5902:0:b0:39c:e440:6adb with SMTP id 2-20020ac85902000000b0039ce4406adbmr29352310qty.18.1667569482512; Fri, 04 Nov 2022 06:44:42 -0700 (PDT) Received: from localhost.localdomain (96-67-140-173-static.hfc.comcastbusiness.net. [96.67.140.173]) by smtp.gmail.com with ESMTPSA id ey21-20020a05622a4c1500b003988b3d5280sm2470577qtb.70.2022.11.04.06.44.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 06:44:41 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/6] diagnostics: Use an inline function rather than hardcoding string Date: Fri, 4 Nov 2022 09:44:10 -0400 Message-Id: <65bfbf319942664358737a1d9d9103f7304199d0.1667514153.git.lhyatt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-3038.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Lewis Hyatt via Gcc-patches From: Lewis Hyatt Reply-To: Lewis Hyatt Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748573499222994061?= X-GMAIL-MSGID: =?utf-8?q?1748573499222994061?= The string "" is hard-coded in several places throughout the diagnostics code, and in some of those places, it is used incorrectly with respect to internationalization. (Comparing a translated string to an untranslated string.) The error is not currently observable in any output GCC actually produces, hence no testcase added here, but it's worth fixing, and also, I am shortly going to add a new such string and want to avoid hardcoding that one in similar places. gcc/c-family/ChangeLog: * c-opts.cc (c_finish_options): Use special_fname_builtin () rather than a hard-coded string. gcc/ChangeLog: * diagnostic.cc (diagnostic_get_location_text): Use special_fname_builtin () rather than a hardcoded string (which was also incorrectly left untranslated previously.) * input.cc (special_fname_builtin): New function. (expand_location_1): Use special_fname_builtin () rather than a hard-coded string. (test_builtins): Likewise. * input.h (special_fname_builtin): Declare. gcc/fortran/ChangeLog: * cpp.cc (gfc_cpp_init): Use special_fname_builtin () rather than a hardcoded string (which was also incorrectly left untranslated previously.) * error.cc (gfc_diagnostic_build_locus_prefix): Likewise. * f95-lang.cc (gfc_init): Likewise. --- gcc/c-family/c-opts.cc | 2 +- gcc/diagnostic.cc | 2 +- gcc/fortran/cpp.cc | 2 +- gcc/fortran/error.cc | 4 ++-- gcc/fortran/f95-lang.cc | 2 +- gcc/input.cc | 10 ++++++++-- gcc/input.h | 3 +++ 7 files changed, 17 insertions(+), 8 deletions(-) diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc index 32b929e3ece..521797fb7eb 100644 --- a/gcc/c-family/c-opts.cc +++ b/gcc/c-family/c-opts.cc @@ -1476,7 +1476,7 @@ c_finish_options (void) { const line_map_ordinary *bltin_map = linemap_check_ordinary (linemap_add (line_table, LC_RENAME, 0, - _(""), 0)); + special_fname_builtin (), 0)); cb_file_change (parse_in, bltin_map); linemap_line_start (line_table, 0, 1); diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc index 22f7b0b6d6e..7c7ee6da746 100644 --- a/gcc/diagnostic.cc +++ b/gcc/diagnostic.cc @@ -470,7 +470,7 @@ diagnostic_get_location_text (diagnostic_context *context, const char *file = s.file ? s.file : progname; int line = 0; int col = -1; - if (strcmp (file, N_(""))) + if (strcmp (file, special_fname_builtin ())) { line = s.line; if (context->show_column) diff --git a/gcc/fortran/cpp.cc b/gcc/fortran/cpp.cc index 364bd0d2a85..0b5755edbb4 100644 --- a/gcc/fortran/cpp.cc +++ b/gcc/fortran/cpp.cc @@ -605,7 +605,7 @@ gfc_cpp_init (void) if (gfc_option.flag_preprocessed) return; - cpp_change_file (cpp_in, LC_RENAME, _("")); + cpp_change_file (cpp_in, LC_RENAME, special_fname_builtin ()); if (!gfc_cpp_option.no_predefined) { /* Make sure all of the builtins about to be declared have diff --git a/gcc/fortran/error.cc b/gcc/fortran/error.cc index c9d6edbb923..214fb78ba7b 100644 --- a/gcc/fortran/error.cc +++ b/gcc/fortran/error.cc @@ -1147,7 +1147,7 @@ gfc_diagnostic_build_locus_prefix (diagnostic_context *context, const char *locus_ce = colorize_stop (pp_show_color (pp)); return (s.file == NULL ? build_message_string ("%s%s:%s", locus_cs, progname, locus_ce ) - : !strcmp (s.file, N_("")) + : !strcmp (s.file, special_fname_builtin ()) ? build_message_string ("%s%s:%s", locus_cs, s.file, locus_ce) : context->show_column ? build_message_string ("%s%s:%d:%d:%s", locus_cs, s.file, s.line, @@ -1167,7 +1167,7 @@ gfc_diagnostic_build_locus_prefix (diagnostic_context *context, return (s.file == NULL ? build_message_string ("%s%s:%s", locus_cs, progname, locus_ce ) - : !strcmp (s.file, N_("")) + : !strcmp (s.file, special_fname_builtin ()) ? build_message_string ("%s%s:%s", locus_cs, s.file, locus_ce) : context->show_column ? build_message_string ("%s%s:%d:%d-%d:%s", locus_cs, s.file, s.line, diff --git a/gcc/fortran/f95-lang.cc b/gcc/fortran/f95-lang.cc index a6750bea787..0d83f3f8b69 100644 --- a/gcc/fortran/f95-lang.cc +++ b/gcc/fortran/f95-lang.cc @@ -259,7 +259,7 @@ gfc_init (void) if (!gfc_cpp_enabled ()) { linemap_add (line_table, LC_ENTER, false, gfc_source_file, 1); - linemap_add (line_table, LC_RENAME, false, "", 0); + linemap_add (line_table, LC_RENAME, false, special_fname_builtin (), 0); } else gfc_cpp_init_0 (); diff --git a/gcc/input.cc b/gcc/input.cc index a28abfac5ac..483cb6e940d 100644 --- a/gcc/input.cc +++ b/gcc/input.cc @@ -29,6 +29,12 @@ along with GCC; see the file COPYING3. If not see #define HAVE_ICONV 0 #endif +const char * +special_fname_builtin () +{ + return _(""); +} + /* Input charset configuration. */ static const char *default_charset_callback (const char *) { @@ -275,7 +281,7 @@ expand_location_1 (location_t loc, xloc.data = block; if (loc <= BUILTINS_LOCATION) - xloc.file = loc == UNKNOWN_LOCATION ? NULL : _(""); + xloc.file = loc == UNKNOWN_LOCATION ? NULL : special_fname_builtin (); return xloc; } @@ -2102,7 +2108,7 @@ test_unknown_location () static void test_builtins () { - assert_loceq (_(""), 0, 0, BUILTINS_LOCATION); + assert_loceq (special_fname_builtin (), 0, 0, BUILTINS_LOCATION); ASSERT_PRED1 (is_location_from_builtin_token, BUILTINS_LOCATION); } diff --git a/gcc/input.h b/gcc/input.h index 11c571d076f..0b23e66e53b 100644 --- a/gcc/input.h +++ b/gcc/input.h @@ -32,6 +32,9 @@ extern GTY(()) class line_maps *saved_line_table; /* The location for declarations in "" */ #define BUILTINS_LOCATION ((location_t) 1) +/* Returns the translated string referring to the special location. */ +const char *special_fname_builtin (); + /* line-map.cc reserves RESERVED_LOCATION_COUNT to the user. Ensure both UNKNOWN_LOCATION and BUILTINS_LOCATION fit into that. */ STATIC_ASSERT (BUILTINS_LOCATION < RESERVED_LOCATION_COUNT);