Patchwork Fix PR56344

login
register
mail settings
Submitter Marek Polacek
Date Feb. 26, 2013, 6:27 p.m.
Message ID <20130226182733.GG25197@redhat.com>
Download mbox | patch
Permalink /patch/223365/
State New
Headers show

Comments

Marek Polacek - Feb. 26, 2013, 6:27 p.m.
This "fixes" PR56344 by prohibiting passing arguments by value
of size >= 2^30 bytes.  Probably no sane programmer would want to 
do that, but it's better to issue an error than to segfault.
This would be a good opportunity to use __builtin_expect, but
we don't use that much in the codebase...

Regtested/bootstrapped on x86_64-linux, ok for trunk?

Do we need a testcase for this (compiling it is quite slow)?

2013-02-26  Marek Polacek  <polacek@redhat.com>

	PR middle-end/56344
	* calls.c (expand_call): Disallow passing huge arguments
	by value.


	Marek
Joseph S. Myers - Feb. 26, 2013, 11:17 p.m.
On Tue, 26 Feb 2013, Marek Polacek wrote:

> +	      /* We don't allow passing huge (> 2^30 B) arguments
> +	         by value.  It would cause an overflow later on.  */
> +	      if (adjusted_args_size.constant >= (1 << 30))
> +	        {
> +	          error ("passing too large argument on stack");
> +		  continue;

This should be sorry () not error (), as a compiler limitation rather than 
a defect in the user's program.  (And is input_location set to something 
useful here so the diagnostic points to the argument in question rather 
than e.g. to the end of the function containing the problem call?)

Patch

--- gcc/calls.c.mp	2013-02-26 17:04:33.159555349 +0100
+++ gcc/calls.c	2013-02-26 18:50:54.864084545 +0100
@@ -3037,6 +3037,14 @@  expand_call (tree exp, rtx target, int i
 	    {
 	      rtx 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 >= (1 << 30))
+	        {
+	          error ("passing too large argument on stack");
+		  continue;
+		}
+
 	      if (store_one_arg (&args[i], argblock, flags,
 				 adjusted_args_size.var != 0,
 				 reg_parm_stack_space)