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){
75 warn(Z, "no return at end of function: %s", n1->sym->name);
77 diag(Z, "no return at end of function: %s", n1->sym->name);
82 if(!debug['N'] || debug['R'] || debug['P'])
85 if(thechar=='6' || thechar=='7' || thechar=='9' || hasdoubled) /* [sic] */
86 maxargsafe = round(maxargsafe, 8);
87 sp->to.offset += maxargsafe;
115 while(n != Z && n->op == OCOMMA) {
126 Prog *sp, *spc, *spb;
129 int snbreak, sncontin;
139 print("%L %O\n", nearln, o);
151 /* all handled specially - see switch body below */
155 warn(n, "unreachable code %O", o);
178 warnreach = !suppress;
182 l = uncomma(n->left);
188 if(typecmplx[n->type->etype]) {
194 nod.complex = l->complex;
200 if(newvlongcode && !typefd[n->type->etype]){
208 nod.complex = l->complex;
217 if(typefd[n->type->etype])
232 gbranch(OGOTO); /* prevent self reference in reg */
238 warnreach = !suppress;
242 if(n->complex == 0) {
243 diag(Z, "label undefined: %s", n->sym->name);
254 patch(n->label, pc-1);
262 diag(n, "case/default outside a switch");
274 if(l->op != OCONST || !typeswitch[l->type->etype]) {
275 diag(n, "case expression must be integer constant");
279 cases->val = l->vconst;
282 cases->isv = typev[l->type->etype];
290 if(!typeswitch[l->type->etype]) {
291 diag(n, "switch expression must be integer");
295 gbranch(OGOTO); /* entry */
309 gen(n->right); /* body */
317 regalloc(&nod, l, Z);
319 if(typev[l->type->etype])
320 nod.type = types[TVLONG];
322 nod.type = types[TLONG];
330 canreach = nbreak!=0;
332 warnreach = !suppress;
339 gbranch(OGOTO); /* entry */
357 bcomplex(l, Z); /* test */
359 if(l->op != OCONST || vconst(l) == 0)
364 gen(n->right); /* body */
371 canreach = nbreak!=0;
373 warnreach = !suppress;
379 if(!canreach && l->right->left && warnreach) {
380 warn(n, "unreachable code FOR");
383 gen(l->right->left); /* init */
384 gbranch(OGOTO); /* entry */
388 * if there are no incoming labels in the
389 * body and the top's not reachable, warn
391 if(!canreach && warnreach && deadheads(n)) {
392 warn(n, "unreachable code %O", o);
411 gen(l->right->right); /* inc */
413 if(l->left != Z) { /* test */
414 bcomplex(l->left, Z);
416 if(l->left->op != OCONST || vconst(l->left) == 0)
420 gen(n->right); /* body */
426 if(!ncontin && l->right->right && warnreach) {
427 warn(l->right->right, "unreachable FOR inc");
434 canreach = nbreak!=0;
436 warnreach = !suppress;
443 diag(n, "continue not in a loop");
450 warnreach = !suppress;
455 diag(n, "break not in a loop");
459 * Don't complain about unreachable break statements.
460 * There are breaks hidden in yacc's output and some people
461 * write return; break; in their switch statements out of habit.
462 * However, don't confuse the analysis by inserting an
463 * unreachable reference to breakpc either.
471 warnreach = !suppress;
476 if(bcomplex(l, n->right)) {
477 if(typefd[l->type->etype])
482 print("%L const if %s\n", nearln, f ? "false" : "true");
485 supgen(n->right->left);
488 gen(n->right->right);
490 * treat constant ifs as regular ifs for
491 * reachability warnings.
493 if(!canreach && oldreach && debug['w'] < 2)
501 supgen(n->right->right);
503 * treat constant ifs as regular ifs for
504 * reachability warnings.
506 if(!oldreach && canreach && debug['w'] < 2)
514 if(n->right->left != Z)
518 if(n->right->right != Z) {
522 gen(n->right->right);
525 canreach = canreach || oldreach;
527 warnreach = !suppress;
539 usedset(Node *n, int o)
543 usedset(n->right, o);
548 case OADDR: /* volatile */
561 bcomplex(Node *n, Node *c)
568 if(tcompat(n, T, n->type, tnot))
574 if(c != Z && n->op == OCONST && deadheads(c))
576 /* this is not quite right yet, so ignore it for now */
577 if(0 && newvlongcode && typev[n->type->etype] && machcap(Z)) {
581 b->right = new(0, Z, Z);
582 *b->right = *nodconst(0);
583 b->right->type = n->type;
584 b->type = types[TLONG];