re PR tree-optimization/89314 (ICE in wide_int_to_tree_1, at tree.c:1561)
authorJakub Jelinek <jakub@redhat.com>
Thu, 14 Feb 2019 09:25:01 +0000 (10:25 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 14 Feb 2019 09:25:01 +0000 (10:25 +0100)
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: r268868

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

index b0cea85e47a7394c955a7556c7dde5619cb57d62..c800ee18da31e7301c3619dded93d5d95cda8b0f 100644 (file)
@@ -1,5 +1,9 @@
 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.
+
        PR middle-end/89284
        * passes.def: Swap pass_ubsan and pass_early_warn_uninitialized.
 
index 640a6ece44e6ca88ae985e55d0e2ffbca67d0853..fcc1c450129427926165e5ea11700435e053f885 100644 (file)
@@ -10740,20 +10740,24 @@ 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);
 
          if (fndecl
              && fndecl_built_in_p (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 c082cddf4a0dc5f3c62ca9b7356621c757d5b732..7c2b71bb0108db90fbddc8917abb696d8e53591b 100644 (file)
@@ -1,5 +1,8 @@
 2019-02-14  Jakub Jelinek  <jakub@redhat.com>
 
+       PR tree-optimization/89314
+       * gcc.dg/pr89314.c: New test.
+
        PR middle-end/89284
        * gcc.dg/ubsan/pr89284.c: New test.
 
diff --git a/gcc/testsuite/gcc.dg/pr89314.c b/gcc/testsuite/gcc.dg/pr89314.c
new file mode 100644 (file)
index 0000000..e35dd8c
--- /dev/null
@@ -0,0 +1,13 @@
+/* PR tree-optimization/89314 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wbuiltin-declaration-mismatch -Wextra" } */
+
+extern __SIZE_TYPE__ strlen (const float *);   /* { dg-warning "mismatch in argument 1 type of built-in function" } */
+void bar (void);
+
+void
+foo (float *s)
+{
+  if (strlen (s) > 0)
+    bar ();
+}