This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v2] Fix PR64242


On Fri, Dec 07, 2018 at 02:52:48PM +0000, Wilco Dijkstra wrote:
> -  struct __attribute__((aligned (32))) S { int a[4]; } s;                                                                                         
> -  bar (&s);                                                                                                                                       

Any reason to remove the above?

>    p = __builtin_alloca (x);
> +  q = __builtin_alloca (x);
>    if (!__builtin_setjmp (buf))
>      broken_longjmp (buf);
>  
> +  /* Compute expected next alloca offset - some targets don't align properly
> +     and allocate too much.  */
> +  p = q + (q - p);

This is UB, pointer difference is only defined within the same object.
So, you can only do such subtraction in some integral type rather than as
pointer subtraction. 

> +
>    /* Fails if stack pointer corrupted.  */
> -  q = __builtin_alloca (x);
> -  if (foo (p) < foo (q))
> -    {
> -      if (foo (q) - foo (p) >= 1024)
> -	abort ();
> -    }
> -  else if (foo (p) - foo (q) >= 1024)
> +  if (p != __builtin_alloca (x))

And I'm not sure you have a guarantee that every zero sized alloca is at the
same offset from the previous one.

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]