Module Name:    src
Committed By:   rillig
Date:           Thu Feb 20 20:33:10 UTC 2025

Modified Files:
        src/tests/usr.bin/xlint/lint1: msg_267.c
        src/usr.bin/xlint/lint1: cgram.y debug.c lint1.h

Log Message:
lint: support __attribute__((__mode__(TI)))

This fixes the wrong lint warnings about the shift amount being greater
than the type size in compiler_rt/popcountti2.c.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/msg_267.c
cvs rdiff -u -r1.517 -r1.518 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.82 -r1.83 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.232 -r1.233 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/tests/usr.bin/xlint/lint1/msg_267.c
diff -u src/tests/usr.bin/xlint/lint1/msg_267.c:1.8 src/tests/usr.bin/xlint/lint1/msg_267.c:1.9
--- src/tests/usr.bin/xlint/lint1/msg_267.c:1.8	Tue Mar 12 07:56:08 2024
+++ src/tests/usr.bin/xlint/lint1/msg_267.c	Thu Feb 20 20:33:10 2025
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_267.c,v 1.8 2024/03/12 07:56:08 rillig Exp $	*/
+/*	$NetBSD: msg_267.c,v 1.9 2025/02/20 20:33:10 rillig Exp $	*/
 # 3 "msg_267.c"
 
 // Test for message: shift amount %u equals bit-size of '%s' [267]
@@ -20,15 +20,11 @@ shl32(unsigned int x)
 }
 
 /*
- * As of 2022-08-19, lint ignores the GCC-specific 'mode' attribute, treating
- * the tetra-int as a plain single-int, thus having width 32.
- *
  * https://gcc.gnu.org/onlinedocs/gccint/Machine-Modes.html
  */
 unsigned
 function(unsigned __attribute__((mode(TI))) arg)
 {
-	/* expect+1: warning: shift amount 32 equals bit-size of 'unsigned int' [267] */
 	return (arg >> 32) & 3;
 }
 

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.517 src/usr.bin/xlint/lint1/cgram.y:1.518
--- src/usr.bin/xlint/lint1/cgram.y:1.517	Fri Jan  3 03:14:47 2025
+++ src/usr.bin/xlint/lint1/cgram.y	Thu Feb 20 20:33:10 2025
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.517 2025/01/03 03:14:47 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.518 2025/02/20 20:33:10 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: cgram.y,v 1.517 2025/01/03 03:14:47 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.518 2025/02/20 20:33:10 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -1033,6 +1033,18 @@ declmod:
 			dcs_set_used();
 		if ($1.noreturn)
 			dcs->d_noreturn = true;
+		if ($1.bit_width == 128) {
+#ifdef INT128_SIZE
+			dcs->d_abstract_type = dcs->d_sign_mod == UNSIGN
+			    ? UINT128 : INT128;
+			dcs->d_sign_mod = NO_TSPEC;
+#else
+			/* Get as close as possible. */
+			dcs->d_rank_mod = LLONG;
+#endif
+		}
+		if ($1.bit_width == 64)
+			dcs->d_rank_mod = LLONG;
 	}
 ;
 
@@ -2550,6 +2562,15 @@ gcc_attribute:
 		    && $3->args_len == 1)
 			dcs_add_alignas($3->args[0]);
 		$$ = (type_attributes){ .used = false };
+		if (is_either(name, "mode", "__mode__")
+		    && $3->args_len == 1
+		    && $3->args[0]->tn_op == NAME) {
+			const char *arg_name = $3->args[0]->u.sym->s_name;
+			if (strcmp(arg_name, "TI") == 0)
+				$$.bit_width = 128;
+			if (strcmp(arg_name, "DI") == 0)
+				$$.bit_width = 64;
+		}
 	}
 |	type_qualifier {
 		if (!$1.tq_const)

Index: src/usr.bin/xlint/lint1/debug.c
diff -u src/usr.bin/xlint/lint1/debug.c:1.82 src/usr.bin/xlint/lint1/debug.c:1.83
--- src/usr.bin/xlint/lint1/debug.c:1.82	Wed Nov 13 03:43:00 2024
+++ src/usr.bin/xlint/lint1/debug.c	Thu Feb 20 20:33:10 2025
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.82 2024/11/13 03:43:00 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.83 2025/02/20 20:33:10 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: debug.c,v 1.82 2024/11/13 03:43:00 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.83 2025/02/20 20:33:10 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -359,9 +359,11 @@ type_attributes_string(type_attributes a
 {
 	static char buf[32];
 
-	snprintf(buf, sizeof(buf), "%s%s",
+	snprintf(buf, sizeof(buf), "%s%s%s",
 	    attrs.used ? " used" : "",
-	    attrs.noreturn ? " noreturn" : "");
+	    attrs.noreturn ? " noreturn" : "",
+	    attrs.bit_width == 128 ? " 128bit" :
+	    attrs.bit_width == 64 ? " 64bit" : "");
 	return buf[0] != '\0' ? buf + 1 : "none";
 }
 

Index: src/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.232 src/usr.bin/xlint/lint1/lint1.h:1.233
--- src/usr.bin/xlint/lint1/lint1.h:1.232	Fri Jan  3 03:14:47 2025
+++ src/usr.bin/xlint/lint1/lint1.h	Thu Feb 20 20:33:10 2025
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.232 2025/01/03 03:14:47 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.233 2025/02/20 20:33:10 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -81,6 +81,7 @@ typedef struct {
 typedef struct {
 	bool used;
 	bool noreturn;
+	unsigned bit_width;
 } type_attributes;
 
 /* A bool, integer or floating-point value. */

Reply via email to