Module Name: src Committed By: rillig Date: Sat Jul 31 11:03:04 UTC 2021
Modified Files: src/usr.bin/xlint/lint1: decl.c externs1.h func.c init.c lint1.h tree.c Log Message: lint: merge duplicate code for generating unqualified type This is a preparation for fixing the wrong warnings in msg_115.c. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.210 -r1.211 src/usr.bin/xlint/lint1/decl.c cvs rdiff -u -r1.121 -r1.122 src/usr.bin/xlint/lint1/externs1.h cvs rdiff -u -r1.115 -r1.116 src/usr.bin/xlint/lint1/func.c cvs rdiff -u -r1.203 -r1.204 src/usr.bin/xlint/lint1/init.c cvs rdiff -u -r1.118 -r1.119 src/usr.bin/xlint/lint1/lint1.h cvs rdiff -u -r1.319 -r1.320 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/decl.c diff -u src/usr.bin/xlint/lint1/decl.c:1.210 src/usr.bin/xlint/lint1/decl.c:1.211 --- src/usr.bin/xlint/lint1/decl.c:1.210 Sun Jul 25 22:14:36 2021 +++ src/usr.bin/xlint/lint1/decl.c Sat Jul 31 11:03:04 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: decl.c,v 1.210 2021/07/25 22:14:36 rillig Exp $ */ +/* $NetBSD: decl.c,v 1.211 2021/07/31 11:03:04 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: decl.c,v 1.210 2021/07/25 22:14:36 rillig Exp $"); +__RCSID("$NetBSD: decl.c,v 1.211 2021/07/31 11:03:04 rillig Exp $"); #endif #include <sys/param.h> @@ -187,6 +187,27 @@ expr_dup_type(const type_t *tp) } /* + * Return the unqualified version of the type. The returned type is freed at + * the end of the current expression. + * + * See C99 6.2.5p25. + */ +type_t * +expr_unqualified_type(const type_t *tp) +{ + type_t *ntp; + + ntp = expr_zalloc(sizeof(*ntp)); + *ntp = *tp; + ntp->t_const = false; + ntp->t_volatile = false; + + /* TODO: deep-copy struct/union members; see msg_115.c */ + + return ntp; +} + +/* * Returns whether the argument is void or an incomplete array, * struct, union or enum type. */ Index: src/usr.bin/xlint/lint1/externs1.h diff -u src/usr.bin/xlint/lint1/externs1.h:1.121 src/usr.bin/xlint/lint1/externs1.h:1.122 --- src/usr.bin/xlint/lint1/externs1.h:1.121 Sun Jul 25 22:14:36 2021 +++ src/usr.bin/xlint/lint1/externs1.h Sat Jul 31 11:03:04 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: externs1.h,v 1.121 2021/07/25 22:14:36 rillig Exp $ */ +/* $NetBSD: externs1.h,v 1.122 2021/07/31 11:03:04 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -145,6 +145,7 @@ extern void initdecl(void); extern type_t *gettyp(tspec_t); extern type_t *dup_type(const type_t *); extern type_t *expr_dup_type(const type_t *); +extern type_t *expr_unqualified_type(const type_t *); extern bool is_incomplete(const type_t *); extern void setcomplete(type_t *, bool); extern void add_storage_class(scl_t); Index: src/usr.bin/xlint/lint1/func.c diff -u src/usr.bin/xlint/lint1/func.c:1.115 src/usr.bin/xlint/lint1/func.c:1.116 --- src/usr.bin/xlint/lint1/func.c:1.115 Fri Jul 23 17:06:37 2021 +++ src/usr.bin/xlint/lint1/func.c Sat Jul 31 11:03:04 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: func.c,v 1.115 2021/07/23 17:06:37 rillig Exp $ */ +/* $NetBSD: func.c,v 1.116 2021/07/31 11:03:04 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: func.c,v 1.115 2021/07/23 17:06:37 rillig Exp $"); +__RCSID("$NetBSD: func.c,v 1.116 2021/07/31 11:03:04 rillig Exp $"); #endif #include <stdlib.h> @@ -1091,8 +1091,7 @@ do_return(tnode_t *tn) /* Create a temporary node for the left side */ ln = expr_zalloc(sizeof(*ln)); ln->tn_op = NAME; - ln->tn_type = expr_dup_type(funcsym->s_type->t_subt); - ln->tn_type->t_const = false; + ln->tn_type = expr_unqualified_type(funcsym->s_type->t_subt); ln->tn_lvalue = true; ln->tn_sym = funcsym; /* better than nothing */ Index: src/usr.bin/xlint/lint1/init.c diff -u src/usr.bin/xlint/lint1/init.c:1.203 src/usr.bin/xlint/lint1/init.c:1.204 --- src/usr.bin/xlint/lint1/init.c:1.203 Tue Jul 20 19:44:36 2021 +++ src/usr.bin/xlint/lint1/init.c Sat Jul 31 11:03:04 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: init.c,v 1.203 2021/07/20 19:44:36 rillig Exp $ */ +/* $NetBSD: init.c,v 1.204 2021/07/31 11:03:04 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -38,7 +38,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: init.c,v 1.203 2021/07/20 19:44:36 rillig Exp $"); +__RCSID("$NetBSD: init.c,v 1.204 2021/07/31 11:03:04 rillig Exp $"); #endif #include <stdlib.h> @@ -400,8 +400,7 @@ check_init_expr(const type_t *tp, sym_t tspec_t lt, rt; struct memory_block *tmem; - ltp = expr_dup_type(tp); - ltp->t_const = false; + ltp = expr_unqualified_type(tp); /* Create a temporary node for the left side. */ ln = expr_zalloc(sizeof(*ln)); @@ -900,8 +899,7 @@ initialization_expr_using_assign(struct debug_step0("handing over to ASSIGN"); ln = build_name(in->in_sym, 0); - ln->tn_type = expr_dup_type(ln->tn_type); - ln->tn_type->t_const = false; + ln->tn_type = expr_unqualified_type(ln->tn_type); tn = build_binary(ln, ASSIGN, rn); expr(tn, false, false, false, false); Index: src/usr.bin/xlint/lint1/lint1.h diff -u src/usr.bin/xlint/lint1/lint1.h:1.118 src/usr.bin/xlint/lint1/lint1.h:1.119 --- src/usr.bin/xlint/lint1/lint1.h:1.118 Fri Jul 23 17:06:37 2021 +++ src/usr.bin/xlint/lint1/lint1.h Sat Jul 31 11:03:04 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lint1.h,v 1.118 2021/07/23 17:06:37 rillig Exp $ */ +/* $NetBSD: lint1.h,v 1.119 2021/07/31 11:03:04 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -192,6 +192,7 @@ struct lint1_type { }; #define t_dim t_u._t_dim +/* TODO: rename t_str to t_sou, to avoid confusing it with strings. */ #define t_str t_u._t_str #define t_enum t_u._t_enum #define t_args t_u._t_args @@ -264,6 +265,7 @@ typedef struct sym { type_t *s_type; val_t s_value; /* value (if enum or bool constant) */ union { + /* XXX: what is the difference to s_type->t_str? */ struct_or_union *_s_st; enumeration *_s_et; tspec_t _s_tsp; /* type (only for keywords) */ Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.319 src/usr.bin/xlint/lint1/tree.c:1.320 --- src/usr.bin/xlint/lint1/tree.c:1.319 Sun Jul 25 10:39:10 2021 +++ src/usr.bin/xlint/lint1/tree.c Sat Jul 31 11:03:04 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.319 2021/07/25 10:39:10 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.320 2021/07/31 11:03:04 rillig 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.319 2021/07/25 10:39:10 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.320 2021/07/31 11:03:04 rillig Exp $"); #endif #include <float.h> @@ -3611,8 +3611,7 @@ check_prototype_argument( bool dowarn; ln = xcalloc(1, sizeof(*ln)); - ln->tn_type = expr_dup_type(tp); - ln->tn_type->t_const = false; + ln->tn_type = expr_unqualified_type(tp); ln->tn_lvalue = true; if (typeok(FARG, n, ln, tn)) { if (!eqtype(tp, tn->tn_type,