+2018-08-27 Martin Sebor <msebor@redhat.com>
+
+ PR tree-optimization/87112
+ * builtins.c (expand_builtin_strnlen): Convert c_strlen result to
+ the type of the bound argument.
+
2018-08-27 Jeff Law <law@redhat.com>
* tree-ssa-dse.c (compute_trims): Handle case where the reference's
tree func = get_callee_fndecl (exp);
tree len = c_strlen (src, 0);
+ /* FIXME: Change c_strlen() to return sizetype instead of ssizetype
+ so these conversions aren't necessary. */
+ if (len)
+ len = fold_convert_loc (loc, TREE_TYPE (bound), len);
if (TREE_CODE (bound) == INTEGER_CST)
{
if (!len || TREE_CODE (len) != INTEGER_CST)
return NULL_RTX;
- len = fold_convert_loc (loc, size_type_node, len);
len = fold_build2_loc (loc, MIN_EXPR, size_type_node, len, bound);
return expand_expr (len, target, target_mode, EXPAND_NORMAL);
}
+2018-08-27 Martin Sebor <msebor@redhat.com>
+
+ PR tree-optimization/87112
+ * gcc.dg/pr87112.c: New test.
+
2018-08-27 David Malcolm <dmalcolm@redhat.com>
PR c++/63392
--- /dev/null
+/* PR tree-optimization/87112 - ICE due to strnlen mixing integer types
+ { dg-do compile }
+ { dg-options "-Os -Wall" } */
+
+typedef __SIZE_TYPE__ size_t;
+
+extern size_t strnlen (const char*, size_t);
+
+size_t fi (int i)
+{
+ int n = i & 3;
+ return strnlen ("int", n);
+}
+
+size_t fui (unsigned i)
+{
+ unsigned n = i & 3;
+ return strnlen ("unsigned", n);
+}
+
+size_t fl (long i)
+{
+ long n = i & 3;
+ return strnlen ("long", n);
+}
+
+size_t fsz (size_t i)
+{
+ size_t n = i & 3;
+ return strnlen ("size_t", n);
+}