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

            Bug ID: 126163
           Summary: __builtin_mul_overflow wrong code
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gjl at gcc dot gnu.org
  Target Milestone: ---

Created attachment 64962
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=64962&action=edit
y.c.274r.expand: RTL dump

__uint24 abu24;
bool mulu24_ovf (__uint24 a, __uint24 b)
{
    return __builtin_mul_overflow (b, a, &abu24);
}

$ avr-gcc y.c -S -Os -fdump-rtl-expand-details

The generates asm always returns 0, i.e. there will never be an overflow
detected:

mulu24_ovf:
        rcall __mulpsi3
        sts abu24,r22
        sts abu24+1,r23
        sts abu24+2,r24
        ldi r24,0
        ret

The dumped tree in .expand looks reasonable:

_Bool mulu24_ovf (__int24 unsigned a, __int24 unsigned b)
{
  __int24 unsigned _1;
  __int24 unsigned _2;
  __complex__ __int24 unsigned _5;
  _Bool _8;

;;   basic block 2, loop depth 0
;;    pred:       ENTRY
  _5 = .MUL_OVERFLOW (a_3(D), b_4(D));
  _1 = REALPART_EXPR <_5>;
  abu24 = _1;
  _2 = IMAGPART_EXPR <_5>;
  _8 = (_Bool) _2;
  return _8;
;;    succ:       EXIT
}

but the RTL that follows has an unconditional jump to the good case.

Target: avr
Configured with: ../../source/gcc-master/configure --target=avr
--enable-languages=c,c++
Thread model: single
Supported LTO compression algorithms: zlib
gcc version 17.0.0 20260614 (experimental) (GCC)

Reply via email to