Module Name:    src
Committed By:   rillig
Date:           Sat Apr  2 22:15:57 UTC 2022

Modified Files:
        src/usr.bin/xlint/lint1: decl.c lint1.h mem1.c

Log Message:
lint: use appropriate alignment on both the host and target platform


To generate a diff of this commit:
cvs rdiff -u -r1.265 -r1.266 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.143 -r1.144 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.61 -r1.62 src/usr.bin/xlint/lint1/mem1.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.265 src/usr.bin/xlint/lint1/decl.c:1.266
--- src/usr.bin/xlint/lint1/decl.c:1.265	Sat Apr  2 21:47:04 2022
+++ src/usr.bin/xlint/lint1/decl.c	Sat Apr  2 22:15:57 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.265 2022/04/02 21:47:04 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.266 2022/04/02 22:15:57 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.265 2022/04/02 21:47:04 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.266 2022/04/02 22:15:57 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -885,6 +885,9 @@ alignment_in_bits(const type_t *tp)
 	unsigned int a;
 	tspec_t t;
 
+	/* Super conservative so that it works for most systems. */
+	unsigned int worst_align_in_bits = 2 * LONG_SIZE;
+
 	while (tp->t_tspec == ARRAY)
 		tp = tp->t_subt;
 
@@ -894,12 +897,12 @@ alignment_in_bits(const type_t *tp)
 		lint_assert(t != FUNC);
 		if ((a = size_in_bits(t)) == 0) {
 			a = CHAR_SIZE;
-		} else if (a > WORST_ALIGN(1) * CHAR_SIZE) {
-			a = WORST_ALIGN(1) * CHAR_SIZE;
+		} else if (a > worst_align_in_bits) {
+			a = worst_align_in_bits;
 		}
 	}
 	lint_assert(a >= CHAR_SIZE);
-	lint_assert(a <= WORST_ALIGN(1) * CHAR_SIZE);
+	lint_assert(a <= worst_align_in_bits);
 	return a;
 }
 

Index: src/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.143 src/usr.bin/xlint/lint1/lint1.h:1.144
--- src/usr.bin/xlint/lint1/lint1.h:1.143	Sat Apr  2 14:28:30 2022
+++ src/usr.bin/xlint/lint1/lint1.h	Sat Apr  2 22:15:57 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.143 2022/04/02 14:28:30 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.144 2022/04/02 22:15:57 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -36,21 +36,6 @@
 #include "err-msgs.h"
 #include "op.h"
 
-/*
- * XXX - Super conservative so that works for most systems, but we should
- * not depend on the host settings but the target settings in determining
- * the alignment. The only valid use for this is in mem1.c; uses in decl.c
- * are bogus.
- */
-#ifndef WORST_ALIGN
-#ifdef _LP64
-# define AVAL	15
-#else
-# define AVAL	7
-#endif
-#define WORST_ALIGN(x) (((x) + AVAL) & ~AVAL)
-#endif
-
 #define LWARN_BAD	(-3)
 #define LWARN_ALL	(-2)
 #define LWARN_NONE	(-1)

Index: src/usr.bin/xlint/lint1/mem1.c
diff -u src/usr.bin/xlint/lint1/mem1.c:1.61 src/usr.bin/xlint/lint1/mem1.c:1.62
--- src/usr.bin/xlint/lint1/mem1.c:1.61	Sun Feb 27 17:12:06 2022
+++ src/usr.bin/xlint/lint1/mem1.c	Sat Apr  2 22:15:57 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: mem1.c,v 1.61 2022/02/27 17:12:06 rillig Exp $	*/
+/*	$NetBSD: mem1.c,v 1.62 2022/04/02 22:15:57 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: mem1.c,v 1.61 2022/02/27 17:12:06 rillig Exp $");
+__RCSID("$NetBSD: mem1.c,v 1.62 2022/04/02 22:15:57 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -190,7 +190,8 @@ xgetblk(memory_block **mbp, size_t s)
 	memory_block	*mb;
 	void	*p;
 
-	s = WORST_ALIGN(s);
+	size_t worst_align = 2 * sizeof(long) - 1;
+	s = (s + worst_align) & ~worst_align;
 
 	if ((mb = *mbp) == NULL || mb->nfree < s) {
 		size_t block_size = s > mblk_size ? s : mblk_size;

Reply via email to