diff gcc/calls.c @ 132:d34655255c78

update gcc-8.2
author mir3636
date Thu, 25 Oct 2018 10:21:07 +0900
parents fe568345ddd5 84e7813d76e9
children 420680fc7707
line wrap: on
line diff
--- a/gcc/calls.c	Thu Oct 25 08:08:40 2018 +0900
+++ b/gcc/calls.c	Thu Oct 25 10:21:07 2018 +0900
@@ -1,5 +1,5 @@
 /* Convert function calls to rtl insns, for GNU C compiler.
-   Copyright (C) 1989-2017 Free Software Foundation, Inc.
+   Copyright (C) 1989-2018 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -47,13 +47,14 @@
 #include "except.h"
 #include "dbgcnt.h"
 #include "rtl-iter.h"
-#include "tree-chkp.h"
 #include "tree-vrp.h"
 #include "tree-ssanames.h"
-#include "rtl-chkp.h"
+#include "tree-ssa-strlen.h"
 #include "intl.h"
 #include "stringpool.h"
 #include "attribs.h"
+#include "builtins.h"
+#include "gimple-fold.h"
 
 /* Like PREFERRED_STACK_BOUNDARY but in units of bytes, not bits.  */
 #define STACK_BYTES (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)
@@ -130,7 +131,11 @@
 static char *stack_usage_map;
 
 /* Size of STACK_USAGE_MAP.  */
-static int highest_outgoing_arg_in_use;
+static unsigned int highest_outgoing_arg_in_use;
+
+/* Assume that any stack location at this byte index is used,
+   without checking the contents of stack_usage_map.  */
+static unsigned HOST_WIDE_INT stack_usage_watermark = HOST_WIDE_INT_M1U;
 
 /* A bitmap of virtual-incoming stack space.  Bit is set if the corresponding
    stack location's tail call argument has been already stored into the stack.
@@ -139,6 +144,10 @@
    overwritten with tail call arguments.  */
 static sbitmap stored_args_map;
 
+/* Assume that any virtual-incoming location at this byte index has been
+   stored, without checking the contents of stored_args_map.  */
+static unsigned HOST_WIDE_INT stored_args_watermark;
+
 /* stack_arg_under_construction is nonzero when an argument may be
    initialized with a constructor call (including a C function that
    returns a BLKmode struct) and expand_call must take special action
@@ -146,23 +155,12 @@
    argument list for the constructor call.  */
 static int stack_arg_under_construction;
 
-static void emit_call_1 (rtx, tree, tree, tree, HOST_WIDE_INT, HOST_WIDE_INT,
-			 HOST_WIDE_INT, rtx, rtx, int, rtx, int,
-			 cumulative_args_t);
 static void precompute_register_parameters (int, struct arg_data *, int *);
-static void store_bounds (struct arg_data *, struct arg_data *);
 static int store_one_arg (struct arg_data *, rtx, int, int, int);
 static void store_unaligned_arguments_into_pseudos (struct arg_data *, int);
 static int finalize_must_preallocate (int, int, struct arg_data *,
 				      struct args_size *);
 static void precompute_arguments (int, struct arg_data *);
-static int compute_argument_block_size (int, struct args_size *, tree, tree, int);
-static void initialize_argument_information (int, struct arg_data *,
-					     struct args_size *, int,
-					     tree, tree,
-					     tree, tree, cumulative_args_t, int,
-					     rtx *, int *, int *, int *,
-					     bool *, bool);
 static void compute_argument_addresses (struct arg_data *, rtx, int);
 static rtx rtx_for_function_call (tree, tree);
 static void load_register_parameters (struct arg_data *, int, rtx *, int,
@@ -171,8 +169,6 @@
 static int check_sibcall_argument_overlap_1 (rtx);
 static int check_sibcall_argument_overlap (rtx_insn *, struct arg_data *, int);
 
-static int combine_pending_stack_adjustment_and_call (int, struct args_size *,
-						      unsigned int);
 static tree split_complex_types (tree);
 
 #ifdef REG_PARM_STACK_SPACE
@@ -180,6 +176,46 @@
 static void restore_fixed_argument_area (rtx, rtx, int, int);
 #endif
 
+/* Return true if bytes [LOWER_BOUND, UPPER_BOUND) of the outgoing
+   stack region might already be in use.  */
+
+static bool
+stack_region_maybe_used_p (poly_uint64 lower_bound, poly_uint64 upper_bound,
+			   unsigned int reg_parm_stack_space)
+{
+  unsigned HOST_WIDE_INT const_lower, const_upper;
+  const_lower = constant_lower_bound (lower_bound);
+  if (!upper_bound.is_constant (&const_upper))
+    const_upper = HOST_WIDE_INT_M1U;
+
+  if (const_upper > stack_usage_watermark)
+    return true;
+
+  /* Don't worry about things in the fixed argument area;
+     it has already been saved.  */
+  const_lower = MAX (const_lower, reg_parm_stack_space);
+  const_upper = MIN (const_upper, highest_outgoing_arg_in_use);
+  for (unsigned HOST_WIDE_INT i = const_lower; i < const_upper; ++i)
+    if (stack_usage_map[i])
+      return true;
+  return false;
+}
+
+/* Record that bytes [LOWER_BOUND, UPPER_BOUND) of the outgoing
+   stack region are now in use.  */
+
+static void
+mark_stack_region_used (poly_uint64 lower_bound, poly_uint64 upper_bound)
+{
+  unsigned HOST_WIDE_INT const_lower, const_upper;
+  const_lower = constant_lower_bound (lower_bound);
+  if (upper_bound.is_constant (&const_upper))
+    for (unsigned HOST_WIDE_INT i = const_lower; i < const_upper; ++i)
+      stack_usage_map[i] = 1;
+  else
+    stack_usage_watermark = MIN (stack_usage_watermark, const_lower);
+}
+
 /* Force FUNEXP into a form suitable for the address of a CALL,
    and return that as an rtx.  Also load the static chain register
    if FNDECL is a nested function.
@@ -342,17 +378,17 @@
 static void
 emit_call_1 (rtx funexp, tree fntree ATTRIBUTE_UNUSED, tree fndecl ATTRIBUTE_UNUSED,
 	     tree funtype ATTRIBUTE_UNUSED,
-	     HOST_WIDE_INT stack_size ATTRIBUTE_UNUSED,
-	     HOST_WIDE_INT rounded_stack_size,
-	     HOST_WIDE_INT struct_value_size ATTRIBUTE_UNUSED,
+	     poly_int64 stack_size ATTRIBUTE_UNUSED,
+	     poly_int64 rounded_stack_size,
+	     poly_int64 struct_value_size ATTRIBUTE_UNUSED,
 	     rtx next_arg_reg ATTRIBUTE_UNUSED, rtx valreg,
 	     int old_inhibit_defer_pop, rtx call_fusage, int ecf_flags,
 	     cumulative_args_t args_so_far ATTRIBUTE_UNUSED)
 {
-  rtx rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
+  rtx rounded_stack_size_rtx = gen_int_mode (rounded_stack_size, Pmode);
   rtx call, funmem, pat;
   int already_popped = 0;
-  HOST_WIDE_INT n_popped = 0;
+  poly_int64 n_popped = 0;
 
   /* Sibling call patterns never pop arguments (no sibcall(_value)_pop
      patterns exist).  Any popping that the callee does on return will
@@ -404,18 +440,19 @@
 					 next_arg_reg, NULL_RTX);
       else
 	pat = targetm.gen_sibcall (funmem, rounded_stack_size_rtx,
-				   next_arg_reg, GEN_INT (struct_value_size));
+				   next_arg_reg,
+				   gen_int_mode (struct_value_size, Pmode));
     }
   /* If the target has "call" or "call_value" insns, then prefer them
      if no arguments are actually popped.  If the target does not have
      "call" or "call_value" insns, then we must use the popping versions
      even if the call has no arguments to pop.  */
-  else if (n_popped > 0
+  else if (maybe_ne (n_popped, 0)
 	   || !(valreg
 		? targetm.have_call_value ()
 		: targetm.have_call ()))
     {
-      rtx n_pop = GEN_INT (n_popped);
+      rtx n_pop = gen_int_mode (n_popped, Pmode);
 
       /* If this subroutine pops its own args, record that in the call insn
 	 if possible, for the sake of frame pointer elimination.  */
@@ -437,7 +474,7 @@
 				      next_arg_reg, NULL_RTX);
       else
 	pat = targetm.gen_call (funmem, rounded_stack_size_rtx, next_arg_reg,
-				GEN_INT (struct_value_size));
+				gen_int_mode (struct_value_size, Pmode));
     }
   emit_insn (pat);
 
@@ -452,10 +489,6 @@
       && MEM_EXPR (funmem) != NULL_TREE)
     set_mem_expr (XEXP (call, 0), MEM_EXPR (funmem));
 
-  /* Mark instrumented calls.  */
-  if (call && fntree)
-    CALL_EXPR_WITH_BOUNDS_P (call) = CALL_WITH_BOUNDS_P (fntree);
-
   /* Put the register usage information there.  */
   add_function_usage_to (call_insn, call_fusage);
 
@@ -489,7 +522,7 @@
      if the context of the call as a whole permits.  */
   inhibit_defer_pop = old_inhibit_defer_pop;
 
-  if (n_popped > 0)
+  if (maybe_ne (n_popped, 0))
     {
       if (!already_popped)
 	CALL_INSN_FUNCTION_USAGE (call_insn)
@@ -497,10 +530,10 @@
 			       gen_rtx_CLOBBER (VOIDmode, stack_pointer_rtx),
 			       CALL_INSN_FUNCTION_USAGE (call_insn));
       rounded_stack_size -= n_popped;
-      rounded_stack_size_rtx = GEN_INT (rounded_stack_size);
+      rounded_stack_size_rtx = gen_int_mode (rounded_stack_size, Pmode);
       stack_pointer_delta -= n_popped;
 
-      add_reg_note (call_insn, REG_ARGS_SIZE, GEN_INT (stack_pointer_delta));
+      add_args_size_note (call_insn, stack_pointer_delta);
 
       /* If popup is needed, stack realign must use DRAP  */
       if (SUPPORTS_STACK_ALIGNMENT)
@@ -510,7 +543,7 @@
      REG_ARGS_SIZE note to prevent crossjumping of calls with different
      args sizes.  */
   else if (!ACCUMULATE_OUTGOING_ARGS && (ecf_flags & ECF_NORETURN) != 0)
