summaryrefslogtreecommitdiff
path: root/gcc/builtins.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2019-02-16 12:20:33 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2019-02-16 12:20:33 +0100
commit3140b2ed036c51b9df0fda28b153ebecb4f906ec (patch)
tree81cea5780c130ecb2ea39b2cddc613799d6e31dc /gcc/builtins.c
parent1f1d52e33df1b07c3d33b9fe377691ebbf4be157 (diff)
re PR rtl-optimization/66152 (suboptimal load bytes to stack)
PR rtl-optimization/66152 * builtins.h (c_readstr): Declare. * builtins.c (c_readstr): Remove forward declaration. Add null_terminated_p argument, if false, read all bytes from the string instead of stopping after '\0'. * expr.c (string_cst_read_str): New function. (store_expr): Use string_cst_read_str instead of builtin_strncpy_read_str. Try to store by pieces the whole exp_len first, and only if that fails, split it up into store by pieces followed by clear_storage. Formatting fix. * gcc.target/i386/pr66152.c: New test. From-SVN: r268957
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r--gcc/builtins.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c
index 693e8937918..6f266ad15d0 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -95,7 +95,6 @@ builtin_info_type builtin_info[(int)END_BUILTINS];
/* Non-zero if __builtin_constant_p should be folded right away. */
bool force_folding_builtin_constant_p;
-static rtx c_readstr (const char *, scalar_int_mode);
static int target_char_cast (tree, char *);
static rtx get_memory_rtx (tree, tree);
static int apply_args_size (void);
@@ -802,10 +801,14 @@ c_strlen (tree src, int only_value, c_strlen_data *data, unsigned eltsize)
}
/* Return a constant integer corresponding to target reading
- GET_MODE_BITSIZE (MODE) bits from string constant STR. */
+ GET_MODE_BITSIZE (MODE) bits from string constant STR. If
+ NULL_TERMINATED_P, reading stops after '\0' character, all further ones
+ are assumed to be zero, otherwise it reads as many characters
+ as needed. */
-static rtx
-c_readstr (const char *str, scalar_int_mode mode)
+rtx
+c_readstr (const char *str, scalar_int_mode mode,
+ bool null_terminated_p/*=true*/)
{
HOST_WIDE_INT ch;
unsigned int i, j;
@@ -830,7 +833,7 @@ c_readstr (const char *str, scalar_int_mode mode)
j = j + UNITS_PER_WORD - 2 * (j % UNITS_PER_WORD) - 1;
j *= BITS_PER_UNIT;
- if (ch)
+ if (ch || !null_terminated_p)
ch = (unsigned char) str[i];
tmp[j / HOST_BITS_PER_WIDE_INT] |= ch << (j % HOST_BITS_PER_WIDE_INT);
}