Module Name:    src
Committed By:   rillig
Date:           Thu Aug 29 20:35:19 UTC 2024

Modified Files:
        src/tests/usr.bin/xlint/lint1: gcc.c
        src/usr.bin/xlint/common: inittyp.c lint.h
        src/usr.bin/xlint/lint1: cgram.y emit1.c init.c lex.c
        src/usr.bin/xlint/lint2: emit2.c

Log Message:
lint: support GCC's __auto_type

Fixes PR toolchain/58654.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/gcc.c
cvs rdiff -u -r1.42 -r1.43 src/usr.bin/xlint/common/inittyp.c
cvs rdiff -u -r1.50 -r1.51 src/usr.bin/xlint/common/lint.h
cvs rdiff -u -r1.506 -r1.507 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.95 -r1.96 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.269 -r1.270 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.228 -r1.229 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.39 -r1.40 src/usr.bin/xlint/lint2/emit2.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/gcc.c
diff -u src/tests/usr.bin/xlint/lint1/gcc.c:1.3 src/tests/usr.bin/xlint/lint1/gcc.c:1.4
--- src/tests/usr.bin/xlint/lint1/gcc.c:1.3	Sat Jun  8 13:50:47 2024
+++ src/tests/usr.bin/xlint/lint1/gcc.c	Thu Aug 29 20:35:19 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: gcc.c,v 1.3 2024/06/08 13:50:47 rillig Exp $	*/
+/*	$NetBSD: gcc.c,v 1.4 2024/08/29 20:35:19 rillig Exp $	*/
 # 3 "gcc.c"
 
 /*
@@ -92,3 +92,10 @@ typeof_after_statement(void **ptr)
 		ret;
 	});
 }
+
+const char *
+auto_type(const char *ptr)
+{
+	__auto_type pp = &ptr;
+	return *pp;
+}

Index: src/usr.bin/xlint/common/inittyp.c
diff -u src/usr.bin/xlint/common/inittyp.c:1.42 src/usr.bin/xlint/common/inittyp.c:1.43
--- src/usr.bin/xlint/common/inittyp.c:1.42	Sat Jan 20 10:25:57 2024
+++ src/usr.bin/xlint/common/inittyp.c	Thu Aug 29 20:35:18 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: inittyp.c,v 1.42 2024/01/20 10:25:57 rillig Exp $	*/
+/*	$NetBSD: inittyp.c,v 1.43 2024/08/29 20:35:18 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: inittyp.c,v 1.42 2024/01/20 10:25:57 rillig Exp $");
+__RCSID("$NetBSD: inittyp.c,v 1.43 2024/08/29 20:35:18 rillig Exp $");
 #endif
 
 #if IS_LINT1
@@ -114,6 +114,7 @@ ttab_t ttab[NTSPEC] = {
 	typeinfo("long double _Complex", LCOMPLEX, LCOMPLEX,
 	    LDOUBLE_SIZE * 2, 3, 'c'),
 	typeinfo("void", VOID, VOID, 0, 0, ' '),
+	typeinfo("auto", AUTO_TYPE, AUTO_TYPE, 0, 0, ' '),
 	typeinfo("struct", STRUCT, STRUCT, 0, 0, ' '),
 	typeinfo("union", UNION, UNION, 0, 0, ' '),
 	// Will become more complicated in C23, which allows to choose the

Index: src/usr.bin/xlint/common/lint.h
diff -u src/usr.bin/xlint/common/lint.h:1.50 src/usr.bin/xlint/common/lint.h:1.51
--- src/usr.bin/xlint/common/lint.h:1.50	Sun May 12 18:49:35 2024
+++ src/usr.bin/xlint/common/lint.h	Thu Aug 29 20:35:18 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: lint.h,v 1.50 2024/05/12 18:49:35 rillig Exp $	*/
+/*	$NetBSD: lint.h,v 1.51 2024/08/29 20:35:18 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -87,6 +87,7 @@ typedef enum {
 	DCOMPLEX,	/* double _Complex */
 	LCOMPLEX,	/* long double _Complex */
 	VOID,		/* void */
+	AUTO_TYPE,	/* GCC's __auto_type */
 	STRUCT,		/* structure tag */
 	UNION,		/* union tag */
 	ENUM,		/* enum tag */

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.506 src/usr.bin/xlint/lint1/cgram.y:1.507
--- src/usr.bin/xlint/lint1/cgram.y:1.506	Mon Jun 17 22:11:09 2024
+++ src/usr.bin/xlint/lint1/cgram.y	Thu Aug 29 20:35:19 2024
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.506 2024/06/17 22:11:09 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.507 2024/08/29 20:35:19 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.506 2024/06/17 22:11:09 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.507 2024/08/29 20:35:19 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -1113,7 +1113,8 @@ type_init_declarator:
 		begin_initialization($1);
 		cgram_declare($1, true, $2);
 	} T_ASSIGN initializer {
-		check_size($1);
+		if ($1->s_type->t_tspec != AUTO_TYPE)
+			check_size($1);
 		end_initialization();
 	}
 ;

