https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111040

            Bug ID: 111040
           Summary: __builtin_object_size: inconsistent result for
                    subobject with member arrays.
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: qinzhao at gcc dot gnu.org
  Target Milestone: ---

__bos produces different results for subobject with different optimizations:

#include <stddef.h>
#include <stdio.h>

#define noinline __attribute__((__noinline__))

struct fixed {
  size_t foo;
  char b;
  char array[10]; 
} q = {};

static void noinline bar ()
{
  struct fixed *p = &q;

  printf("the__bdos of max p->array sub is %d \n",
__builtin_dynamic_object_size(p->array, 1)); 

  return;
}

int main ()
{
  bar ();
  return 0;
}

when compiled with 
/home/opc/Install/latest-d/bin/gcc -O -fstrict-flex-arrays=3 t.c
./a.out
the__bdos of max p->array sub is 10 

when compiled with (disable the early object size pass):
/home/opc/Install/latest-d/bin/gcc -O -fstrict-flex-arrays=3
-fdisable-tree-early_objsz t.c
./a.out
the__bdos of max p->array sub is 15 

I assume that the correct result for __builtin_dynamic_object_size(p->array, 1)
should be 10.

Reply via email to