-    add_reg_note (call_insn, REG_ARGS_SIZE, GEN_INT (stack_pointer_delta));
+    add_args_size_note (call_insn, stack_pointer_delta);
 
   if (!ACCUMULATE_OUTGOING_ARGS)
     {
@@ -521,7 +554,7 @@
 	 If returning from the subroutine does pop the args, indicate that the
 	 stack pointer will be changed.  */
 
-      if (rounded_stack_size != 0)
+      if (maybe_ne (rounded_stack_size, 0))
 	{
 	  if (ecf_flags & ECF_NORETURN)
 	    /* Just pretend we did the pop.  */
@@ -544,8 +577,8 @@
 
      ??? It will be worthwhile to enable combine_stack_adjustments even for
      such machines.  */
-  else if (n_popped)
-    anti_adjust_stack (GEN_INT (n_popped));
+  else if (maybe_ne (n_popped, 0))
+    anti_adjust_stack (gen_int_mode (n_popped, Pmode));
 }
 
 /* Determine if the function identified by FNDECL is one with
@@ -562,12 +595,6 @@
 {
   tree name_decl = DECL_NAME (fndecl);
 
-  /* For instrumentation clones we want to derive flags
-     from the original name.  */
-  if (cgraph_node::get (fndecl)
-      && cgraph_node::get (fndecl)->instrumentation_clone)
-    name_decl = DECL_NAME (cgraph_node::get (fndecl)->orig_decl);
-
   if (fndecl && name_decl
       && IDENTIFIER_LENGTH (name_decl) <= 11
       /* Exclude functions not at the file scope, or not `extern',
@@ -691,11 +718,11 @@
     return false;
 
   fndecl = gimple_call_fndecl (stmt);
-  if (fndecl && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
+  if (fndecl && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
     switch (DECL_FUNCTION_CODE (fndecl))
       {
       CASE_BUILT_IN_ALLOCA:
-        return true;
+	return gimple_call_num_args (stmt) > 0;
       default:
 	break;
       }
@@ -1011,8 +1038,8 @@
 static rtx
 save_fixed_argument_area (int reg_parm_stack_space, rtx argblock, int *low_to_save, int *high_to_save)
 {
-  int low;
-  int high;
+  unsigned int low;
+  unsigned int high;
 
   /* Compute the boundary of the area that needs to be saved, if any.  */
   high = reg_parm_stack_space;
@@ -1023,7 +1050,7 @@
     high = highest_outgoing_arg_in_use;
 
   for (low = 0; low < high; low++)
-    if (stack_usage_map[low] != 0)
+    if (stack_usage_map[low] != 0 || low >= stack_usage_watermark)
       {
 	int num_to_save;
 	machine_mode save_mode;
@@ -1195,75 +1222,30 @@
 static tree
 alloc_max_size (void)
 {
-  if (!alloc_object_size_limit)
-    {
-      alloc_object_size_limit = TYPE_MAX_VALUE (ssizetype);
-
-      if (warn_alloc_size_limit)
-	{
-	  char *end = NULL;
-	  errno = 0;
-	  unsigned HOST_WIDE_INT unit = 1;
-	  unsigned HOST_WIDE_INT limit
-	    = strtoull (warn_alloc_size_limit, &end, 10);
-
-	  if (!errno)
-	    {
-	      if (end && *end)
-		{
-		  /* Numeric option arguments are at most INT_MAX.  Make it
-		     possible to specify a larger value by accepting common
-		     suffixes.  */
-		  if (!strcmp (end, "kB"))
-		    unit = 1000;
-		  else if (!strcasecmp (end, "KiB") || strcmp (end, "KB"))
-		    unit = 1024;
-		  else if (!strcmp (end, "MB"))
-		    unit = HOST_WIDE_INT_UC (1000) * 1000;
-		  else if (!strcasecmp (end, "MiB"))
-		    unit = HOST_WIDE_INT_UC (1024) * 1024;
-		  else if (!strcasecmp (end, "GB"))
-		    unit = HOST_WIDE_INT_UC (1000) * 1000 * 1000;
-		  else if (!strcasecmp (end, "GiB"))
-		    unit = HOST_WIDE_INT_UC (1024) * 1024 * 1024;
-		  else if (!strcasecmp (end, "TB"))
-		    unit = HOST_WIDE_INT_UC (1000) * 1000 * 1000 * 1000;
-		  else if (!strcasecmp (end, "TiB"))
-		    unit = HOST_WIDE_INT_UC (1024) * 1024 * 1024 * 1024;
-		  else if (!strcasecmp (end, "PB"))
-		    unit = HOST_WIDE_INT_UC (1000) * 1000 * 1000 * 1000 * 1000;
-		  else if (!strcasecmp (end, "PiB"))
-		    unit = HOST_WIDE_INT_UC (1024) * 1024 * 1024 * 1024 * 1024;
-		  else if (!strcasecmp (end, "EB"))
-		    unit = HOST_WIDE_INT_UC (1000) * 1000 * 1000 * 1000 * 1000
-			   * 1000;
-		  else if (!strcasecmp (end, "EiB"))
-		    unit = HOST_WIDE_INT_UC (1024) * 1024 * 1024 * 1024 * 1024
-			   * 1024;
-		  else
-		    unit = 0;
-		}
-
-	      if (unit)
-		{
-		  widest_int w = wi::mul (limit, unit);
-		  if (w < wi::to_widest (alloc_object_size_limit))
-		    alloc_object_size_limit = wide_int_to_tree (ssizetype, w);
-		}
-	    }
-	}
-    }
+  if (alloc_object_size_limit)
+    return alloc_object_size_limit;
+
+  HOST_WIDE_INT limit = warn_alloc_size_limit;
+  if (limit == HOST_WIDE_INT_MAX)
+    limit = tree_to_shwi (TYPE_MAX_VALUE (ptrdiff_type_node));
+
+  alloc_object_size_limit = build_int_cst (size_type_node, limit);
+
   return alloc_object_size_limit;
 }
 
 /* Return true when EXP's range can be determined and set RANGE[] to it
-   after adjusting it if necessary to make EXP a valid size argument to
-   an allocation function declared with attribute alloc_size (whose
-   argument may be signed), or to a string manipulation function like
-   memset.  */
+   after adjusting it if necessary to make EXP a represents a valid size
+   of object, or a valid size argument to an allocation function declared
+   with attribute alloc_size (whose argument may be signed), or to a string
+   manipulation function like memset.  When ALLOW_ZERO is true, allow
+   returning a range of [0, 0] for a size in an anti-range [1, N] where
+   N > PTRDIFF_MAX.  A zero range is a (nearly) invalid argument to
+   allocation functions like malloc but it is a valid argument to
+   functions like memset.  */
 
 bool
-get_size_range (tree exp, tree range[2])
+get_size_range (tree exp, tree range[2], bool allow_zero /* = false */)
 {
   if (tree_fits_uhwi_p (exp))
     {
@@ -1272,20 +1254,33 @@
       return true;
     }
 
+  tree exptype = TREE_TYPE (exp);
+  bool integral = INTEGRAL_TYPE_P (exptype);
+
   wide_int min, max;
-  enum value_range_type range_type
-    = ((TREE_CODE (exp) == SSA_NAME && INTEGRAL_TYPE_P (TREE_TYPE (exp)))
-       ? get_range_info (exp, &min, &max) : VR_VARYING);
+  enum value_range_kind range_type;
+
+  if (integral)
+    range_type = determine_value_range (exp, &min, &max);
+  else
+    range_type = VR_VARYING;
 
   if (range_type == VR_VARYING)
     {
-      /* No range information available.  */
+      if (integral)
+	{
+	  /* Use the full range of the type of the expression when
+	     no value range information is available.  */
+	  range[0] = TYPE_MIN_VALUE (exptype);
+	  range[1] = TYPE_MAX_VALUE (exptype);
+	  return true;
+	}
+
       range[0] = NULL_TREE;
       range[1] = NULL_TREE;
       return false;
     }
 
-  tree exptype = TREE_TYPE (exp);
   unsigned expprec = TYPE_PRECISION (exptype);
 
   bool signed_p = !TYPE_UNSIGNED (exptype);
@@ -1323,11 +1318,16 @@
 	{
 	  /* EXP is unsigned and not in the range [1, MAX].  That means
 	     it's either zero or greater than MAX.  Even though 0 would
-	     normally be detected by -Walloc-zero set the range to
-	     [MAX, TYPE_MAX] so that when MAX is greater than the limit
-	     the whole range is diagnosed.  */
-	  min = max + 1;
-	  max = wi::to_wide (TYPE_MAX_VALUE (exptype));
+	     normally be detected by -Walloc-zero, unless ALLOW_ZERO
+	     is true, set the range to [MAX, TYPE_MAX] so that when MAX
+	     is greater than the limit the whole range is diagnosed.  */
+	  if (allow_zero)
+	    min = max = wi::zero (expprec);
+	  else
+	    {
+	      min = max + 1;
+	      max = wi::to_wide (TYPE_MAX_VALUE (exptype));
+	    }
 	}
       else
 	{
@@ -1454,7 +1454,7 @@
       wide_int x = wi::to_wide (argrange[0][0], szprec);
       wide_int y = wi::to_wide (argrange[1][0], szprec);
 
-      bool vflow;
+      wi::overflow_type vflow;
       wide_int prod = wi::umul (x, y, &vflow);
 
       if (vflow)
@@ -1497,6 +1497,324 @@
     }
 }
 
+/* If EXPR refers to a character array or pointer declared attribute
+   nonstring return a decl for that array or pointer and set *REF to
+   the referenced enclosing object or pointer.  Otherwise returns
+   null.  */
+
+tree
+get_attr_nonstring_decl (tree expr, tree *ref)
+{
+  tree decl = expr;
+  if (TREE_CODE (decl) == SSA_NAME)
+    {
+      gimple *def = SSA_NAME_DEF_STMT (decl);
+
+      if (is_gimple_assign (def))
+	{
+	  tree_code code = gimple_assign_rhs_code (def);
+	  if (code == ADDR_EXPR
+	      || code == COMPONENT_REF
+	      || code == VAR_DECL)
+	    decl = gimple_assign_rhs1 (def);
+	}
+      else if (tree var = SSA_NAME_VAR (decl))
+	decl = var;
+    }
+
+  if (TREE_CODE (decl) == ADDR_EXPR)
+    decl = TREE_OPERAND (decl, 0);
+
+  if (ref)
+    *ref = decl;
+
+  if (TREE_CODE (decl) == ARRAY_REF)
+    decl = TREE_OPERAND (decl, 0);
+  else if (TREE_CODE (decl) == COMPONENT_REF)
+    decl = TREE_OPERAND (decl, 1);
+  else if (TREE_CODE (decl) == MEM_REF)
+    return get_attr_nonstring_decl (TREE_OPERAND (decl, 0), ref);
+
+  if (DECL_P (decl)
+      && lookup_attribute ("nonstring", DECL_ATTRIBUTES (decl)))
+    return decl;
+
+  return NULL_TREE;
+}
+
+/* Warn about passing a non-string array/pointer to a function that
+   expects a nul-terminated string argument.  */
+
+void
+maybe_warn_nonstring_arg (tree fndecl, tree exp)
+{
+  if (!fndecl || !fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
+    return;
+
+  if (TREE_NO_WARNING (exp) || !warn_stringop_overflow)
+    return;
+
+  unsigned nargs = call_expr_nargs (exp);
+
+  /* The bound argument to a bounded string function like strncpy.  */
+  tree bound = NULL_TREE;
+
+  /* The range of lengths of a string argument to one of the comparison
+     functions.  If the length is less than the bound it is used instead.  */
+  tree lenrng[2] = { NULL_TREE, NULL_TREE };
+
+  /* It's safe to call "bounded" string functions with a non-string
+     argument since the functions provide an explicit bound for this
+     purpose.  The exception is strncat where the bound may refer to
+     either the destination or the source.  */
+  int fncode = DECL_FUNCTION_CODE (fndecl);
+  switch (fncode)
+    {
+    case BUILT_IN_STRCMP:
+    case BUILT_IN_STRNCMP:
+    case BUILT_IN_STRNCASECMP:
+      {
+	/* For these, if one argument refers to one or more of a set
+	   of string constants or arrays of known size, determine
+	   the range of their known or possible lengths and use it
+	   conservatively as the bound for the unbounded function,
+	   and to adjust the range of the bound of the bounded ones.  */
+	for (unsigned argno = 0;
+	     argno < MIN (nargs, 2)
+	     && !(lenrng[1] && TREE_CODE (lenrng[1]) == INTEGER_CST); argno++)
+	  {
+	    tree arg = CALL_EXPR_ARG (exp, argno);
+	    if (!get_attr_nonstring_decl (arg))
+	      get_range_strlen (arg, lenrng);
+	  }
+      }
+      /* Fall through.  */
+
+    case BUILT_IN_STRNCAT:
+    case BUILT_IN_STPNCPY:
+    case BUILT_IN_STRNCPY:
+      if (nargs > 2)
+	bound = CALL_EXPR_ARG (exp, 2);
+      break;
+
+    case BUILT_IN_STRNDUP:
+      if (nargs > 1)
+	bound = CALL_EXPR_ARG (exp, 1);
+      break;
+
+    case BUILT_IN_STRNLEN:
+      {
+	tree arg = CALL_EXPR_ARG (exp, 0);
+	if (!get_attr_nonstring_decl (arg))
+	  get_range_strlen (arg, lenrng);
+
+	if (nargs > 1)
+	  bound = CALL_EXPR_ARG (exp, 1);
+	break;
+      }
+
+    default:
+      break;
+    }
+
+  /* Determine the range of the bound argument (if specified).  */
+  tree bndrng[2] = { NULL_TREE, NULL_TREE };
+  if (bound)
+    {
+      STRIP_NOPS (bound);
+      get_size_range (bound, bndrng);
+    }
+
+  location_t loc = EXPR_LOCATION (exp);
+
+  if (bndrng[0])
+    {
+      /* Diagnose excessive bound prior the adjustment below and
+	 regardless of attribute nonstring.  */
+      tree maxobjsize = max_object_size ();
+      if (tree_int_cst_lt (maxobjsize, bndrng[0]))
+	{
+	  if (tree_int_cst_equal (bndrng[0], bndrng[1]))
+	    warning_at (loc, OPT_Wstringop_overflow_,
+			"%K%qD specified bound %E "
+			"exceeds maximum object size %E",
+			exp, fndecl, bndrng[0], maxobjsize);
+	  else
+	    warning_at (loc, OPT_Wstringop_overflow_,
+			"%K%qD specified bound [%E, %E] "
+			"exceeds maximum object size %E",
+			exp, fndecl, bndrng[0], bndrng[1], maxobjsize);
+	  return;
+	}
+    }
+
+  if (lenrng[1] && TREE_CODE (lenrng[1]) == INTEGER_CST)
+    {
+      /* Add one for the nul.  */
+      lenrng[1] = const_binop (PLUS_EXPR, TREE_TYPE (lenrng[1]),
+			       lenrng[1], size_one_node);
+
+      if (!bndrng[0])
+	{
+	  /* Conservatively use the upper bound of the lengths for
+	     both the lower and the upper bound of the operation.  */
+	  bndrng[0] = lenrng[1];
+	  bndrng[1] = lenrng[1];
+	  bound = void_type_node;
+	}
+      else
+	{
+	  /* Replace the bound on the operation with the upper bound
+	     of the length of the string if the latter is smaller.  */
+	  if (tree_int_cst_lt (lenrng[1], bndrng[0]))
+	    bndrng[0] = lenrng[1];
+	  else if (tree_int_cst_lt (lenrng[1], bndrng[1]))
+	    bndrng[1] = lenrng[1];
+	}
+    }
+
+  /* Iterate over the built-in function's formal arguments and check
+     each const char* against the actual argument.  If the actual
+     argument is declared attribute non-string issue a warning unless
+     the argument's maximum length is bounded.  */
+  function_args_iterator it;
+  function_args_iter_init (&it, TREE_TYPE (fndecl));
+
+  for (unsigned argno = 0; ; ++argno, function_args_iter_next (&it))
+    {
+      /* Avoid iterating past the declared argument in a call
+	 to function declared without a prototype.  */
+      if (argno >= nargs)
+	break;
+
+      tree argtype = function_args_iter_cond (&it);
+      if (!argtype)
+	break;
+
+      if (TREE_CODE (argtype) != POINTER_TYPE)
+	continue;
+
+      argtype = TREE_TYPE (argtype);
+
+      if (TREE_CODE (argtype) != INTEGER_TYPE
+	  || !TYPE_READONLY (argtype))
+	continue;
+
+      argtype = TYPE_MAIN_VARIANT (argtype);
+      if (argtype != char_type_node)
+	continue;
+
+      tree callarg = CALL_EXPR_ARG (exp, argno);
+      if (TREE_CODE (callarg) == ADDR_EXPR)
+	callarg = TREE_OPERAND (callarg, 0);
+
+      /* See if the destination is declared with attribute "nonstring".  */
+      tree decl = get_attr_nonstring_decl (callarg);
+      if (!decl)
+	continue;
+
+      /* The maximum number of array elements accessed.  */
+      offset_int wibnd = 0;
+
+      if (argno && fncode == BUILT_IN_STRNCAT)
+	{
+	  /* See if the bound in strncat is derived from the length
+	     of the strlen of the destination (as it's expected to be).
+	     If so, reset BOUND and FNCODE to trigger a warning.  */
+	  tree dstarg = CALL_EXPR_ARG (exp, 0);
+	  if (is_strlen_related_p (dstarg, bound))
+	    {
+	      /* The bound applies to the destination, not to the source,
+		 so reset these to trigger a warning without mentioning
+		 the bound.  */
+	      bound = NULL;
+	      fncode = 0;
+	    }
+	  else if (bndrng[1])
+	    /* Use the upper bound of the range for strncat.  */
+	    wibnd = wi::to_offset (bndrng[1]);
+	}
+      else if (bndrng[0])
+	/* Use the lower bound of the range for functions other than
+	   strncat.  */
+	wibnd = wi::to_offset (bndrng[0]);
+
+      /* Determine the size of the argument array if it is one.  */
+      offset_int asize = wibnd;
+      bool known_size = false;
+      tree type = TREE_TYPE (decl);
+
+      /* Determine the array size.  For arrays of unknown bound and
+	 pointers reset BOUND to trigger the appropriate warning.  */
+      if (TREE_CODE (type) == ARRAY_TYPE)
+	{
+	  if (tree arrbnd = TYPE_DOMAIN (type))
+	    {
+	      if ((arrbnd = TYPE_MAX_VALUE (arrbnd)))
+		{
+		  asize = wi::to_offset (arrbnd) + 1;
+		  known_size = true;
+		}
+	    }
+	  else if (bound == void_type_node)
+	    bound = NULL_TREE;
+	}
+      else if (bound == void_type_node)
+	bound = NULL_TREE;
+
+      /* In a call to strncat with a bound in a range whose lower but
+	 not upper bound is less than the array size, reset ASIZE to
+	 be the same as the bound and the other variable to trigger
+	 the apprpriate warning below.  */
+      if (fncode == BUILT_IN_STRNCAT
+	  && bndrng[0] != bndrng[1]
+	  && wi::ltu_p (wi::to_offset (bndrng[0]), asize)
+	  && (!known_size
+	      || wi::ltu_p (asize, wibnd)))
+	{
+	  asize = wibnd;
+	  bound = NULL_TREE;
+	  fncode = 0;
+	}
+
+      bool warned = false;
+
+      auto_diagnostic_group d;
+      if (wi::ltu_p (asize, wibnd))
+	{
+	  if (bndrng[0] == bndrng[1])
+	    warned = warning_at (loc, OPT_Wstringop_overflow_,
+				 "%qD argument %i declared attribute "
+				 "%<nonstring%> is smaller than the specified "
+				 "bound %wu",
+				 fndecl, argno + 1, wibnd.to_uhwi ());
+	  else if (wi::ltu_p (asize, wi::to_offset (bndrng[0])))
+	    warned = warning_at (loc, OPT_Wstringop_overflow_,
+				 "%qD argument %i declared attribute "
+				 "%<nonstring%> is smaller than "
+				 "the specified bound [%E, %E]",
+				 fndecl, argno + 1, bndrng[0], bndrng[1]);
+	  else
+	    warned = warning_at (loc, OPT_Wstringop_overflow_,
+				 "%qD argument %i declared attribute "
+				 "%<nonstring%> may be smaller than "
+				 "the specified bound [%E, %E]",
+				 fndecl, argno + 1, bndrng[0], bndrng[1]);
+	}
+      else if (fncode == BUILT_IN_STRNCAT)
+	; /* Avoid warning for calls to strncat() when the bound
+	     is equal to the size of the non-string argument.  */
+      else if (!bound)
+	warned = warning_at (loc, OPT_Wstringop_overflow_,
+			     "%qD argument %i declared attribute %<nonstring%>",
+			     fndecl, argno + 1);
+
+      if (warned)
+	inform (DECL_SOURCE_LOCATION (decl),
+		"argument %qD declared here", decl);
+    }
+}
+
 /* Issue an error if CALL_EXPR was flagged as requiring
    tall-call optimization.  */
 
@@ -1549,7 +1867,8 @@
 				 tree fndecl, tree fntype,
 				 cumulative_args_t args_so_far,
 				 int reg_parm_stack_space,
-				 rtx *old_stack_level, int *old_pending_adj,
+				 rtx *old_stack_level,
+				 poly_int64_pod *old_pending_adj,
 				 int *must_preallocate, int *ecf_flags,
 				 bool *may_tailcall, bool call_from_thunk_p)
 {
@@ -1571,7 +1890,7 @@
 
   i = num_actuals - 1;
   {
-    int j = i, ptr_arg = -1;
+    int j = i;
     call_expr_arg_iterator iter;
     tree arg;
     bitmap slots = NULL;
@@ -1580,79 +1899,12 @@
       {
 	args[j].tree_value = struct_value_addr_value;
 	j--;
-
-	/* If we pass structure address then we need to
-	   create bounds for it.  Since created bounds is
-	   a call statement, we expand it right here to avoid
-	   fixing all other places where it may be expanded.  */
-	if (CALL_WITH_BOUNDS_P (exp))
-	  {
-	    args[j].value = gen_reg_rtx (targetm.chkp_bound_mode ());
-	    args[j].tree_value
-	      = chkp_make_bounds_for_struct_addr (struct_value_addr_value);
-	    expand_expr_real (args[j].tree_value, args[j].value, VOIDmode,
-			      EXPAND_NORMAL, 0, false);
-	    args[j].pointer_arg = j + 1;
-	    j--;
-	  }
       }
     argpos = 0;
     FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
       {
 	tree argtype = TREE_TYPE (arg);
 
-	/* Remember last param with pointer and associate it
-	   with following pointer bounds.  */
-	if (CALL_WITH_BOUNDS_P (exp)
-	    && chkp_type_has_pointer (argtype))
-	  {
-	    if (slots)
-	      BITMAP_FREE (slots);
-	    ptr_arg = j;
-	    if (!BOUNDED_TYPE_P (argtype))
-	      {
-		slots = BITMAP_ALLOC (NULL);
-		chkp_find_bound_slots (argtype, slots);
-	      }
-	  }
-	else if (CALL_WITH_BOUNDS_P (exp)
-		 && pass_by_reference (NULL, TYPE_MODE (argtype), argtype,
-				       argpos < n_named_args))
-	  {
-	    if (slots)
-	      BITMAP_FREE (slots);
-	    ptr_arg = j;
-	  }
-	else if (POINTER_BOUNDS_TYPE_P (argtype))
-	  {
-	    /* We expect bounds in instrumented calls only.
-	       Otherwise it is a sign we lost flag due to some optimization
-	       and may emit call args incorrectly.  */
-	    gcc_assert (CALL_WITH_BOUNDS_P (exp));
-
-	    /* For structures look for the next available pointer.  */
-	    if (ptr_arg != -1 && slots)
-	      {
-		unsigned bnd_no = bitmap_first_set_bit (slots);
-		args[j].pointer_offset =
-		  bnd_no * POINTER_SIZE / BITS_PER_UNIT;
-
-		bitmap_clear_bit (slots, bnd_no);
-
-		/* Check we have no more pointers in the structure.  */
-		if (bitmap_empty_p (slots))
-		  BITMAP_FREE (slots);
-	      }
-	    args[j].pointer_arg = ptr_arg;
-
-	    /* Check we covered all pointers in the previous
-	       non bounds arg.  */
-	    if (!slots)
-	      ptr_arg = -1;
-	  }
-	else
-	  ptr_arg = -1;
-
 	if (targetm.calls.split_complex_arg
 	    && argtype
 	    && TREE_CODE (argtype) == COMPLEX_TYPE
@@ -1773,7 +2025,7 @@
 		  *may_tailcall = false;
 		  maybe_complain_about_tail_call (exp,
 						  "a callee-copied argument is"
-						  " stored in the current "
+						  " stored in the current"
 						  " function's frame");
 		}
 
@@ -1853,6 +2105,8 @@
       args[i].unsignedp = unsignedp;
       args[i].mode = mode;
 
+      targetm.calls.warn_parameter_passing_abi (args_so_far, type);
+
       args[i].reg = targetm.calls.function_arg (args_so_far, mode, type,
 						argpos < n_named_args);
 
@@ -1895,11 +2149,8 @@
 	  || (args[i].pass_on_stack && args[i].reg != 0))
 	*must_preallocate = 1;
 
-      /* No stack allocation and padding for bounds.  */
-      if (POINTER_BOUNDS_P (args[i].tree_value))
-	;
       /* Compute the stack-size of this argument.  */
-      else if (args[i].reg == 0 || args[i].partial != 0
+      if (args[i].reg == 0 || args[i].partial != 0
 	       || reg_parm_stack_space > 0
 	       || args[i].pass_on_stack)
 	locate_and_pad_parm (mode, type,
@@ -1946,6 +2197,10 @@
 	 alloc_size.  */
       maybe_warn_alloc_args_overflow (fndecl, exp, alloc_args, alloc_idx);
     }
+
+  /* Detect passing non-string arguments to functions expecting
+     nul-terminated strings.  */
+  maybe_warn_nonstring_arg (fndecl, exp);
 }
 
 /* Update ARGS_SIZE to contain the total size for the argument block.
@@ -1954,14 +2209,14 @@
    REG_PARM_STACK_SPACE holds the number of bytes of stack space reserved
    for arguments passed in registers.  */
 
-static int
+static poly_int64
 compute_argument_block_size (int reg_parm_stack_space,
 			     struct args_size *args_size,
 			     tree fndecl ATTRIBUTE_UNUSED,
 			     tree fntype ATTRIBUTE_UNUSED,
 			     int preferred_stack_boundary ATTRIBUTE_UNUSED)
 {
-  int unadjusted_args_size = args_size->constant;
+  poly_int64 unadjusted_args_size = args_size->constant;
 
   /* For accumulate outgoing args mode we don't need to align, since the frame
      will be already aligned.  Align to STACK_BOUNDARY in order to prevent
@@ -1984,7 +2239,8 @@
 	  /* We don't handle this case yet.  To handle it correctly we have
 	     to add the delta, round and subtract the delta.
 	     Currently no machine description requires this support.  */
-	  gcc_assert (!(stack_pointer_delta & (preferred_stack_boundary - 1)));
+	  gcc_assert (multiple_p (stack_pointer_delta,
+				  preferred_stack_boundary));
 	  args_size->var = round_up (args_size->var, preferred_stack_boundary);
 	}
 
@@ -2007,15 +2263,13 @@
       preferred_stack_boundary /= BITS_PER_UNIT;
       if (preferred_stack_boundary < 1)
 	preferred_stack_boundary = 1;
-      args_size->constant = (((args_size->constant
-			       + stack_pointer_delta
-			       + preferred_stack_boundary - 1)
-			      / preferred_stack_boundary
-			      * preferred_stack_boundary)
+      args_size->constant = (aligned_upper_bound (args_size->constant
+						  + stack_pointer_delta,
+						  preferred_stack_boundary)
 			     - stack_pointer_delta);
 
-      args_size->constant = MAX (args_size->constant,
-				 reg_parm_stack_space);
+      args_size->constant = upper_bound (args_size->constant,
+					 reg_parm_stack_space);
 
       if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
 	args_size->constant -= reg_parm_stack_space;
@@ -2120,7 +2374,7 @@
   if (! must_preallocate)
     {
       int partial_seen = 0;
-      int copy_to_evaluate_size = 0;
+      poly_int64 copy_to_evaluate_size = 0;
       int i;
 
       for (i = 0; i < num_actuals && ! must_preallocate; i++)
@@ -2129,12 +2383,6 @@
 	    partial_seen = 1;
 	  else if (partial_seen && args[i].reg == 0)
 	    must_preallocate = 1;
-	  /* We preallocate in case there are bounds passed
-	     in the bounds table to have precomputed address
-	     for bounds association.  */
-	  else if (POINTER_BOUNDS_P (args[i].tree_value)
-		   && !args[i].reg)
-	    must_preallocate = 1;
 
 	  if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode
 	      && (TREE_CODE (args[i].tree_value) == CALL_EXPR
@@ -2145,8 +2393,8 @@
 	      += int_size_in_bytes (TREE_TYPE (args[i].tree_value));
 	}
 
-      if (copy_to_evaluate_size * 2 >= args_size->constant
-	  && args_size->constant > 0)
+      if (maybe_ne (args_size->constant, 0)
+	  && maybe_ge (copy_to_evaluate_size * 2, args_size->constant))
 	must_preallocate = 1;
     }
   return must_preallocate;
@@ -2166,10 +2414,14 @@
   if (argblock)
     {
       rtx arg_reg = argblock;
-      int i, arg_offset = 0;
+      int i;
+      poly_int64 arg_offset = 0;
 
       if (GET_CODE (argblock) == PLUS)
-	arg_reg = XEXP (argblock, 0), arg_offset = INTVAL (XEXP (argblock, 1));
+	{
+	  arg_reg = XEXP (argblock, 0);
+	  arg_offset = rtx_to_poly_int64 (XEXP (argblock, 1));
+	}
 
       for (i = 0; i < num_actuals; i++)
 	{
@@ -2177,7 +2429,7 @@
 	  rtx slot_offset = ARGS_SIZE_RTX (args[i].locate.slot_offset);
 	  rtx addr;
 	  unsigned int align, boundary;
-	  unsigned int units_on_stack = 0;
+	  poly_uint64 units_on_stack = 0;
 	  machine_mode partial_mode = VOIDmode;
 
 	  /* Skip this parm if it will not be passed on the stack.  */
@@ -2186,8 +2438,7 @@
 	      && args[i].partial == 0)
 	    continue;
 
-	  /* Pointer Bounds are never passed on the stack.  */
-	  if (POINTER_BOUNDS_P (args[i].tree_value))
+	  if (TYPE_EMPTY_P (TREE_TYPE (args[i].tree_value)))
 	    continue;
 
 	  addr = simplify_gen_binary (PLUS, Pmode, arg_reg, offset);
@@ -2198,7 +2449,7 @@
 	      /* Only part of the parameter is being passed on the stack.
 		 Generate a simple memory reference of the correct size.  */
 	      units_on_stack = args[i].locate.size.constant;
-	      unsigned int bits_on_stack = units_on_stack * BITS_PER_UNIT;
+	      poly_uint64 bits_on_stack = units_on_stack * BITS_PER_UNIT;
 	      partial_mode = int_mode_for_size (bits_on_stack, 1).else_blk ();
 	      args[i].stack = gen_rtx_MEM (partial_mode, addr);
 	      set_mem_size (args[i].stack, units_on_stack);
@@ -2211,12 +2462,16 @@
 	    }
 	  align = BITS_PER_UNIT;
 	  boundary = args[i].locate.boundary;
+	  poly_int64 offset_val;
 	  if (args[i].locate.where_pad != PAD_DOWNWARD)
 	    align = boundary;
-	  else if (CONST_INT_P (offset))
+	  else if (poly_int_rtx_p (offset, &offset_val))
 	    {
-	      align = INTVAL (offset) * BITS_PER_UNIT | boundary;
-	      align = least_bit_hwi (align);
+	      align = least_bit_hwi (boundary);
+	      unsigned int offset_align
+		= known_alignment (offset_val) * BITS_PER_UNIT;
+	      if (offset_align != 0)
+		align = MIN (align, offset_align);
 	    }
 	  set_mem_align (args[i].stack, align);
 
@@ -2281,6 +2536,17 @@
   return funexp;
 }
 
+/* Return the static chain for this function, if any.  */
+
+rtx
+rtx_for_static_chain (const_tree fndecl_or_type, bool incoming_p)
+{
+  if (DECL_P (fndecl_or_type) && !DECL_STATIC_CHAIN (fndecl_or_type))
+    return NULL;
+
+  return targetm.calls.static_chain (fndecl_or_type, incoming_p);
+}
+
 /* Internal state for internal_arg_pointer_based_exp and its helpers.  */
 static struct
 {
@@ -2359,12 +2625,13 @@
   if (REG_P (rtl) && HARD_REGISTER_P (rtl))
     return NULL_RTX;
 
-  if (GET_CODE (rtl) == PLUS && CONST_INT_P (XEXP (rtl, 1)))
+  poly_int64 offset;
+  if (GET_CODE (rtl) == PLUS && poly_int_rtx_p (XEXP (rtl, 1), &offset))
     {
       rtx val = internal_arg_pointer_based_exp (XEXP (rtl, 0), toplevel);
       if (val == NULL_RTX || val == pc_rtx)
 	return val;
-      return plus_constant (Pmode, val, INTVAL (XEXP (rtl, 1)));
+      return plus_constant (Pmode, val, offset);
     }
 
   /* When called at the topmost level, scan pseudo assignments in between the
@@ -2395,45 +2662,53 @@
   return NULL_RTX;
 }
 
-/* Return true if and only if SIZE storage units (usually bytes)
-   starting from address ADDR overlap with already clobbered argument
-   area.  This function is used to determine if we should give up a
-   sibcall.  */
+/* Return true if SIZE bytes starting from address ADDR might overlap an
+   already-clobbered argument area.  This function is used to determine
+   if we should give up a sibcall.  */
 
 static bool
-mem_overlaps_already_clobbered_arg_p (rtx addr, unsigned HOST_WIDE_INT size)
+mem_might_overlap_already_clobbered_arg_p (rtx addr, poly_uint64 size)
 {
-  HOST_WIDE_INT i;
+  poly_int64 i;
+  unsigned HOST_WIDE_INT start, end;
   rtx val;
 
-  if (bitmap_empty_p (stored_args_map))
+  if (bitmap_empty_p (stored_args_map)
+      && stored_args_watermark == HOST_WIDE_INT_M1U)
     return false;
   val = internal_arg_pointer_based_exp (addr, true);
   if (val == NULL_RTX)
     return false;
-  else if (val == pc_rtx)
+  else if (!poly_int_rtx_p (val, &i))
     return true;
-  else
-    i = INTVAL (val);
+
+  if (known_eq (size, 0U))
+    return false;
 
   if (STACK_GROWS_DOWNWARD)
     i -= crtl->args.pretend_args_size;
   else
     i += crtl->args.pretend_args_size;
 
-
   if (ARGS_GROW_DOWNWARD)
     i = -i - size;
 
-  if (size > 0)
-    {
-      unsigned HOST_WIDE_INT k;
-
-      for (k = 0; k < size; k++)
-	if (i + k < SBITMAP_SIZE (stored_args_map)
-	    && bitmap_bit_p (stored_args_map, i + k))
-	  return true;
-    }
+  /* We can ignore any references to the function's pretend args,
+     which at this point would manifest as negative values of I.  */
+  if (known_le (i, 0) && known_le (size, poly_uint64 (-i)))
+    return false;
+
+  start = maybe_lt (i, 0) ? 0 : constant_lower_bound (i);
+  if (!(i + size).is_constant (&end))
+    end = HOST_WIDE_INT_M1U;
+
+  if (end > stored_args_watermark)
+    return true;
+
+  end = MIN (end, SBITMAP_SIZE (stored_args_map));
+  for (unsigned HOST_WIDE_INT k = start; k < end; ++k)
+    if (bitmap_bit_p (stored_args_map, k))
+      return true;
 
   return false;
 }
@@ -2463,7 +2738,8 @@
 	{
 	  int partial = args[i].partial;
 	  int nregs;
-	  int size = 0;
+	  poly_int64 size = 0;
+	  HOST_WIDE_INT const_size = 0;
 	  rtx_insn *before_arg = get_last_insn ();
 	  /* Set non-negative if we must move a word at a time, even if
 	     just one word (e.g, partial == 4 && mode == DFmode).  Set
@@ -2479,8 +2755,12 @@
 	    }
 	  else if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode)
 	    {
-	      size = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
-	      nregs = (size + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
+	      /* Variable-sized parameters should be described by a
+		 PARALLEL instead.  */
+	      const_size = int_size_in_bytes (TREE_TYPE (args[i].tree_value));
+	      gcc_assert (const_size >= 0);
+	      nregs = (const_size + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
+	      size = const_size;
 	    }
 	  else
 	    size = GET_MODE_SIZE (args[i].mode);
@@ -2502,21 +2782,27 @@
 	      /* Handle case where we have a value that needs shifting
 		 up to the msb.  eg. a QImode value and we're padding
 		 upward on a BYTES_BIG_ENDIAN machine.  */
-	      if (size < UNITS_PER_WORD
-		  && (args[i].locate.where_pad
-		      == (BYTES_BIG_ENDIAN ? PAD_UPWARD : PAD_DOWNWARD)))
+	      if (args[i].locate.where_pad
+		  == (BYTES_BIG_ENDIAN ? PAD_UPWARD : PAD_DOWNWARD))
 		{
-		  rtx x;
-		  int shift = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
-
-		  /* Assigning REG here rather than a temp makes CALL_FUSAGE
-		     report the whole reg as used.  Strictly speaking, the
-		     call only uses SIZE bytes at the msb end, but it doesn't
-		     seem worth generating rtl to say that.  */
-		  reg = gen_rtx_REG (word_mode, REGNO (reg));
-		  x = expand_shift (LSHIFT_EXPR, word_mode, reg, shift, reg, 1);
-		  if (x != reg)
-		    emit_move_insn (reg, x);
+		  gcc_checking_assert (ordered_p (size, UNITS_PER_WORD));
+		  if (maybe_lt (size, UNITS_PER_WORD))
+		    {
+		      rtx x;
+		      poly_int64 shift
+			= (UNITS_PER_WORD - size) * BITS_PER_UNIT;
+
+		      /* Assigning REG here rather than a temp makes
+			 CALL_FUSAGE report the whole reg as used.
+			 Strictly speaking, the call only uses SIZE
+			 bytes at the msb end, but it doesn't seem worth
+			 generating rtl to say that.  */
+		      reg = gen_rtx_REG (word_mode, REGNO (reg));
+		      x = expand_shift (LSHIFT_EXPR, word_mode,
+					reg, shift, reg, 1);
+		      if (x != reg)
+			emit_move_insn (reg, x);
+		    }
 		}
 #endif
 	    }
@@ -2531,17 +2817,20 @@
 
 	  else if (partial == 0 || args[i].pass_on_stack)
 	    {
+	      /* SIZE and CONST_SIZE are 0 for partial arguments and
+		 the size of a BLKmode type otherwise.  */
+	      gcc_checking_assert (known_eq (size, const_size));
 	      rtx mem = validize_mem (copy_rtx (args[i].value));
 
 	      /* Check for overlap with already clobbered argument area,
 	         providing that this has non-zero size.  */
 	      if (is_sibcall
-		  && size != 0
-		  && (mem_overlaps_already_clobbered_arg_p
-		      (XEXP (args[i].value, 0), size)))
+		  && const_size != 0
+		  && (mem_might_overlap_already_clobbered_arg_p
+		      (XEXP (args[i].value, 0), const_size)))
 		*sibcall_failure = 1;
 
-	      if (size % UNITS_PER_WORD == 0
+	      if (const_size % UNITS_PER_WORD == 0
 		  || MEM_ALIGN (mem) % BITS_PER_WORD == 0)
 		move_block_to_reg (REGNO (reg), mem, nregs, args[i].mode);
 	      else
@@ -2551,7 +2840,7 @@
 				       args[i].mode);
 		  rtx dest = gen_rtx_REG (word_mode, REGNO (reg) + nregs - 1);
 		  unsigned int bitoff = (nregs - 1) * BITS_PER_WORD;
-		  unsigned int bitsize = size * BITS_PER_UNIT - bitoff;
+		  unsigned int bitsize = const_size * BITS_PER_UNIT - bitoff;
 		  rtx x = extract_bit_field (mem, bitsize, bitoff, 1, dest,
 					     word_mode, word_mode, false,
 					     NULL);
@@ -2563,7 +2852,7 @@
 		}
 
 	      /* Handle a BLKmode that needs shifting.  */
-	      if (nregs == 1 && size < UNITS_PER_WORD
+	      if (nregs == 1 && const_size < UNITS_PER_WORD
 #ifdef BLOCK_REG_PADDING
 		  && args[i].locate.where_pad == PAD_DOWNWARD
 #else
@@ -2572,7 +2861,7 @@
 		  )
 		{
 		  rtx dest = gen_rtx_REG (word_mode, REGNO (reg));
-		  int shift = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
+		  int shift = (UNITS_PER_WORD - const_size) * BITS_PER_UNIT;
 		  enum tree_code dir = (BYTES_BIG_ENDIAN
 					? RSHIFT_EXPR : LSHIFT_EXPR);
 		  rtx x;
@@ -2606,27 +2895,32 @@
 /* We need to pop PENDING_STACK_ADJUST bytes.  But, if the arguments
    wouldn't fill up an even multiple of PREFERRED_UNIT_STACK_BOUNDARY
    bytes, then we would need to push some additional bytes to pad the
-   arguments.  So, we compute an adjust to the stack pointer for an
+   arguments.  So, we try to compute an adjust to the stack pointer for an
    amount that will leave the stack under-aligned by UNADJUSTED_ARGS_SIZE
    bytes.  Then, when the arguments are pushed the stack will be perfectly
-   aligned.  ARGS_SIZE->CONSTANT is set to the number of bytes that should
-   be popped after the call.  Returns the adjustment.  */
-
-static int
-combine_pending_stack_adjustment_and_call (int unadjusted_args_size,
+   aligned.
+
+   Return true if this optimization is possible, storing the adjustment
+   in ADJUSTMENT_OUT and setting ARGS_SIZE->CONSTANT to the number of
+   bytes that should be popped after the call.  */
+
+static bool
+combine_pending_stack_adjustment_and_call (poly_int64_pod *adjustment_out,
+					   poly_int64 unadjusted_args_size,
 					   struct args_size *args_size,
 					   unsigned int preferred_unit_stack_boundary)
 {
   /* The number of bytes to pop so that the stack will be
      under-aligned by UNADJUSTED_ARGS_SIZE bytes.  */
-  HOST_WIDE_INT adjustment;
+  poly_int64 adjustment;
   /* The alignment of the stack after the arguments are pushed, if we
      just pushed the arguments without adjust the stack here.  */
   unsigned HOST_WIDE_INT unadjusted_alignment;
 
-  unadjusted_alignment
-    = ((stack_pointer_delta + unadjusted_args_size)
-       % preferred_unit_stack_boundary);
+  if (!known_misalignment (stack_pointer_delta + unadjusted_args_size,
+			   preferred_unit_stack_boundary,
+			   &unadjusted_alignment))
+    return false;
 
   /* We want to get rid of as many of the PENDING_STACK_ADJUST bytes
      as possible -- leaving just enough left to cancel out the
@@ -2635,15 +2929,24 @@
      -UNADJUSTED_ALIGNMENT modulo the PREFERRED_UNIT_STACK_BOUNDARY.  */
 
   /* Begin by trying to pop all the bytes.  */
-  unadjusted_alignment
-    = (unadjusted_alignment
-       - (pending_stack_adjust % preferred_unit_stack_boundary));
+  unsigned HOST_WIDE_INT tmp_misalignment;
+  if (!known_misalignment (pending_stack_adjust,
+			   preferred_unit_stack_boundary,
+			   &tmp_misalignment))
+    return false;
+  unadjusted_alignment -= tmp_misalignment;
   adjustment = pending_stack_adjust;
   /* Push enough additional bytes that the stack will be aligned
      after the arguments are pushed.  */
   if (preferred_unit_stack_boundary > 1 && unadjusted_alignment)
     adjustment -= preferred_unit_stack_boundary - unadjusted_alignment;
 
+  /* We need to know whether the adjusted argument size
+     (UNADJUSTED_ARGS_SIZE - ADJUSTMENT) constitutes an allocation
+     or a deallocation.  */
+  if (!ordered_p (adjustment, unadjusted_args_size))
+    return false;
+
   /* Now, sets ARGS_SIZE->CONSTANT so that we pop the right number of
      bytes after the call.  The right number is the entire
      PENDING_STACK_ADJUST less our ADJUSTMENT plus the amount required
@@ -2651,7 +2954,8 @@
   args_size->constant
     = pending_stack_adjust - adjustment + unadjusted_args_size;
 
-  return adjustment;
+  *adjustment_out = adjustment;
+  return true;
 }
 
 /* Scan X expression if it does not dereference any argument slots
@@ -2677,8 +2981,8 @@
     return 0;
 
   if (code == MEM)
-    return mem_overlaps_already_clobbered_arg_p (XEXP (x, 0),
-						 GET_MODE_SIZE (GET_MODE (x)));
+    return (mem_might_overlap_already_clobbered_arg_p
+	    (XEXP (x, 0), GET_MODE_SIZE (GET_MODE (x))));
 
   /* Scan all subexpressions.  */
   fmt = GET_RTX_FORMAT (code);
@@ -2710,7 +3014,8 @@
 check_sibcall_argument_overlap (rtx_insn *insn, struct arg_data *arg,
 				int mark_stored_args_map)
 {
-  int low, high;
+  poly_uint64 low, high;
+  unsigned HOST_WIDE_INT const_low, const_high;
 
   if (insn == NULL_RTX)
     insn = get_insns ();
@@ -2728,9 +3033,14 @@
 	low = -arg->locate.slot_offset.constant - arg->locate.size.constant;
       else
 	low = arg->locate.slot_offset.constant;
-
-      for (high = low + arg->locate.size.constant; low < high; low++)
-	bitmap_set_bit (stored_args_map, low);
+      high = low + arg->locate.size.constant;
+
+      const_low = constant_lower_bound (low);
+      if (high.is_constant (&const_high))
+	for (unsigned HOST_WIDE_INT i = const_low; i < const_high; ++i)
+	  bitmap_set_bit (stored_args_map, i);
+      else
+	stored_args_watermark = MIN (stored_args_watermark, const_low);
     }
   return insn != NULL_RTX;
 }
@@ -2742,18 +3052,19 @@
 bool
 shift_return_value (machine_mode mode, bool left_p, rtx value)
 {
-  HOST_WIDE_INT shift;
-
   gcc_assert (REG_P (value) && HARD_REGISTER_P (value));
-  shift = GET_MODE_BITSIZE (GET_MODE (value)) - GET_MODE_BITSIZE (mode);
-  if (shift == 0)
+  machine_mode value_mode = GET_MODE (value);
+  poly_int64 shift = GET_MODE_BITSIZE (value_mode) - GET_MODE_BITSIZE (mode);
+
+  if (known_eq (shift, 0))
     return false;
 
   /* Use ashr rather than lshr for right shifts.  This is for the benefit
      of the MIPS port, which requires SImode values to be sign-extended
      when stored in 64-bit registers.  */
-  if (!force_expand_binop (GET_MODE (value), left_p ? ashl_optab : ashr_optab,
-			   value, GEN_INT (shift), value, 1, OPTAB_WIDEN))
+  if (!force_expand_binop (value_mode, left_p ? ashl_optab : ashr_optab,
+			   value, gen_int_shift_amount (value_mode, shift),
+			   value, 1, OPTAB_WIDEN))
     gcc_unreachable ();
   return true;
 }
@@ -2875,7 +3186,8 @@
      function, we cannot change it into a sibling call.
      crtl->args.pretend_args_size is not part of the
      stack allocated by our caller.  */
-  if (args_size.constant > (crtl->args.size - crtl->args.pretend_args_size))
+  if (maybe_gt (args_size.constant,
+		crtl->args.size - crtl->args.pretend_args_size))
     {
       maybe_complain_about_tail_call (exp,
 				      "callee required more stack slots"
@@ -2885,10 +3197,12 @@
 
   /* If the callee pops its own arguments, then it must pop exactly
      the same number of arguments as the current function.  */
-  if (targetm.calls.return_pops_args (fndecl, funtype, args_size.constant)
-      != targetm.calls.return_pops_args (current_function_decl,
-					 TREE_TYPE (current_function_decl),
-					 crtl->args.size))
+  if (maybe_ne (targetm.calls.return_pops_args (fndecl, funtype,
+						args_size.constant),
+		targetm.calls.return_pops_args (current_function_decl,
+						TREE_TYPE
+						(current_function_decl),
+						crtl->args.size)))
     {
       maybe_complain_about_tail_call (exp,
 				      "inconsistent number of"
@@ -2941,8 +3255,6 @@
   /* Register in which non-BLKmode value will be returned,
      or 0 if no value or if value is BLKmode.  */
   rtx valreg;
-  /* Register(s) in which bounds are returned.  */
-  rtx valbnd = NULL;
   /* Address where we should return a BLKmode value;
      0 if value not BLKmode.  */
   rtx structure_value_addr = 0;
@@ -2955,7 +3267,7 @@
   /* Size of aggregate value wanted, or zero if none wanted
      or if we are using the non-reentrant PCC calling convention
      or expecting the value in registers.  */
-  HOST_WIDE_INT struct_value_size = 0;
+  poly_int64 struct_value_size = 0;
   /* Nonzero if called function returns an aggregate in memory PCC style,
      by returning the address of where to find it.  */
   int pcc_struct_value = 0;
@@ -2978,7 +3290,7 @@
   struct args_size args_size;
   struct args_size adjusted_args_size;
   /* Size of arguments before any adjustments (such as rounding).  */
-  int unadjusted_args_size;
+  poly_int64 unadjusted_args_size;
   /* Data on reg parms scanned so far.  */
   CUMULATIVE_ARGS args_so_far_v;
   cumulative_args_t args_so_far;
@@ -3011,22 +3323,23 @@
   rtx save_area = 0;		/* Place that it is saved */
 #endif
 
-  int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
+  unsigned int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
   char *initial_stack_usage_map = stack_usage_map;
+  unsigned HOST_WIDE_INT initial_stack_usage_watermark = stack_usage_watermark;
   char *stack_usage_map_buf = NULL;
 
-  int old_stack_allocated;
+  poly_int64 old_stack_allocated;
 
   /* State variables to track stack modifications.  */
   rtx old_stack_level = 0;
   int old_stack_arg_under_construction = 0;
-  int old_pending_adj = 0;
+  poly_int64 old_pending_adj = 0;
   int old_inhibit_defer_pop = inhibit_defer_pop;
 
   /* Some stack pointer alterations we make are performed via
      allocate_dynamic_stack_space. This modifies the stack_pointer_delta,
      which we then also need to save/restore along the way.  */
-  int old_stack_pointer_delta = 0;
+  poly_int64 old_stack_pointer_delta = 0;
 
   rtx call_fusage;
   tree addr = CALL_EXPR_FN (exp);
@@ -3116,16 +3429,22 @@
       }
 #else /* not PCC_STATIC_STRUCT_RETURN */
       {
-	struct_value_size = int_size_in_bytes (rettype);
+	if (!poly_int_tree_p (TYPE_SIZE_UNIT (rettype), &struct_value_size))
+	  struct_value_size = -1;
 
 	/* Even if it is semantically safe to use the target as the return
 	   slot, it may be not sufficiently aligned for the return type.  */
 	if (CALL_EXPR_RETURN_SLOT_OPT (exp)
 	    && target
 	    && MEM_P (target)
-	    && !(MEM_ALIGN (target) < TYPE_ALIGN (rettype)
-		 && targetm.slow_unaligned_access (TYPE_MODE (rettype),
-						   MEM_ALIGN (target))))
+	    /* If rettype is addressable, we may not create a temporary.
+	       If target is properly aligned at runtime and the compiler
+	       just doesn't know about it, it will work fine, otherwise it
+	       will be UB.  */
+	    && (TREE_ADDRESSABLE (rettype)
+		|| !(MEM_ALIGN (target) < TYPE_ALIGN (rettype)
+		     && targetm.slow_unaligned_access (TYPE_MODE (rettype),
+						       MEM_ALIGN (target)))))
 	  structure_value_addr = XEXP (target, 0);
 	else
 	  {
@@ -3203,7 +3522,7 @@
 
       structure_value_addr_value =
 	make_tree (build_pointer_type (TREE_TYPE (funtype)), temp);
-      structure_value_addr_parm = CALL_WITH_BOUNDS_P (exp) ? 2 : 1;
+      structure_value_addr_parm = 1;
     }
 
   /* Count the arguments and set NUM_ACTUALS.  */
@@ -3290,7 +3609,8 @@
 	  || reg_mentioned_p (virtual_outgoing_args_rtx,
 			      structure_value_addr))
       && (args_size.var
-	  || (!ACCUMULATE_OUTGOING_ARGS && args_size.constant)))
+	  || (!ACCUMULATE_OUTGOING_ARGS
+	      && maybe_ne (args_size.constant, 0))))
     structure_value_addr = copy_to_reg (structure_value_addr);
 
   /* Tail calls can make things harder to debug, and we've traditionally
@@ -3299,11 +3619,12 @@
      there's cleanups, as we know there's code to follow the call.  */
 
   // -O2オプションがないときも末尾最適化が行われるように(Code Segmentのみ)
+
   if (currently_expanding_call++ != 0
 #ifndef noCbC
-      || ((!fntype|| !CbC_IS_CODE_SEGMENT (fntype)) && !flag_optimize_sibling_calls)
+      || ((!fntype|| !CbC_IS_CODE_SEGMENT (fntype)) && (!flag_optimize_sibling_calls && !CALL_FROM_THUNK_P (exp)))
 #else
-      || !flag_optimize_sibling_calls
+      || (!flag_optimize_sibling_calls && !CALL_FROM_THUNK_P (exp))
 #endif
       || args_size.var
       || dbg_cnt (tail_call) == false)
@@ -3465,10 +3786,10 @@
 	 call sequence.
 	 Also do the adjustments before a throwing call, otherwise
 	 exception handling can fail; PR 19225. */
-      if (pending_stack_adjust >= 32
-	  || (pending_stack_adjust > 0
+      if (maybe_ge (pending_stack_adjust, 32)
+	  || (maybe_ne (pending_stack_adjust, 0)
 	      && (flags & ECF_MAY_BE_ALLOCA))
-	  || (pending_stack_adjust > 0
+	  || (maybe_ne (pending_stack_adjust, 0)
 	      && flag_exceptions && !(flags & ECF_NOTHROW))
 	  || pass == 0)
 	do_pending_stack_adjust ();
@@ -3529,8 +3850,10 @@
 	    argblock
 	      = plus_constant (Pmode, argblock, -crtl->args.pretend_args_size);
 
-	  stored_args_map = sbitmap_alloc (args_size.constant);
+	  HOST_WIDE_INT map_size = constant_lower_bound (args_size.constant);
+	  stored_args_map = sbitmap_alloc (map_size);
 	  bitmap_clear (stored_args_map);
+	  stored_args_watermark = HOST_WIDE_INT_M1U;
 	}
 
       /* If we have no actual push instructions, or shouldn't use them,
@@ -3560,14 +3883,14 @@
 	     in the area reserved for register arguments, which may be part of
 	     the stack frame.  */
 
-	  int needed = adjusted_args_size.constant;
+	  poly_int64 needed = adjusted_args_size.constant;
 
 	  /* Store the maximum argument space used.  It will be pushed by
 	     the prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow
 	     checking).  */
 
-	  if (needed > crtl->outgoing_args_size)
-	    crtl->outgoing_args_size = needed;
+	  crtl->outgoing_args_size = upper_bound (crtl->outgoing_args_size,
+						  needed);
 
 	  if (must_preallocate)
 	    {
@@ -3593,12 +3916,16 @@
 		  if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
 		    needed += reg_parm_stack_space;
 
+		  poly_int64 limit = needed;
 		  if (ARGS_GROW_DOWNWARD)
-		    highest_outgoing_arg_in_use
-		      = MAX (initial_highest_arg_in_use, needed + 1);
-		  else
-		    highest_outgoing_arg_in_use
-		      = MAX (initial_highest_arg_in_use, needed);
+		    limit += 1;
+
+		  /* For polynomial sizes, this is the maximum possible
+		     size needed for arguments with a constant size
+		     and offset.  */
+		  HOST_WIDE_INT const_limit = constant_lower_bound (limit);
+		  highest_outgoing_arg_in_use
+		    = MAX (initial_highest_arg_in_use, const_limit);
 
 		  free (stack_usage_map_buf);
 		  stack_usage_map_buf = XNEWVEC (char, highest_outgoing_arg_in_use);
@@ -3623,23 +3950,25 @@
 		}
 	      else
 		{
-		  if (inhibit_defer_pop == 0)
+		  /* Try to reuse some or all of the pending_stack_adjust
+		     to get this space.  */
+		  if (inhibit_defer_pop == 0
+		      && (combine_pending_stack_adjustment_and_call
+			  (&needed,
+			   unadjusted_args_size,
+			   &adjusted_args_size,
+			   preferred_unit_stack_boundary)))
 		    {
-		      /* Try to reuse some or all of the pending_stack_adjust
-			 to get this space.  */
-		      needed
-			= (combine_pending_stack_adjustment_and_call
-			   (unadjusted_args_size,
-			    &adjusted_args_size,
-			    preferred_unit_stack_boundary));
-
 		      /* combine_pending_stack_adjustment_and_call computes
 			 an adjustment before the arguments are allocated.
 			 Account for them and see whether or not the stack
 			 needs to go up or down.  */
 		      needed = unadjusted_args_size - needed;
 
-		      if (needed < 0)
+		      /* Checked by
+			 combine_pending_stack_adjustment_and_call.  */
+		      gcc_checking_assert (ordered_p (needed, 0));
+		      if (maybe_lt (needed, 0))
 			{
 			  /* We're releasing stack space.  */
 			  /* ??? We can avoid any adjustment at all if we're
@@ -3656,11 +3985,12 @@
 
 		  /* Special case this because overhead of `push_block' in
 		     this case is non-trivial.  */
-		  if (needed == 0)
+		  if (known_eq (needed, 0))
 		    argblock = virtual_outgoing_args_rtx;
 		  else
 		    {
-		      argblock = push_block (GEN_INT (needed), 0, 0);
+		      rtx needed_rtx = gen_int_mode (needed, Pmode);
+		      argblock = push_block (needed_rtx, 0, 0);
 		      if (ARGS_GROW_DOWNWARD)
 			argblock = plus_constant (Pmode, argblock, needed);
 		    }
@@ -3686,10 +4016,11 @@
 	  if (stack_arg_under_construction)
 	    {
 	      rtx push_size
-		= GEN_INT (adjusted_args_size.constant
-			   + (OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype
-			   					      : TREE_TYPE (fndecl))) ? 0
-			      : reg_parm_stack_space));
+		= (gen_int_mode
+		   (adjusted_args_size.constant
+		    + (OUTGOING_REG_PARM_STACK_SPACE (!fndecl ? fntype
+						      : TREE_TYPE (fndecl))
+		       ? 0 : reg_parm_stack_space), Pmode));
 	      if (old_stack_level == 0)
 		{
 		  emit_stack_save (SAVE_BLOCK, &old_stack_level);
@@ -3708,6 +4039,7 @@
 		  stack_usage_map_buf = XCNEWVEC (char, highest_outgoing_arg_in_use);
 		  stack_usage_map = stack_usage_map_buf;
 		  highest_outgoing_arg_in_use = 0;
+		  stack_usage_watermark = HOST_WIDE_INT_M1U;
 		}
 	      /* We can pass TRUE as the 4th argument because we just
 		 saved the stack pointer and will restore it right after
@@ -3743,24 +4075,23 @@
 
       /* Perform stack alignment before the first push (the last arg).  */
       if (argblock == 0
-          && adjusted_args_size.constant > reg_parm_stack_space
-	  && adjusted_args_size.constant != unadjusted_args_size)
+	  && maybe_gt (adjusted_args_size.constant, reg_parm_stack_space)
+	  && maybe_ne (adjusted_args_size.constant, unadjusted_args_size))
 	{
 	  /* When the stack adjustment is pending, we get better code
 	     by combining the adjustments.  */
-	  if (pending_stack_adjust
-	      && ! inhibit_defer_pop)
-	    {
-	      pending_stack_adjust
-		= (combine_pending_stack_adjustment_and_call
-		   (unadjusted_args_size,
-		    &adjusted_args_size,
-		    preferred_unit_stack_boundary));
-	      do_pending_stack_adjust ();
-	    }
+	  if (maybe_ne (pending_stack_adjust, 0)
+	      && ! inhibit_defer_pop
+	      && (combine_pending_stack_adjustment_and_call
+		  (&pending_stack_adjust,
+		   unadjusted_args_size,
+		   &adjusted_args_size,
+		   preferred_unit_stack_boundary)))
+	    do_pending_stack_adjust ();
 	  else if (argblock == 0)
-	    anti_adjust_stack (GEN_INT (adjusted_args_size.constant
-					- unadjusted_args_size));
+	    anti_adjust_stack (gen_int_mode (adjusted_args_size.constant
+					     - unadjusted_args_size,
+					     Pmode));
 	}
       /* Now that the stack is properly aligned, pops can't safely
 	 be deferred during the evaluation of the arguments.  */
@@ -3774,9 +4105,10 @@
 	  && pass
 	  && adjusted_args_size.var == 0)
 	{
-	  int pushed = adjusted_args_size.constant + pending_stack_adjust;
-	  if (pushed > current_function_pushed_stack_size)
-	    current_function_pushed_stack_size = pushed;
+	  poly_int64 pushed = (adjusted_args_size.constant
+			       + pending_stack_adjust);
+	  current_function_pushed_stack_size
+	    = upper_bound (current_function_pushed_stack_size, pushed);
 	}
 
       funexp = rtx_for_function_call (fndecl, addr);
@@ -3802,16 +4134,13 @@
 
       for (i = 0; i < num_actuals; i++)
 	{
-	  /* Delay bounds until all other args are stored.  */
-	  if (POINTER_BOUNDS_P (args[i].tree_value))
-	    continue;
-	  else if (args[i].reg == 0 || args[i].pass_on_stack)
+	  if (args[i].reg == 0 || args[i].pass_on_stack)
 	    {
 	      rtx_insn *before_arg = get_last_insn ();
 
 	      /* We don't allow passing huge (> 2^30 B) arguments
 	         by value.  It would cause an overflow later on.  */
-	      if (adjusted_args_size.constant
+	      if (constant_lower_bound (adjusted_args_size.constant)
 		  >= (1 << (HOST_BITS_PER_INT - 2)))
 	        {
 	          sorry ("passing too large argument on stack");
@@ -3879,28 +4208,15 @@
 
       /* Figure out the register where the value, if any, will come back.  */
       valreg = 0;
-      valbnd = 0;
       if (TYPE_MODE (rettype) != VOIDmode
 	  && ! structure_value_addr)
 	{
 	  if (pcc_struct_value)
-	    {
-	      valreg = hard_function_value (build_pointer_type (rettype),
-					    fndecl, NULL, (pass == 0));
-	      if (CALL_WITH_BOUNDS_P (exp))
-		valbnd = targetm.calls.
-		  chkp_function_value_bounds (build_pointer_type (rettype),
-					      fndecl, (pass == 0));
-	    }
+	    valreg = hard_function_value (build_pointer_type (rettype),
+					  fndecl, NULL, (pass == 0));
 	  else
-	    {
-	      valreg = hard_function_value (rettype, fndecl, fntype,
-					    (pass == 0));
-	      if (CALL_WITH_BOUNDS_P (exp))
-		valbnd = targetm.calls.chkp_function_value_bounds (rettype,
-								   fndecl,
-								   (pass == 0));
-	    }
+	    valreg = hard_function_value (rettype, fndecl, fntype,
+					  (pass == 0));
 
 	  /* If VALREG is a PARALLEL whose first member has a zero
 	     offset, use that.  This is for targets such as m68k that
@@ -3916,17 +4232,6 @@
 	    }
 	}
 
-      /* Store all bounds not passed in registers.  */
-      for (i = 0; i < num_actuals; i++)
-	{
-	  if (POINTER_BOUNDS_P (args[i].tree_value)
-	      && !args[i].reg)
-	    store_bounds (&args[i],
-			  args[i].pointer_arg == -1
-			  ? NULL
-			  : &args[args[i].pointer_arg]);
-	}
-
       /* If register arguments require space on the stack and stack space
 	 was not preallocated, allocate stack space here for arguments
 	 passed in registers.  */
@@ -3994,7 +4299,8 @@
 
       /* Stack must be properly aligned now.  */
       gcc_assert (!pass
-		  || !(stack_pointer_delta % preferred_unit_stack_boundary));
+		  || multiple_p (stack_pointer_delta,
+				 preferred_unit_stack_boundary));
 
       /* Generate the actual call instruction.  */
       emit_call_1 (funexp, exp, fndecl, funtype, unadjusted_args_size,
@@ -4198,8 +4504,8 @@
 					 funtype, 1);
 	  gcc_assert (GET_MODE (target) == pmode);
 
-	  unsigned int offset = subreg_lowpart_offset (TYPE_MODE (type),
-						       GET_MODE (target));
+	  poly_uint64 offset = subreg_lowpart_offset (TYPE_MODE (type),
+						      GET_MODE (target));
 	  target = gen_rtx_SUBREG (TYPE_MODE (type), target, offset);
 	  SUBREG_PROMOTED_VAR_P (target) = 1;
 	  SUBREG_PROMOTED_SET (target, unsignedp);
@@ -4222,6 +4528,7 @@
 	  stack_arg_under_construction = old_stack_arg_under_construction;
 	  highest_outgoing_arg_in_use = initial_highest_arg_in_use;
 	  stack_usage_map = initial_stack_usage_map;
+	  stack_usage_watermark = initial_stack_usage_watermark;
 	  sibcall_failure = 1;
 	}
       else if (ACCUMULATE_OUTGOING_ARGS && pass)
@@ -4246,12 +4553,14 @@
 		  emit_move_insn (stack_area, args[i].save_area);
 		else
 		  emit_block_move (stack_area, args[i].save_area,
-				   GEN_INT (args[i].locate.size.constant),
+				   (gen_int_mode
+				    (args[i].locate.size.constant, Pmode)),
 				   BLOCK_OP_CALL_PARM);
 	      }
 
 	  highest_outgoing_arg_in_use = initial_highest_arg_in_use;
 	  stack_usage_map = initial_stack_usage_map;
+	  stack_usage_watermark = initial_stack_usage_watermark;
 	}
 
       /* If this was alloca, record the new stack level.  */
@@ -4294,8 +4603,9 @@
 
 	  /* Verify that we've deallocated all the stack we used.  */
 	  gcc_assert ((flags & ECF_NORETURN)
-		      || (old_stack_allocated
-			  == stack_pointer_delta - pending_stack_adjust));
+		      || known_eq (old_stack_allocated,
+				   stack_pointer_delta
+				   - pending_stack_adjust));
 	}
 
       /* If something prevents making this a sibling call,
@@ -4341,10 +4651,6 @@
 
   free (stack_usage_map_buf);
   free (args);
-
-  /* Join result with returned bounds so caller may use them if needed.  */
-  target = chkp_join_splitted_slot (target, valbnd);
-
   return target;
 }
 
@@ -4474,10 +4780,10 @@
   rtx mem_value = 0;
   rtx valreg;
   int pcc_struct_value = 0;
-  int struct_value_size = 0;
+  poly_int64 struct_value_size = 0;
   int flags;
   int reg_parm_stack_space = 0;
-  int needed;
+  poly_int64 needed;
   rtx_insn *before_call;
   bool have_push_fusage;
   tree tfom;			/* type_for_mode (outmode, 0) */
@@ -4490,8 +4796,9 @@
 #endif
 
   /* Size of the stack reserved for parameter registers.  */
-  int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
+  unsigned int initial_highest_arg_in_use = highest_outgoing_arg_in_use;
   char *initial_stack_usage_map = stack_usage_map;
+  unsigned HOST_WIDE_INT initial_stack_usage_watermark = stack_usage_watermark;
   char *stack_usage_map_buf = NULL;
 
   rtx struct_value = targetm.calls.struct_value_rtx (0, 0);
@@ -4712,7 +5019,7 @@
 	   end it should be padded.  */
 	argvec[count].locate.where_pad =
 	  BLOCK_REG_PADDING (mode, NULL_TREE,
-			     GET_MODE_SIZE (mode) <= UNITS_PER_WORD);
+			     known_le (GET_MODE_SIZE (mode), UNITS_PER_WORD));
 #endif
 
       targetm.calls.function_arg_advance (args_so_far, mode, (tree) 0, true);
@@ -4723,27 +5030,25 @@
   assemble_external_libcall (fun);
 
   original_args_size = args_size;
-  args_size.constant = (((args_size.constant
-			  + stack_pointer_delta
-			  + STACK_BYTES - 1)
-			  / STACK_BYTES
-			  * STACK_BYTES)
-			 - stack_pointer_delta);
-
-  args_size.constant = MAX (args_size.constant,
-			    reg_parm_stack_space);
+  args_size.constant = (aligned_upper_bound (args_size.constant
+					     + stack_pointer_delta,
+					     STACK_BYTES)
+			- stack_pointer_delta);
+
+  args_size.constant = upper_bound (args_size.constant,
+				    reg_parm_stack_space);
 
   if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
     args_size.constant -= reg_parm_stack_space;
 
-  if (args_size.constant > crtl->outgoing_args_size)
-    crtl->outgoing_args_size = args_size.constant;
+  crtl->outgoing_args_size = upper_bound (crtl->outgoing_args_size,
+					  args_size.constant);
 
   if (flag_stack_usage_info && !ACCUMULATE_OUTGOING_ARGS)
     {
-      int pushed = args_size.constant + pending_stack_adjust;
-      if (pushed > current_function_pushed_stack_size)
-	current_function_pushed_stack_size = pushed;
+      poly_int64 pushed = args_size.constant + pending_stack_adjust;
+      current_function_pushed_stack_size
+	= upper_bound (current_function_pushed_stack_size, pushed);
     }
 
   if (ACCUMULATE_OUTGOING_ARGS)
@@ -4768,11 +5073,15 @@
       if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))))
 	needed += reg_parm_stack_space;
 
+      poly_int64 limit = needed;
       if (ARGS_GROW_DOWNWARD)
-	highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
-					   needed + 1);
-      else
-	highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use, needed);
+	limit += 1;
+
+      /* For polynomial sizes, this is the maximum possible size needed
+	 for arguments with a constant size and offset.  */
+      HOST_WIDE_INT const_limit = constant_lower_bound (limit);
+      highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
+					 const_limit);
 
       stack_usage_map_buf = XNEWVEC (char, highest_outgoing_arg_in_use);
       stack_usage_map = stack_usage_map_buf;
