This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: c-family/c-pretty-print.c - fix for 'restrict' quliafiers
- From: Marek Polacek <polacek at redhat dot com>
- To: Gary Funck <gary at intrepid dot com>
- Cc: Gcc Patches <gcc-patches at gcc dot gnu dot org>, Nenad Vukicevic <nenad at intrepid dot com>
- Date: Mon, 17 Aug 2015 12:06:08 +0200
- Subject: Re: c-family/c-pretty-print.c - fix for 'restrict' quliafiers
- Authentication-results: sourceware.org; auth=none
- References: <20150817011418 dot GD9735 at intrepid dot com>
On Sun, Aug 16, 2015 at 06:14:18PM -0700, Gary Funck wrote:
>
> While reviewing some code, I noticed that the logic for
> pretty-printing 'restrict' qualifiers is likely missing a
> statement that sets 'previous'.
>
> OK to commit?
>
> 2015-08-l6 Gary Funck <gary@intrepid.com>
>
> * c-pretty-print.c (pp_c_cv_qualifiers):
> Set 'previous' for restrict qualifiers.
>
> Index: c-pretty-print.c
> ===================================================================
> --- c-pretty-print.c (revision 226928)
> +++ c-pretty-print.c (working copy)
> @@ -207,16 +207,17 @@ pp_c_cv_qualifiers (c_pretty_printer *pp
> }
>
> if (qualifiers & TYPE_QUAL_RESTRICT)
> {
> if (previous)
> pp_c_whitespace (pp);
> pp_c_ws_string (pp, (flag_isoc99 && !c_dialect_cxx ()
> ? "restrict" : "__restrict__"));
> + previous = true;
No, I don't think this assignment is missing here. The restrict qualifier
is printed last so we don't need to mark that we've printed something.
Actually, the whole "previous" flag seems to be redundant; pp_c_ws_string
calls pp_c_maybe_whitespace so it prints a whitespace if necessary.
So I suggest the following instead (haven't tested it yet).
2015-08-17 Marek Polacek <polacek@redhat.com>
* c-pretty-print.c (pp_c_cv_qualifiers): Remove code dealing
with whitespaces before qualifier names.
diff --git gcc/c-family/c-pretty-print.c gcc/c-family/c-pretty-print.c
index 90f8c3d..e2809cf 100644
--- gcc/c-family/c-pretty-print.c
+++ gcc/c-family/c-pretty-print.c
@@ -173,7 +173,6 @@ void
pp_c_cv_qualifiers (c_pretty_printer *pp, int qualifiers, bool func_type)
{
const char *p = pp_last_position_in_text (pp);
- bool previous = false;
if (!qualifiers)
return;
@@ -185,34 +184,14 @@ pp_c_cv_qualifiers (c_pretty_printer *pp, int qualifiers, bool func_type)
pp_c_whitespace (pp);
if (qualifiers & TYPE_QUAL_ATOMIC)
- {
- pp_c_ws_string (pp, "_Atomic");
- previous = true;
- }
-
+ pp_c_ws_string (pp, "_Atomic");
if (qualifiers & TYPE_QUAL_CONST)
- {
- if (previous)
- pp_c_whitespace (pp);
- pp_c_ws_string (pp, func_type ? "__attribute__((const))" : "const");
- previous = true;
- }
-
+ pp_c_ws_string (pp, func_type ? "__attribute__((const))" : "const");
if (qualifiers & TYPE_QUAL_VOLATILE)
- {
- if (previous)
- pp_c_whitespace (pp);
- pp_c_ws_string (pp, func_type ? "__attribute__((noreturn))" : "volatile");
- previous = true;
- }
-
+ pp_c_ws_string (pp, func_type ? "__attribute__((noreturn))" : "volatile");
if (qualifiers & TYPE_QUAL_RESTRICT)
- {
- if (previous)
- pp_c_whitespace (pp);
- pp_c_ws_string (pp, (flag_isoc99 && !c_dialect_cxx ()
- ? "restrict" : "__restrict__"));
- }
+ pp_c_ws_string (pp, (flag_isoc99 && !c_dialect_cxx ()
+ ? "restrict" : "__restrict__"));
}
/* Pretty-print T using the type-cast notation '( type-name )'. */
Marek