• I found and reported the bool FFI miscompilation. The behaviour I was observing was very confusing, and I’m generally extremely hesitant to blame the compiler. Eventually I brought the problem to the rest of the team and started with “I’m running into some strange behaviour, which is smelling like a compiler bug.” somewhat reassuring that my suspicions did turn out to be correct in this case.


      score 3 · canonical

        • The initially observed issue was failing tests in our test suite. As I traced that through I eventually landed on a Rust function that returned a bool to Mercury code. Logging the value on the Rust side was fine, but then attempting to log the same value on the Mercury side was crashing the Mercury runtime. Eventually I logged the value from a C foreign_proc in Mercury and was seeing it was receiving the value 16 instead of 0 or 1. It was at this point that I suspected a compiler bug. Comparing the assembly of the function was also suspect:

          1.99:
          
          Disassembly of section .text.fontcode_rust_font_has_glyf:
          
          0000000000000000 <fontcode_rust_font_has_glyf>:
                 0: 0f b6 87 9f 01 00 00          movzbl  0x19f(%rdi), %eax
                 7: c3                            retq
          
          
          1.83:
          
          Disassembly of section .text.fontcode_rust_font_has_glyf:
          
          0000000000000000 <fontcode_rust_font_has_glyf>:
                 0: 0f b6 87 9f 01 00 00          movzbl  0x19f(%rdi), %eax
                 7: 24 01                         andb    $0x1, %al
                 9: c3                            retq
          

          From there I was able to build a small reproducer and open an issue on the rust repo.


          score 1 · canonical

      • lobsters__chc4@crustaceanson.theshelf.topM
        link
        fedilink
        arrow-up
        1
        ·
        edit-2
        13 days ago

        I ran into this a few weeks ago, so thank you very much for reporting it! In my case the type guards for my JIT compiler were incorrectly falling through because I was comparing the result of a runtime type guard that returned a bool, and it was returning bytes with other bits set despite ABI requirements :( https://github.com/chc4/lunacy/commit/1b94b976fd00869148fb0db3d639f65e9bda5a64


        score 1 · canonical