Debian Codegraph @

gcc/testsuite/gm2/switches/pim4/run/pass/FpuIOBug.mod

raw
1 (* Copyright (C) 2005, 2006 Free Software Foundation, Inc. *)
2 (* This file is part of GNU Modula-2.
3
4 GNU Modula-2 is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with gm2; see the file COPYING. If not, write to the Free Software
16 Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *)
17
18 MODULE FpuIOBug;
19
20 (*
21 * This module tests the implementation of InOut by stress testing
22 * StringConvert (and checks to see that the -Wpim4 flag does cause
23 * any unexpected DIV and MOD results).
24 *)
25
26 FROM StringConvert IMPORT LongIntegerToString ;
27 FROM DynamicStrings IMPORT String, InitString, EqualArray, KillString, string ;
28 FROM libc IMPORT exit, printf ;
29 FROM SYSTEM IMPORT ADR, TSIZE ;
30
31
32 PROCEDURE Assert (v: BOOLEAN; f: ARRAY OF CHAR; l: CARDINAL; e: ARRAY OF CHAR) ;
33 VAR
34 r: INTEGER ;
35 BEGIN
36 IF v
37 THEN
38 r := printf("successfully evaluated %s\n", ADR(e))
39 ELSE
40 r := printf("%s:%d assertion failed when evaluating %s\n", ADR(f), l, ADR(e)) ;
41 res := 1
42 END
43 END Assert ;
44
45
46 PROCEDURE WriteLongInt (x: LONGINT; n: CARDINAL) : String ;
47 BEGIN
48 RETURN LongIntegerToString(x, n, ' ', FALSE, 10, TRUE)
49 END WriteLongInt ;
50
51
52 VAR
53 s : String ;
54 r, res: INTEGER ;
55 BEGIN
56 res := 0 ;
57
58 s := WriteLongInt(MAX(LONGINT), 0) ;
59 r := printf('result of MAX(LONGINT) = %s\n', string(s)) ;
60 IF TSIZE(LONGINT)=4
61 THEN
62 Assert(EqualArray(s, '2147483647'), __FILE__, __LINE__,
63 'MAX(LONGINT) in LongIntegerToString')
64 ELSE
65 Assert(EqualArray(s, '9223372036854775807'), __FILE__, __LINE__,
66 'MAX(LONGINT) in LongIntegerToString')
67 END ;
68
69 s := KillString(s) ;
70
71 s := WriteLongInt(MIN(LONGINT), 0) ;
72 r := printf('result of MIN(LONGINT) = %s\n', string(s)) ;
73 IF TSIZE(LONGINT)=4
74 THEN
75 Assert(EqualArray(s, '-2147483648'), __FILE__, __LINE__,
76 'MIN(LONGINT) in LongIntegerToString')
77 ELSE
78 Assert(EqualArray(s, '-9223372036854775808'), __FILE__, __LINE__,
79 'MIN(LONGINT) in LongIntegerToString')
80 END ;
81
82 s := KillString(s) ;
83
84 s := WriteLongInt(MIN(LONGINT)+1, 0) ;
85 r := printf('result of MIN(LONGINT)+1 = %s\n', string(s)) ;
86 IF TSIZE(LONGINT)=4
87 THEN
88 Assert(EqualArray(s, '-2147483647'), __FILE__, __LINE__,
89 'MIN(LONGINT)+1 in itos')
90 ELSE
91 Assert(EqualArray(s, '-9223372036854775807'), __FILE__, __LINE__,
92 'MIN(LONGINT)+1 in itos')
93 END ;
94
95 s := KillString(s) ;
96 exit(res)
97 END FpuIOBug.