On Wed, Jun 11, 2014 at 6:08 PM, Ilya Enkovich <enkovich....@gmail.com> wrote:
> Hi,
>
> This patch fixes problem with size emitted for static structures with 
> flexible array.  I found a couple of trackers in guzilla for this problem but 
> all of them are marked as fixed and problem still exists.
>
> For a simple testcase
>
> struct S { int a; int b[0]; } s = { 1, { 0, 0} };
>
> current trunk produces (no flags):
>
>         .globl  s
>         .data
>         .align 4
>         .type   s, @object
>         .size   s, 4
> s:
>         .long   1
>         .long   0
>         .long   0
>
> which has wrong size for object s.
>
> This problem is important for checker because wrong size leads to wrong 
> bounds and false bounds violations.  Following patch uses DECL_SIZE_UNIT 
> instead of type size and works well for me.  Does it look OK?

There is a bug about this in bugzilla somewhere.

It looks ok to me - did you test with all languages?  In particular did
you test Ada?

Thanks,
Richard.

> Bootstrapped and tested on linux-x86_64.
>
> Thanks,
> Ilya
> --
> gcc/
>
> 2014-06-11  Ilya Enkovich  <ilya.enkov...@intel.com>
>
>         * config/elfos.h (ASM_DECLARE_OBJECT_NAME): Use decl size
>         instead of type size.
>         (ASM_FINISH_DECLARE_OBJECT): Likewise.
>
>
> diff --git a/gcc/config/elfos.h b/gcc/config/elfos.h
> index c1d5553..7929708 100644
> --- a/gcc/config/elfos.h
> +++ b/gcc/config/elfos.h
> @@ -313,7 +313,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
> If not, see
>           && (DECL) && DECL_SIZE (DECL))                                \
>         {                                                               \
>           size_directive_output = 1;                                    \
> -         size = int_size_in_bytes (TREE_TYPE (DECL));                  \
> +         size = tree_to_uhwi (DECL_SIZE_UNIT (DECL));                  \
>           ASM_OUTPUT_SIZE_DIRECTIVE (FILE, NAME, size);                 \
>         }                                                               \
>                                                                         \
> @@ -341,7 +341,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
> If not, see
>           && !size_directive_output)                            \
>         {                                                       \
>           size_directive_output = 1;                            \
> -         size = int_size_in_bytes (TREE_TYPE (DECL));          \
> +         size = tree_to_uhwi (DECL_SIZE_UNIT (DECL));          \
>           ASM_OUTPUT_SIZE_DIRECTIVE (FILE, name, size);         \
>         }                                                       \
>      }                                                          \

Reply via email to