shithub: riscv

Download patch

ref: 433b18ec2b54387119abdeb0a85767cd92e4a23b
parent: 3d4fcc6c8ab02d0370919714fc08229e87f414ed
author: cinap_lenrek <[email protected]>
date: Thu Apr 16 10:32:42 EDT 2015

cc: catch non constant pointer initializers

char	FOO[] = "abc";	/* ok */
char	*BAR = FOO;		/* ok */
char	*BAZ = BAR;		/* wrong */

--- a/sys/src/cmd/cc/dcl.c
+++ b/sys/src/cmd/cc/dcl.c
@@ -381,8 +381,14 @@
 				diag(a, "initialization of incompatible pointers: %s\n%T and %T",
 					s->name, t, a->type);
 			}
-			if(a->op == OADDR)
+			if(a->op == OADDR) {
 				a = a->left;
+				goto gext;
+			}
+			if(a->type->etype == TIND) {
+				diag(a, "initializer is not a constant: %s", s->name);
+				return Z;
+			}
 			goto gext;
 		}