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

            Bug ID: 129219
           Summary: [16/17 Regression] ICE in
                    gimplify_modify_expr_to_memset with an empty
                    variable-size compound literal stored through a
                    __seg_fs pointer
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: ice-on-valid-code
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lzy20000419 at outlook dot com
  Target Milestone: ---
              Host: x86_64-pc-linux-gnu
            Target: x86_64-pc-linux-gnu

Fails with trunk (gcc 17.0.0 20261201, afe83e260737), 16.1.0 and 16.2.0, at -O0
and -O2. Target: x86_64-pc-linux-gnu.

    void
    bar (int n, __seg_fs void *p)
    {
      typedef struct { char t[n]; } T;
      *(__seg_fs T *)p = (T) {};
    }

    gcc -O2 -S t.c
    t.c: In function 'bar':
    t.c:5:20: internal compiler error: in gimplify_modify_expr_to_memset, at
gimplify.cc:5812
        5 |   *(__seg_fs T *)p = (T) {};
          |   ~~~~~~~~~~~~~~~~~^~~~~~~~

Expected: no ICE. 16.1.0 reports the ICE at gimplify.cc:5918 and 16.2.0 at
gimplify.cc:5925. The same happens with __seg_gs. Without the address space
qualifier the function compiles fine. With -pedantic, trunk first warns "a
member of a structure or union cannot have a variably modified type" and
"compound literal has variable size", and then ICEs.

12.5.0, 13.4.0, 14.4.0, 15.2.0 and 15.3.0 reject the function with "error:
compound literal has variable size", so there is no ICE there. With a non-empty
initializer, (T) { 0 }, trunk gives "error: variable-sized object may not be
initialized except with an empty initializer".

Godbolt (trunk): https://godbolt.org/z/7jYdzGohW

This is the testcase from PR112830 comment 11. The fix for PR112830 (r14-6182)
made gimplify_modify_expr_to_memset assert that the destination is in the
generic address space, and its commit message notes that the same issue exists
for initialization from an empty CTOR, which is gimplified to a memset call,
and that no testcase was possible without extending the GNU C extension for VLA
structs. GCC 16 accepts the empty variable-size compound literal, so the assert
is now reachable.

The problem seems to be that the empty variable-size CONSTRUCTOR is still
lowered to memset in gimplify_modify_expr without checking the address space of
the destination. I have not tested a patch.

Disclaimer: This test case was generated by a fuzzer, and the report was
written with LLM assistance.

Reply via email to