shithub: scc

Download patch

ref: e74b4c840eed17236373664d1fcf773a434e5f6b
parent: eda760b338438afdf9f20d30be45b04042daa74e
author: Roberto E. Vargas Caballero <[email protected]>
date: Thu Jul 10 10:58:06 EDT 2014

Detect bad class specifiers in function declarations

function declarations in non external context could be specified
with a class storage, but a good compiler should detect this
situation and gives and error this problem.

--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -397,7 +397,7 @@
 {
 	Type *tp;
 	Symbol *sym;
-	int8_t sclass;
+	int8_t sclass, isfun;
 
 	tp = specifier(&sclass);
 	if (accept(';'))
@@ -406,12 +406,30 @@
 	do {
 		sym = declarator(tp, ID_EXPECTED);
 		sym->s.isdefined = 1;
+		isfun = BTYPE(sym->type) != FTN;
+
 		switch (sclass) {
-		case REGISTER: sym->s.isregister = 1; break;
-		case STATIC: sym->s.isstatic = 1; break;
-		case EXTERN: sym->s.isdefined = 0; break;
-		case TYPEDEF: /* TODO: */;break;
-		case AUTO: default: sym->s.isauto = 1;
+		case TYPEDEF:
+			/* TODO: */
+			break;
+		case STATIC:
+			sym->s.isstatic = 1;
+			break;
+		case EXTERN:
+			sym->s.isdefined = 0;
+			break;
+		case REGISTER:
+			sym->s.isregister = 1;
+			if (isfun)
+				goto bad_function;
+			break;
+		case AUTO:
+			if (isfun)
+				goto bad_function;
+			/* passtrough */
+		default:
+			sym->s.isauto = 1;
+			break;
 		}
 		if (accept('='))
 			initializer(sym);
@@ -419,6 +437,10 @@
 	} while (accept(','));
 
 	expect(';');
+	return;
+
+bad_function:
+	error("invalid storage class for function '%s'", sym->name);
 }
 
 Type *