Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/xlint/lint1 lint: test emitting of symbol informatio...



details:   https://anonhg.NetBSD.org/src/rev/c2e558dd485c
branches:  trunk
changeset: 1020651:c2e558dd485c
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Apr 18 20:02:56 2021 +0000

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

diffstat:

 distrib/sets/lists/tests/mi                |    4 +-
 tests/usr.bin/xlint/lint1/Makefile         |    5 +-
 tests/usr.bin/xlint/lint1/emit.c           |  146 +++++++++++++++++++++++++++++
 tests/usr.bin/xlint/lint1/emit.exp         |    3 +
 tests/usr.bin/xlint/lint1/emit.ln          |   52 ++++++++++
 tests/usr.bin/xlint/lint1/t_integration.sh |   19 +++-
 usr.bin/xlint/lint1/emit1.c                |   25 ++--
 7 files changed, 236 insertions(+), 18 deletions(-)

diffs (truncated from 361 to 300 lines):

diff -r f8da4dd2610f -r c2e558dd485c distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sun Apr 18 19:56:09 2021 +0000
+++ b/distrib/sets/lists/tests/mi       Sun Apr 18 20:02:56 2021 +0000
@@ -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
diff -r f8da4dd2610f -r c2e558dd485c tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile        Sun Apr 18 19:56:09 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile        Sun Apr 18 20:02:56 2021 +0000
@@ -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_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
diff -r f8da4dd2610f -r c2e558dd485c tests/usr.bin/xlint/lint1/emit.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/emit.c  Sun Apr 18 20:02:56 2021 +0000
@@ -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 */
diff -r f8da4dd2610f -r c2e558dd485c tests/usr.bin/xlint/lint1/emit.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/emit.exp        Sun Apr 18 20:02:56 2021 +0000
@@ -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]
diff -r f8da4dd2610f -r c2e558dd485c tests/usr.bin/xlint/lint1/emit.ln
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/emit.ln Sun Apr 18 20:02:56 2021 +0000
@@ -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
diff -r f8da4dd2610f -r c2e558dd485c tests/usr.bin/xlint/lint1/t_integration.sh
--- a/tests/usr.bin/xlint/lint1/t_integration.sh        Sun Apr 18 19:56:09 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/t_integration.sh        Sun Apr 18 20:02:56 2021 +0000
@@ -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 @@
 {
        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_incorrect_array_size
 test_case d_long_double_int
 
+test_case emit
+
 test_case gcc_init_compound_literal
 
 test_case op_colon
diff -r f8da4dd2610f -r c2e558dd485c usr.bin/xlint/lint1/emit1.c
--- a/usr.bin/xlint/lint1/emit1.c       Sun Apr 18 19:56:09 2021 +0000



Home | Main Index | Thread Index | Old Index