Fri Oct 2 21:49:30 2009 UTC ()
handle bit fields in packed structures.


(christos)
diff -r1.50 -r1.51 src/usr.bin/xlint/lint1/decl.c

cvs diff -r1.50 -r1.51 src/usr.bin/xlint/lint1/decl.c (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/decl.c 2009/10/02 21:04:03 1.50
+++ src/usr.bin/xlint/lint1/decl.c 2009/10/02 21:49:30 1.51
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: decl.c,v 1.50 2009/10/02 21:04:03 christos Exp $ */ 1/* $NetBSD: decl.c,v 1.51 2009/10/02 21:49:30 christos Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. 4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
5 * Copyright (c) 1994, 1995 Jochen Pohl 5 * Copyright (c) 1994, 1995 Jochen Pohl
6 * All Rights Reserved. 6 * All Rights Reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -28,27 +28,27 @@ @@ -28,27 +28,27 @@
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */ 33 */
34 34
35#if HAVE_NBTOOL_CONFIG_H 35#if HAVE_NBTOOL_CONFIG_H
36#include "nbtool_config.h" 36#include "nbtool_config.h"
37#endif 37#endif
38 38
39#include <sys/cdefs.h> 39#include <sys/cdefs.h>
40#if defined(__RCSID) && !defined(lint) 40#if defined(__RCSID) && !defined(lint)
41__RCSID("$NetBSD: decl.c,v 1.50 2009/10/02 21:04:03 christos Exp $"); 41__RCSID("$NetBSD: decl.c,v 1.51 2009/10/02 21:49:30 christos Exp $");
42#endif 42#endif
43 43
44#include <sys/param.h> 44#include <sys/param.h>
45#include <limits.h> 45#include <limits.h>
46#include <stdlib.h> 46#include <stdlib.h>
47#include <string.h> 47#include <string.h>
48 48
49#include "lint1.h" 49#include "lint1.h"
50 50
51const char *unnamed = "<unnamed>"; 51const char *unnamed = "<unnamed>";
52 52
53/* shared type structures for arithmtic types and void */ 53/* shared type structures for arithmtic types and void */
54static type_t *typetab; 54static type_t *typetab;
@@ -485,39 +485,46 @@ settdsym(type_t *tp, sym_t *sym) @@ -485,39 +485,46 @@ settdsym(type_t *tp, sym_t *sym)
485 tp->t_enum->etdef = sym; 485 tp->t_enum->etdef = sym;
486 } 486 }
487} 487}
488 488
489static void 489static void
490setpackedsize(type_t *tp) 490setpackedsize(type_t *tp)
491{ 491{
492 str_t *sp; 492 str_t *sp;
493 sym_t *mem; 493 sym_t *mem;
494 char buf[256]; 494 char buf[256];
495 495
496 switch (tp->t_tspec) { 496 switch (tp->t_tspec) {
497 case STRUCT: 497 case STRUCT:
498 sp = tp->t_str; 
499 sp->size = 0; 
500 for (mem = sp->memb; mem != NULL; mem = mem->s_nxt) { 
501 size_t x = (size_t)tsize(mem->s_type); 
502 sp->size += x; 
503 } 
504 break; 
505 case UNION: 498 case UNION:
506 sp = tp->t_str; 499 sp = tp->t_str;
507 sp->size = 0; 500 sp->size = 0;
508 for (mem = sp->memb; mem != NULL; mem = mem->s_nxt) { 501 for (mem = sp->memb; mem != NULL; mem = mem->s_nxt) {
 502 if (mem->s_type->t_isfield) {
 503 size_t len = mem->s_type->t_flen;
 504 while (mem && mem->s_type->t_isfield) {
 505 len += mem->s_type->t_flen;
 506 mem = mem->s_nxt;
 507 }
 508 len = ((len + INT_SIZE - 1) /
 509 INT_SIZE) * INT_SIZE;
 510 sp->size += len;
 511 if (mem == NULL)
 512 break;
 513 }
509 size_t x = (size_t)tsize(mem->s_type); 514 size_t x = (size_t)tsize(mem->s_type);
510 if (x > sp->size) 515 if (tp->t_tspec == STRUCT)
 516 sp->size += x;
 517 else if (x > sp->size)
511 sp->size = x; 518 sp->size = x;
512 } 519 }
513 break; 520 break;
514 default: 521 default:
515 warning(326, "packed", tyname(buf, sizeof(buf), tp)); 522 warning(326, "packed", tyname(buf, sizeof(buf), tp));
516 break; 523 break;
517 } 524 }
518} 525}
519 526
520void 527void
521addpacked(void) 528addpacked(void)
522{ 529{
523 if (dcs->d_type == NULL) 530 if (dcs->d_type == NULL)