From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id DEDCF3858C2B for ; Fri, 4 Nov 2022 15:55:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DEDCF3858C2B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667577315; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uvu55jGkWZht1T6DjD+/mClw+CbhUuKKLWqpcs5fDxY=; b=BR0LeGTtAJiiidfMlOuSLeI+K6p3wws8vLH6aVenwbrrlFQRJyvPeAS6zuiEXtDTBz1fqM zL65dMZkXzneUAIf5qWOcR+lW4xquGlUHx/xake/t4wjWJRjMLh0uKj6KOl+B+PhGVCJ+H 5Zd/670hdGDpkVaHCYzoVh1LHWEhe7o= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-253-EhwuP_M4Mn-YO9dcSx8faA-1; Fri, 04 Nov 2022 11:55:14 -0400 X-MC-Unique: EhwuP_M4Mn-YO9dcSx8faA-1 Received: by mail-qk1-f200.google.com with SMTP id n13-20020a05620a294d00b006cf933c40feso4731098qkp.20 for ; Fri, 04 Nov 2022 08:55:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=uvu55jGkWZht1T6DjD+/mClw+CbhUuKKLWqpcs5fDxY=; b=MoPsILTiWBAZOF20XLtHIPAFJq54gL629LQK7qzm7xoKeFnfbp6M9ardsnDZhFdQAj 87x7hZGhUOtBi2VGk7AELw/HAADw/BE5p7rGZjKC+Q/GkXkEboGJpRiFfVLyI8Fyq3iL hzZR9GFaokR0aWnCriWZXTO96Zc4WZeH1b7fdbbjTNPw5joqErbDKdrXmYGIbQTa/WYI NUfCjmSEpFzevCW/xBSMMOm/h4Q9c4zhLGYojs7JWnEK93KWPo01mTQuCKiam1rtXNlc HTqEHoFwC2OvleoFQERbE/grPE9bCyrL4V+bTxH7AoPJUsvpVP0Prj8IgLlpovsT5g/d se5Q== X-Gm-Message-State: ACrzQf1x4icdGOr+XRYJn69mMNLTWhaRpHNlpKK5gcnDL6gdJgP0pDUe 1q3sQYi6X8k3K+HvqTwgoQ3Eh3wuLbTpvYnon5Jc6kGEP3QW/wsvNMFYd/r6EA+j9xZhVcRTyCX LLo0Loz5tQ4VGhOfL3A== X-Received: by 2002:a05:620a:132a:b0:6fa:2050:4042 with SMTP id p10-20020a05620a132a00b006fa20504042mr24187223qkj.485.1667577313485; Fri, 04 Nov 2022 08:55:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Z09xsA7DmqiBC/deO7jhwaImKuvW/o9EQ8RrW901Go1e6CXfqiStOJbhU57Zt2r7Ro8iSbg== X-Received: by 2002:a05:620a:132a:b0:6fa:2050:4042 with SMTP id p10-20020a05620a132a00b006fa20504042mr24187207qkj.485.1667577313206; Fri, 04 Nov 2022 08:55:13 -0700 (PDT) Received: from t14s.localdomain (c-73-69-212-193.hsd1.nh.comcast.net. [73.69.212.193]) by smtp.gmail.com with ESMTPSA id l5-20020a05620a28c500b006eeae49537bsm3161792qkp.98.2022.11.04.08.55.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 08:55:12 -0700 (PDT) Message-ID: <0778ff93d5da38dfde39d2a755710fe8225e4110.camel@redhat.com> Subject: Re: [PATCH 2/6] diagnostics: Use an inline function rather than hardcoding string From: David Malcolm To: Lewis Hyatt , gcc-patches@gcc.gnu.org Date: Fri, 04 Nov 2022 11:55:12 -0400 In-Reply-To: <65bfbf319942664358737a1d9d9103f7304199d0.1667514153.git.lhyatt@gmail.com> References: <65bfbf319942664358737a1d9d9103f7304199d0.1667514153.git.lhyatt@gmail.com> User-Agent: Evolution 3.44.4 (3.44.4-1.fc36) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00,BODY_8BITS,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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 List-Id: On Fri, 2022-11-04 at 09:44 -0400, Lewis Hyatt via Gcc-patches wrote: > 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. Thanks; looks good to me. Dave >=20 > gcc/c-family/ChangeLog: >=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* c-opts.cc (c_finish_opt= ions): Use special_fname_builtin () > rather > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0than a hard-coded string. >=20 > gcc/ChangeLog: >=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* diagnostic.cc (diagnost= ic_get_location_text): Use > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0special_fname_builtin () = rather than a hardcoded string > (which was > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0also incorrectly left unt= ranslated previously.) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* input.cc (special_fname= _builtin): New function. > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0(expand_location_1): Use = special_fname_builtin () rather than > a > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0hard-coded string. > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0(test_builtins): Likewise= . > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* input.h (special_fname_= builtin): Declare. >=20 > gcc/fortran/ChangeLog: >=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* cpp.cc (gfc_cpp_init): = Use special_fname_builtin () rather > than a > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0hardcoded string (which w= as also incorrectly left > untranslated > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0previously.) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* error.cc (gfc_diagnosti= c_build_locus_prefix): Likewise. > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* f95-lang.cc (gfc_init):= Likewise. > --- > =C2=A0gcc/c-family/c-opts.cc=C2=A0 |=C2=A0 2 +- > =C2=A0gcc/diagnostic.cc=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0 2 +- > =C2=A0gcc/fortran/cpp.cc=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0 2 +- > =C2=A0gcc/fortran/error.cc=C2=A0=C2=A0=C2=A0 |=C2=A0 4 ++-- > =C2=A0gcc/fortran/f95-lang.cc |=C2=A0 2 +- > =C2=A0gcc/input.cc=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 | 10 ++++++++-- > =C2=A0gcc/input.h=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 |=C2=A0 3 +++ > =C2=A07 files changed, 17 insertions(+), 8 deletions(-) >=20 > 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) > =C2=A0=C2=A0=C2=A0=C2=A0 { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 const line_map_ordinary *bltin_map > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=3D linemap_check_ordinar= y (linemap_add (line_table, LC_RENAME, > 0, > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 _(""), 0)); > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 special_fname_builtin > (), 0)); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cb_file_change (parse_in, bltin_map)= ; > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 linemap_line_start (line_table, 0, 1= ); > =C2=A0 > 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, > =C2=A0=C2=A0 const char *file =3D s.file ? s.file : progname; > =C2=A0=C2=A0 int line =3D 0; > =C2=A0=C2=A0 int col =3D -1; > -=C2=A0 if (strcmp (file, N_(""))) > +=C2=A0 if (strcmp (file, special_fname_builtin ())) > =C2=A0=C2=A0=C2=A0=C2=A0 { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 line =3D s.line; > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 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) > =C2=A0=C2=A0 if (gfc_option.flag_preprocessed) > =C2=A0=C2=A0=C2=A0=C2=A0 return; > =C2=A0 > -=C2=A0 cpp_change_file (cpp_in, LC_RENAME, _("")); > +=C2=A0 cpp_change_file (cpp_in, LC_RENAME, special_fname_builtin ()); > =C2=A0=C2=A0 if (!gfc_cpp_option.no_predefined) > =C2=A0=C2=A0=C2=A0=C2=A0 { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* Make sure all of the builtins abo= ut 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, > =C2=A0=C2=A0 const char *locus_ce =3D colorize_stop (pp_show_color (pp)); > =C2=A0=C2=A0 return (s.file =3D=3D NULL > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ? build_message_st= ring ("%s%s:%s", locus_cs, progname, > locus_ce ) > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 : !strcmp (s.file, N_("= ")) > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 : !strcmp (s.file, spec= ial_fname_builtin ()) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ? build_message_st= ring ("%s%s:%s", locus_cs, s.file, > locus_ce) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 : context->show_co= lumn > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ? build_message_st= ring ("%s%s:%d:%d:%s", locus_cs, s.file, > s.line, > @@ -1167,7 +1167,7 @@ gfc_diagnostic_build_locus_prefix > (diagnostic_context *context, > =C2=A0 > =C2=A0=C2=A0 return (s.file =3D=3D NULL > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ? build_message_st= ring ("%s%s:%s", locus_cs, progname, > locus_ce ) > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 : !strcmp (s.file, N_("= ")) > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 : !strcmp (s.file, spec= ial_fname_builtin ()) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ? build_message_st= ring ("%s%s:%s", locus_cs, s.file, > locus_ce) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 : context->show_co= lumn > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ? build_message_st= ring ("%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) > =C2=A0=C2=A0 if (!gfc_cpp_enabled ()) > =C2=A0=C2=A0=C2=A0=C2=A0 { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 linemap_add (line_table, LC_ENTER, f= alse, gfc_source_file, 1); > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 linemap_add (line_table, LC_RENAME, false= , "", 0); > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 linemap_add (line_table, LC_RENAME, false= , > special_fname_builtin (), 0); > =C2=A0=C2=A0=C2=A0=C2=A0 } > =C2=A0=C2=A0 else > =C2=A0=C2=A0=C2=A0=C2=A0 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.=C2=A0 If not se= e > =C2=A0#define HAVE_ICONV 0 > =C2=A0#endif > =C2=A0 > +const char * > +special_fname_builtin () > +{ > +=C2=A0 return _(""); > +} > + > =C2=A0/* Input charset configuration.=C2=A0 */ > =C2=A0static const char *default_charset_callback (const char *) > =C2=A0{ > @@ -275,7 +281,7 @@ expand_location_1 (location_t loc, > =C2=A0 > =C2=A0=C2=A0 xloc.data =3D block; > =C2=A0=C2=A0 if (loc <=3D BUILTINS_LOCATION) > -=C2=A0=C2=A0=C2=A0 xloc.file =3D loc =3D=3D UNKNOWN_LOCATION ? NULL : _(= ""); > +=C2=A0=C2=A0=C2=A0 xloc.file =3D loc =3D=3D UNKNOWN_LOCATION ? NULL : > special_fname_builtin (); > =C2=A0 > =C2=A0=C2=A0 return xloc; > =C2=A0} > @@ -2102,7 +2108,7 @@ test_unknown_location () > =C2=A0static void > =C2=A0test_builtins () > =C2=A0{ > -=C2=A0 assert_loceq (_(""), 0, 0, BUILTINS_LOCATION); > +=C2=A0 assert_loceq (special_fname_builtin (), 0, 0, BUILTINS_LOCATION); > =C2=A0=C2=A0 ASSERT_PRED1 (is_location_from_builtin_token, BUILTINS_LOCAT= ION); > =C2=A0} > =C2=A0 > 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; > =C2=A0/* The location for declarations in "" */ > =C2=A0#define BUILTINS_LOCATION ((location_t) 1) > =C2=A0 > +/* Returns the translated string referring to the special location.=C2= =A0 > */ > +const char *special_fname_builtin (); > + > =C2=A0/* line-map.cc reserves RESERVED_LOCATION_COUNT to the user.=C2=A0 = Ensure > =C2=A0=C2=A0=C2=A0 both UNKNOWN_LOCATION and BUILTINS_LOCATION fit into t= hat.=C2=A0 */ > =C2=A0STATIC_ASSERT (BUILTINS_LOCATION < RESERVED_LOCATION_COUNT); >=20