From: Joseph Myers Date: Sun, 1 May 2005 10:39:15 +0000 (+0100) Subject: re PR c/20740 (cc1 segfaults) X-Git-Tag: releases/gcc-3.4.4~58 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=08703617c6852f0997400dd6ca7425a632bd1474;p=thirdparty%2Fgcc.git re PR c/20740 (cc1 segfaults) PR c/20740 * c-format.c (init_dynamic_asm_fprintf_info): Give errors, not aborts, if __gcc_host_wide_int__ is not properly defined. (init_dynamic_diag_info): Give errors, not aborts, if location_t, tree or __gcc_host_wide_int__ are not properly defined. testsuite: * gcc.dg/format/asm_fprintf-2.c, gcc.dg/format/asm_fprintf-3.c, gcc.dg/format/asm_fprintf-4.c, gcc.dg/format/asm_fprintf-5.c, gcc.dg/format/gcc_diag-2.c, gcc.dg/format/gcc_diag-3.c, gcc.dg/format/gcc_diag-4.c, gcc.dg/format/gcc_diag-5.c, gcc.dg/format/gcc_diag-6.c, gcc.dg/format/gcc_diag-7.c , gcc.dg/format/gcc_diag-8.c, gcc.dg/format/gcc_diag-9.c: New tests. From-SVN: r99062 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e2d23c876b39..f3f0b79cd620 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2005-05-01 Joseph S. Myers + + PR c/20740 + * c-format.c (init_dynamic_asm_fprintf_info): Give errors, not + aborts, if __gcc_host_wide_int__ is not properly defined. + (init_dynamic_diag_info): Give errors, not aborts, if location_t, + tree or __gcc_host_wide_int__ are not properly defined. + 2005-05-01 Joseph S. Myers PR c/11459 diff --git a/gcc/c-format.c b/gcc/c-format.c index a532259750c4..620277ff604a 100644 --- a/gcc/c-format.c +++ b/gcc/c-format.c @@ -2518,9 +2518,27 @@ init_dynamic_asm_fprintf_info (void) length modifier to work, one must have issued: "typedef HOST_WIDE_INT __gcc_host_wide_int__;" in one's source code prior to using that modifier. */ - if (!(hwi = maybe_get_identifier ("__gcc_host_wide_int__")) - || !(hwi = DECL_ORIGINAL_TYPE (identifier_global_value (hwi)))) + hwi = maybe_get_identifier ("__gcc_host_wide_int__"); + if (!hwi) + { + error ("'__gcc_host_wide_int__' is not defined as a type"); + return; + } + hwi = identifier_global_value (hwi); + if (!hwi || TREE_CODE (hwi) != TYPE_DECL) + { + error ("'__gcc_host_wide_int__' is not defined as a type"); + return; + } + hwi = DECL_ORIGINAL_TYPE (hwi); + if (!hwi) abort (); + if (hwi != long_integer_type_node && hwi != long_long_integer_type_node) + { + error ("'__gcc_host_wide_int__' is not defined as 'long'" + " or 'long long'"); + return; + } /* Create a new (writable) copy of asm_fprintf_length_specs. */ new_asm_fprintf_length_specs = xmemdup (asm_fprintf_length_specs, @@ -2563,19 +2581,71 @@ init_dynamic_diag_info (void) However we don't force a hard ICE because we may see only one or the other type. */ if ((loc = maybe_get_identifier ("location_t"))) - loc = TREE_TYPE (identifier_global_value (loc)); + { + loc = identifier_global_value (loc); + if (loc) + { + if (TREE_CODE (loc) != TYPE_DECL) + { + error ("'location_t' is not defined as a type"); + loc = 0; + } + else + loc = TREE_TYPE (loc); + } + } /* We need to grab the underlying `union tree_node' so peek into an extra type level. */ if ((t = maybe_get_identifier ("tree"))) - t = TREE_TYPE (TREE_TYPE (identifier_global_value (t))); + { + t = identifier_global_value (t); + if (t) + { + if (TREE_CODE (t) != TYPE_DECL) + { + error ("'tree' is not defined as a type"); + t = 0; + } + else if (TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE) + { + error ("'tree' is not defined as a pointer type"); + t = 0; + } + else + t = TREE_TYPE (TREE_TYPE (t)); + } + } /* Find the underlying type for HOST_WIDE_INT. For the %w length modifier to work, one must have issued: "typedef HOST_WIDE_INT __gcc_host_wide_int__;" in one's source code prior to using that modifier. */ if ((hwi = maybe_get_identifier ("__gcc_host_wide_int__"))) - hwi = DECL_ORIGINAL_TYPE (identifier_global_value (hwi)); + { + hwi = identifier_global_value (hwi); + if (hwi) + { + if (TREE_CODE (hwi) != TYPE_DECL) + { + error ("'__gcc_host_wide_int__' is not defined as a type"); + hwi = 0; + } + else + { + hwi = DECL_ORIGINAL_TYPE (hwi); + if (!hwi) + abort (); + if (hwi != long_integer_type_node + && hwi != long_long_integer_type_node) + { + error ("'__gcc_host_wide_int__' is not defined" + " as 'long' or 'long long'"); + hwi = 0; + } + } + } + } /* Assign the new data for use. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f4d7eb4a72c5..c0ac69e59d50 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,13 @@ +2005-05-01 Joseph S. Myers + + PR c/20740 + * gcc.dg/format/asm_fprintf-2.c, gcc.dg/format/asm_fprintf-3.c, + gcc.dg/format/asm_fprintf-4.c, gcc.dg/format/asm_fprintf-5.c, + gcc.dg/format/gcc_diag-2.c, gcc.dg/format/gcc_diag-3.c, + gcc.dg/format/gcc_diag-4.c, gcc.dg/format/gcc_diag-5.c, + gcc.dg/format/gcc_diag-6.c, gcc.dg/format/gcc_diag-7.c , + gcc.dg/format/gcc_diag-8.c, gcc.dg/format/gcc_diag-9.c: New tests. + 2005-05-01 Joseph S. Myers PR c/11459