Module Name:    src
Committed By:   christos
Date:           Fri Apr 18 00:23:46 UTC 2014

Modified Files:
        src/usr.bin/xlint/lint1: cgram.y externs1.h scan.l

Log Message:
Handle the rest of gcc __attribute__ s.


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.31 -r1.32 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.54 -r1.55 src/usr.bin/xlint/lint1/scan.l

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/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.60 src/usr.bin/xlint/lint1/cgram.y:1.61
--- src/usr.bin/xlint/lint1/cgram.y:1.60	Thu Apr 17 13:29:24 2014
+++ src/usr.bin/xlint/lint1/cgram.y	Thu Apr 17 20:23:46 2014
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.60 2014/04/17 17:29:24 christos Exp $ */
+/* $NetBSD: cgram.y,v 1.61 2014/04/18 00:23:46 christos Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.60 2014/04/17 17:29:24 christos Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.61 2014/04/18 00:23:46 christos Exp $");
 #endif
 
 #include <stdlib.h>
@@ -189,11 +189,17 @@ static inline void RESTORE(const char *f
 %token <y_type>		T_ATTRIBUTE
 %token <y_type>		T_AT_ALIGNED
 %token <y_type>		T_AT_DEPRECATED
+%token <y_type>		T_AT_NORETURN
 %token <y_type>		T_AT_MAY_ALIAS
 %token <y_type>		T_AT_PACKED
+%token <y_type>		T_AT_PURE
 %token <y_type>		T_AT_TUINION
 %token <y_type>		T_AT_TUNION
 %token <y_type>		T_AT_UNUSED
+%token <y_type>		T_AT_FORMAT
+%token <y_type>		T_AT_FORMAT_PRINTF
+%token <y_type>		T_AT_FORMAT_SCANF
+%token <y_type>		T_AT_FORMAT_STRFTIME
 
 
 
@@ -470,19 +476,33 @@ declaration:
 	| error T_SEMI
 	;
 
+type_attribute_format_type:
+	  T_AT_FORMAT_PRINTF
+	| T_AT_FORMAT_SCANF
+	| T_AT_FORMAT_STRFTIME
+	;
+
 type_attribute_spec:
 	  T_AT_DEPRECATED
 	| T_AT_ALIGNED T_LPARN constant T_RPARN
 	| T_AT_MAY_ALIAS
+	| T_AT_NORETURN
 	| T_AT_PACKED {
 		addpacked();
 	}
+	| T_AT_PURE
 	| T_AT_TUNION
+	| T_AT_FORMAT T_LPARN type_attribute_format_type T_COMMA
+	    constant T_COMMA constant T_RPARN
 	| T_AT_UNUSED
 	;
 
 type_attribute:
-	  T_ATTRIBUTE T_LPARN T_LPARN type_attribute_spec T_RPARN T_RPARN
+	  T_ATTRIBUTE T_LPARN T_LPARN {
+	    attron = 1;
+	} type_attribute_spec {
+	    attron = 0;
+	} T_RPARN T_RPARN
 	| T_PACKED {
 		addpacked();
 	}

Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.31 src/usr.bin/xlint/lint1/externs1.h:1.32
--- src/usr.bin/xlint/lint1/externs1.h:1.31	Fri Apr 19 13:43:05 2013
+++ src/usr.bin/xlint/lint1/externs1.h	Thu Apr 17 20:23:46 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: externs1.h,v 1.31 2013/04/19 17:43:05 christos Exp $	*/
+/*	$NetBSD: externs1.h,v 1.32 2014/04/18 00:23:46 christos Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -68,6 +68,7 @@ extern	int	yyparse(void);
 /*
  * scan.l
  */
+extern  int	attron;
 extern	pos_t	curr_pos;
 extern	pos_t	csrc_pos;
 extern	symt_t	symtyp;

