public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/111030] New: tree-object-size: incorrect sub-object size for VLA
@ 2023-08-15 14:05 qinzhao at gcc dot gnu.org
  2023-08-16  7:40 ` [Bug tree-optimization/111030] " sjames at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: qinzhao at gcc dot gnu.org @ 2023-08-15 14:05 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111030
           Summary: tree-object-size: incorrect sub-object size for VLA
           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: ---

current __builtin_dynamic_object_size cannot handle VLA correctly for the
sub-object size, please see the following testing case:

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

#define expect(p, _v) do { \
    size_t v = _v; \
    if (p == v) \
        __builtin_printf ("ok:  %s == %zd\n", #p, p); \
    else \
        {  \
          __builtin_printf ("WAT: %s == %zd (expected %zd)\n", #p, p, v); \
        } \
} while (0);

#define noinline __attribute__((__noinline__))

static void noinline bar (int index)
{
  struct annotated {
    long foo;
    char b;
    char array[index];
    long c;
  } q, *p;

  p = &q;

  expect (__builtin_dynamic_object_size(p->array, 0), 
          sizeof (struct annotated) - offsetof (struct annotated, array[0]));
  expect (__builtin_dynamic_object_size(p->array, 1), 
          offsetof (struct annotated, array[index]) - offsetof (struct
annotated, array[0]));
  return;
}

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

when compiled with the latest gcc and run:
/home/opc/Install/latest-d/bin/gcc -O t.c
ok:  __builtin_dynamic_object_size(p->array, 0) == 23
WAT: __builtin_dynamic_object_size(p->array, 1) == 23 (expected 10)

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug tree-optimization/111030] tree-object-size: incorrect sub-object size for VLA
  2023-08-15 14:05 [Bug tree-optimization/111030] New: tree-object-size: incorrect sub-object size for VLA qinzhao at gcc dot gnu.org
@ 2023-08-16  7:40 ` sjames at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: sjames at gcc dot gnu.org @ 2023-08-16  7:40 UTC (permalink / raw)
  To: gcc-bugs

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

Sam James <sjames at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sjames at gcc dot gnu.org

--- Comment #1 from Sam James <sjames at gcc dot gnu.org> ---
For completeness, the ML discussion was
https://inbox.sourceware.org/gcc-patches/34DCF245-5E66-4FC3-B817-E3C205EB5484@oracle.com.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-08-16  7:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-15 14:05 [Bug tree-optimization/111030] New: tree-object-size: incorrect sub-object size for VLA qinzhao at gcc dot gnu.org
2023-08-16  7:40 ` [Bug tree-optimization/111030] " sjames at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).