Index: src/usr.bin/xlint/lint1/emit1.c
diff -u src/usr.bin/xlint/lint1/emit1.c:1.95 src/usr.bin/xlint/lint1/emit1.c:1.96
--- src/usr.bin/xlint/lint1/emit1.c:1.95	Sun May 12 18:49:36 2024
+++ src/usr.bin/xlint/lint1/emit1.c	Thu Aug 29 20:35:19 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: emit1.c,v 1.95 2024/05/12 18:49:36 rillig Exp $ */
+/* $NetBSD: emit1.c,v 1.96 2024/08/29 20:35:19 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: emit1.c,v 1.95 2024/05/12 18:49:36 rillig Exp $");
+__RCSID("$NetBSD: emit1.c,v 1.96 2024/08/29 20:35:19 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -91,11 +91,11 @@ outtype(const type_t *tp)
 {
 	/* Available letters: ------GH--K-MNO--R--U-W-YZ */
 #ifdef INT128_SIZE
-	static const char tt[NTSPEC] = "???BCCCSSIILLQQJJDDD?XXXVTTTPAF";
-	static const char ss[NTSPEC] = "???  su u u u u us l?s l sue   ";
+	static const char tt[NTSPEC] = "???BCCCSSIILLQQJJDDD?XXXV?TTTPAF";
+	static const char ss[NTSPEC] = "???  su u u u u us l?s l ?sue   ";
 #else
-	static const char tt[NTSPEC] = "???BCCCSSIILLQQDDD?XXXVTTTPAF";
-	static const char ss[NTSPEC] = "???  su u u u us l?s l sue   ";
+	static const char tt[NTSPEC] = "???BCCCSSIILLQQDDD?XXXV?TTTPAF";
+	static const char ss[NTSPEC] = "???  su u u u us l?s l ?sue   ";
 #endif
 	int na;
 	tspec_t ts;

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.269 src/usr.bin/xlint/lint1/init.c:1.270
--- src/usr.bin/xlint/lint1/init.c:1.269	Thu May  9 20:53:13 2024
+++ src/usr.bin/xlint/lint1/init.c	Thu Aug 29 20:35:19 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.269 2024/05/09 20:53:13 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.270 2024/08/29 20:35:19 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: init.c,v 1.269 2024/05/09 20:53:13 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.270 2024/08/29 20:35:19 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -892,6 +892,8 @@ initialization_expr(initialization *in, 
 		in->in_err = true;
 		goto done;
 	}
+	if (in->in_sym->s_type->t_tspec == AUTO_TYPE)
+		in->in_sym->s_type = block_dup_type(tn->tn_type);
 	if (initialization_expr_using_op(in, tn))
 		goto done;
 	if (initialization_init_array_from_string(in, tn))

Index: src/usr.bin/xlint/lint1/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.228 src/usr.bin/xlint/lint1/lex.c:1.229
--- src/usr.bin/xlint/lint1/lex.c:1.228	Sun May 12 18:49:36 2024
+++ src/usr.bin/xlint/lint1/lex.c	Thu Aug 29 20:35:19 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.228 2024/05/12 18:49:36 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.229 2024/08/29 20:35:19 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: lex.c,v 1.228 2024/05/12 18:49:36 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.229 2024/08/29 20:35:19 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -133,6 +133,7 @@ static const struct keyword {
 	kwdef_token(	"alignof",	T_ALIGNOF,		78,0,6),
 	kwdef_token(	"asm",		T_ASM,			78,1,7),
 	kwdef_token(	"_Atomic",	T_ATOMIC,		11,0,1),
+	kwdef("__auto_type", T_TYPE, .u.kw_tspec = AUTO_TYPE,	99,1,1),
 	kwdef_token(	"attribute",	T_ATTRIBUTE,		78,1,6),
 	kwdef_sclass(	"auto",		AUTO,			78,0,1),
 	kwdef_type(	"_Bool",	BOOL,			99),

Index: src/usr.bin/xlint/lint2/emit2.c
diff -u src/usr.bin/xlint/lint2/emit2.c:1.39 src/usr.bin/xlint/lint2/emit2.c:1.40
--- src/usr.bin/xlint/lint2/emit2.c:1.39	Sun May 12 18:49:36 2024
+++ src/usr.bin/xlint/lint2/emit2.c	Thu Aug 29 20:35:19 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: emit2.c,v 1.39 2024/05/12 18:49:36 rillig Exp $ */
+/* $NetBSD: emit2.c,v 1.40 2024/08/29 20:35:19 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -34,7 +34,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: emit2.c,v 1.39 2024/05/12 18:49:36 rillig Exp $");
+__RCSID("$NetBSD: emit2.c,v 1.40 2024/08/29 20:35:19 rillig Exp $");
 #endif
 
 #include "lint2.h"
@@ -49,11 +49,11 @@ static void
 outtype(type_t *tp)
 {
 #ifdef INT128_SIZE
-	static const char tt[NTSPEC] = "???BCCCSSIILLQQJJDDD?XXXVTTTPAF";
-	static const char ss[NTSPEC] = "???  su u u u u us l?s l sue   ";
+	static const char tt[NTSPEC] = "???BCCCSSIILLQQJJDDD?XXXV?TTTPAF";
+	static const char ss[NTSPEC] = "???  su u u u u us l?s l ?sue   ";
 #else
-	static const char tt[NTSPEC] = "???BCCCSSIILLQQDDD?XXXVTTTPAF";
-	static const char ss[NTSPEC] = "???  su u u u us l?s l sue   ";
+	static const char tt[NTSPEC] = "???BCCCSSIILLQQDDD?XXXV?TTTPAF";
+	static const char ss[NTSPEC] = "???  su u u u us l?s l ?sue   ";
 #endif
 
 	while (tp != NULL) {

Reply via email to