Index: src/usr.bin/xlint/lint1/scan.l
diff -u src/usr.bin/xlint/lint1/scan.l:1.54 src/usr.bin/xlint/lint1/scan.l:1.55
--- src/usr.bin/xlint/lint1/scan.l:1.54	Tue Feb 18 17:01:36 2014
+++ src/usr.bin/xlint/lint1/scan.l	Thu Apr 17 20:23:46 2014
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: scan.l,v 1.54 2014/02/18 22:01:36 christos Exp $ */
+/* $NetBSD: scan.l,v 1.55 2014/04/18 00:23:46 christos Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: scan.l,v 1.54 2014/02/18 22:01:36 christos Exp $");
+__RCSID("$NetBSD: scan.l,v 1.55 2014/04/18 00:23:46 christos Exp $");
 #endif
 
 #include <stdlib.h>
@@ -60,6 +60,9 @@ pos_t	curr_pos = { 1, "", 0 };
  */
 pos_t	csrc_pos = { 1, "", 0 };
 
+/* Are we parsing a gcc attribute? */
+int attron;
+
 static	void	incline(void);
 static	void	badchar(int);
 static	sbuf_t	*allocsb(void);
@@ -193,81 +196,95 @@ static	struct	kwtab {
 	scl_t	kw_scl;		/* storage class if kw_token T_SCLASS */
 	tspec_t	kw_tspec;	/* type spec. if kw_token T_TYPE or T_SOU */
 	tqual_t	kw_tqual;	/* type qual. fi kw_token T_QUAL */
-	u_int	kw_c89;		/* c89 keyword */
-	u_int	kw_c99;		/* c99 keyword */
-	u_int	kw_gcc;		/* GCC keyword */
+	u_int	kw_c89 : 1;	/* c89 keyword */
+	u_int	kw_c99 : 1;	/* c99 keyword */
+	u_int	kw_gcc : 1;	/* GCC keyword */
+	u_int	kw_attr : 1;	/* GCC attribute, keyword */
 } kwtab[] = {
-	{ "__alignof__", T_ALIGNOF,	0,	0,	0,	  0, 0, 0 },
-	{ "__attribute__",T_ATTRIBUTE,	0,	0,	0,	  0, 0, 1 },
-	{ "attribute",	T_ATTRIBUTE,	0,	0,	0,	  0, 0, 1 },
-	{ "__packed__",	T_AT_PACKED,	0,	0,	0,	  0, 0, 1 },
-	{ "packed",	T_AT_PACKED,	0,	0,	0,	  0, 0, 1 },
-	{ "__aligned__",T_AT_ALIGNED,	0,	0,	0,	  0, 0, 1 },
-	{ "aligned",	T_AT_ALIGNED,	0,	0,	0,	  0, 0, 1 },
-	{ "__transparent_union__",T_AT_TUNION,0,0,	0,	  0, 0, 1 },
-	{ "transparent_union",T_AT_TUNION,0,	0,	0,	  0, 0, 1 },
-	{ "__unused__",	T_AT_UNUSED,	0,	0,	0,	  0, 0, 1 },
-	{ "unused",	T_AT_UNUSED,	0,	0,	0,	  0, 0, 1 },
-	{ "__deprecated__",T_AT_DEPRECATED,0,	0,	0,	  0, 0, 1 },
-	{ "deprecated",	T_AT_DEPRECATED,0,	0,	0,	  0, 0, 1 },
-	{ "__may_alias__",T_AT_MAY_ALIAS,0,	0,	0,	  0, 0, 1 },
-	{ "may_alias",	T_AT_MAY_ALIAS,	0,	0,	0,	  0, 0, 1 },
-	{ "asm",	T_ASM,		0,	0,	0,	  0, 0, 1 },
-	{ "__asm",	T_ASM,		0,	0,	0,	  0, 0, 0 },
-	{ "__asm__",	T_ASM,		0,	0,	0,	  0, 0, 0 },
-	{ "auto",	T_SCLASS,	AUTO,	0,	0,	  0, 0, 0 },
-	{ "break",	T_BREAK,	0,	0,	0,	  0, 0, 0 },
-	{ "_Bool",	T_TYPE,		0,	BOOL,	0,	  0, 1, 0 },
-	{ "case",	T_CASE,		0,	0,	0,	  0, 0, 0 },
-	{ "char",	T_TYPE,		0,	CHAR,	0,	  0, 0, 0 },
-	{ "const",	T_QUAL,		0,	0,	CONST,	  1, 0, 0 },
-	{ "_Complex",	T_TYPE,		0,	COMPLEX,0,	  0, 1, 0 },
-	{ "__const__",	T_QUAL,		0,	0,	CONST,	  0, 0, 0 },
-	{ "__const",	T_QUAL,		0,	0,	CONST,	  0, 0, 0 },
-	{ "continue",	T_CONTINUE,	0,	0,	0,	  0, 0, 0 },
-	{ "default",	T_DEFAULT,	0,	0,	0,	  0, 0, 0 },
-	{ "do",		T_DO,		0,	0,	0,	  0, 0, 0 },
-	{ "double",	T_TYPE,		0,	DOUBLE,	0,	  0, 0, 0 },
-	{ "else",	T_ELSE,		0,	0,	0,	  0, 0, 0 },
-	{ "enum",	T_ENUM,		0,	0,	0,	  0, 0, 0 },
-	{ "__extension__", T_EXTENSION,	0,	0,	0,	  0, 0, 1 },
-	{ "extern",	T_SCLASS,	EXTERN,	0,	0,	  0, 0, 0 },
-	{ "float",	T_TYPE,		0,	FLOAT,	0,	  0, 0, 0 },
-	{ "for",	T_FOR,		0,	0,	0,	  0, 0, 0 },
-	{ "goto",	T_GOTO,		0,	0,	0,	  0, 0, 0 },
-	{ "if",		T_IF,		0,	0,	0,	  0, 0, 0 },
-	{ "__imag__",	T_IMAG,		0,	0,	0,	  0, 1, 0 },
-	{ "inline",	T_SCLASS,	INLINE,	0,	0,	  0, 1, 0 },
-	{ "__inline__",	T_SCLASS,	INLINE,	0,	0,	  0, 0, 0 },
-	{ "__inline",	T_SCLASS,	INLINE,	0,	0,	  0, 0, 0 },
-	{ "int",	T_TYPE,		0,	INT,	0,	  0, 0, 0 },
-	{ "__symbolrename", T_SYMBOLRENAME, 0,	0,	0,	  0, 0, 0 },
-	{ "long",	T_TYPE,		0,	LONG,	0,	  0, 0, 0 },
-	{ "__real__",	T_REAL,		0,	0,	0,	  0, 1, 0 },
-	{ "register",	T_SCLASS,	REG,	0,	0,	  0, 0, 0 },
-	{ "restrict",	T_QUAL,		0,	0,	RESTRICT, 0, 1, 0 },
-	{ "return",	T_RETURN,	0,	0,	0,	  0, 0, 0 },
-	{ "__packed",	T_PACKED,	0,	0,	0,	  0, 0, 0 },
-	{ "short",	T_TYPE,		0,	SHORT,	0,	  0, 0, 0 },
-	{ "signed",	T_TYPE,		0,	SIGNED,	0,	  1, 0, 0 },
-	{ "__signed__",	T_TYPE,		0,	SIGNED,	0,	  0, 0, 0 },
-	{ "__signed",	T_TYPE,		0,	SIGNED,	0,	  0, 0, 0 },
-	{ "sizeof",	T_SIZEOF,	0,	0,	0,	  0, 0, 0 },
-	{ "static",	T_SCLASS,	STATIC,	0,	0,	  0, 0, 0 },
-	{ "struct",	T_SOU,		0,	STRUCT,	0,	  0, 0, 0 },
-	{ "switch",	T_SWITCH,	0,	0,	0,	  0, 0, 0 },
-	{ "typedef",	T_SCLASS,	TYPEDEF, 0,	0,	  0, 0, 0 },
-	{ "typeof",	T_TYPEOF,	0,	0,	0,	  0, 0, 1 },
-	{ "__typeof",	T_TYPEOF,	0,	0,	0,	  0, 0, 1 },
-	{ "__typeof__",	T_TYPEOF,	0,	0,	0,	  0, 0, 1 },
-	{ "union",	T_SOU,		0,	UNION,	0,	  0, 0, 0 },
-	{ "unsigned",	T_TYPE,		0,	UNSIGN,	0,	  0, 0, 0 },
-	{ "void",	T_TYPE,		0,	VOID,	0,	  0, 0, 0 },
-	{ "volatile",	T_QUAL,		0,	0,	VOLATILE, 1, 0, 0 },
-	{ "__volatile__", T_QUAL,	0,	0,	VOLATILE, 0, 0, 0 },
-	{ "__volatile",	T_QUAL,		0,	0,	VOLATILE, 0, 0, 0 },
-	{ "while",	T_WHILE,	0,	0,	0,	  0, 0, 0 },
-	{ NULL,		0,		0,	0,	0,	  0, 0, 0 }
+	{ "__alignof__", T_ALIGNOF,	0,	0,	0,	  0, 0, 0, 0 },
+	{ "__attribute__",T_ATTRIBUTE,	0,	0,	0,	  0, 0, 1, 0 },
+	{ "attribute",	T_ATTRIBUTE,	0,	0,	0,	  0, 0, 1, 0 },
+	{ "__packed__",	T_AT_PACKED,	0,	0,	0,	  0, 0, 1, 1 },
+	{ "packed",	T_AT_PACKED,	0,	0,	0,	  0, 0, 1, 1 },
+	{ "__aligned__",T_AT_ALIGNED,	0,	0,	0,	  0, 0, 1, 1 },
+	{ "aligned",	T_AT_ALIGNED,	0,	0,	0,	  0, 0, 1, 1 },
+	{ "__transparent_union__",T_AT_TUNION,0,0,	0,	  0, 0, 1, 1 },
+	{ "transparent_union",T_AT_TUNION,0,	0,	0,	  0, 0, 1, 1 },
+	{ "__unused__",	T_AT_UNUSED,	0,	0,	0,	  0, 0, 1, 1 },
+	{ "unused",	T_AT_UNUSED,	0,	0,	0,	  0, 0, 1, 1 },
+	{ "__deprecated__",T_AT_DEPRECATED,0,	0,	0,	  0, 0, 1, 1 },
+	{ "deprecated",	T_AT_DEPRECATED,0,	0,	0,	  0, 0, 1, 1 },
+	{ "__may_alias__",T_AT_MAY_ALIAS,0,	0,	0,	  0, 0, 1, 1 },
+	{ "may_alias",	T_AT_MAY_ALIAS,	0,	0,	0,	  0, 0, 1, 1 },
+	{ "format",	T_AT_FORMAT,	0,	0,	0,	  0, 0, 1, 1 },
+	{ "__format__",	T_AT_FORMAT,	0,	0,	0,	  0, 0, 1, 1 },
+	{ "printf",	T_AT_FORMAT_PRINTF,0,	0,	0,	  0, 0, 1, 1 },
+	{ "__printf__",	T_AT_FORMAT_PRINTF,0,	0,	0,	  0, 0, 1, 1 },
+	{ "scanf",	T_AT_FORMAT_SCANF,0,	0,	0,	  0, 0, 1, 1 },
+	{ "__scanf__",	T_AT_FORMAT_SCANF,0,	0,	0,	  0, 0, 1, 1 },
+	{ "strftime",	T_AT_FORMAT_SCANF,0,	0,	0,	  0, 0, 1, 1 },
+	{ "__strftime__",T_AT_FORMAT_STRFTIME,0,0,	0,	  0, 0, 1, 1 },
+	{ "pure",	T_AT_PURE,	0,	0,	0,	  0, 0, 1, 1 },
+	{ "__pure__",	T_AT_PURE,	0,	0,	0,	  0, 0, 1, 1 },
+	{ "noreturn",	T_AT_NORETURN,	0,	0,	0,	  0, 0, 1, 1 },
+	{ "__noreturn__",T_AT_NORETURN,	0,	0,	0,	  0, 0, 1, 1 },
+	{ "asm",	T_ASM,		0,	0,	0,	  0, 0, 1, 1 },
+	{ "__asm",	T_ASM,		0,	0,	0,	  0, 0, 0, 0 },
+	{ "__asm__",	T_ASM,		0,	0,	0,	  0, 0, 0, 0 },
+	{ "auto",	T_SCLASS,	AUTO,	0,	0,	  0, 0, 0, 0 },
+	{ "break",	T_BREAK,	0,	0,	0,	  0, 0, 0, 0 },
+	{ "_Bool",	T_TYPE,		0,	BOOL,	0,	  0, 1, 0, 0 },
+	{ "case",	T_CASE,		0,	0,	0,	  0, 0, 0, 0 },
+	{ "char",	T_TYPE,		0,	CHAR,	0,	  0, 0, 0, 0 },
+	{ "const",	T_QUAL,		0,	0,	CONST,	  1, 0, 0, 0 },
+	{ "_Complex",	T_TYPE,		0,	COMPLEX,0,	  0, 1, 0, 0 },
+	{ "__const__",	T_QUAL,		0,	0,	CONST,	  0, 0, 0, 0 },
+	{ "__const",	T_QUAL,		0,	0,	CONST,	  0, 0, 0, 0 },
+	{ "continue",	T_CONTINUE,	0,	0,	0,	  0, 0, 0, 0 },
+	{ "default",	T_DEFAULT,	0,	0,	0,	  0, 0, 0, 0 },
+	{ "do",		T_DO,		0,	0,	0,	  0, 0, 0, 0 },
+	{ "double",	T_TYPE,		0,	DOUBLE,	0,	  0, 0, 0, 0 },
+	{ "else",	T_ELSE,		0,	0,	0,	  0, 0, 0, 0 },
+	{ "enum",	T_ENUM,		0,	0,	0,	  0, 0, 0, 0 },
+	{ "__extension__", T_EXTENSION,	0,	0,	0,	  0, 0, 1, 0 },
+	{ "extern",	T_SCLASS,	EXTERN,	0,	0,	  0, 0, 0, 0 },
+	{ "float",	T_TYPE,		0,	FLOAT,	0,	  0, 0, 0, 0 },
+	{ "for",	T_FOR,		0,	0,	0,	  0, 0, 0, 0 },
+	{ "goto",	T_GOTO,		0,	0,	0,	  0, 0, 0, 0 },
+	{ "if",		T_IF,		0,	0,	0,	  0, 0, 0, 0 },
+	{ "__imag__",	T_IMAG,		0,	0,	0,	  0, 1, 0, 0 },
+	{ "inline",	T_SCLASS,	INLINE,	0,	0,	  0, 1, 0, 0 },
+	{ "__inline__",	T_SCLASS,	INLINE,	0,	0,	  0, 0, 0, 0 },
+	{ "__inline",	T_SCLASS,	INLINE,	0,	0,	  0, 0, 0, 0 },
+	{ "int",	T_TYPE,		0,	INT,	0,	  0, 0, 0, 0 },
+	{ "__symbolrename", T_SYMBOLRENAME, 0,	0,	0,	  0, 0, 0, 0 },
+	{ "long",	T_TYPE,		0,	LONG,	0,	  0, 0, 0, 0 },
+	{ "__real__",	T_REAL,		0,	0,	0,	  0, 1, 0, 0 },
+	{ "register",	T_SCLASS,	REG,	0,	0,	  0, 0, 0, 0 },
+	{ "__restrict__",T_QUAL,	0,	0,	RESTRICT, 0, 1, 0, 0 },
+	{ "restrict",	T_QUAL,		0,	0,	RESTRICT, 0, 1, 0, 0 },
+	{ "return",	T_RETURN,	0,	0,	0,	  0, 0, 0, 0 },
+	{ "__packed",	T_PACKED,	0,	0,	0,	  0, 0, 0, 0 },
+	{ "short",	T_TYPE,		0,	SHORT,	0,	  0, 0, 0, 0 },
+	{ "signed",	T_TYPE,		0,	SIGNED,	0,	  1, 0, 0, 0 },
+	{ "__signed__",	T_TYPE,		0,	SIGNED,	0,	  0, 0, 0, 0 },
+	{ "__signed",	T_TYPE,		0,	SIGNED,	0,	  0, 0, 0, 0 },
+	{ "sizeof",	T_SIZEOF,	0,	0,	0,	  0, 0, 0, 0 },
+	{ "static",	T_SCLASS,	STATIC,	0,	0,	  0, 0, 0, 0 },
+	{ "struct",	T_SOU,		0,	STRUCT,	0,	  0, 0, 0, 0 },
+	{ "switch",	T_SWITCH,	0,	0,	0,	  0, 0, 0, 0 },
+	{ "typedef",	T_SCLASS,	TYPEDEF, 0,	0,	  0, 0, 0, 0 },
+	{ "typeof",	T_TYPEOF,	0,	0,	0,	  0, 0, 1, 0 },
+	{ "__typeof",	T_TYPEOF,	0,	0,	0,	  0, 0, 1, 0 },
+	{ "__typeof__",	T_TYPEOF,	0,	0,	0,	  0, 0, 1, 0 },
+	{ "union",	T_SOU,		0,	UNION,	0,	  0, 0, 0, 0 },
+	{ "unsigned",	T_TYPE,		0,	UNSIGN,	0,	  0, 0, 0, 0 },
+	{ "void",	T_TYPE,		0,	VOID,	0,	  0, 0, 0, 0 },
+	{ "volatile",	T_QUAL,		0,	0,	VOLATILE, 1, 0, 0, 0 },
+	{ "__volatile__", T_QUAL,	0,	0,	VOLATILE, 0, 0, 0, 0 },
+	{ "__volatile",	T_QUAL,		0,	0,	VOLATILE, 0, 0, 0, 0 },
+	{ "while",	T_WHILE,	0,	0,	0,	  0, 0, 0, 0 },
+	{ NULL,		0,		0,	0,	0,	  0, 0, 0, 0 }
 };
 
 /* Symbol table */
