re PR c/20740 (cc1 segfaults)

PR c/20740
	* c-format.c (init_dynamic_asm_fprintf_info): Give errors, not
	assertion failures, if __gcc_host_wide_int__ is not properly
	defined.
	(init_dynamic_diag_info): Give errors, not assertion failures, 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: r98800
This commit is contained in:
Joseph Myers 2005-04-27 00:58:04 +01:00 committed by Joseph Myers
parent 4b0ec99aac
commit 5e49f16b80
15 changed files with 211 additions and 5 deletions

View File

@ -1,3 +1,13 @@
2005-04-27 Joseph S. Myers <joseph@codesourcery.com>
PR c/20740
* c-format.c (init_dynamic_asm_fprintf_info): Give errors, not
assertion failures, if __gcc_host_wide_int__ is not properly
defined.
(init_dynamic_diag_info): Give errors, not assertion failures, if
location_t, tree or __gcc_host_wide_int__ are not properly
defined.
2005-04-26 Kazu Hirata <kazu@cs.umass.edu>
* tree-ssa-loop-ivopts.c (ivopts_data, decl_rtl_to_reset,

View File

@ -2284,9 +2284,25 @@ init_dynamic_asm_fprintf_info (void)
HOST_WIDE_INT __gcc_host_wide_int__;" in one's source code
prior to using that modifier. */
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);
gcc_assert (hwi);
hwi = DECL_ORIGINAL_TYPE (identifier_global_value (hwi));
gcc_assert (hwi);
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 = (format_length_info *)
@ -2330,19 +2346,70 @@ 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);
gcc_assert (hwi);
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. */

View File

@ -1,3 +1,13 @@
2005-04-27 Joseph S. Myers <joseph@codesourcery.com>
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-04-26 Jeff Law <law@redhat.com>
* gcc.gc/tree-ssa/ssa-dce-1.c: New test.

View File

@ -0,0 +1,9 @@
/* Test for ICE handling internal formats: bug 20740. The code did
not check that, if the required typedef names had been used as
identifiers, they were defined to suitable types. Test
"__gcc_host_wide_int__", not used at all, asm_fprintf format. */
/* Origin: Joseph Myers <joseph@codesourcery.com> */
/* { dg-do compile } */
/* { dg-options "-Wformat" } */
void bar (const char *, ...) __attribute__ ((__format__ (__asm_fprintf__, 1, 2))); /* { dg-error "error: '__gcc_host_wide_int__' is not defined as a type" } */

View File

@ -0,0 +1,10 @@
/* Test for ICE handling internal formats: bug 20740. The code did
not check that, if the required typedef names had been used as
identifiers, they were defined to suitable types. Test
"__gcc_host_wide_int__", not defined, asm_fprintf format. */
/* Origin: Joseph Myers <joseph@codesourcery.com> */
/* { dg-do compile } */
/* { dg-options "-Wformat" } */
void foo (int __gcc_host_wide_int__);
void bar (const char *, ...) __attribute__ ((__format__ (__asm_fprintf__, 1, 2))); /* { dg-error "error: '__gcc_host_wide_int__' is not defined as a type" } */

View File

@ -0,0 +1,10 @@
/* Test for ICE handling internal formats: bug 20740. The code did
not check that, if the required typedef names had been used as
identifiers, they were defined to suitable types. Test
"__gcc_host_wide_int__", not a type, asm_fprintf. */
/* Origin: Joseph Myers <joseph@codesourcery.com> */
/* { dg-do compile } */
/* { dg-options "-Wformat" } */
int __gcc_host_wide_int__;
void bar (const char *, ...) __attribute__ ((__format__ (__asm_fprintf__, 1, 2))); /* { dg-error "error: '__gcc_host_wide_int__' is not defined as a type" } */

View File

@ -0,0 +1,10 @@
/* Test for ICE handling internal formats: bug 20740. The code did
not check that, if the required typedef names had been used as
identifiers, they were defined to suitable types. Test
"__gcc_host_wide_int__", bad type, asm_fprintf format. */
/* Origin: Joseph Myers <joseph@codesourcery.com> */
/* { dg-do compile } */
/* { dg-options "-Wformat" } */
typedef int __gcc_host_wide_int__;
void bar (const char *, ...) __attribute__ ((__format__ (__asm_fprintf__, 1, 2))); /* { dg-error "error: '__gcc_host_wide_int__' is not defined as 'long' or 'long long'" } */

