diff options
author | Joseph Myers <joseph@codesourcery.com> | 2005-04-27 00:58:04 +0100 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2005-04-27 00:58:04 +0100 |
commit | 5e49f16b8090faaf53469c51bdadb8ca5c0e115e (patch) | |
tree | b6cc6b305db8b4514a4e4e05aef654458f32633d /gcc | |
parent | 4b0ec99aaca0c0a3e90593ff166eb474947241c0 (diff) | |
download | gcc-5e49f16b8090faaf53469c51bdadb8ca5c0e115e.zip gcc-5e49f16b8090faaf53469c51bdadb8ca5c0e115e.tar.gz gcc-5e49f16b8090faaf53469c51bdadb8ca5c0e115e.tar.bz2 |
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
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 10 | ||||
-rw-r--r-- | gcc/c-format.c | 77 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 10 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/format/asm_fprintf-2.c | 9 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/format/asm_fprintf-3.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/format/asm_fprintf-4.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/format/asm_fprintf-5.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/format/gcc_diag-2.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/format/gcc_diag-3.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/format/gcc_diag-4.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/format/gcc_diag-5.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/format/gcc_diag-6.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/format/gcc_diag-7.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/format/gcc_diag-8.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/format/gcc_diag-9.c | 10 |
15 files changed, 211 insertions, 5 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8ba855b..89af6e5 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -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, diff --git a/gcc/c-format.c b/gcc/c-format.c index 7db8add..dd570ab 100644 --- a/gcc/c-format.c +++ b/gcc/c-format.c @@ -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. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1c08f01..0f6ab3d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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. diff --git a/gcc/testsuite/gcc.dg/format/asm_fprintf-2.c b/gcc/testsuite/gcc.dg/format/asm_fprintf-2.c new file mode 100644 index 0000000..847eeee --- /dev/null +++ b/gcc/testsuite/gcc.dg/format/asm_fprintf-2.c @@ -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" } */ diff --git a/gcc/testsuite/gcc.dg/format/asm_fprintf-3.c b/gcc/testsuite/gcc.dg/format/asm_fprintf-3.c new file mode 100644 index 0000000..f5fd5c0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/format/asm_fprintf-3.c @@ -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" } */ diff --git a/gcc/testsuite/gcc.dg/format/asm_fprintf-4.c b/gcc/testsuite/gcc.dg/format/asm_fprintf-4.c new file mode 100644 index 0000000..9de0513 --- /dev/null +++ b/gcc/testsuite/gcc.dg/format/asm_fprintf-4.c @@ -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" } */ diff --git a/gcc/testsuite/gcc.dg/format/asm_fprintf-5.c b/gcc/testsuite/gcc.dg/format/asm_fprintf-5.c new file mode 100644 index 0000000..14ffb60 --- /dev/null +++ b/gcc/testsuite/gcc.dg/format/asm_fprintf-5.c @@ -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'" } */ diff --git a/gcc/testsuite/gcc.dg/format/gcc_diag-2.c b/gcc/testsuite/gcc.dg/format/gcc_diag-2.c new file mode 100644 index 0000000..60c6835 --- /dev/null +++ b/gcc/testsuite/gcc.dg/format/gcc_diag-2.c @@ -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))); diff --git a/gcc/testsuite/gcc.dg/format/gcc_diag-3.c b/gcc/testsuite/gcc.dg/format/gcc_diag-3.c new file mode 100644 index 0000000..1a7848e --- /dev/null +++ b/gcc/testsuite/gcc.dg/format/gcc_diag-3.c @@ -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" } */ diff --git a/gcc/testsuite/gcc.dg/format/gcc_diag-4.c b/gcc/testsuite/gcc.dg/format/gcc_diag-4.c new file mode 100644 index 0000000..20661c4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/format/gcc_diag-4.c @@ -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" } */ diff --git a/gcc/testsuite/gcc.dg/format/gcc_diag-5.c b/gcc/testsuite/gcc.dg/format/gcc_diag-5.c new file mode 100644 index 0000000..f8f12d6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/format/gcc_diag-5.c @@ -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))); diff --git a/gcc/testsuite/gcc.dg/format/gcc_diag-6.c b/gcc/testsuite/gcc.dg/format/gcc_diag-6.c new file mode 100644 index 0000000..fdb493d --- /dev/null +++ b/gcc/testsuite/gcc.dg/format/gcc_diag-6.c @@ -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" } */ diff --git a/gcc/testsuite/gcc.dg/format/gcc_diag-7.c b/gcc/testsuite/gcc.dg/format/gcc_diag-7.c new file mode 100644 index 0000000..fccf5d2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/format/gcc_diag-7.c @@ -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))); diff --git a/gcc/testsuite/gcc.dg/format/gcc_diag-8.c b/gcc/testsuite/gcc.dg/format/gcc_diag-8.c new file mode 100644 index 0000000..835ec3f --- /dev/null +++ b/gcc/testsuite/gcc.dg/format/gcc_diag-8.c @@ -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" } */ diff --git a/gcc/testsuite/gcc.dg/format/gcc_diag-9.c b/gcc/testsuite/gcc.dg/format/gcc_diag-9.c new file mode 100644 index 0000000..6481c26 --- /dev/null +++ b/gcc/testsuite/gcc.dg/format/gcc_diag-9.c @@ -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'" } */ |