@@ -4800,14 +5109,15 @@
   else
     {
       if (!PUSH_ARGS)
-	argblock = push_block (GEN_INT (args_size.constant), 0, 0);
+	argblock = push_block (gen_int_mode (args_size.constant, Pmode), 0, 0);
     }
 
   /* We push args individually in reverse order, perform stack alignment
      before the first push (the last arg).  */
   if (argblock == 0)
-    anti_adjust_stack (GEN_INT (args_size.constant
-				- original_args_size.constant));
+    anti_adjust_stack (gen_int_mode (args_size.constant
+				     - original_args_size.constant,
+				     Pmode));
 
   argnum = nargs - 1;
 
@@ -4847,7 +5157,7 @@
       rtx reg = argvec[argnum].reg;
       int partial = argvec[argnum].partial;
       unsigned int parm_align = argvec[argnum].locate.boundary;
-      int lower_bound = 0, upper_bound = 0, i;
+      poly_int64 lower_bound = 0, upper_bound = 0;
 
       if (! (reg != 0 && partial == 0))
 	{
@@ -4871,18 +5181,11 @@
 		  upper_bound = lower_bound + argvec[argnum].locate.size.constant;
 		}
 
-	      i = lower_bound;
-	      /* Don't worry about things in the fixed argument area;
-		 it has already been saved.  */
-	      if (i < reg_parm_stack_space)
-		i = reg_parm_stack_space;
-	      while (i < upper_bound && stack_usage_map[i] == 0)
-		i++;
-
-	      if (i < upper_bound)
+	      if (stack_region_maybe_used_p (lower_bound, upper_bound,
+					     reg_parm_stack_space))
 		{
 		  /* We need to make a save area.  */
-		  unsigned int size
+		  poly_uint64 size
 		    = argvec[argnum].locate.size.constant * BITS_PER_UNIT;
 		  machine_mode save_mode
 		    = int_mode_for_size (size, 1).else_blk ();
@@ -4902,7 +5205,9 @@
 		      emit_block_move (validize_mem
 				         (copy_rtx (argvec[argnum].save_area)),
 				       stack_area,
-				       GEN_INT (argvec[argnum].locate.size.constant),
+				       (gen_int_mode
+					(argvec[argnum].locate.size.constant,
+					 Pmode)),
 				       BLOCK_OP_CALL_PARM);
 		    }
 		  else
