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

            Bug ID: 128959
           Summary: RISC-V: ICE when an incompatible arch= follows cpu= in
                    a target attribute
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: majin at gcc dot gnu.org
  Target Milestone: ---

After diagnosing an incompatible target-attribute architecture, GCC
deletes the same subset list a second time and then ICEs.

Compiler information
--------------------

GCC version: 17.0.0 20261116 (experimental)
Target: riscv64-unknown-linux-gnu
GCC master revision tested:
bcf94a94bc385270d80a97800d20dec378d668ab

Reproducer
----------

Save as testcase.c:

__attribute__ ((target ("cpu=sifive-u74;arch=rv32i")))
void invalid_arch (void) {}

Compile with:

riscv64-unknown-linux-gnu-gcc -O2 -march=rv64gc -mabi=lp64d \
  -S testcase.c -o testcase.s

Actual result
-------------

error: unexpected arch for 'target()' attribute: must start with rv64 but found
'rv32i'
munmap_chunk(): invalid pointer
internal compiler error: Aborted

The second delete happens in the parse_arch fail block of
riscv-target-attr.cc.

Expected result
---------------

A diagnostic and normal rejection, without an ICE.

Analysis
--------

cpu= allocates m_subset_list first. parse_arch() deletes it at entry
without clearing the pointer; the XLEN mismatch jumps to fail, which
deletes it again. Clearing the pointer after the first delete fixes it.

Reply via email to