diff gcc/sanopt.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
line wrap: on
line diff
--- a/gcc/sanopt.c	Fri Oct 27 22:46:09 2017 +0900
+++ b/gcc/sanopt.c	Thu Oct 25 07:37:49 2018 +0900
@@ -1,5 +1,5 @@
 /* Optimize and expand sanitizer functions.
-   Copyright (C) 2014-2017 Free Software Foundation, Inc.
+   Copyright (C) 2014-2018 Free Software Foundation, Inc.
    Contributed by Marek Polacek <polacek@redhat.com>
 
 This file is part of GCC.
@@ -459,7 +459,7 @@
 static bool
 maybe_optimize_ubsan_ptr_ifn (sanopt_ctx *ctx, gimple *stmt)
 {
-  HOST_WIDE_INT bitsize, bitpos;
+  poly_int64 bitsize, pbitpos;
   machine_mode mode;
   int volatilep = 0, reversep, unsignedp = 0;
   tree offset;
@@ -483,12 +483,20 @@
     {
       base = TREE_OPERAND (base, 0);
 
-      base = get_inner_reference (base, &bitsize, &bitpos, &offset, &mode,
+      HOST_WIDE_INT bitpos;
+      base = get_inner_reference (base, &bitsize, &pbitpos, &offset, &mode,
 				  &unsignedp, &reversep, &volatilep);
-      if (offset == NULL_TREE && DECL_P (base))
+      if ((offset == NULL_TREE || TREE_CODE (offset) == INTEGER_CST)
+	  && DECL_P (base)
+	  && !DECL_REGISTER (base)
+	  && pbitpos.is_constant (&bitpos))
 	{
-	  gcc_assert (!DECL_REGISTER (base));
-	  offset_int expr_offset = bitpos / BITS_PER_UNIT;
+	  offset_int expr_offset;
+	  if (offset)
+	    expr_offset = wi::to_offset (offset) + bitpos / BITS_PER_UNIT;
+	  else
+	    expr_offset = bitpos / BITS_PER_UNIT;
+	  expr_offset = wi::sext (expr_offset, POINTER_SIZE);
 	  offset_int total_offset = expr_offset + cur_offset;
 	  if (total_offset != wi::sext (total_offset, POINTER_SIZE))
 	    {
@@ -508,7 +516,7 @@
 	      && (!is_global_var (base) || decl_binds_to_current_def_p (base)))
 	    {
 	      offset_int base_size = wi::to_offset (DECL_SIZE_UNIT (base));
-	      if (bitpos >= 0
+	      if (!wi::neg_p (expr_offset)
 		  && wi::les_p (total_offset, base_size))
 		{
 		  if (!wi::neg_p (total_offset)
@@ -529,7 +537,7 @@
 	     */
 
 	  bool sign_cur_offset = !wi::neg_p (cur_offset);
-	  bool sign_expr_offset = bitpos >= 0;
+	  bool sign_expr_offset = !wi::neg_p (expr_offset);
 
 	  tree base_addr
 	    = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (base)), base);
@@ -1140,7 +1148,9 @@
        arg; arg = DECL_CHAIN (arg))
     {
       tree type = TREE_TYPE (arg);
-      if (TREE_ADDRESSABLE (arg) && !TREE_ADDRESSABLE (type)
+      if (TREE_ADDRESSABLE (arg)
+	  && !TREE_ADDRESSABLE (type)
+	  && !TREE_THIS_VOLATILE (arg)
 	  && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
 	{
 	  TREE_ADDRESSABLE (arg) = 0;
@@ -1155,13 +1165,15 @@
 
 	  gimple_add_tmp_var (var);
 
+	  /* We skip parameters that have a DECL_VALUE_EXPR.  */
+	  if (DECL_HAS_VALUE_EXPR_P (arg))
+	    continue;
+
 	  if (dump_file)
 	    fprintf (dump_file,
 		     "Rewriting parameter whose address is taken: %s\n",
 		     IDENTIFIER_POINTER (DECL_NAME (arg)));
 
-	  gcc_assert (!DECL_HAS_VALUE_EXPR_P (arg));
-
 	  SET_DECL_PT_UID (var, DECL_PT_UID (arg));
 
 	  /* Assign value of parameter to newly created variable.  */