Module Name: src
Committed By: rillig
Date: Sat Jul 31 19:52:44 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: op_shl_lp64.c op_shl_lp64.exp
src/usr.bin/xlint/lint1: decl.c emit1.c lint1.h
src/usr.bin/xlint/lint2: read.c
Log Message:
lint: improve support for __int128_t and __uint128_t
For the .ln files, I chose the letter 'J' to represent the 128-bit
integer types since it is close to 'I' for int. The naming of 'L' for
'long' is obvious, but 'Q' for 64-bit integers is a quad-16-bit word,
which is an unusual measurement unit nowadays. One benefit of choosing
'J' is that the next letter, 'K' can then be used for 256-bit integer
types.
Support for 128-bit integer types is still very basic. Plus, it is only
supported on LP64 platforms, which means that lint cannot be
cross-compiled to check for an LP64 platform while running on an ILP32
platform.
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/op_shl_lp64.c \
src/tests/usr.bin/xlint/lint1/op_shl_lp64.exp
cvs rdiff -u -r1.214 -r1.215 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.46 -r1.47 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.119 -r1.120 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.45 -r1.46 src/usr.bin/xlint/lint2/read.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/usr.bin/xlint/lint1/op_shl_lp64.c
diff -u src/tests/usr.bin/xlint/lint1/op_shl_lp64.c:1.1 src/tests/usr.bin/xlint/lint1/op_shl_lp64.c:1.2
--- src/tests/usr.bin/xlint/lint1/op_shl_lp64.c:1.1 Sun Jul 4 20:22:31 2021
+++ src/tests/usr.bin/xlint/lint1/op_shl_lp64.c Sat Jul 31 19:52:44 2021
@@ -1,18 +1,25 @@
-/* $NetBSD: op_shl_lp64.c,v 1.1 2021/07/04 20:22:31 rillig Exp $ */
+/* $NetBSD: op_shl_lp64.c,v 1.2 2021/07/31 19:52:44 rillig Exp $ */
# 3 "op_shl_lp64.c"
/*
- * Test overflow on shl of 128-bit integers, as seen in
- * ecp_nistp256.c(296).
+ * Before decl.c 1.215 from 2021-07-31, lint wrongly treated __uint128_t and
+ * __int128_t as being equivalent to a missing type specifier, thereby
+ * defaulting to int. This led to warnings like:
+ *
+ * shift amount 105 is greater than bit-size 32 of 'int' [122]
+ *
+ * These warnings had been discovered in ecp_nistp256.c(296).
*/
/* lint1-only-if lp64 */
const __uint128_t zero105 =
- /* FIXME: 105 is ok for __uint128_t */
- /* expect+1: warning: shift amount 105 is greater than bit-size 32 of 'int' [122] */
(((__uint128_t)1) << 105)
- /* FIXME: 41 is ok for __uint128_t */
- /* expect+1: warning: shift amount 41 is greater than bit-size 32 of 'int' [122] */
- (((__uint128_t)1) << 41)
- (((__uint128_t)1) << 9);
+
+const __uint128_t shl_128_129 =
+ /* expect+1: warning: shift equal to size of object [267] */
+ (((__uint128_t)1) << 128)
+ /* expect+1: warning: shift amount 129 is greater than bit-size 128 of '__uint128_t' [122] */
+ - (((__uint128_t)1) << 129);
Index: src/tests/usr.bin/xlint/lint1/op_shl_lp64.exp
diff -u src/tests/usr.bin/xlint/lint1/op_shl_lp64.exp:1.1 src/tests/usr.bin/xlint/lint1/op_shl_lp64.exp:1.2
--- src/tests/usr.bin/xlint/lint1/op_shl_lp64.exp:1.1 Sun Jul 4 20:22:31 2021
+++ src/tests/usr.bin/xlint/lint1/op_shl_lp64.exp Sat Jul 31 19:52:44 2021
@@ -1,2 +1,2 @@
-op_shl_lp64.c(14): warning: shift amount 105 is greater than bit-size 32 of 'int' [122]
-op_shl_lp64.c(17): warning: shift amount 41 is greater than bit-size 32 of 'int' [122]
+op_shl_lp64.c(23): warning: shift equal to size of object [267]
+op_shl_lp64.c(25): warning: shift amount 129 is greater than bit-size 128 of '__uint128_t' [122]
Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.214 src/usr.bin/xlint/lint1/decl.c:1.215
--- src/usr.bin/xlint/lint1/decl.c:1.214 Sat Jul 31 19:20:59 2021
+++ src/usr.bin/xlint/lint1/decl.c Sat Jul 31 19:52:44 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.214 2021/07/31 19:20:59 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.215 2021/07/31 19:52:44 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.214 2021/07/31 19:20:59 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.215 2021/07/31 19:52:44 rillig Exp $");
#endif
#include <sys/param.h>
@@ -126,8 +126,8 @@ initdecl(void)
typetab[QUAD].t_tspec = QUAD;
typetab[UQUAD].t_tspec = UQUAD;
#ifdef INT128_SIZE
- /* TODO: add __int128_t */
- /* TODO: add __uint128_t */
+ typetab[INT128].t_tspec = INT128;
+ typetab[UINT128].t_tspec = UINT128;
#endif
typetab[FLOAT].t_tspec = FLOAT;
typetab[DOUBLE].t_tspec = DOUBLE;
Index: src/usr.bin/xlint/lint1/emit1.c
diff -u src/usr.bin/xlint/lint1/emit1.c:1.46 src/usr.bin/xlint/lint1/emit1.c:1.47
--- src/usr.bin/xlint/lint1/emit1.c:1.46 Thu Jul 15 17:03:50 2021
+++ src/usr.bin/xlint/lint1/emit1.c Sat Jul 31 19:52:44 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: emit1.c,v 1.46 2021/07/15 17:03:50 rillig Exp $ */
+/* $NetBSD: emit1.c,v 1.47 2021/07/31 19:52:44 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: emit1.c,v 1.46 2021/07/15 17:03:50 rillig Exp $");
+__RCSID("$NetBSD: emit1.c,v 1.47 2021/07/31 19:52:44 rillig Exp $");
#endif
#include "lint1.h"
@@ -99,6 +99,7 @@ outtype(const type_t *tp)
while (tp != NULL) {
if ((ts = tp->t_tspec) == INT && tp->t_is_enum)
ts = ENUM;
+ /* Available letters: ----E-GH--K-MNO--R--U-W-YZ */
switch (ts) {
case BOOL: t = 'B'; s = '\0'; break;
case CHAR: t = 'C'; s = '\0'; break;
@@ -112,16 +113,20 @@ outtype(const type_t *tp)
case ULONG: t = 'L'; s = 'u'; break;
case QUAD: t = 'Q'; s = '\0'; break;
case UQUAD: t = 'Q'; s = 'u'; break;
+#ifdef INT128_SIZE
+ case INT128: t = 'J'; s = '\0'; break;
+ case UINT128: t = 'J'; s = 'u'; break;
+#endif
case FLOAT: t = 'D'; s = 's'; break;
case DOUBLE: t = 'D'; s = '\0'; break;
case LDOUBLE: t = 'D'; s = 'l'; break;
case VOID: t = 'V'; s = '\0'; break;
+ case STRUCT: t = 'T'; s = 's'; break;
+ case UNION: t = 'T'; s = 'u'; break;
+ case ENUM: t = 'T'; s = 'e'; break;
case PTR: t = 'P'; s = '\0'; break;
case ARRAY: t = 'A'; s = '\0'; break;
case FUNC: t = 'F'; s = '\0'; break;
- case ENUM: t = 'T'; s = 'e'; break;
- case STRUCT: t = 'T'; s = 's'; break;
- case UNION: t = 'T'; s = 'u'; break;
case FCOMPLEX: t = 'X'; s = 's'; break;
case DCOMPLEX: t = 'X'; s = '\0'; break;
case LCOMPLEX: t = 'X'; s = 'l'; break;
Index: src/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.119 src/usr.bin/xlint/lint1/lint1.h:1.120
--- src/usr.bin/xlint/lint1/lint1.h:1.119 Sat Jul 31 11:03:04 2021
+++ src/usr.bin/xlint/lint1/lint1.h Sat Jul 31 19:52:44 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.119 2021/07/31 11:03:04 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.120 2021/07/31 19:52:44 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -556,6 +556,13 @@ is_nonzero(const tnode_t *tn)
static inline uint64_t
bit(unsigned i)
{
+ /*
+ * TODO: Add proper support for INT128.
+ * This involves changing val_t to 128 bits.
+ */
+ if (i >= 64)
+ return 0; /* XXX: not correct for INT128 and UINT128 */
+
lint_assert(i < 64);
return (uint64_t)1 << i;
}
Index: src/usr.bin/xlint/lint2/read.c
diff -u src/usr.bin/xlint/lint2/read.c:1.45 src/usr.bin/xlint/lint2/read.c:1.46
--- src/usr.bin/xlint/lint2/read.c:1.45 Sun Apr 18 22:51:24 2021
+++ src/usr.bin/xlint/lint2/read.c Sat Jul 31 19:52:44 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: read.c,v 1.45 2021/04/18 22:51:24 rillig Exp $ */
+/* $NetBSD: read.c,v 1.46 2021/07/31 19:52:44 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: read.c,v 1.45 2021/04/18 22:51:24 rillig Exp $");
+__RCSID("$NetBSD: read.c,v 1.46 2021/07/31 19:52:44 rillig Exp $");
#endif
#include <ctype.h>
@@ -627,6 +627,11 @@ inptype(const char *cp, const char **epp
case 'Q':
tp->t_tspec = s == 'u' ? UQUAD : QUAD;
break;
+#ifdef INT128_SIZE
+ case 'J':
+ tp->t_tspec = s == 'u' ? UINT128 : INT128;
+ break;
+#endif
case 'D':
tp->t_tspec = s == 's' ? FLOAT : (s == 'l' ? LDOUBLE : DOUBLE);
break;