aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimple-ssa-sprintf.c
diff options
context:
space:
mode:
authorJeff Law <law@gcc.gnu.org>2018-10-03 20:55:10 -0600
committerJeff Law <law@gcc.gnu.org>2018-10-03 20:55:10 -0600
commit0863decda9aef33b8073c13f6d27826b881e6280 (patch)
tree56b96595c17f69c273072996d93b7f56cdf8b0e5 /gcc/gimple-ssa-sprintf.c
parent74ac60743f6cb84921477c6526b53fc9250ec4c1 (diff)
downloadgcc-0863decda9aef33b8073c13f6d27826b881e6280.zip
gcc-0863decda9aef33b8073c13f6d27826b881e6280.tar.gz
gcc-0863decda9aef33b8073c13f6d27826b881e6280.tar.bz2
gimple-ssa-sprintf.c (format_string): Do not hardcode size of target's wchar_t.
* gimple-ssa-sprintf.c (format_string): Do not hardcode size of target's wchar_t. * tree.c (get_typenode_from_name): Moved from fortran/trans-types.c. * tree.h (get_typenode_from_name): Prototype. * trans-types.c (get_typenode_from_name): Moved into gcc/tree.c. From-SVN: r264833
Diffstat (limited to 'gcc/gimple-ssa-sprintf.c')
-rw-r--r--gcc/gimple-ssa-sprintf.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/gcc/gimple-ssa-sprintf.c b/gcc/gimple-ssa-sprintf.c
index 88e9528..471bfc4 100644
--- a/gcc/gimple-ssa-sprintf.c
+++ b/gcc/gimple-ssa-sprintf.c
@@ -2179,7 +2179,19 @@ format_string (const directive &dir, tree arg, vr_values *)
fmtresult res;
/* Compute the range the argument's length can be in. */
- int count_by = dir.specifier == 'S' || dir.modifier == FMT_LEN_l ? 4 : 1;
+ int count_by = 1;
+ if (dir.specifier == 'S' || dir.modifier == FMT_LEN_l)
+ {
+ /* Get a node for a C type that will be the same size
+ as a wchar_t on the target. */
+ tree node = get_typenode_from_name (MODIFIED_WCHAR_TYPE);
+
+ /* Now that we have a suitable node, get the number of
+ bytes it occupies. */
+ count_by = int_size_in_bytes (node);
+ gcc_checking_assert (count_by == 2 || count_by == 4);
+ }
+
fmtresult slen = get_string_length (arg, count_by);
if (slen.range.min == slen.range.max
&& slen.range.min < HOST_WIDE_INT_MAX)