Module Name:    src
Committed By:   rillig
Date:           Sun Apr 18 20:02:56 UTC 2021

Modified Files:
        src/distrib/sets/lists/tests: mi
        src/tests/usr.bin/xlint/lint1: Makefile t_integration.sh
        src/usr.bin/xlint/lint1: emit1.c
Added Files:
        src/tests/usr.bin/xlint/lint1: emit.c emit.exp emit.ln

Log Message:
lint: test emitting of symbol information in the .ln files

Even though the new test is quite large, it didn't find any bugs in the
code.  The only thing I'm unsure about is why static functions are
exported as well, since they are supposed to be local to the translation
unit.


To generate a diff of this commit:
cvs rdiff -u -r1.1042 -r1.1043 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.43 -r1.44 src/tests/usr.bin/xlint/lint1/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/emit.c \
    src/tests/usr.bin/xlint/lint1/emit.exp \
    src/tests/usr.bin/xlint/lint1/emit.ln
cvs rdiff -u -r1.42 -r1.43 src/tests/usr.bin/xlint/lint1/t_integration.sh
cvs rdiff -u -r1.43 -r1.44 src/usr.bin/xlint/lint1/emit1.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1042 src/distrib/sets/lists/tests/mi:1.1043
--- src/distrib/sets/lists/tests/mi:1.1042	Sat Apr 17 20:36:17 2021
+++ src/distrib/sets/lists/tests/mi	Sun Apr 18 20:02:56 2021
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1042 2021/04/17 20:36:17 rillig Exp $
+# $NetBSD: mi,v 1.1043 2021/04/18 20:02:56 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -6184,6 +6184,8 @@
 ./usr/tests/usr.bin/xlint/lint1/d_typefun.c			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/d_typename_as_var.c		tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/d_zero_sized_arrays.c		tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/emit.c				tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/emit.exp			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/feat_stacktrace.c		tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/feat_stacktrace.exp		tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c	tests-usr.bin-tests	compattestfile,atf

Index: src/tests/usr.bin/xlint/lint1/Makefile
diff -u src/tests/usr.bin/xlint/lint1/Makefile:1.43 src/tests/usr.bin/xlint/lint1/Makefile:1.44
--- src/tests/usr.bin/xlint/lint1/Makefile:1.43	Sat Apr 17 20:36:17 2021
+++ src/tests/usr.bin/xlint/lint1/Makefile	Sun Apr 18 20:02:56 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.43 2021/04/17 20:36:17 rillig Exp $
+# $NetBSD: Makefile,v 1.44 2021/04/18 20:02:56 rillig Exp $
 
 NOMAN=		# defined
 MAX_MESSAGE=	343		# see lint1/err.c
@@ -100,6 +100,9 @@ FILES+=		d_type_question_colon.c
 FILES+=		d_typefun.c
 FILES+=		d_typename_as_var.c
 FILES+=		d_zero_sized_arrays.c
+FILES+=		emit.c
+FILES+=		emit.exp
+FILES+=		emit.ln
 FILES+=		feat_stacktrace.c
 FILES+=		feat_stacktrace.exp
 FILES+=		gcc_init_compound_literal.c