@@ -310,7 +327,7 @@ initscan(void)
 			continue;
 		sym = getblk(sizeof (sym_t));
 		sym->s_name = kw->kw_name;
-		sym->s_keyw = 1;
+		sym->s_keyw = kw;
 		sym->s_value.v_quad = kw->kw_token;
 		if (kw->kw_token == T_TYPE || kw->kw_token == T_SOU) {
 			sym->s_tspec = kw->kw_tspec;
@@ -347,10 +364,15 @@ allocsb(void)
 
 	if ((sb = sbfrlst) != NULL) {
 		sbfrlst = sb->sb_nxt;
+#ifdef BLKDEBUG
+		(void)memset(sb, 0, sizeof (*sb));
+#else
+		sb->sb_nxt = NULL;
+#endif
 	} else {
 		sb = xmalloc(sizeof (sbuf_t));
+		(void)memset(sb, 0, sizeof (*sb));
 	}
-	(void)memset(sb, 0, sizeof (*sb));
 	return (sb);
 }
 
@@ -361,6 +383,7 @@ static void
 freesb(sbuf_t *sb)
 {
 
+	(void)memset(sb, ZERO, sizeof (*sb));
 	sb->sb_nxt = sbfrlst;
 	sbfrlst = sb;
 }
@@ -421,8 +444,11 @@ name(void)
 	sb->sb_len = yyleng;
 	sb->sb_hash = hash(yytext);
 	if ((sym = search(sb)) != NULL && sym->s_keyw) {
-		freesb(sb);
-		return (keyw(sym));
+		struct kwtab *kw = sym->s_keyw;
+		if (!kw->kw_attr || attron) {
+			freesb(sb);
+			return (keyw(sym));
+		}
 	}
 
 	sb->sb_sym = sym;

Reply via email to