View File

@ -0,0 +1,10 @@
/* Test for ICE handling internal formats: bug 20740. The code did
not check that, if the required typedef names had been used as
identifiers, they were defined to suitable types. Test "tree", not
defined. */
/* Origin: Joseph Myers <joseph@codesourcery.com> */
/* { dg-do compile } */
/* { dg-options "-Wformat" } */
void foo (int tree);
void bar (const char *, ...) __attribute__ ((__format__ (__gcc_diag__, 1, 2)));

View File

@ -0,0 +1,10 @@
/* Test for ICE handling internal formats: bug 20740. The code did
not check that, if the required typedef names had been used as
identifiers, they were defined to suitable types. Test "tree", not
a type. */
/* Origin: Joseph Myers <joseph@codesourcery.com> */
/* { dg-do compile } */
/* { dg-options "-Wformat" } */
int tree;
void bar (const char *, ...) __attribute__ ((__format__ (__gcc_diag__, 1, 2))); /* { dg-error "error: 'tree' is not defined as a type" } */

View File

@ -0,0 +1,10 @@
/* Test for ICE handling internal formats: bug 20740. The code did
not check that, if the required typedef names had been used as
identifiers, they were defined to suitable types. Test "tree", not
a pointer type. */
/* Origin: Joseph Myers <joseph@codesourcery.com> */
/* { dg-do compile } */
/* { dg-options "-Wformat" } */
typedef int tree;
void bar (const char *, ...) __attribute__ ((__format__ (__gcc_diag__, 1, 2))); /* { dg-error "error: 'tree' is not defined as a pointer type" } */

View File

@ -0,0 +1,10 @@
/* Test for ICE handling internal formats: bug 20740. The code did
not check that, if the required typedef names had been used as
identifiers, they were defined to suitable types. Test
"location_t", not defined. */
/* Origin: Joseph Myers <joseph@codesourcery.com> */
/* { dg-do compile } */
/* { dg-options "-Wformat" } */
void foo (int location_t);
void bar (const char *, ...) __attribute__ ((__format__ (__gcc_diag__, 1, 2)));

View File

@ -0,0 +1,10 @@
/* Test for ICE handling internal formats: bug 20740. The code did
not check that, if the required typedef names had been used as
identifiers, they were defined to suitable types. Test
"location_t", not a type. */
/* Origin: Joseph Myers <joseph@codesourcery.com> */
/* { dg-do compile } */
/* { dg-options "-Wformat" } */
int location_t;
void bar (const char *, ...) __attribute__ ((__format__ (__gcc_diag__, 1, 2))); /* { dg-error "error: 'location_t' is not defined as a type" } */

View File

@ -0,0 +1,10 @@
/* Test for ICE handling internal formats: bug 20740. The code did
not check that, if the required typedef names had been used as
identifiers, they were defined to suitable types. Test
"__gcc_host_wide_int__", not defined. */
/* Origin: Joseph Myers <joseph@codesourcery.com> */
/* { dg-do compile } */
/* { dg-options "-Wformat" } */
void foo (int __gcc_host_wide_int__);
void bar (const char *, ...) __attribute__ ((__format__ (__gcc_diag__, 1, 2)));

View File

@ -0,0 +1,10 @@
/* Test for ICE handling internal formats: bug 20740. The code did
not check that, if the required typedef names had been used as
identifiers, they were defined to suitable types. Test
"__gcc_host_wide_int__", not a type. */
/* Origin: Joseph Myers <joseph@codesourcery.com> */
/* { dg-do compile } */
/* { dg-options "-Wformat" } */
int __gcc_host_wide_int__;
void bar (const char *, ...) __attribute__ ((__format__ (__gcc_diag__, 1, 2))); /* { dg-error "error: '__gcc_host_wide_int__' is not defined as a type" } */

View File

@ -0,0 +1,10 @@
/* Test for ICE handling internal formats: bug 20740. The code did
not check that, if the required typedef names had been used as
identifiers, they were defined to suitable types. Test
"__gcc_host_wide_int__", bad type. */
/* Origin: Joseph Myers <joseph@codesourcery.com> */
/* { dg-do compile } */
/* { dg-options "-Wformat" } */
typedef int __gcc_host_wide_int__;
void bar (const char *, ...) __attribute__ ((__format__ (__gcc_diag__, 1, 2))); /* { dg-error "error: '__gcc_host_wide_int__' is not defined as 'long' or 'long long'" } */