@@ -4916,14 +5221,14 @@
 
 	  emit_push_insn (val, mode, NULL_TREE, NULL_RTX, parm_align,
 			  partial, reg, 0, argblock,
-			  GEN_INT (argvec[argnum].locate.offset.constant),
+			  (gen_int_mode
+			   (argvec[argnum].locate.offset.constant, Pmode)),
 			  reg_parm_stack_space,
 			  ARGS_SIZE_RTX (argvec[argnum].locate.alignment_pad), false);
 
 	  /* Now mark the segment we just used.  */
 	  if (ACCUMULATE_OUTGOING_ARGS)
-	    for (i = lower_bound; i < upper_bound; i++)
-	      stack_usage_map[i] = 1;
+	    mark_stack_region_used (lower_bound, upper_bound);
 
 	  NO_DEFER_POP;
 
@@ -4965,9 +5270,6 @@
       rtx val = argvec[argnum].value;
       rtx reg = argvec[argnum].reg;
       int partial = argvec[argnum].partial;
-#ifdef BLOCK_REG_PADDING
-      int size = 0;
-#endif
       
       /* Handle calls that pass values in multiple non-contiguous
 	 locations.  The PA64 has examples of this for library calls.  */
@@ -4977,19 +5279,19 @@
         {
 	  emit_move_insn (reg, val);
 #ifdef BLOCK_REG_PADDING
-	  size = GET_MODE_SIZE (argvec[argnum].mode);
+	  poly_int64 size = GET_MODE_SIZE (argvec[argnum].mode);
 
 	  /* Copied from load_register_parameters.  */
 
 	  /* Handle case where we have a value that needs shifting
 	     up to the msb.  eg. a QImode value and we're padding
 	     upward on a BYTES_BIG_ENDIAN machine.  */
-	  if (size < UNITS_PER_WORD
+	  if (known_lt (size, UNITS_PER_WORD)
 	      && (argvec[argnum].locate.where_pad
 		  == (BYTES_BIG_ENDIAN ? PAD_UPWARD : PAD_DOWNWARD)))
 	    {
 	      rtx x;
-	      int shift = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
+	      poly_int64 shift = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
 
 	      /* Assigning REG here rather than a temp makes CALL_FUSAGE
 		 report the whole reg as used.  Strictly speaking, the
@@ -5045,8 +5347,8 @@
 	    ? hard_libcall_value (outmode, orgfun) : NULL_RTX);
 
   /* Stack must be properly aligned now.  */
-  gcc_assert (!(stack_pointer_delta
-		& (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1)));
+  gcc_assert (multiple_p (stack_pointer_delta,
+			  PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT));
 
   before_call = get_last_insn ();
 
@@ -5184,7 +5486,8 @@
 	      emit_block_move (stack_area,
 			       validize_mem
 			         (copy_rtx (argvec[count].save_area)),
-			       GEN_INT (argvec[count].locate.size.constant),
+			       (gen_int_mode
+				(argvec[count].locate.size.constant, Pmode)),
 			       BLOCK_OP_CALL_PARM);
 	    else
 	      emit_move_insn (stack_area, argvec[count].save_area);
@@ -5192,6 +5495,7 @@
 
       highest_outgoing_arg_in_use = initial_highest_arg_in_use;
       stack_usage_map = initial_stack_usage_map;
+      stack_usage_watermark = initial_stack_usage_watermark;
     }
 
   free (stack_usage_map_buf);
@@ -5201,67 +5505,6 @@
 }
 
 
-/* Store pointer bounds argument ARG  into Bounds Table entry
-   associated with PARM.  */
-static void
-store_bounds (struct arg_data *arg, struct arg_data *parm)
-{
-  rtx slot = NULL, ptr = NULL, addr = NULL;
-
-  /* We may pass bounds not associated with any pointer.  */
-  if (!parm)
-    {
-      gcc_assert (arg->special_slot);
-      slot = arg->special_slot;
-      ptr = const0_rtx;
-    }
-  /* Find pointer associated with bounds and where it is
-     passed.  */
-  else
-    {
-      if (!parm->reg)
-	{
-	  gcc_assert (!arg->special_slot);
-
-	  addr = adjust_address (parm->stack, Pmode, arg->pointer_offset);
-	}
-      else if (REG_P (parm->reg))
-	{
-	  gcc_assert (arg->special_slot);
-	  slot = arg->special_slot;
-
-	  if (MEM_P (parm->value))
-	    addr = adjust_address (parm->value, Pmode, arg->pointer_offset);
-	  else if (REG_P (parm->value))
-	    ptr = gen_rtx_SUBREG (Pmode, parm->value, arg->pointer_offset);
-	  else
-	    {
-	      gcc_assert (!arg->pointer_offset);
-	      ptr = parm->value;
-	    }
-	}
-      else
-	{
-	  gcc_assert (GET_CODE (parm->reg) == PARALLEL);
-
-	  gcc_assert (arg->special_slot);
-	  slot = arg->special_slot;
-
-	  if (parm->parallel_value)
-	    ptr = chkp_get_value_with_offs (parm->parallel_value,
-					    GEN_INT (arg->pointer_offset));
-	  else
-	    gcc_unreachable ();
-	}
-    }
-
-  /* Expand bounds.  */
-  if (!arg->value)
-    arg->value = expand_normal (arg->tree_value);
-
-  targetm.calls.store_bounds_for_arg (ptr, addr, arg->value, slot);
-}
-
 /* Store a single argument for a function call
    into the register or memory area where it must be passed.
    *ARG describes the argument value and where to pass it.
@@ -5288,8 +5531,8 @@
   tree pval = arg->tree_value;
   rtx reg = 0;
   int partial = 0;
-  int used = 0;
-  int i, lower_bound = 0, upper_bound = 0;
+  poly_int64 used = 0;
+  poly_int64 lower_bound = 0, upper_bound = 0;
   int sibcall_failure = 0;
 
   if (TREE_CODE (pval) == ERROR_MARK)
@@ -5310,7 +5553,10 @@
 	      /* stack_slot is negative, but we want to index stack_usage_map
 		 with positive values.  */
 	      if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
-		upper_bound = -INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)) + 1;
+		{
+		  rtx offset = XEXP (XEXP (arg->stack_slot, 0), 1);
+		  upper_bound = -rtx_to_poly_int64 (offset) + 1;
+		}
 	      else
 		upper_bound = 0;
 
