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

--- Comment #15 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Dmitrii Pasechnik from comment #12)
> A colleague disassembled, using ghidra (https://ghidra-sre.org/), the
> results of the compilations with, respectively, -O2 and with -O0 flags.
> Comparing the results, in the broken (built with -O2) case one sees a
> miscompilation of a call to GAP_CallFunc3Args - it is called with one
> argument less than it should, three instead of four!
> 
> broken (-O2):
> 
> >               plVar9 = (long *)GAP_CallFunc3Args(*(undefined8 *)(param_1 + 
> > 0x20),local_a0[4],
> >                                                  local_a8[4]);
> 
> vs. good (-O0):
> 
> < LAB_0013cbd9:
> <             plVar10 = (long *)GAP_CallFunc3Args(*(undefined8 *)(param_1 +
> 0x20),local_a8[4],
> <                                                 local_a0[4],plVar16[4]);
> 
> And this is despite the prototype for calling GAP_CallFunc3Args() is
> found in "gap/libgap-api.h", which is included in example.c as #include
> "gap/libgap-api.h",  meant to be respected during the compilation. 
> 
> I hope this helps in chasing down the obvious compiler bug. Perhaps it can
> be also seen without disassembling, simply on the intermediate data
> generated by the compiler.

Both calls pass 4 arguments, both in optimized -O2 -fPIC GCC 13.2.1 dump and in
assembly:
        movq    -88(%rbp), %rdx
        movq    %r12, %rcx
        movq    %r13, %rsi
        movq    %rax, %rdi
        call    GAP_CallFunc3Args@PLT
...
        movq    -88(%rbp), %rdx
        movq    %r12, %rcx
        movq    %r13, %rsi
        movq    %rax, %rdi
        call    GAP_CallFunc3Args@PLT
and
  GAP_CallFunc3Args (_53, _47, __pyx_v_func_54(D), _49);
...
  _441 = GAP_CallFunc3Args (_98, _97, _96, _95);

Reply via email to