Pristine Ack-5.5
[Ack-5.5.git] / lang / cem / ctest / cterr / bugs.c
1 /*
2  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3  * See the copyright notice in the ACK home directory, in the file "Copyright".
4  *
5  */
6
7 /* Author: E.G. Keizer */
8
9 char rcs_id[] = "$Id: bugs.c,v 2.4 1994/06/24 12:08:03 ceriel Exp $" ;
10
11 /* This programs is a collection of derived from small tests develloped
12    for specific bugs/features in the C->EM compiler
13 */
14
15 char * err_name ;
16
17 set_err(s) char *s ; {
18         printf("%s\n",s) ;
19         err_name= s ;
20 }
21 e(i) {
22         printf("%s: error %d\n",err_name,i) ;
23 }
24
25 main() {
26         cmp_rev() ;
27         loc_dif() ;
28         con_fold() ;
29         ass_res() ;
30         c_to_l() ;
31         acc_struct() ;
32         char_param() ;
33         addr_lb() ;
34         compl_ind() ;
35         printf("END\n") ;
36         return 0;
37 }
38
39 cmp_rev() {
40         /* Some compilers magically transform the second < into a > */
41         int i,j ;
42         int result ;
43
44         set_err("cmp_rev") ;
45         i=2 ; j=1 ;
46         result= ( (j-i<0) == (j-i<0) ) ? 1 : 0 ;
47         if ( !result ) e(1) ;
48 }
49
50 loc_dif() {
51         set_err("loc_dif") ;
52         loc_fa(1,2) ;
53 }
54
55 loc_fa(p1,p2) {
56         int i ;
57         if ( &p1-&p2 != -1 ) e(1) ;
58         if ( &i-&p1 >=0 ) e(2) ;
59         if ( &p1-&i <=0 ) e(3) ;
60 }
61
62 con_fold() {
63         set_err("con_fold") ;
64 #ifndef NOFLOAT
65         con_flo( (1 ? 3 : 4.5), 200, 200, 200 ) ;
66 #endif
67         con_lo( 4L + 3, 1 ) ;
68 }
69 #ifndef NOFLOAT
70 con_flo(d) double d ; {
71         if ( d>3.00001 || d<2.99999 ) e(1) ;
72 }
73 #endif
74 con_lo(l) long l ; {
75         if ( l!=7 ) e(2) ;
76 }
77
78 ass_res() {
79         char c, *pc ;
80         int i ;
81         int s_extend ;
82
83         set_err("ass_res") ;
84         c = -1 ;  i=c ;
85         s_extend= i== -1 ;
86
87         pc = &c ;
88         i = ( *pc++ = 01777 ) ;
89         switch ( i ) {
90         case 01777 :
91                 e(1) ; break ;
92         case -1 :
93                 if ( !s_extend ) e(2) ;
94                 break ;
95         case 0377 :
96                 if  ( s_extend ) e(3) ;
97                 break ;
98         default :
99                 e(4) ;
100         }
101 }
102
103 c_to_l() {
104         char c = -1 ;
105         long l ;
106
107         set_err("c_to_l") ;
108         l= c ;
109         if ( c==255 ) {
110                 if ( l!=255 ) e(1) ;
111         } else {
112                 if ( l!= -1 ) e(2) ;
113         }
114 }
115
116 acc_struct() {
117         struct s1 { char s1_a[3] ; } ss1, is1 ;
118         struct s2 {
119                 int             s2_i ;
120                 struct s1       s2_s1 ;
121         } ;
122         struct s3 {
123                 int             s3_i ;
124                 struct s2       s3_s2 ;
125         } ss3, *ps3 ;
126
127         set_err("acc_struct") ;
128         ps3 = &ss3 ;
129         is1.s1_a[0]=1 ; is1.s1_a[1]=100 ; is1.s1_a[2]=127 ;
130         ss3.s3_s2.s2_s1= is1 ;
131         ss1 = ps3->s3_s2.s2_s1 ;
132         if ( ss1.s1_a[0]!=1 )   e(1) ;
133         if ( ss1.s1_a[1]!=100 ) e(2) ;
134         if ( ss1.s1_a[2]!=127 ) e(3) ;
135 }
136
137 char_param() {
138         set_err("char_param") ;
139         fcall(1,01002,-1) ;
140 }
141
142 fcall(c1,c2,c3) char c1,c2,c3 ; {
143         if ( c1!=1 ) e(1) ;
144         if ( c2!=2 ) e(2) ;
145         c_alter(&c1,127) ;
146         if ( c1!=127 ) e(3) ;
147         c_alter(&c3,0) ;
148         if ( c3 ) e(4) ;
149 }
150
151 c_alter(ptr,val) char *ptr ; int val ; {
152         *ptr= val ;
153 }
154
155 addr_lb() {
156         char a[6] ;
157         int i ;
158
159         set_err("addr_lb");
160         i=6 ;
161         if ( &a[6] != a+i ) e(1) ;
162 }
163 compl_ind() {
164         char arr[20] ;
165         int i ;
166         set_err("compl_ind") ;
167         arr[10]=111 ;
168         i=0 ; if ( arr[i+10] != 111 ) e(1) ;
169 }