@@ -5319,25 +5565,21 @@
 	  else
 	    {
 	      if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS)
-		lower_bound = INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1));
+		{
+		  rtx offset = XEXP (XEXP (arg->stack_slot, 0), 1);
+		  lower_bound = rtx_to_poly_int64 (offset);
+		}
 	      else
 		lower_bound = 0;
 
 	      upper_bound = lower_bound + arg->locate.size.constant;
 	    }
 
-	  i = lower_bound;
-	  /* Don't worry about things in the fixed argument area;
-	     it has already been saved.  */
-	  if (i < reg_parm_stack_space)
-	    i = reg_parm_stack_space;
-	  while (i < upper_bound && stack_usage_map[i] == 0)
-	    i++;
-
-	  if (i < upper_bound)
+	  if (stack_region_maybe_used_p (lower_bound, upper_bound,
+					 reg_parm_stack_space))
 	    {
 	      /* We need to make a save area.  */
-	      unsigned int size = arg->locate.size.constant * BITS_PER_UNIT;
+	      poly_uint64 size = arg->locate.size.constant * BITS_PER_UNIT;
 	      machine_mode save_mode
 		= int_mode_for_size (size, 1).else_blk ();
 	      rtx adr = memory_address (save_mode, XEXP (arg->stack_slot, 0));
@@ -5350,7 +5592,8 @@
 		  preserve_temp_slots (arg->save_area);
 		  emit_block_move (validize_mem (copy_rtx (arg->save_area)),
 				   stack_area,
-				   GEN_INT (arg->locate.size.constant),
+				   (gen_int_mode
+				    (arg->locate.size.constant, Pmode)),
 				   BLOCK_OP_CALL_PARM);
 		}
 	      else
