public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/101838] New: sizeof of struct with array of unspecified bound folded to constant
@ 2021-08-10  5:57 muecker at gwdg dot de
  2021-08-10 21:17 ` [Bug c/101838] " muecker at gwdg dot de
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: muecker at gwdg dot de @ 2021-08-10  5:57 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101838
           Summary: sizeof of struct with array of unspecified bound
                    folded to constant
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: muecker at gwdg dot de
  Target Milestone: ---

In this example the size of is folded to zero:

int foo(struct { int z[*]; } v, int (*y)[sizeof v]);


c_vla_type_p should probably be replaced by C_VARIABLE_SIZE
in c_expr_sizeof_type.

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

* [Bug c/101838] sizeof of struct with array of unspecified bound folded to constant
  2021-08-10  5:57 [Bug c/101838] New: sizeof of struct with array of unspecified bound folded to constant muecker at gwdg dot de
@ 2021-08-10 21:17 ` muecker at gwdg dot de
  2021-08-12 18:37 ` cvs-commit at gcc dot gnu.org
  2021-08-14 17:47 ` muecker at gwdg dot de
  2 siblings, 0 replies; 4+ messages in thread
From: muecker at gwdg dot de @ 2021-08-10 21:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Martin Uecker <muecker at gwdg dot de> ---

Actually, the example before might have been fixed already, but these two are
still wrong:

int bar(
        struct f { int a[*]; } v,
        int (*b)[sizeof(struct f)] // folded to zero
);

int foo(void)
{
        int n = 0;
        return sizeof(typeof(*({ n = 10; struct foo { int x[n]; } x; &x; })));
}

int main()
{
        if (sizeof(struct foo { int x[10]; }) != foo())
                __builtin_abort();

        return 0;
}
~

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

* [Bug c/101838] sizeof of struct with array of unspecified bound folded to constant
  2021-08-10  5:57 [Bug c/101838] New: sizeof of struct with array of unspecified bound folded to constant muecker at gwdg dot de
  2021-08-10 21:17 ` [Bug c/101838] " muecker at gwdg dot de
@ 2021-08-12 18:37 ` cvs-commit at gcc dot gnu.org
  2021-08-14 17:47 ` muecker at gwdg dot de
  2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-08-12 18:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Uecker <uecker@gcc.gnu.org>:

https://gcc.gnu.org/g:d2ba65ab6010f0d507bf5512a0223692e6653b23

commit r12-2882-gd2ba65ab6010f0d507bf5512a0223692e6653b23
Author: Martin Uecker <muecker@gwdg.de>
Date:   Thu Aug 12 20:32:16 2021 +0200

    Evaluate type arguments of sizeof that are structs of variable size
[PR101838]

    Evaluate type arguments of sizeof for all types of variable size
    and not just for VLAs. This fixes PR101838 and some issues related
    to PR29970 where statement expressions need to be evaluated so that
    the size is well defined.

    2021-08-12  Martin Uecker  <muecker@gwdg.de>

    gcc/c/
            PR c/101838
            PR c/29970
            * c-typeck.c (c_expr_sizeof_type): Evaluate
            size expressions for structs of variable size.

    gcc/testsuite/
            PR c/101838
            * gcc.dg/vla-stexp-2.c: New test.

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

* [Bug c/101838] sizeof of struct with array of unspecified bound folded to constant
  2021-08-10  5:57 [Bug c/101838] New: sizeof of struct with array of unspecified bound folded to constant muecker at gwdg dot de
  2021-08-10 21:17 ` [Bug c/101838] " muecker at gwdg dot de
  2021-08-12 18:37 ` cvs-commit at gcc dot gnu.org
@ 2021-08-14 17:47 ` muecker at gwdg dot de
  2 siblings, 0 replies; 4+ messages in thread
From: muecker at gwdg dot de @ 2021-08-14 17:47 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Uecker <muecker at gwdg dot de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED

--- Comment #3 from Martin Uecker <muecker at gwdg dot de> ---
Fixed on trunk.

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

end of thread, other threads:[~2021-08-14 17:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-10  5:57 [Bug c/101838] New: sizeof of struct with array of unspecified bound folded to constant muecker at gwdg dot de
2021-08-10 21:17 ` [Bug c/101838] " muecker at gwdg dot de
2021-08-12 18:37 ` cvs-commit at gcc dot gnu.org
2021-08-14 17:47 ` muecker at gwdg dot de

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).