shithub: scc

Download patch

ref: 3272d1353b0c12caafed7986c710c9e76f3e68e1
parent: d13389de9fd2734c139925967611dcca12939890
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Aug 9 10:06:39 EDT 2016

[cc1] Do not allow operations with pointers to incomplete types

The only operations allowed with pointers to incomplete types
is the assignation and the comparition, so we have to catch
all the rest and give a good error message.

--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -316,7 +316,12 @@
 	if (lp->type->op != PTR)
 		XCHG(lp, rp, np);
 
+	tp = rp->type;
+	if (tp->op == PTR && !(tp->type->prop & TDEFINED))
+		goto incomplete;
 	tp = lp->type;
+	if (!(tp->type->prop & TDEFINED))
+		goto incomplete;
 	size = sizeofnode(tp->type);
 
 	if (op == OSUB && BTYPE(rp) == PTR) {
@@ -334,9 +339,13 @@
 
 	return simplify(OADD, tp, lp, rp);
 
+incomplete:
+	errorp("invalid use of undefined type");
+	return lp;
 incorrect:
 	errorp("incorrect arithmetic operands");
-	return node(OADD, tp, lp, rp);
+	return lp;
+
 }
 
 static Node *
@@ -541,6 +550,10 @@
 
 	if (!(tp->prop & TDEFINED)) {
 		errorp("invalid use of undefined type");
+		return np;
+	} else if (tp->op == PTR && !(tp->type->prop & TDEFINED)) {
+		errorp("%s of pointer to an incomplete type",
+		       (op == OINC) ? "increment" : "decrement");
 		return np;
 	} else if (tp->prop & TARITH) {
 		inc = constnode(one);