@@ -5427,8 +5670,8 @@
   /* Check for overlap with already clobbered argument area.  */
   if ((flags & ECF_SIBCALL)
       && MEM_P (arg->value)
-      && mem_overlaps_already_clobbered_arg_p (XEXP (arg->value, 0),
-					       arg->locate.size.constant))
+      && mem_might_overlap_already_clobbered_arg_p (XEXP (arg->value, 0),
+						    arg->locate.size.constant))
     sibcall_failure = 1;
 
   /* Don't allow anything left on stack from computation
@@ -5441,7 +5684,6 @@
     ;
   else if (arg->mode != BLKmode)
     {
-      int size;
       unsigned int parm_align;
 
       /* Argument is a scalar, not entirely passed in registers.
@@ -5454,7 +5696,9 @@
 	 Note that in C the default argument promotions
 	 will prevent such mismatches.  */
 
-      size = GET_MODE_SIZE (arg->mode);
+      poly_int64 size = (TYPE_EMPTY_P (TREE_TYPE (pval))
+			 ? 0 : GET_MODE_SIZE (arg->mode));
+
       /* Compute how much space the push instruction will push.
 	 On many machines, pushing a byte will advance the stack
 	 pointer by a halfword.  */
@@ -5467,29 +5711,30 @@
 	 round up to a multiple of the alignment for arguments.  */
       if (targetm.calls.function_arg_padding (arg->mode, TREE_TYPE (pval))
 	  != PAD_NONE)
