1 /* { dg-do run } */
2 /* { dg-require-effective-target arm_eabi } */
3 /* { dg-options "" } */
4 
5 /* Check that long long divmod functions pass the right argument to
6    __aeabi_ldiv0 on divide by zero.  */
7 
8 #ifdef DEBUGME
9 #include <stdio.h>
10 #else
11 extern void abort (void);
12 #endif
13 
14 /* Override div zero handler and simply return the provided value.  */
__aeabi_ldiv0(long long r)15 long long __aeabi_ldiv0 (long long r)
16 {
17   return r;
18 }
19 
lldiv(long long a,long long b)20 long long lldiv (long long a, long long b)
21 {
22   return a / b;
23 }
24 
ulldiv(unsigned long long a,unsigned long long b)25 unsigned long long ulldiv (unsigned long long a, unsigned long long b)
26 {
27   return a / b;
28 }
29 
check(long long num,long long expected)30 void check (long long num, long long expected)
31 {
32   long long res = lldiv (num, 0LL);
33   if (res != expected)
34 #ifdef DEBUGME
35     {
36       printf ("num=%08X:%08X\n", (unsigned)(num >> 32), (unsigned)num);
37       printf ("res=%08X:%08X\n", (unsigned)(res >> 32), (unsigned)res);
38     }
39 #else
40     abort ();
41 #endif
42 }
43 
ucheck(unsigned long long num,unsigned long long expected)44 void ucheck (unsigned long long num, unsigned long long expected)
45 {
46   unsigned long long res = ulldiv (num, 0ULL);
47   if (res != expected)
48 #ifdef DEBUGME
49     {
50       printf ("num=%08X:%08X\n", (unsigned)(num >> 32), (unsigned)num);
51       printf ("res=%08X:%08X\n", (unsigned)(res >> 32), (unsigned)res);
52     }
53 #else
54     abort ();
55 #endif
56 }
57 
58 #define POS_BIG 0x7fffffffffffffffLL
59 #define NEG_BIG 0x8000000000000000LL
60 #define UNS_BIG 0xffffffffffffffffULL
61 
main()62 int main ()
63 {
64   check (0LL, 0LL);
65   check (1LL, POS_BIG);
66   check (0x000000007fffffffLL, POS_BIG);
67   check (0x00000000ffffffffLL, POS_BIG);
68   check (0x0000000100000000LL, POS_BIG);
69   check (POS_BIG, POS_BIG);
70   check (-1LL, NEG_BIG);
71   check (-0x000000007fffffffLL, NEG_BIG);
72   check (-0x00000000ffffffffLL, NEG_BIG);
73   check (-0x0000000100000000LL, NEG_BIG);
74   check (NEG_BIG, NEG_BIG);
75 
76   ucheck (0ULL, 0ULL);
77   ucheck (1ULL, UNS_BIG);
78   ucheck (0x000000007fffffffULL, UNS_BIG);
79   ucheck (0x00000000ffffffffULL, UNS_BIG);
80   ucheck (0x0000000100000000ULL, UNS_BIG);
81   ucheck ((unsigned long long)POS_BIG, UNS_BIG);
82   ucheck (UNS_BIG, UNS_BIG);
83 
84   return 0;
85 }
86