diff options
author | jsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-04-26 23:58:04 +0000 |
---|---|---|
committer | jsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-04-26 23:58:04 +0000 |
commit | 58db2592787518a0c3d3ac400ca4af602e7a03ca (patch) | |
tree | b6cc6b305db8b4514a4e4e05aef654458f32633d /gcc/c-format.c | |
parent | 882e3bab8d13c1432a57c0955261606af76e8ede (diff) | |
download | gcc-58db2592787518a0c3d3ac400ca4af602e7a03ca.tar.gz |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@98800 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-format.c')
-rw-r--r-- | gcc/c-format.c | 77 |
1 files changed, 72 insertions, 5 deletions
diff --git a/gcc/c-format.c b/gcc/c-format.c index 7db8add15d3..dd570ab23dc 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. */ |