4 codgen(Node *n, Node *nn)
17 for(n1 = nn;; n1 = n1->left) {
19 diag(nn, "cant find function name");
26 gpseudo(ATEXT, n1->sym, nodconst(stkoff));
29 if(typecmplx[thisfn->link->etype]) {
31 nodret = new(ONAME, Z, Z);
32 nodret->sym = slookup(".ret");
33 nodret->class = CPARAM;
34 nodret->type = types[TIND];
36 nodret = new(OIND, nodret, Z);
39 if(n1->type == T || n1->type->link != thisfn->link) {
40 n1->type = typ(TIND, thisfn->link);
41 n1->etype = n1->type->etype;
42 nodret = new(OIND, n1, Z);
48 * isolate first argument
51 if(typecmplx[thisfn->link->etype]) {
53 nodreg(&nod, &nod1, REGARG);
56 if(firstarg && typeword[firstargtype->etype]) {
60 nod1.type = firstargtype;
62 nod1.xoffset = align(0, firstargtype, Aarg1);
63 nod1.etype = firstargtype->etype;
65 nodreg(&nod, &nod1, REGARG);
73 if(canreach && thisfn->link->etype != TVOID)
74 warn(Z, "no return at end of function: %s", n1->sym->name);
78 if(!debug['N'] || debug['R'] || debug['P'])
81 if(thechar=='6' || thechar=='7' || thechar=='9' || hasdoubled) /* [sic] */
82 maxargsafe = round(maxargsafe, 8);
83 sp->to.offset += maxargsafe;
112 Prog *sp, *spc, *spb;
115 int snbreak, sncontin;
125 print("%L %O\n", nearln, o);
136 /* all handled specially - see switch body below */
140 warn(n, "unreachable code %O", o);
162 warnreach = !suppress;
172 if(typecmplx[n->type->etype]) {
178 nod.complex = l->complex;
187 if(typefd[n->type->etype])
202 gbranch(OGOTO); /* prevent self reference in reg */
208 warnreach = !suppress;
212 if(n->complex == 0) {
213 diag(Z, "label undefined: %s", n->sym->name);
224 patch(n->label, pc-1);
232 diag(n, "case/default outside a switch");
245 if(typeword[l->type->etype] && l->type->etype != TIND) {
247 cases->val = l->vconst;
250 cases->isv = typev[l->type->etype];
253 diag(n, "case expression must be integer constant");
261 if(!typeword[l->type->etype] || l->type->etype == TIND) {
262 diag(n, "switch expression must be integer");
266 gbranch(OGOTO); /* entry */
280 gen(n->right); /* body */
288 regalloc(&nod, l, Z);
290 if(typev[l->type->etype])
291 nod.type = types[TVLONG];
293 nod.type = types[TLONG];
301 canreach = nbreak!=0;
303 warnreach = !suppress;
310 gbranch(OGOTO); /* entry */
328 bcomplex(l, Z); /* test */
330 if(l->op != OCONST || vconst(l) == 0)
335 gen(n->right); /* body */
342 canreach = nbreak!=0;
344 warnreach = !suppress;
350 if(!canreach && l->right->left && warnreach) {
351 warn(n, "unreachable code FOR");
354 gen(l->right->left); /* init */
355 gbranch(OGOTO); /* entry */
359 * if there are no incoming labels in the
360 * body and the top's not reachable, warn
362 if(!canreach && warnreach && deadheads(n)) {
363 warn(n, "unreachable code %O", o);
382 gen(l->right->right); /* inc */
384 if(l->left != Z) { /* test */
385 bcomplex(l->left, Z);
387 if(l->left->op != OCONST || vconst(l->left) == 0)
391 gen(n->right); /* body */
397 if(!ncontin && l->right->right && warnreach) {
398 warn(l->right->right, "unreachable FOR inc");
405 canreach = nbreak!=0;
407 warnreach = !suppress;
414 diag(n, "continue not in a loop");
421 warnreach = !suppress;
426 diag(n, "break not in a loop");
430 * Don't complain about unreachable break statements.
431 * There are breaks hidden in yacc's output and some people
432 * write return; break; in their switch statements out of habit.
433 * However, don't confuse the analysis by inserting an
434 * unreachable reference to breakpc either.
442 warnreach = !suppress;
447 if(bcomplex(l, n->right)) {
448 if(typefd[l->type->etype])
453 print("%L const if %s\n", nearln, f ? "false" : "true");
456 supgen(n->right->left);
459 gen(n->right->right);
461 * treat constant ifs as regular ifs for
462 * reachability warnings.
464 if(!canreach && oldreach && debug['w'] < 2)
472 supgen(n->right->right);
474 * treat constant ifs as regular ifs for
475 * reachability warnings.
477 if(!oldreach && canreach && debug['w'] < 2)
485 if(n->right->left != Z)
489 if(n->right->right != Z) {
493 gen(n->right->right);
496 canreach = canreach || oldreach;
498 warnreach = !suppress;
510 usedset(Node *n, int o)
514 usedset(n->right, o);
519 case OADDR: /* volatile */
532 bcomplex(Node *n, Node *c)
537 if(tcompat(n, T, n->type, tnot))
543 if(c != Z && n->op == OCONST && deadheads(c))