Regarding integer division by 0, x86_64 behaves like i386.
[gnulib.git] / m4 / intdiv0.m4
1 # intdiv0.m4 serial 2 (gettext-0.16.2)
2 dnl Copyright (C) 2002, 2007 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 dnl From Bruno Haible.
8
9 AC_DEFUN([gt_INTDIV0],
10 [
11   AC_REQUIRE([AC_PROG_CC])dnl
12   AC_REQUIRE([AC_CANONICAL_HOST])dnl
13
14   AC_CACHE_CHECK([whether integer division by zero raises SIGFPE],
15     gt_cv_int_divbyzero_sigfpe,
16     [
17       AC_TRY_RUN([
18 #include <stdlib.h>
19 #include <signal.h>
20
21 static void
22 sigfpe_handler (int sig)
23 {
24   /* Exit with code 0 if SIGFPE, with code 1 if any other signal.  */
25   exit (sig != SIGFPE);
26 }
27
28 int x = 1;
29 int y = 0;
30 int z;
31 int nan;
32
33 int main ()
34 {
35   signal (SIGFPE, sigfpe_handler);
36 /* IRIX and AIX (when "xlc -qcheck" is used) yield signal SIGTRAP.  */
37 #if (defined (__sgi) || defined (_AIX)) && defined (SIGTRAP)
38   signal (SIGTRAP, sigfpe_handler);
39 #endif
40 /* Linux/SPARC yields signal SIGILL.  */
41 #if defined (__sparc__) && defined (__linux__)
42   signal (SIGILL, sigfpe_handler);
43 #endif
44
45   z = x / y;
46   nan = y / y;
47   exit (1);
48 }
49 ], gt_cv_int_divbyzero_sigfpe=yes, gt_cv_int_divbyzero_sigfpe=no,
50         [
51           # Guess based on the CPU.
52 changequote(,)dnl
53           case "$host_cpu" in
54             alpha* | i[34567]86 | x86_64 | m68k | s390*)
55               gt_cv_int_divbyzero_sigfpe="guessing yes";;
56             *)
57               gt_cv_int_divbyzero_sigfpe="guessing no";;
58           esac
59 changequote([,])dnl
60         ])
61     ])
62   case "$gt_cv_int_divbyzero_sigfpe" in
63     *yes) value=1;;
64     *) value=0;;
65   esac
66   AC_DEFINE_UNQUOTED(INTDIV0_RAISES_SIGFPE, $value,
67     [Define if integer division by zero raises signal SIGFPE.])
68 ])