
#include <stddef.h>
#include <stdint.h>

#include "cc1.h"

Symbol *curfun;

extern Node *convert(Node *np, Type *tp1, char iscast);

static void
Return(void)
{
	Node *np;
	Type *tp = curfun->type->type;

	expect(RETURN);
	np = expr();
	if (np->type != tp) {
		if (tp == voidtype)
			warn(1, "function returning void returns a value");
		else if ((np = convert(np, tp, 0)) == NULL)
			error("incorrect type in return");
	}
	emitret(tp);
	emitexp(np);
}

void
compound(void)
{
	expect('{');
	while (!accept('}')) {
		switch (yytoken) {
		case TYPE: case SCLASS: case TQUALIFIER:
			decl();
			break;
		case RETURN:
			Return();
			break;
		default:
			emitexp(expr());
		}
		expect(';');
	}
}


#include <stddef.h>
#include <stdint.h>

#include "cc1.h"

Symbol *curfun;

extern Node *convert(Node *np, Type *tp1, char iscast);

static void
Return(void)
{
	Node *np;
	Type *tp = curfun->type->type;

	expect(RETURN);
	np = expr();
	if (np->type != tp) {
		if ((np = convert(np, tp, 0)) == NULL)
			error("incorrect type in return");
	}
	emitret(tp);
	emitexp(np);
}

void
compound(void)
{
	expect('{');
	while (!accept('}')) {
		switch (yytoken) {
		case TYPE: case SCLASS: case TQUALIFIER:
			decl();
			break;
		case RETURN:
			Return();
			break;
		default:
			emitexp(expr());
		}
		expect(';');
	}
}

--- 
+++ 
@@ -17,7 +17,9 @@
 	expect(RETURN);
 	np = expr();
 	if (np->type != tp) {
-		if ((np = convert(np, tp, 0)) == NULL)
+		if (tp == voidtype)
+			warn(1, "function returning void returns a value");
+		else if ((np = convert(np, tp, 0)) == NULL)
 			error("incorrect type in return");
 	}
 	emitret(tp);
Check that void function can return a value