-	used = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1)
-		 / (PARM_BOUNDARY / BITS_PER_UNIT))
-		* (PARM_BOUNDARY / BITS_PER_UNIT));
+	/* At the moment we don't (need to) support ABIs for which the
+	   padding isn't known at compile time.  In principle it should
+	   be easy to add though.  */
+	used = force_align_up (size, PARM_BOUNDARY / BITS_PER_UNIT);
 
       /* Compute the alignment of the pushed argument.  */
       parm_align = arg->locate.boundary;
       if (targetm.calls.function_arg_padding (arg->mode, TREE_TYPE (pval))
 	  == PAD_DOWNWARD)
 	{
-	  int pad = used - size;
-	  if (pad)
-	    {
-	      unsigned int pad_align = least_bit_hwi (pad) * BITS_PER_UNIT;
-	      parm_align = MIN (parm_align, pad_align);
-	    }
+	  poly_int64 pad = used - size;
+	  unsigned int pad_align = known_alignment (pad) * BITS_PER_UNIT;
+	  if (pad_align != 0)
+	    parm_align = MIN (parm_align, pad_align);
 	}
 
       /* This isn't already where we want it on the stack, so put it there.
 	 This can either be done with push or copy insns.  */
-      if (!emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), NULL_RTX,
-		      parm_align, partial, reg, used - size, argblock,
-		      ARGS_SIZE_RTX (arg->locate.offset), reg_parm_stack_space,
-		      ARGS_SIZE_RTX (arg->locate.alignment_pad), true))
+      if (maybe_ne (used, 0)
+	  && !emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval),
+			      NULL_RTX, parm_align, partial, reg, used - size,
+			      argblock, ARGS_SIZE_RTX (arg->locate.offset),
+			      reg_parm_stack_space,
+			      ARGS_SIZE_RTX (arg->locate.alignment_pad), true))
 	sibcall_failure = 1;
 
       /* Unless this is a partially-in-register argument, the argument is now
@@ -5502,7 +5747,7 @@
       /* BLKmode, at least partly to be pushed.  */
 
       unsigned int parm_align;
