1 /*
2     bug 2756
3     A non-connected live-range not caught by the live-range splitter resulted
4     in an invalid register allocation and an assertion failure in code generation.
5 */
6 
7 #include <testfwk.h>
8 
9 #pragma disable_warning 84
10 #pragma disable_warning 85
11 
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 
16 #ifdef __SDCC
17 
18 struct _bstdio_file {int i;};
19 typedef struct _bstdio_file FILE;
20 
bfprintf(FILE * _bstream,const char * __fmt,...)21 int bfprintf(FILE *_bstream, const char *__fmt, ...)
22 {
23 	return 0;
24 }
25 
bprintf(const char * _bfmt,...)26 int bprintf(const char *_bfmt, ...)
27 {
28 	return 0;
29 }
30 
__fopen(const char * _bpath,int _bfd,FILE * _bstream,const char * _bmode)31 FILE *__fopen(const char *_bpath, int _bfd, FILE * _bstream, const char *_bmode)
32 {
33 	return 0;
34 }
35 
36 #define fopen(__file, __mode)	      __fopen((__file), -1, (FILE*)0, (__mode))
37 
bgetenv(char * __name)38 char *bgetenv(char *__name)
39 {
40 	return "env";
41 }
42 
bfgets(char * _bs,size_t _bsize,FILE * _bstream)43 char *bfgets(char *_bs, size_t _bsize, FILE *_bstream)
44 {
45 	return 0;
46 }
47 
48 FILE bstderr[1];
49 
err(int _beval,const char * _bfmt,...)50 void err(int _beval, const char *_bfmt, ...)
51 {
52 }
53 
errx(int _beval,const char * _bfmt,...)54 void errx(int _beval, const char *_bfmt, ...)
55 {
56 }
57 
58 #if !defined( __SDCC_pdk14) && !defined( __SDCC_pdk15) // Lack of memory
59 char *argv0;
60 int all = 0;
61 int wday;
62 int advance;
63 char CurLine[64];
64 char *CurLinep;
65 #endif
66 
67 enum {NONE, DAY, WEEK, MONTH} mflag;
68 
69 #define	CALFILE	"/.calendar"
70 
pnmatch(const char * s,const char * p,int unanch)71 int pnmatch(const char *s, const char *p, int unanch)
72 {
73 	return 0;
74 }
75 
usage(void)76 void usage(void)
77 {
78 }
79 
findmon1(void)80 int findmon1(void)
81 {
82 	return 0;
83 }
84 
findmon2(void)85 int findmon2(void)
86 {
87 	return 0;
88 }
89 
findmon3(void)90 int findmon3(void)
91 {
92 	return 0;
93 }
94 
findday(void)95 int findday(void)
96 {
97 	return 0;
98 }
99 
findyear(void)100 int findyear(void)
101 {
102 	return 0;
103 }
104 
current(int opt)105 int current(int opt)
106 {
107 	return 0;
108 }
109 
date(int day,int month,int year)110 int date(int day, int month, int year)
111 {
112 	return 0;
113 }
114 
doall(void)115 void doall(void)
116 {
117 }
118 
m(int argc,char * argv[])119 int m(int argc, char *argv[])
120 {
121 #if !(defined (__SDCC_mcs51) && defined (__SDCC_MODEL_SMALL)) && !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Not enough memory
122 #if !(defined (__SDCC_mcs51) && (defined (__SDCC_MODEL_LARGE) || defined (__SDCC_MODEL_HUGE))) // build failure
123 	int arg = 1;
124 	char *cp;
125 	char *thisline;
126 	char *matchstr;
127 	char *filename[10];
128 	FILE *fp[10];
129 	int matchdate;
130 	int foundfiles;
131 	int nfiles;
132 	int thismonth, thisday, thisyear;
133 	int thisdate;
134 	char *atsign;
135 
136 	argv0 = argv[0];
137 	mflag = NONE; 				/* Default to no match */
138 
139 	for (arg = 1; arg < argc; arg++)  { 	/* Read option string */
140 		cp = argv[arg];
141 	sw:	switch (*cp) {
142 			case '-':
143 				cp++;
144 				goto sw;
145 			case 'a':
146 				all = 1;
147 				break;
148 			case 'f':
149 				filename[arg-1] = ++cp;
150 				nfiles++;
151 				continue;
152 			case 'd':
153 				matchstr = ++cp;
154 				mflag = DAY;
155 				continue;
156 			case 'w':
157 				matchstr = ++cp;
158 				mflag = WEEK;
159 				continue;
160 			case 'm':
161 				matchstr = ++cp;
162 				mflag = MONTH;
163 				continue;
164 			default:
165 				bfprintf(bstderr, "%s: unrecognized option '%c'\n", argv0, *cp);
166 				usage();
167 		}
168 	}
169 	if (all)
170 		doall();
171 
172 	/*
173 	 * Open files.
174 	 */
175 	if (nfiles)  {
176 		for (arg = 0; arg < nfiles; arg++ )  {
177 			if ((fp[arg] = fopen(filename[arg], "r")) == NULL)
178 				bfprintf(bstderr, "cannot open file %s\n", filename[arg]);
179 			else
180 				foundfiles++;
181 		}
182 		if (!foundfiles)
183 			err(1, "cannot open any files specified");
184 	} else {
185 		char *hp;
186 
187 		nfiles = 1;
188 		if ((hp = bgetenv("HOME")) == NULL)
189 			errx(1, "can't find my way back HOME");
190 		filename[0] = malloc(strlen(hp) + strlen(CALFILE) + 1);
191 		if (filename[0] == NULL)
192 			errx(1, "out of memory");
193 		strcpy(filename[0], hp);
194 		strcat(filename[0], CALFILE);
195 		if ((fp[0] = fopen(filename[0], "r")) == NULL)
196 			err(1, "cannot open file $HOME/.calendar");
197 	}
198 	/*
199 	 * Find match condition from options or current date
200 	 */
201 	switch (mflag)  {
202 		case NONE:
203 			matchdate = current(0);
204 			break;
205 		case DAY:
206 		case WEEK:
207 			if (*matchstr == '\0')
208 				matchdate = current(0);
209 			else {
210 				strncpy(CurLine, matchstr, sizeof(CurLine));
211 				CurLinep = &CurLine[0];
212 				if ((thismonth = findmon1()) == -1)
213 					errx(1, "invalid month in match date");
214 				if ((thisday = findday()) == -1)
215 					errx(1, "invalid day in match date");
216 				if ((thisyear = findyear()) == -1)
217 					thisyear = current(1);
218 				matchdate = date(thisday, thismonth, thisyear);
219 			}
220 			break;
221 		case MONTH:
222 			if (*matchstr == '\0')
223 				matchdate = current(2);
224 			else  {
225 				strncpy(CurLine, matchstr, sizeof(CurLine));
226 				CurLinep = &CurLine[0];
227 				if ((matchdate = findmon2()) == -1)
228 					errx(1, "invalid month in match date");
229 			}
230 			break;
231 	}
232 	/*
233 	 * Read the calendar files, print matched lines.
234 	 */
235 	for (arg = 0; arg < nfiles; arg++) {
236 		if (fp[arg] == NULL)
237 			continue;
238 		while ((thisline = bfgets(CurLine,sizeof(CurLine),fp[arg]))!=NULL) {
239 			CurLinep = &CurLine[0];
240 			advance = 0;
241 			if ((atsign = strchr(CurLinep, '@')) != NULL)
242 				advance = atoi(atsign + 1);
243 			if ((thismonth = findmon3()) == -1)
244 				thismonth = 0;
245 			if ((thisday = findday()) == -1)
246 				thisday = 0;
247 			if ((thisyear = findyear()) == -1)
248 				thisyear = current(1);
249 			thisdate = date(thisday, thismonth, thisyear);
250 			if (thisdate >= matchdate &&
251 			    thisdate <= matchdate + advance)
252 				bprintf("%s", thisline);
253 			else switch (mflag)  {
254 				case NONE:
255 					if (wday == 6)
256 						if (thisdate == matchdate ||
257 						  thisdate == matchdate + 1 ||
258 						  thisdate == matchdate + 2 ||
259 						  thisdate == matchdate + 3)
260 							bprintf("%s", thisline);
261 					if (wday == 7)
262 						if (thisdate == matchdate ||
263 						  thisdate == matchdate + 1 ||
264 						  thisdate == matchdate + 2)
265 							bprintf("%s", thisline);
266 					if (0 <= wday && wday < 6)
267 						if (thisdate == matchdate ||
268 						   thisdate == matchdate + 1)
269 							bprintf("%s", thisline);
270 					break;
271 				case DAY:
272 					if (thisdate == matchdate)
273 						bprintf("%s", thisline);
274 					break;
275 				case WEEK:
276 					if (matchdate <= thisdate &&
277 						    thisdate <= matchdate+7)
278 						bprintf("%s", thisline);
279 					break;
280 				case MONTH:
281 					if (thismonth == matchdate)
282 						bprintf("%s", thisline);
283 					break;
284 			}
285 			thisline = NULL;
286 		}
287 	}
288 #endif
289 #endif
290 	return 0;
291 }
292 
293 #endif // __SDCC
294 
testBug(void)295 void testBug(void)
296 {
297 }
298 
299