Index: src/tests/usr.bin/xlint/lint1/t_integration.sh
diff -u src/tests/usr.bin/xlint/lint1/t_integration.sh:1.42 src/tests/usr.bin/xlint/lint1/t_integration.sh:1.43
--- src/tests/usr.bin/xlint/lint1/t_integration.sh:1.42	Sat Apr 17 20:36:17 2021
+++ src/tests/usr.bin/xlint/lint1/t_integration.sh	Sun Apr 18 20:02:56 2021
@@ -1,4 +1,4 @@
-# $NetBSD: t_integration.sh,v 1.42 2021/04/17 20:36:17 rillig Exp $
+# $NetBSD: t_integration.sh,v 1.43 2021/04/18 20:02:56 rillig Exp $
 #
 # Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -57,16 +57,27 @@ check_lint1()
 {
 	local src="$(atf_get_srcdir)/$1"
 	local exp="${src%.c}.exp"
+	local src_ln="${src%.c}.ln"
+	local wrk_ln="${1%.c}.ln"
 	local flags="$(extract_flags "${src}")"
 
+	if [ ! -f "${src_ln}" ]; then
+		src_ln="/dev/null"
+		wrk_ln="/dev/null"
+	fi
+
 	if [ -f "${exp}" ]; then
 		# shellcheck disable=SC2086
 		atf_check -s not-exit:0 -o "file:${exp}" -e empty \
-		    ${LINT1} ${flags} "${src}" /dev/null
+		    ${LINT1} ${flags} "${src}" "${wrk_ln}"
 	else
 		# shellcheck disable=SC2086
 		atf_check -s exit:0 \
-		    ${LINT1} ${flags} "${src}" /dev/null
+		    ${LINT1} ${flags} "${src}" "${wrk_ln}"
+	fi
+
+	if [ "${src_ln}" != "/dev/null" ]; then
+		atf_check -o "file:${src_ln}" cat "${wrk_ln}"
 	fi
 }
 
@@ -166,6 +177,8 @@ test_case d_type_conv3
 test_case d_incorrect_array_size
 test_case d_long_double_int
 
+test_case emit
+
 test_case gcc_init_compound_literal
 
 test_case op_colon

