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

            Bug ID: 128899
           Summary: A virtual `transaction_safe` call inside
                    `__transaction_atomic` causes an ICE at `-O2`.
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ipa
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yihan4845 at gmail dot com
  Target Milestone: ---

**Compiler Explorer reproducer:**
https://godbolt.org/z/s6ecjqvEe

**Minimal testcase (min.cc):**
```cpp
struct Base {
  virtual int get(int) __attribute__((transaction_safe));
};
int shared;
int dispatch(Base *p, int n) { __transaction_atomic { shared = p->get(n); }
return shared; }
```

**Command:**
```sh
g++ -fgnu-tm -O2 -c min.cc
```

**Actual result:**
- Checking build: ICE in `obj_type_ref_class` (ipa-devirt.cc:1988), called from
`ipa_analyze_call_uses` during IPA pass `cp`.
- Release build: ICE due to a segmentation fault in `obj_type_ref_class`.

**Expected result:** Successful compilation.

**Additional observations:**
- Reproduces with `-O2`, `-O3`, and `-Os`, but not `-O0` or `-O1`.
- `-fno-devirtualize` avoids the crash.
- `-fno-ipa-cp` moves the crash to IPA pass `fnsummary`.

**Suspected root cause:**
`ipa_tm_insert_gettmclone_call` replaces the `OBJ_TYPE_REF` call target with an
`SSA_NAME` and marks the polymorphic information unusable. However,
`ipa_analyze_call_uses` still processes that information without checking
`usable_p()`, eventually passing the `SSA_NAME` to `obj_type_ref_class`, which
expects an `OBJ_TYPE_REF`.

The polymorphic information should likely be checked for usability before this
analysis.

Reply via email to