Module Name: src
Committed By: christos
Date: Fri Aug 19 10:19:46 UTC 2016
Modified Files:
src/usr.bin/xlint/lint1: err.c tree.c
Log Message:
Add union casts.
To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.82 -r1.83 src/usr.bin/xlint/lint1/tree.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/xlint/lint1/err.c
diff -u src/usr.bin/xlint/lint1/err.c:1.50 src/usr.bin/xlint/lint1/err.c:1.51
--- src/usr.bin/xlint/lint1/err.c:1.50 Thu Aug 18 10:42:48 2016
+++ src/usr.bin/xlint/lint1/err.c Fri Aug 19 06:19:45 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: err.c,v 1.50 2016/08/18 14:42:48 christos Exp $ */
+/* $NetBSD: err.c,v 1.51 2016/08/19 10:19:45 christos Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: err.c,v 1.50 2016/08/18 14:42:48 christos Exp $");
+__RCSID("$NetBSD: err.c,v 1.51 2016/08/19 10:19:45 christos Exp $");
#endif
#include <sys/types.h>
@@ -387,6 +387,8 @@ const char *msgs[] = {
"variable declaration in for loop", /* 325 */
"%s attribute ignored for %s", /* 326 */
"declarations after statements is a C9X feature", /* 327 */
+ "union cast is a C9X feature", /* 328 */
+ "type '%s' is not a member of '%s'", /* 329 */
};
/*
Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.82 src/usr.bin/xlint/lint1/tree.c:1.83
--- src/usr.bin/xlint/lint1/tree.c:1.82 Wed Oct 14 14:31:52 2015
+++ src/usr.bin/xlint/lint1/tree.c Fri Aug 19 06:19:45 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.82 2015/10/14 18:31:52 christos Exp $ */
+/* $NetBSD: tree.c,v 1.83 2016/08/19 10:19:45 christos Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.82 2015/10/14 18:31:52 christos Exp $");
+__RCSID("$NetBSD: tree.c,v 1.83 2016/08/19 10:19:45 christos Exp $");
#endif
#include <stdlib.h>
@@ -3143,7 +3143,28 @@ cast(tnode_t *tn, type_t *tp)
* XXX ANSI C requires scalar types or void (Plauger&Brodie).
* But this seams really questionable.
*/
- } else if (nt == STRUCT || nt == UNION || nt == ARRAY || nt == FUNC) {
+ } else if (nt == UNION) {
+ char buf[256], buf1[256];
+ sym_t *m;
+ str_t *str = tp->t_str;
+ if (!Sflag) {
+ error(328);
+ return NULL;
+ }
+ for (m = str->memb; m != NULL; m = m->s_nxt) {
+ if (sametype(m->s_type, tn->tn_type)) {
+ tn = getnode();
+ tn->tn_op = CVT;
+ tn->tn_type = tp;
+ tn->tn_cast = 1;
+ tn->tn_right = NULL;
+ return tn;
+ }
+ }
+ error(329, tyname(buf, sizeof(buf), tn->tn_type),
+ tyname(buf1, sizeof(buf1), tp));
+ return NULL;
+ } else if (nt == STRUCT || nt == ARRAY || nt == FUNC) {
/* invalid cast expression */
error(147);
return (NULL);