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, PR 57748] Check for out of bounds access, Part 2


> I agree, that assigning a non-BLKmode to structures with zero-sized arrays
> should be considered a bug.

Fine, then let's apply Martin's patch, on mainline at least.

> And again, this is not only a problem of structures with zero-sized
> arrays at the end. Remember my previous example code:
> On ARM (or anything with STRICT_ALIGNMENT) this union has the
> same problems:
> 
> /* PR middle-end/57748 */
> /* arm-eabi-gcc -mcpu=cortex-a9 -O3 */
> #include <stdlib.h>
> 
> union  x
> {
>   short a[2];
>   char x[4];
> } __attribute__((packed, aligned(4))) ;
> typedef volatile union  x *s;
> 
> void __attribute__((noinline, noclone))
> check (void)
> {
>   s xx=(s)(0x80000002);
>   /* although volatile xx->x[3] reads 4 bytes here */
>   if (xx->x[3] != 3)
>     abort ();
> }
> 
> void __attribute__((noinline, noclone))
> foo (void)
> {
>   s xx=(s)(0x80000002);
>   xx->x[3] = 3;
> }
> 
> int
> main ()
> {
>   foo ();
>   check ();
>   return 0;
> }

But this testcase is invalid on STRICT_ALIGNMENT platforms: xx is pointer to a 
type with 4-byte alignment so its value must be a multiple of 4.

-- 
Eric Botcazou


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