public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix typedef-name printing (PR c/56980)
@ 2014-10-24 14:20 Marek Polacek
  2014-10-24 16:30 ` Jeff Law
  0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2014-10-24 14:20 UTC (permalink / raw)
  To: GCC Patches

Our current C pretty printer output sometimes looks a bit goofy:
"expected ‘enum F *’ but argument is of type ‘enum F *’".
It's because it always prints "struct"/"union"/"enum" even though
the type is a typedef name.  This patch ought to fix this. 
We've got a bunch of reports about this over the years...

The C++ printer can also print "B* {aka A*}", I'll try to learn
c_tree_printer to do something similar as well.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2014-10-24  Marek Polacek  <polacek@redhat.com>

	PR c/56980
	* c-pretty-print.c (c_pretty_printer::simple_type_specifier): Don't
	print "struct"/"union"/"enum" for typedefed names.

	* gcc.dg/pr56980.c: New test.

diff --git gcc/c-family/c-pretty-print.c gcc/c-family/c-pretty-print.c
index 3b2dbc1..9096a07 100644
--- gcc/c-family/c-pretty-print.c
+++ gcc/c-family/c-pretty-print.c
@@ -416,7 +416,9 @@ c_pretty_printer::simple_type_specifier (tree t)
     case UNION_TYPE:
     case RECORD_TYPE:
     case ENUMERAL_TYPE:
-      if (code == UNION_TYPE)
+      if (TYPE_NAME (t) && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL)
+	/* Don't decorate the type if this is a typedef name.  */;
+      else if (code == UNION_TYPE)
 	pp_c_ws_string (this, "union");
       else if (code == RECORD_TYPE)
 	pp_c_ws_string (this, "struct");
diff --git gcc/testsuite/gcc.dg/pr56980.c gcc/testsuite/gcc.dg/pr56980.c
index e69de29..f48379a 100644
--- gcc/testsuite/gcc.dg/pr56980.c
+++ gcc/testsuite/gcc.dg/pr56980.c
@@ -0,0 +1,24 @@
+/* PR c/56980 */
+/* { dg-do compile } */
+
+typedef struct A { int i; } B;
+typedef union U { int i; } V;
+typedef enum E { G } F;
+
+void foo_s (struct A); /* { dg-message "expected .struct A. but argument is of type .B \\*." } */
+void foo_u (union U); /* { dg-message "expected .union U. but argument is of type .V \\*." } */
+void foo_e (enum E); /* { dg-message "expected .enum E. but argument is of type .F \\*." } */
+void foo_sp (B *); /* { dg-message "expected .B \\*. but argument is of type .struct B \\*." } */
+void foo_up (V *); /* { dg-message "expected .V \\*. but argument is of type .union V \\*." } */
+void foo_ep (F *); /* { dg-message "expected .F \\*. but argument is of type .enum F \\*." } */
+
+void 
+bar (B *b, V *v, F *f)
+{
+  foo_s (b); /* { dg-error "incompatible" } */
+  foo_u (v); /* { dg-error "incompatible" } */
+  foo_e (f); /* { dg-error "incompatible" } */
+  foo_sp ((struct B *) b); /* { dg-error "passing argument" } */
+  foo_up ((union V *) v); /* { dg-error "passing argument" } */
+  foo_ep (__extension__ (enum F *) f); /* { dg-error "passing argument" } */
+}

	Marek

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix typedef-name printing (PR c/56980)
  2014-10-24 14:20 [PATCH] Fix typedef-name printing (PR c/56980) Marek Polacek
@ 2014-10-24 16:30 ` Jeff Law
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2014-10-24 16:30 UTC (permalink / raw)
  To: Marek Polacek, GCC Patches

On 10/24/14 08:16, Marek Polacek wrote:
> Our current C pretty printer output sometimes looks a bit goofy:
> "expected ‘enum F *’ but argument is of type ‘enum F *’".
> It's because it always prints "struct"/"union"/"enum" even though
> the type is a typedef name.  This patch ought to fix this.
> We've got a bunch of reports about this over the years...
>
> The C++ printer can also print "B* {aka A*}", I'll try to learn
> c_tree_printer to do something similar as well.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2014-10-24  Marek Polacek  <polacek@redhat.com>
>
> 	PR c/56980
> 	* c-pretty-print.c (c_pretty_printer::simple_type_specifier): Don't
> 	print "struct"/"union"/"enum" for typedefed names.
>
> 	* gcc.dg/pr56980.c: New test.
OK.
Jeff

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-10-24 16:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-24 14:20 [PATCH] Fix typedef-name printing (PR c/56980) Marek Polacek
2014-10-24 16:30 ` Jeff Law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).