Index: src/usr.bin/xlint/lint1/emit1.c
diff -u src/usr.bin/xlint/lint1/emit1.c:1.43 src/usr.bin/xlint/lint1/emit1.c:1.44
--- src/usr.bin/xlint/lint1/emit1.c:1.43	Sat Mar 27 12:32:19 2021
+++ src/usr.bin/xlint/lint1/emit1.c	Sun Apr 18 20:02:56 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: emit1.c,v 1.43 2021/03/27 12:32:19 rillig Exp $ */
+/* $NetBSD: emit1.c,v 1.44 2021/04/18 20:02:56 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.43 2021/03/27 12:32:19 rillig Exp $");
+__RCSID("$NetBSD: emit1.c,v 1.44 2021/04/18 20:02:56 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -76,16 +76,16 @@ static	void	outfstrg(strg_t *);
  *	[n]			A n
  *	()			F
  *	(void)			F 0
- *	(n arguments)		F n arg1 arg2 ... argn
- *	(n arguments, ...)	F n arg1 arg2 ... argn-1 E
- *	(a, b, c, ...)		f n arg1 arg2 ...
+ *	(n parameters)		F n arg1 arg2 ... argn
+ *	(n parameters, ...)	F n arg1 arg2 ... argn-1 E
  *	enum tag		e T tag_or_typename
  *	struct tag		s T tag_or_typename
  *	union tag		u T tag_or_typename
  *
- *	tag_or_typename		0			no tag or type name
- *				1 n tag			Tag
+ *	tag_or_typename		0 (obsolete)		no tag or type name
+ *				1 n tag			tagged type
  *				2 n typename		only type name
+ *				3 line.file.uniq	anonymous types
  *
  * spaces are only for better readability
  * additionally it is possible to prepend the characters 'c' (for const)
@@ -191,17 +191,16 @@ ttos(const type_t *tp)
 /*
  * write the name of a tag or typename
  *
- * if the tag is named, the name of the
- * tag is written, otherwise, if a typename exists which
- * refers to this tag, this typename is written
+ * if the tag is named, the name of the tag is written,
+ * otherwise, if a typename exists which refers to this tag,
+ * this typename is written
  */
 static void
 outtt(sym_t *tag, sym_t *tdef)
 {
 
-	/*
-	 * 0 is no longer used.
-	 */
+	/* 0 is no longer used. */
+
 	if (tag->s_name != unnamed) {
 		outint(1);
 		outname(tag->s_name);

Added files:

Index: src/tests/usr.bin/xlint/lint1/emit.c
diff -u /dev/null src/tests/usr.bin/xlint/lint1/emit.c:1.1
--- /dev/null	Sun Apr 18 20:02:56 2021
+++ src/tests/usr.bin/xlint/lint1/emit.c	Sun Apr 18 20:02:56 2021
@@ -0,0 +1,146 @@
+/*	$NetBSD: emit.c,v 1.1 2021/04/18 20:02:56 rillig Exp $	*/
+# 3 "emit.c"
+
+/*
+ * Test the symbol information that lint1 writes to a .ln file.  Using this
+ * symbol information, lint2 later checks that the symbols are used
+ * consistently across different translation units.
+ */
+
+// omit the option '-g' to avoid having the GCC builtins in the .ln file.
+/* lint1-flags: -Sw */
+
+/*
+ * Define some derived types.
+ */
+
+struct struct_tag {
+	int member;
+};
+
+typedef struct {
+	int member;
+} struct_typedef;
+
+union union_tag {
+	int member;
+};
+
+typedef union {
+	int member;
+} union_typedef;
+
+enum enum_tag {
+	enum_tag_constant
+};
+
+typedef enum {
+	enum_typedef_constant
+} enum_typedef;
+
+/*
+ * Variable declarations using the basic types (C99 6.2.5p14).
+ *
+ * Last synced with function outtype from emit1.c 1.43.
+ */
+
+extern _Bool			extern__Bool;
+extern float _Complex 		extern__Complex_float;
+extern double _Complex		extern__Complex_double;
+extern long double _Complex	extern__Complex_long_double;
+extern char			extern_char;
+extern signed char		extern_signed_char;
+extern unsigned char		extern_unsigned_char;
+extern short			extern_short;
+extern signed short		extern_signed_short;
+extern unsigned short		extern_unsigned_short;
+extern int			extern_int;
+extern signed int		extern_signed_int;
+extern unsigned int		extern_unsigned_int;
+extern long			extern_long;
+extern signed long		extern_signed_long;
+extern unsigned long		extern_unsigned_long;
+extern long long		extern_long_long;
+extern signed long long		extern_signed_long_long;
+extern unsigned long long	extern_unsigned_long_long;
+extern float			extern_float;
+extern double			extern_double;
+extern long double		extern_long_double;
+
+/*
+ * Variable declarations using derived types (C99 6.2.5p20).
+ */
+
+extern void *			extern_pointer_to_void;
+extern int			extern_array_5_of_int[5];
+
+/*
+ * Type tags are written to the .ln file as 'T kind length name', where 'kind'
+ * is either 1, 2 or 3.  This is confusing at first since in 'T110struct_tag',
+ * the apparent number 110 is to be read as 'tag kind 1, length 10'.
+ */
+extern struct struct_tag	extern_struct_tag;
+extern struct_typedef		extern_struct_typedef;
+extern union union_tag		extern_union_tag;
+extern union_typedef		extern_union_typedef;
+extern enum enum_tag		extern_enum_tag;
+extern enum_typedef		extern_enum_typedef;
+
+extern struct {
+	int member;
+}				extern_anonymous_struct;
+extern union {
+	int member;
+}				extern_anonymous_union;
+extern enum {
+	anonymous_enum_constant
+}				extern_anonymous_enum;
+
+/*
+ * Variable definitions.
+ *
+ * Static variables are not recorded in the .ln file.
+ */
+
+extern int			declared_int;
+int				defined_int;
+static int			static_int;		/* expect: unused */
+
+/*
+ * Type qualifiers.
+ */
+
+extern const int		extern_const_int;
+extern volatile int		extern_volatile_int;
+extern const volatile int	extern_const_volatile_int;
+
+/*
+ * Functions.
+ */
+
+extern void return_void_unknown_parameters();
+extern /* implicit int */ return_implicit_int_unknown_parameters();
+
+/* For function declarations, the keyword 'extern' is optional. */
+extern void extern_return_void_no_parameters(void);
+/* implicit extern */ void return_void_no_parameters(void);
+static void static_return_void_no_parameters(void);	/* expect: declared */
+
+void taking_int(int);
+/* The 'const' parameter does not make a difference. */
+void taking_const_int(const int);
+void taking_int_double_bool(int, double, _Bool);
+void taking_struct_union_enum_tags(struct struct_tag, union union_tag,
+    enum enum_tag);
+void taking_struct_union_enum_typedefs(struct_typedef, union_typedef,
+    enum_typedef);
+
+void taking_varargs(const char *, ...);
+
+/*
+ * This function does not affect anything outside this translation unit.
+ * Naively there is no need to record this function in the .ln file, but it
+ * is nevertheless recorded.  There's probably a good reason for recording
+ * it.
+ */
+static int static_function(void);			/* expect: declared */
Index: src/tests/usr.bin/xlint/lint1/emit.exp
diff -u /dev/null src/tests/usr.bin/xlint/lint1/emit.exp:1.1
--- /dev/null	Sun Apr 18 20:02:56 2021
+++ src/tests/usr.bin/xlint/lint1/emit.exp	Sun Apr 18 20:02:56 2021
@@ -0,0 +1,3 @@
+emit.c(107): warning: static variable static_int unused [226]
+emit.c(127): warning: static function static_return_void_no_parameters declared but not defined [290]
+emit.c(146): warning: static function static_function declared but not defined [290]
Index: src/tests/usr.bin/xlint/lint1/emit.ln
diff -u /dev/null src/tests/usr.bin/xlint/lint1/emit.ln:1.1
--- /dev/null	Sun Apr 18 20:02:56 2021
+++ src/tests/usr.bin/xlint/lint1/emit.ln	Sun Apr 18 20:02:56 2021
@@ -0,0 +1,52 @@
+0semit.c
+Semit.c
+47d0.47e12extern__BoolB
+48d0.48e21extern__Complex_floatsX
+49d0.49e22extern__Complex_doubleX
+50d0.50e27extern__Complex_long_doublelX
+51d0.51e11extern_charC
+52d0.52e18extern_signed_charsC
+53d0.53e20extern_unsigned_charuC
+54d0.54e12extern_shortS
+55d0.55e19extern_signed_shortS
+56d0.56e21extern_unsigned_shortuS
+57d0.57e10extern_intI
+58d0.58e17extern_signed_intI
+59d0.59e19extern_unsigned_intuI
+60d0.60e11extern_longL
+61d0.61e18extern_signed_longL
+62d0.62e20extern_unsigned_longuL
+63d0.63e16extern_long_longQ
+64d0.64e23extern_signed_long_longQ
+65d0.65e25extern_unsigned_long_longuQ
+66d0.66e12extern_floatsD
+67d0.67e13extern_doubleD
+68d0.68e18extern_long_doublelD
+74d0.74e22extern_pointer_to_voidPV
+75d0.75e21extern_array_5_of_intA5I
+82d0.82e17extern_struct_tagsT110struct_tag
+83d0.83e21extern_struct_typedefsT214struct_typedef
+84d0.84e16extern_union_taguT19union_tag
+85d0.85e20extern_union_typedefuT213union_typedef
+86d0.86e15extern_enum_tageT18enum_tag
+87d0.87e19extern_enum_typedefeT212enum_typedef
+91d0.91e23extern_anonymous_structsT389.0.0
+94d0.94e22extern_anonymous_unionuT392.0.0
+97d0.97e21extern_anonymous_enumeT395.0.0
+105d0.105e12declared_intI
+106d0.106t11defined_intI
+113d0.113e16extern_const_intcI
+114d0.114e19extern_volatile_intvI
+115d0.115e25extern_const_volatile_intcvI
+121d0.121e30return_void_unknown_parametersFV
+122d0.122e38return_implicit_int_unknown_parametersFI
+125d0.125e32extern_return_void_no_parametersF0V
+126d0.126e25return_void_no_parametersF0V
+127d0.127es32static_return_void_no_parametersF0V
+129d0.129e10taking_intF1IV
+131d0.131e16taking_const_intF1cIV
+132d0.132e22taking_int_double_boolF3IDBV
+134d0.133e29taking_struct_union_enum_tagsF3sT110struct_taguT19union_tageT18enum_tagV
+136d0.135e33taking_struct_union_enum_typedefsF3sT214struct_typedefuT213union_typedefeT212enum_typedefV
+138d0.138e14taking_varargsF2PcCEV
+146d0.146es15static_functionF0I

Reply via email to