This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH, obvious?] Some minor nits in string folding functions
- From: Bernd Edlinger <bernd dot edlinger at hotmail dot de>
- To: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>, Richard Biener <rguenther at suse dot de>, Jeff Law <law at redhat dot com>, Martin Sebor <msebor at gmail dot com>
- Date: Thu, 19 Jul 2018 18:04:12 +0000
- Subject: [PATCH, obvious?] Some minor nits in string folding functions
Hi,
this fixes a few minor nits, which I spotted while
looking at the string folding functions:
string_constant: Remove impossible check: TREE_CODE (arg)
can't be COMPONENT_REF and MEM_REF at the same time.
c_strlen: maxelts is (signed) HOST_WIDE_INT, therefore
use tree_to_shwi.
c_getstr: tree_to_uhwi needs to be protected by
tree_fits_uhwi_p.
BTW: c_getstr uses string_constant which appears to be
able to extract wide char string initializers, but c_getstr
does not seem to be prepared for wide char strings:
else if (string[string_length - 1] != '\0')
{
/* Support only properly NUL-terminated strings but handle
consecutive strings within the same array, such as the six
substrings in "1\0002\0003". */
return NULL;
}
Bootstrapped and reg-tested on x86_64-pc-linux-gnu.
Is it OK for trunk?
Thanks
Bernd.
2018-07-19 Bernd Edlinger <bernd.edlinger@hotmail.de>
* builtins.c (c_strlen): Use tree_to_shwi.
* expr.c (string_constant): Remove impossible check.
* fold-const.c (c_getstr): Use tree_fits_uhwi_p.
Index: gcc/builtins.c
===================================================================
--- gcc/builtins.c (revision 262861)
+++ gcc/builtins.c (working copy)
@@ -610,7 +610,7 @@ c_strlen (tree src, int only_value)
tree type = TREE_TYPE (src);
if (tree size = TYPE_SIZE_UNIT (type))
if (tree_fits_shwi_p (size))
- maxelts = tree_to_uhwi (size);
+ maxelts = tree_to_shwi (size);
maxelts = maxelts / eltsize - 1;
Index: gcc/expr.c
===================================================================
--- gcc/expr.c (revision 262861)
+++ gcc/expr.c (working copy)
@@ -11371,11 +11371,6 @@ string_constant (tree arg, tree *ptr_offset)
return NULL_TREE;
if (TREE_CODE (init) == CONSTRUCTOR)
{
- if (TREE_CODE (arg) != ARRAY_REF
- && TREE_CODE (arg) == COMPONENT_REF
- && TREE_CODE (arg) == MEM_REF)
- return NULL_TREE;
-
/* Convert the 64-bit constant offset to a wider type to avoid
overflow. */
offset_int wioff;
Index: gcc/fold-const.c
===================================================================
--- gcc/fold-const.c (revision 262861)
+++ gcc/fold-const.c (working copy)
@@ -14613,7 +14613,7 @@ c_getstr (tree src, unsigned HOST_WIDE_INT *strlen
unsigned HOST_WIDE_INT string_size = string_length;
tree type = TREE_TYPE (src);
if (tree size = TYPE_SIZE_UNIT (type))
- if (tree_fits_shwi_p (size))
+ if (tree_fits_uhwi_p (size))
string_size = tree_to_uhwi (size);
if (strlen)