]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR tree-optimization/89314 (ICE in wide_int_to_tree_1, at tree.c:1561)
authorJakub Jelinek <jakub@redhat.com>
Fri, 30 Aug 2019 11:52:29 +0000 (13:52 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 30 Aug 2019 11:52:29 +0000 (13:52 +0200)
Backported from mainline
2019-02-14  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/89314
* fold-const.c (fold_binary_loc): Cast strlen argument to
const char * before dereferencing it.  Formatting fixes.

* gcc.dg/pr89314.c: New test.

From-SVN: r275110

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr89314.c [new file with mode: 0644]

index 0b4bef2d1562368cd0e6414bf7e95d39c6d2ef12..b0acf9e48fe0dc6386b4b3d1b27a3a362e9392e7 100644 (file)
@@ -1,6 +1,12 @@
 2019-08-30  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2019-02-14  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/89314
+       * fold-const.c (fold_binary_loc): Cast strlen argument to
+       const char * before dereferencing it.  Formatting fixes.
+
        2019-02-13  Jakub Jelinek  <jakub@redhat.com>
 
        PR middle-end/89303
index abe2ee34e7d09c7a0deb7a39dbf9a629db3ceff2..3e1355f7b2f49f8403a530f736820e3a85423399 100644 (file)
@@ -10726,8 +10726,7 @@ fold_binary_loc (location_t loc, enum tree_code code, tree type,
                strlen(ptr) != 0   =>  *ptr != 0
         Other cases should reduce to one of these two (or a constant)
         due to the return value of strlen being unsigned.  */
-      if (TREE_CODE (arg0) == CALL_EXPR
-         && integer_zerop (arg1))
+      if (TREE_CODE (arg0) == CALL_EXPR && integer_zerop (arg1))
        {
          tree fndecl = get_callee_fndecl (arg0);
 
@@ -10735,12 +10734,17 @@ fold_binary_loc (location_t loc, enum tree_code code, tree type,
              && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
              && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_STRLEN
              && call_expr_nargs (arg0) == 1
-             && TREE_CODE (TREE_TYPE (CALL_EXPR_ARG (arg0, 0))) == POINTER_TYPE)
+             && (TREE_CODE (TREE_TYPE (CALL_EXPR_ARG (arg0, 0)))
+                 == POINTER_TYPE))
            {
-             tree iref = build_fold_indirect_ref_loc (loc,
-                                                  CALL_EXPR_ARG (arg0, 0));
+             tree ptrtype
+               = build_pointer_type (build_qualified_type (char_type_node,
+                                                           TYPE_QUAL_CONST));
+             tree ptr = fold_convert_loc (loc, ptrtype,
+                                          CALL_EXPR_ARG (arg0, 0));
+             tree iref = build_fold_indirect_ref_loc (loc, ptr);
              return fold_build2_loc (loc, code, type, iref,
-                                 build_int_cst (TREE_TYPE (iref), 0));
+                                     build_int_cst (TREE_TYPE (iref), 0));
            }
        }
 
index 85e0a2ee2943a667ba7c70a66e32c03f3a2fc407..1a02952c35b25ff54e5cc293c17c55e9113a9d08 100644 (file)
@@ -1,6 +1,11 @@
 2019-08-30  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2019-02-14  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/89314
+       * gcc.dg/pr89314.c: New test.
+
        2019-02-13  Jonathan Wakely  <jwakely@redhat.com>
                    Jakub Jelinek  <jakub@redhat.com>
 
diff --git a/gcc/testsuite/gcc.dg/pr89314.c b/gcc/testsuite/gcc.dg/pr89314.c
new file mode 100644 (file)
index 0000000..d9c53fb
--- /dev/null
@@ -0,0 +1,13 @@
+/* PR tree-optimization/89314 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+extern __SIZE_TYPE__ strlen (const float *);
+void bar (void);
+
+void
+foo (float *s)
+{
+  if (strlen (s) > 0)
+    bar ();
+}