Help with integer division overflow issue

Jason Thorpe <[email protected]> Tue, 9 Jan 2024 06:50:31 -0800
Newsgroups gmane.os.netbsd.ports.m68k
Message-ID <[email protected]>
Hey folks…

The NetBSD ATF tests discovered a bug in Qemu that causes Qemu to crash with a SIGFPE on x86-64 if the following test program is compiled and run in an m68k guest:

#include <limits.h>
#include <stdlib.h>

int divisor = -1;

int
main(int argc, char *argv[])
{

     if (argc > 1)
          divisor = atoi(argv[1]);

     return INT_MIN / divisor;
}

(Shenanigans are there to keep the compiler from const-folding.)

Basically, “INT_MIN / -1”.  It causes an integer overflow, and I forget exactly what the behavior of a real m68k is … does it raise an exception, or does it merely set the V flag?

Can someone with a Real 68040 (or 68030 or 68020) give it a whirl, please?

-- thorpej