aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2014-10-24 16:29:56 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2014-10-24 16:29:56 +0000
commit90f3520ea50cee07c83bd51a1eced989915a8523 (patch)
tree3825e01b2814f972b29c284a1989ce1e281e6078
parent820aecbf23385cd7c2acc8247dee468e02eeb8e7 (diff)
downloadgcc-90f3520ea50cee07c83bd51a1eced989915a8523.zip
gcc-90f3520ea50cee07c83bd51a1eced989915a8523.tar.gz
gcc-90f3520ea50cee07c83bd51a1eced989915a8523.tar.bz2
re PR c/56980 (C pretty-printer does not handle well pointer to typedef of struct)
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. From-SVN: r216674
-rw-r--r--gcc/c-family/ChangeLog6
-rw-r--r--gcc/c-family/c-pretty-print.c4
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/pr56980.c24
4 files changed, 38 insertions, 1 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 05254c8..fb0e63b 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,9 @@
+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.
+
2014-10-23 Marek Polacek <polacek@redhat.com>
* c-ubsan.c (ubsan_instrument_shift): Perform the MINUS_EXPR
diff --git a/gcc/c-family/c-pretty-print.c b/gcc/c-family/c-pretty-print.c
index 3b2dbc1..a4dd93d 100644
--- a/gcc/c-family/c-pretty-print.c
+++ b/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 a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 3b35375..39d4871 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2014-10-24 Marek Polacek <polacek@redhat.com>
+
+ PR c/56980
+ * gcc.dg/pr56980.c: New test.
+
2014-10-24 Jiong Wang <jiong.wang@arm.com>
* lib/target-supports.exp
diff --git a/gcc/testsuite/gcc.dg/pr56980.c b/gcc/testsuite/gcc.dg/pr56980.c
new file mode 100644
index 0000000..f48379a
--- /dev/null
+++ b/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" } */
+}