Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint2 lint: improve support for __int128_t and...



details:   https://anonhg.NetBSD.org/src/rev/1709819bcce0
branches:  trunk
changeset: 984932:1709819bcce0
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jul 31 19:52:44 2021 +0000

description:
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.

diffstat:

 tests/usr.bin/xlint/lint1/op_shl_lp64.c   |  21 ++++++++++++++-------
 tests/usr.bin/xlint/lint1/op_shl_lp64.exp |   4 ++--
 usr.bin/xlint/lint1/decl.c                |   8 ++++----
 usr.bin/xlint/lint1/emit1.c               |  15 ++++++++++-----
 usr.bin/xlint/lint1/lint1.h               |   9 ++++++++-
 usr.bin/xlint/lint2/read.c                |   9 +++++++--
 6 files changed, 45 insertions(+), 21 deletions(-)

diffs (176 lines):

diff -r 1d15d0129d62 -r 1709819bcce0 tests/usr.bin/xlint/lint1/op_shl_lp64.c
--- a/tests/usr.bin/xlint/lint1/op_shl_lp64.c   Sat Jul 31 19:20:59 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/op_shl_lp64.c   Sat Jul 31 19:52:44 2021 +0000
@@ -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);
diff -r 1d15d0129d62 -r 1709819bcce0 tests/usr.bin/xlint/lint1/op_shl_lp64.exp
--- a/tests/usr.bin/xlint/lint1/op_shl_lp64.exp Sat Jul 31 19:20:59 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/op_shl_lp64.exp Sat Jul 31 19:52:44 2021 +0000
@@ -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]
diff -r 1d15d0129d62 -r 1709819bcce0 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sat Jul 31 19:20:59 2021 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sat Jul 31 19:52:44 2021 +0000
@@ -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 @@
        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;
diff -r 1d15d0129d62 -r 1709819bcce0 usr.bin/xlint/lint1/emit1.c
--- a/usr.bin/xlint/lint1/emit1.c       Sat Jul 31 19:20:59 2021 +0000
+++ b/usr.bin/xlint/lint1/emit1.c       Sat Jul 31 19:52:44 2021 +0000
@@ -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 @@
        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 @@
                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;
diff -r 1d15d0129d62 -r 1709819bcce0 usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h       Sat Jul 31 19:20:59 2021 +0000
+++ b/usr.bin/xlint/lint1/lint1.h       Sat Jul 31 19:52:44 2021 +0000
@@ -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 @@
 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;
 }
diff -r 1d15d0129d62 -r 1709819bcce0 usr.bin/xlint/lint2/read.c
--- a/usr.bin/xlint/lint2/read.c        Sat Jul 31 19:20:59 2021 +0000
+++ b/usr.bin/xlint/lint2/read.c        Sat Jul 31 19:52:44 2021 +0000
@@ -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 @@
        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;



Home | Main Index | Thread Index | Old Index