Source-Changes-HG archive

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

[src/trunk]: src tests/lint: test initialization using string literals



details:   https://anonhg.NetBSD.org/src/rev/082b7d39f585
branches:  trunk
changeset: 981864:082b7d39f585
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Mar 23 21:19:08 2021 +0000

description:
tests/lint: test initialization using string literals

The errors in line 74 and 75 of the test are wrong.  Everything is fine
there.  The bug lies in init_array_using_string, try to see if you can
spot it, neither GCC 9.3.0 nor Clang 8.0.1 could.

diffstat:

 distrib/sets/lists/tests/mi                             |   4 +-
 tests/usr.bin/xlint/lint1/Makefile                      |   4 +-
 tests/usr.bin/xlint/lint1/d_init_array_using_string.c   |  77 +++++++++++++++++
 tests/usr.bin/xlint/lint1/d_init_array_using_string.exp |  10 ++
 tests/usr.bin/xlint/lint1/t_integration.sh              |   3 +-
 5 files changed, 95 insertions(+), 3 deletions(-)

diffs (148 lines):

diff -r c388d1fbaf1f -r 082b7d39f585 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Tue Mar 23 20:59:02 2021 +0000
+++ b/distrib/sets/lists/tests/mi       Tue Mar 23 21:19:08 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1032 2021/03/14 11:49:37 rillig Exp $
+# $NetBSD: mi,v 1.1033 2021/03/23 21:19:08 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -6151,6 +6151,8 @@
 ./usr/tests/usr.bin/xlint/lint1/d_gcc_variable_array_init.c    tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/d_incorrect_array_size.c       tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/d_incorrect_array_size.exp     tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/d_init_array_using_string.c    tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/d_init_array_using_string.exp  tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/d_init_pop_member.c            tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/d_init_pop_member.exp          tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/d_lint_assert.c                        tests-usr.bin-tests     compattestfile,atf
diff -r c388d1fbaf1f -r 082b7d39f585 tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile        Tue Mar 23 20:59:02 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile        Tue Mar 23 21:19:08 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.35 2021/03/07 19:42:54 rillig Exp $
+# $NetBSD: Makefile,v 1.36 2021/03/23 21:19:08 rillig Exp $
 
 NOMAN=         # defined
 
@@ -70,6 +70,8 @@
 FILES+=                d_gcc_variable_array_init.c
 FILES+=                d_incorrect_array_size.c
 FILES+=                d_incorrect_array_size.exp
+FILES+=                d_init_array_using_string.c
+FILES+=                d_init_array_using_string.exp
 FILES+=                d_init_pop_member.c
 FILES+=                d_init_pop_member.exp
 FILES+=                d_lint_assert.c
diff -r c388d1fbaf1f -r 082b7d39f585 tests/usr.bin/xlint/lint1/d_init_array_using_string.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/d_init_array_using_string.c     Tue Mar 23 21:19:08 2021 +0000
@@ -0,0 +1,77 @@
+/*     $NetBSD: d_init_array_using_string.c,v 1.1 2021/03/23 21:19:08 rillig Exp $     */
+# 3 "d_init_array_using_string.c"
+
+/*
+ * Test initialization of arrays and pointers by string literals.
+ */
+
+void sink(const void *);
+
+void
+test_assignment_initialization(void)
+{
+       const char *cs_match = "";
+       const int *ws_match = L"";
+
+       const char *cs_mismatch = L"";  /* expect: illegal pointer combination */
+       const int *ws_mismatch = "";    /* expect: illegal pointer combination */
+}
+
+void
+test_pointer_initialization_in_struct(void)
+{
+       struct cs_ws {
+               const char *cs;
+               const int *ws;
+       };
+
+       struct cs_ws type_match = {
+               "",
+               L"",
+       };
+
+       struct cs_ws type_mismatch = {
+               L"",            /* expect: illegal pointer combination */
+               "",             /* expect: illegal pointer combination */
+       };
+
+       struct cs_ws extra_braces = {
+               { "" },
+               { L"" },
+       };
+}
+
+
+void
+test_array_initialization_in_struct(void)
+{
+       struct cs_ws {
+               const char cs[10];
+               const int ws[10];
+       };
+
+       struct cs_ws type_match = {
+               "",
+               L"",
+       };
+
+       struct cs_ws type_mismatch = {
+               L"",            /* expect: illegal combination */
+               "",             /* expect: illegal combination */
+       };
+
+       struct cs_ws no_terminating_null = {
+               "0123456789",
+               L"0123456789",
+       };
+
+       struct cs_ws too_many_characters = {
+               "0123456789X",  /* expect: non-null byte ignored */
+               L"0123456789X", /* expect: non-null byte ignored */
+       };
+
+       struct cs_ws extra_braces = {
+               { "" },         /* expect: illegal combination *//*FIXME*/
+               { L"" },        /* expect: illegal combination *//*FIXME*/
+       };
+}
diff -r c388d1fbaf1f -r 082b7d39f585 tests/usr.bin/xlint/lint1/d_init_array_using_string.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/d_init_array_using_string.exp   Tue Mar 23 21:19:08 2021 +0000
@@ -0,0 +1,10 @@
+d_init_array_using_string.c(16): warning: illegal pointer combination (pointer to const char) and (pointer to int), op = [124]
+d_init_array_using_string.c(17): warning: illegal pointer combination (pointer to const int) and (pointer to char), op = [124]
+d_init_array_using_string.c(34): warning: illegal pointer combination [184]
+d_init_array_using_string.c(35): warning: illegal pointer combination [184]
+d_init_array_using_string.c(59): warning: illegal combination of integer (char) and pointer (pointer to int) [183]
+d_init_array_using_string.c(60): warning: illegal combination of integer (char) and pointer (pointer to char) [183]
+d_init_array_using_string.c(69): warning: non-null byte ignored in string initializer [187]
+d_init_array_using_string.c(70): warning: non-null byte ignored in string initializer [187]
+d_init_array_using_string.c(74): warning: illegal combination of integer (char) and pointer (pointer to char) [183]
+d_init_array_using_string.c(75): warning: illegal combination of integer (int) and pointer (pointer to int) [183]
diff -r c388d1fbaf1f -r 082b7d39f585 tests/usr.bin/xlint/lint1/t_integration.sh
--- a/tests/usr.bin/xlint/lint1/t_integration.sh        Tue Mar 23 20:59:02 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/t_integration.sh        Tue Mar 23 21:19:08 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_integration.sh,v 1.33 2021/03/07 19:42:54 rillig Exp $
+# $NetBSD: t_integration.sh,v 1.34 2021/03/23 21:19:08 rillig Exp $
 #
 # Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -108,6 +108,7 @@
 test_case decl_old_style_arguments
 test_case fold_test
 test_case gcc_extension
+test_case init_array_using_string
 test_case init_pop_member
 test_case lint_assert
 test_case return_type



Home | Main Index | Thread Index | Old Index