-      int excess;
+      poly_int64 excess;
       rtx size_rtx;
 
       /* Pushing a nonscalar.
@@ -5522,9 +5767,9 @@
 	  /* PUSH_ROUNDING has no effect on us, because emit_push_insn
 	     for BLKmode is careful to avoid it.  */
 	  excess = (arg->locate.size.constant
-		    - int_size_in_bytes (TREE_TYPE (pval))
+		    - arg_int_size_in_bytes (TREE_TYPE (pval))
 		    + partial);
-	  size_rtx = expand_expr (size_in_bytes (TREE_TYPE (pval)),
+	  size_rtx = expand_expr (arg_size_in_bytes (TREE_TYPE (pval)),
 				  NULL_RTX, TYPE_MODE (sizetype),
 				  EXPAND_NORMAL);
 	}
@@ -5538,10 +5783,12 @@
 	{
 	  if (arg->locate.size.var)
 	    parm_align = BITS_PER_UNIT;
-	  else if (excess)
+	  else
 	    {
-	      unsigned int excess_align = least_bit_hwi (excess) * BITS_PER_UNIT;
-	      parm_align = MIN (parm_align, excess_align);
+	      unsigned int excess_align
+		= known_alignment (excess) * BITS_PER_UNIT;
+	      if (excess_align != 0)
+		parm_align = MIN (parm_align, excess_align);
 	    }
 	}
 
@@ -5550,17 +5797,11 @@
 	  /* emit_push_insn might not work properly if arg->value and
 	     argblock + arg->locate.offset areas overlap.  */
 	  rtx x = arg->value;
-	  int i = 0;
-
-	  if (XEXP (x, 0) == crtl->args.internal_arg_pointer
-	      || (GET_CODE (XEXP (x, 0)) == PLUS
-		  && XEXP (XEXP (x, 0), 0) ==
-		     crtl->args.internal_arg_pointer
-		  && CONST_INT_P (XEXP (XEXP (x, 0), 1))))
+	  poly_int64 i = 0;
+
+	  if (strip_offset (XEXP (x, 0), &i)
+	      == crtl->args.internal_arg_pointer)
 	    {
-	      if (XEXP (x, 0) != crtl->args.internal_arg_pointer)
-		i = INTVAL (XEXP (XEXP (x, 0), 1));
-
 	      /* arg.locate doesn't contain the pretend_args_size offset,
 		 it's part of argblock.  Ensure we don't count it in I.  */
 	      if (STACK_GROWS_DOWNWARD)
@@ -5570,40 +5811,37 @@
 
 	      /* expand_call should ensure this.  */
 	      gcc_assert (!arg->locate.offset.var
-			  && arg->locate.size.var == 0
-			  && CONST_INT_P (size_rtx));
-
-	      if (arg->locate.offset.constant > i)
-		{
-		  if (arg->locate.offset.constant < i + INTVAL (size_rtx))
-		    sibcall_failure = 1;
-		}
-	      else if (arg->locate.offset.constant < i)
-		{
-		  /* Use arg->locate.size.constant instead of size_rtx
-		     because we only care about the part of the argument
-		     on the stack.  */
-		  if (i < (arg->locate.offset.constant
-			   + arg->locate.size.constant))
-		    sibcall_failure = 1;
-		}
-	      else
+			  && arg->locate.size.var == 0);
+	      poly_int64 size_val = rtx_to_poly_int64 (size_rtx);
+
+	      if (known_eq (arg->locate.offset.constant, i))
 		{
 		  /* Even though they appear to be at the same location,
 		     if part of the outgoing argument is in registers,
 		     they aren't really at the same location.  Check for
 		     this by making sure that the incoming size is the
 		     same as the outgoing size.  */
-		  if (arg->locate.size.constant != INTVAL (size_rtx))
+		  if (maybe_ne (arg->locate.size.constant, size_val))
 		    sibcall_failure = 1;
 		}
+	      else if (maybe_in_range_p (arg->locate.offset.constant,
+					 i, size_val))
+		sibcall_failure = 1;
+	      /* Use arg->locate.size.constant instead of size_rtx
+		 because we only care about the part of the argument
+		 on the stack.  */
+	      else if (maybe_in_range_p (i, arg->locate.offset.constant,
+					 arg->locate.size.constant))
+		sibcall_failure = 1;
 	    }
 	}
 
-      emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), size_rtx,
-		      parm_align, partial, reg, excess, argblock,
-		      ARGS_SIZE_RTX (arg->locate.offset), reg_parm_stack_space,
-		      ARGS_SIZE_RTX (arg->locate.alignment_pad), false);
+      if (!CONST_INT_P (size_rtx) || INTVAL (size_rtx) != 0)
+	emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), size_rtx,
+			parm_align, partial, reg, excess, argblock,
+			ARGS_SIZE_RTX (arg->locate.offset),
+			reg_parm_stack_space,
+			ARGS_SIZE_RTX (arg->locate.alignment_pad), false);
 
       /* Unless this is a partially-in-register argument, the argument is now
 	 in the stack.
@@ -5628,8 +5866,7 @@
   /* Mark all slots this store used.  */
   if (ACCUMULATE_OUTGOING_ARGS && !(flags & ECF_SIBCALL)
       && argblock && ! variable_size && arg->stack)
-    for (i = lower_bound; i < upper_bound; i++)
-      stack_usage_map[i] = 1;
+    mark_stack_region_used (lower_bound, upper_bound);
 
   /* Once we have pushed something, pops can't safely
      be deferred during the rest of the arguments.  */
@@ -5681,6 +5918,9 @@
   if (TREE_ADDRESSABLE (type))
     return true;
 
+  if (TYPE_EMPTY_P (type))
+    return false;
+
   /* If the padding and mode of the type is such that a copy into
      a register would put it into the wrong part of the register.  */
   if (mode == BLKmode