From a92c58c27304547c9c75e4cbb0a2ad92f55c17e0 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Thu, 3 Nov 2005 03:30:36 +0000 Subject: [PATCH] re PR c/24329 (segfault with -Wall and long integer literal) PR c/24329 * c-pretty-print.c (pp_c_type_specifier): Do not recurse if c_common_type_for_mode returns an unnamed type. testsuite: * gcc.dg/format/unnamed-1.c: New test. From-SVN: r106421 --- gcc/ChangeLog | 6 ++++++ gcc/c-pretty-print.c | 27 ++++++++++++++++++++++--- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/format/unnamed-1.c | 22 ++++++++++++++++++++ 4 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/format/unnamed-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a2e518a14f5..8de34f21c4b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2005-11-03 Joseph S. Myers + + PR c/24329 + * c-pretty-print.c (pp_c_type_specifier): Do not recurse if + c_common_type_for_mode returns an unnamed type. + 2005-11-02 Richard Henderson PR target/9350 diff --git a/gcc/c-pretty-print.c b/gcc/c-pretty-print.c index bbc19be9fd4..5e67a96cf4e 100644 --- a/gcc/c-pretty-print.c +++ b/gcc/c-pretty-print.c @@ -323,11 +323,32 @@ pp_c_type_specifier (c_pretty_printer *pp, tree t) { int prec = TYPE_PRECISION (t); t = c_common_type_for_mode (TYPE_MODE (t), TYPE_UNSIGNED (t)); - pp_c_type_specifier (pp, t); - if (TYPE_PRECISION (t) != prec) + if (TYPE_NAME (t)) { - pp_string (pp, ":"); + pp_c_type_specifier (pp, t); + if (TYPE_PRECISION (t) != prec) + { + pp_string (pp, ":"); + pp_decimal_int (pp, prec); + } + } + else + { + switch (code) + { + case INTEGER_TYPE: + pp_string (pp, (TYPE_UNSIGNED (t) + ? ""); } } break; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b52603ba2cc..393452736f0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2005-11-03 Joseph S. Myers + + PR c/24329 + * gcc.dg/format/unnamed-1.c: New test. + 2005-11-02 Mark Mitchell PR c++/22434 diff --git a/gcc/testsuite/gcc.dg/format/unnamed-1.c b/gcc/testsuite/gcc.dg/format/unnamed-1.c new file mode 100644 index 00000000000..5fc11a12c57 --- /dev/null +++ b/gcc/testsuite/gcc.dg/format/unnamed-1.c @@ -0,0 +1,22 @@ +/* Test for warnings with possibly unnamed integer types. Bug 24329. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-Wformat" } */ + +#include "format.h" + +/* Definition of TItype follows same logic as in gcc.dg/titype-1.c, + but must be a #define to avoid giving the type a name. */ +#if defined(__LP64__) && !defined(__hppa__) +#define TItype int __attribute__ ((mode (TI))) +#else +#define TItype long +#endif + +void +f (TItype x) +{ + printf("%d", x); /* { dg-warning "expects type" } */ + printf("%d", 141592653589793238462643383279502884197169399375105820974944); /* { dg-warning "expects type" } */ + /* { dg-warning "unsigned only|too large" "constant" { target *-*-* } 20 } */ +}