Module Name: src Committed By: christos Date: Fri Oct 2 15:03:45 UTC 2009
Modified Files: src/usr.bin/xlint/lint1: cgram.y decl.c err.c externs1.h lint1.h scan.l Log Message: understand __attribute__((__packed__)) and __packed. To generate a diff of this commit: cvs rdiff -u -r1.44 -r1.45 src/usr.bin/xlint/lint1/cgram.y \ src/usr.bin/xlint/lint1/scan.l cvs rdiff -u -r1.46 -r1.47 src/usr.bin/xlint/lint1/decl.c cvs rdiff -u -r1.42 -r1.43 src/usr.bin/xlint/lint1/err.c cvs rdiff -u -r1.27 -r1.28 src/usr.bin/xlint/lint1/externs1.h cvs rdiff -u -r1.22 -r1.23 src/usr.bin/xlint/lint1/lint1.h 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/cgram.y diff -u src/usr.bin/xlint/lint1/cgram.y:1.44 src/usr.bin/xlint/lint1/cgram.y:1.45 --- src/usr.bin/xlint/lint1/cgram.y:1.44 Sat May 2 12:10:49 2009 +++ src/usr.bin/xlint/lint1/cgram.y Fri Oct 2 11:03:45 2009 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: cgram.y,v 1.44 2009/05/02 16:10:49 christos Exp $ */ +/* $NetBSD: cgram.y,v 1.45 2009/10/02 15:03:45 christos Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -35,7 +35,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: cgram.y,v 1.44 2009/05/02 16:10:49 christos Exp $"); +__RCSID("$NetBSD: cgram.y,v 1.45 2009/10/02 15:03:45 christos Exp $"); #endif #include <stdlib.h> @@ -182,6 +182,18 @@ %token T_RETURN %token T_ASM %token T_SYMBOLRENAME +%token T_PACKED +/* Type Attributes */ +%token <y_type> T_ATTRIBUTE +%token <y_type> T_AT_ALIGNED +%token <y_type> T_AT_DEPRECATED +%token <y_type> T_AT_MAY_ALIAS +%token <y_type> T_AT_PACKED +%token <y_type> T_AT_TUINION +%token <y_type> T_AT_TUNION +%token <y_type> T_AT_UNUSED + + %left T_COMMA %right T_ASSIGN T_OPASS @@ -212,6 +224,8 @@ %type <y_type> notype_typespec %type <y_type> struct_spec %type <y_type> enum_spec +%type <y_type> type_attribute +%type <y_type> type_attribute_spec %type <y_sym> struct_tag %type <y_sym> enum_tag %type <y_tspec> struct @@ -454,6 +468,24 @@ | error T_SEMI ; +type_attribute_spec: + T_AT_DEPRECATED + | T_AT_ALIGNED T_LPARN constant T_RPARN + | T_AT_MAY_ALIAS + | T_AT_PACKED { + addpacked(); + } + | T_AT_TUNION + | T_AT_UNUSED + ; + +type_attribute: + T_ATTRIBUTE T_LPARN T_LPARN type_attribute_spec T_RPARN T_RPARN + | T_PACKED { + addpacked(); + } + ; + clrtyp: { clrtyp(); @@ -473,6 +505,7 @@ | declmods typespec { addtype($2); } + | declspecs type_attribute | declspecs declmod | declspecs notype_typespec { addtype($2); Index: src/usr.bin/xlint/lint1/scan.l diff -u src/usr.bin/xlint/lint1/scan.l:1.44 src/usr.bin/xlint/lint1/scan.l:1.45 --- src/usr.bin/xlint/lint1/scan.l:1.44 Sat May 2 12:10:49 2009 +++ src/usr.bin/xlint/lint1/scan.l Fri Oct 2 11:03:45 2009 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: scan.l,v 1.44 2009/05/02 16:10:49 christos Exp $ */ +/* $NetBSD: scan.l,v 1.45 2009/10/02 15:03:45 christos Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -35,7 +35,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: scan.l,v 1.44 2009/05/02 16:10:49 christos Exp $"); +__RCSID("$NetBSD: scan.l,v 1.45 2009/10/02 15:03:45 christos Exp $"); #endif #include <stdlib.h> @@ -193,7 +193,21 @@ u_int kw_c99; /* c99 keyword */ u_int kw_gcc; /* GCC keyword */ } kwtab[] = { - { "__alignof__",T_ALIGNOF, 0, 0, 0, 0, 0, 0 }, + { "__alignof__", T_ALIGNOF, 0, 0, 0, 0, 0, 0 }, + { "__attribute__",T_ATTRIBUTE, 0, 0, 0, 0, 0, 1 }, + { "attribute", T_ATTRIBUTE, 0, 0, 0, 0, 0, 1 }, + { "__packed__", T_AT_PACKED, 0, 0, 0, 0, 0, 1 }, + { "packed", T_AT_PACKED, 0, 0, 0, 0, 0, 1 }, + { "__aligned__",T_AT_ALIGNED, 0, 0, 0, 0, 0, 1 }, + { "aligned", T_AT_ALIGNED, 0, 0, 0, 0, 0, 1 }, + { "__transparent_union__",T_AT_TUNION,0,0, 0, 0, 0, 1 }, + { "transparent_union",T_AT_TUNION,0, 0, 0, 0, 0, 1 }, + { "__unused__", T_AT_UNUSED, 0, 0, 0, 0, 0, 1 }, + { "unused", T_AT_UNUSED, 0, 0, 0, 0, 0, 1 }, + { "__deprecated__",T_AT_DEPRECATED,0, 0, 0, 0, 0, 1 }, + { "deprecated", T_AT_DEPRECATED,0, 0, 0, 0, 0, 1 }, + { "__may_alias__",T_AT_MAY_ALIAS,0, 0, 0, 0, 0, 1 }, + { "may_alias", T_AT_MAY_ALIAS, 0, 0, 0, 0, 0, 1 }, { "asm", T_ASM, 0, 0, 0, 0, 0, 1 }, { "__asm", T_ASM, 0, 0, 0, 0, 0, 0 }, { "__asm__", T_ASM, 0, 0, 0, 0, 0, 0 }, @@ -228,6 +242,7 @@ { "register", T_SCLASS, REG, 0, 0, 0, 0, 0 }, { "restrict", T_QUAL, 0, 0, RESTRICT, 0, 1, 0 }, { "return", T_RETURN, 0, 0, 0, 0, 0, 0 }, + { "__packed", T_PACKED, 0, 0, 0, 0, 0, 0 }, { "short", T_TYPE, 0, SHORT, 0, 0, 0, 0 }, { "signed", T_TYPE, 0, SIGNED, 0, 1, 0, 0 }, { "__signed__", T_TYPE, 0, SIGNED, 0, 0, 0, 0 }, Index: src/usr.bin/xlint/lint1/decl.c diff -u src/usr.bin/xlint/lint1/decl.c:1.46 src/usr.bin/xlint/lint1/decl.c:1.47 --- src/usr.bin/xlint/lint1/decl.c:1.46 Tue Apr 14 21:20:57 2009 +++ src/usr.bin/xlint/lint1/decl.c Fri Oct 2 11:03:45 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: decl.c,v 1.46 2009/04/15 01:20:57 christos Exp $ */ +/* $NetBSD: decl.c,v 1.47 2009/10/02 15:03:45 christos 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.46 2009/04/15 01:20:57 christos Exp $"); +__RCSID("$NetBSD: decl.c,v 1.47 2009/10/02 15:03:45 christos Exp $"); #endif #include <sys/param.h> @@ -484,6 +484,41 @@ } } +void +addpacked(void) +{ + str_t *sp; + sym_t *mem; + type_t *tp = dcs->d_type; + char buf[256]; + + if (tp == NULL) + LERROR("no type attr"); + + tp->t_ispacked = 1; + + switch (tp->t_tspec) { + case STRUCT: + sp = tp->t_str; + sp->size = 0; + for (mem = sp->memb; mem != NULL; mem = mem->s_nxt) + sp->size += size(mem->s_type->t_tspec); + break; + case UNION: + sp = tp->t_str; + sp->size = 0; + for (mem = sp->memb; mem != NULL; mem = mem->s_nxt) { + size_t x = size(mem->s_type->t_tspec); + if (x > sp->size) + sp->size = x; + } + break; + default: + warning(326, "packed", tyname(buf, sizeof(buf), tp)); + break; + } +} + /* * Remember a qualifier which is part of the declaration specifiers * (and not the declarator) in the top element of the declaration stack. @@ -522,15 +557,15 @@ { dinfo_t *di; - if (dflag) - (void)printf("pushdecl(%d)\n", (int)sc); - /* put a new element on the declaration stack */ di = xcalloc(1, sizeof (dinfo_t)); di->d_nxt = dcs; dcs = di; di->d_ctx = sc; di->d_ldlsym = &di->d_dlsyms; + if (dflag) + (void)printf("pushdecl(%p %d)\n", dcs, (int)sc); + } /* @@ -542,7 +577,7 @@ dinfo_t *di; if (dflag) - (void)printf("popdecl(%d)\n", (int)dcs->d_ctx); + (void)printf("popdecl(%p %d)\n", dcs, (int)dcs->d_ctx); if (dcs->d_nxt == NULL) LERROR("popdecl()"); @@ -1617,7 +1652,6 @@ /* ist unvollstaendiger Typ */ setcompl(tp, 1); } - return (tp); } Index: src/usr.bin/xlint/lint1/err.c diff -u src/usr.bin/xlint/lint1/err.c:1.42 src/usr.bin/xlint/lint1/err.c:1.43 --- src/usr.bin/xlint/lint1/err.c:1.42 Sat May 2 12:10:49 2009 +++ src/usr.bin/xlint/lint1/err.c Fri Oct 2 11:03:45 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: err.c,v 1.42 2009/05/02 16:10:49 christos Exp $ */ +/* $NetBSD: err.c,v 1.43 2009/10/02 15:03: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.42 2009/05/02 16:10:49 christos Exp $"); +__RCSID("$NetBSD: err.c,v 1.43 2009/10/02 15:03:45 christos Exp $"); #endif #include <sys/types.h> @@ -385,6 +385,7 @@ "continue in 'do ... while (0)' loop", /* 323 */ "suggest cast from '%s' to '%s' on op %s to avoid overflow", /* 324 */ "variable declaration in for loop", /* 325 */ + "%s attribute ignored for %s", /* 326 */ }; /* Index: src/usr.bin/xlint/lint1/externs1.h diff -u src/usr.bin/xlint/lint1/externs1.h:1.27 src/usr.bin/xlint/lint1/externs1.h:1.28 --- src/usr.bin/xlint/lint1/externs1.h:1.27 Sat May 2 12:10:49 2009 +++ src/usr.bin/xlint/lint1/externs1.h Fri Oct 2 11:03:45 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: externs1.h,v 1.27 2009/05/02 16:10:49 christos Exp $ */ +/* $NetBSD: externs1.h,v 1.28 2009/10/02 15:03:45 christos Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -141,6 +141,7 @@ extern void addscl(scl_t); extern void addtype(type_t *); extern void addqual(tqual_t); +extern void addpacked(void); extern void pushdecl(scl_t); extern void popdecl(void); extern void setasm(void); Index: src/usr.bin/xlint/lint1/lint1.h diff -u src/usr.bin/xlint/lint1/lint1.h:1.22 src/usr.bin/xlint/lint1/lint1.h:1.23 --- src/usr.bin/xlint/lint1/lint1.h:1.22 Wed Dec 10 11:12:39 2008 +++ src/usr.bin/xlint/lint1/lint1.h Fri Oct 2 11:03:45 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: lint1.h,v 1.22 2008/12/10 16:12:39 joerg Exp $ */ +/* $NetBSD: lint1.h,v 1.23 2009/10/02 15:03:45 christos Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -143,6 +143,7 @@ u_int t_typedef : 1; /* type defined with typedef */ u_int t_isfield : 1; /* type is bitfield */ u_int t_isenum : 1; /* type is (or was) enum (t_enum valid) */ + u_int t_ispacked : 1; /* type is packed */ union { int _t_dim; /* dimension */ str_t *_t_str; /* struct/union tag */