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

            Bug ID: 123598
           Summary: [15/16 Regression] ICE in emit_swap_insn, at
                    reg-stack.cc:850 with -O2 flag
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jirehguo at tju dot edu.cn
  Target Milestone: ---

Compiler Explorer: https://godbolt.org/z/xo6obnY6a
The following c++ code crash gcc trunk with -O2 flag.
And goes back to 15.1 with checking.

Code:
```cpp
namespace {
double simulate_intrinsic_exp(double x) {
  double result;
  __asm__("fstpl %0" : "=t"(result) : : "ax", "st");
  return result;
}
}
int main() {
  for (;;) {
    int shared_state;
    for (int i; i;) {
      auto lambda = [i, shared_state] {
        int result = shared_state;
        struct Nested {
          static constexpr int calc(int);
        };
        return Nested::calc(result);
      };
      lambda();
      double large_value;
      double computed_result = simulate_intrinsic_exp(large_value);
      if (computed_result)
        for (int j; 1000;)
          ;
    }
  }
}
```

Stack dump:
```
<source>:15:32: warning: inline function 'static constexpr int
main()::<lambda()>::Nested::calc(int)' used but never defined
   15 |           static constexpr int calc(int);
      |                                ^~~~
In function 'double {anonymous}::simulate_intrinsic_exp(double)',
    inlined from 'int main()' at <source>:21:54:
<source>:4:3: error: 'asm' operand has impossible constraints or there are not
enough registers
    4 |   __asm__("fstpl %0" : "=t"(result) : : "ax", "st");
      |   ^~~~~~~
during RTL pass: stack
<source>: In function 'int main()':
<source>:27:1: internal compiler error: in emit_swap_insn, at reg-stack.cc:850
   27 | }
      | ^
0x292a498 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
        ???:0
0x291f25b internal_error(char const*, ...)
        ???:0
0xb1670c fancy_abort(char const*, int, char const*)
        ???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1
```

Reply via email to