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: fix option -Ac11, add test for _Ge...



details:   https://anonhg.NetBSD.org/src/rev/28f98d5f0d85
branches:  trunk
changeset: 984201:28f98d5f0d85
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jun 27 18:48:45 2021 +0000

description:
lint: fix option -Ac11, add test for _Generic

Previously, selecting the option -Ac11 allowed features from C11 but at
the same time prohibited 'long long', which was added in C99.  This was
caused by the option -s, which is interpreted as "allow features from
C90, but no later".

The test for _Generic, which has been added in C11, demonstrates that
the current implementation is broken.  Lint currently thinks that the
return type of a _Generic selection is the type of the expression, but
it really is the type of the selected expression.  In the current tests,
this is always 'const char *', but C11 does not require that the types
of a generic selection are compatible.

diffstat:

 distrib/sets/lists/tests/mi                          |   4 +-
 tests/usr.bin/xlint/lint1/Makefile                   |   4 +-
 tests/usr.bin/xlint/lint1/c11_generic_expression.c   |  46 ++++++++++++++++++++
 tests/usr.bin/xlint/lint1/c11_generic_expression.exp |   4 +
 tests/usr.bin/xlint/lint1/t_integration.sh           |   3 +-
 usr.bin/xlint/lint1/main1.c                          |   6 +-
 6 files changed, 61 insertions(+), 6 deletions(-)

diffs (138 lines):

diff -r 40acc2de311c -r 28f98d5f0d85 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sun Jun 27 18:19:13 2021 +0000
+++ b/distrib/sets/lists/tests/mi       Sun Jun 27 18:48:45 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1065 2021/06/27 12:11:10 rillig Exp $
+# $NetBSD: mi,v 1.1066 2021/06/27 18:48:45 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -6105,6 +6105,8 @@
 ./usr/tests/usr.bin/xlint/lint1                                tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/Atffile                                tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/Kyuafile                       tests-usr.bin-tests     compattestfile,atf,kyua
+./usr/tests/usr.bin/xlint/lint1/c11_generic_expression.c       tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/c11_generic_expression.exp     tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/c99_init_designator.c          tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/c99_init_designator.exp                tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/d_alignof.c                    tests-usr.bin-tests     compattestfile,atf
diff -r 40acc2de311c -r 28f98d5f0d85 tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile        Sun Jun 27 18:19:13 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile        Sun Jun 27 18:48:45 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.66 2021/06/27 09:22:31 rillig Exp $
+# $NetBSD: Makefile,v 1.67 2021/06/27 18:48:45 rillig Exp $
 
 NOMAN=         # defined
 MAX_MESSAGE=   344             # see lint1/err.c
@@ -10,6 +10,8 @@
 TESTS_SH=      t_integration
 
 FILESDIR=      ${TESTSDIR}
+FILES+=                c11_generic_expression.c
+FILES+=                c11_generic_expression.exp
 FILES+=                c99_init_designator.c
 FILES+=                c99_init_designator.exp
 FILES+=                d_alignof.c
diff -r 40acc2de311c -r 28f98d5f0d85 tests/usr.bin/xlint/lint1/c11_generic_expression.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/c11_generic_expression.c        Sun Jun 27 18:48:45 2021 +0000
@@ -0,0 +1,46 @@
+/*     $NetBSD: c11_generic_expression.c,v 1.1 2021/06/27 18:48:45 rillig Exp $        */
+# 3 "c11_generic_expression.c"
+
+/*
+ * C99 added support for type-generic macros, but these were limited to the
+ * header <tgmath.h>.  C11 made this feature generally available.
+ *
+ * The generic selection is typically used with macros, but since lint1 works
+ * on the preprocessed source, the test cases look a bit strange.
+ *
+ * C99 6.5.1.1 "Generic selection"
+ */
+
+/* lint1-extra-flags: -Ac11 */
+
+/*
+ * The type of 'var' is not compatible with any of the types from the
+ * generic-association.  This is a compile-time error.
+ */
+const char *
+classify_integer_without_default(double var)
+{
+       return _Generic(var,
+           long double: "long double",
+           long long: "long long",
+           unsigned: "unsigned"
+       );
+       /* expect-7: argument 'var' unused */
+       /* expect-2: type mismatch (pointer to const char) and (double) *//* FIXME */
+}
+
+/*
+ * In this case, the 'default' expression is selected.
+ */
+const char *
+classify_integer_with_default(double var)
+{
+       return _Generic(var,
+           long double: "long double",
+           long long: "long long",
+           unsigned: "unsigned",
+           default: "unknown"
+       );
+       /* expect-8: argument 'var' unused */
+       /* expect-2: type mismatch (pointer to const char) and (double) *//* FIXME */
+}
diff -r 40acc2de311c -r 28f98d5f0d85 tests/usr.bin/xlint/lint1/c11_generic_expression.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/c11_generic_expression.exp      Sun Jun 27 18:48:45 2021 +0000
@@ -0,0 +1,4 @@
+c11_generic_expression.c(27): error: return value type mismatch (pointer to const char) and (double) [211]
+c11_generic_expression.c(21): warning: argument 'var' unused in function 'classify_integer_without_default' [231]
+c11_generic_expression.c(43): error: return value type mismatch (pointer to const char) and (double) [211]
+c11_generic_expression.c(36): warning: argument 'var' unused in function 'classify_integer_with_default' [231]
diff -r 40acc2de311c -r 28f98d5f0d85 tests/usr.bin/xlint/lint1/t_integration.sh
--- a/tests/usr.bin/xlint/lint1/t_integration.sh        Sun Jun 27 18:19:13 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/t_integration.sh        Sun Jun 27 18:48:45 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_integration.sh,v 1.59 2021/06/27 10:14:43 rillig Exp $
+# $NetBSD: t_integration.sh,v 1.60 2021/06/27 18:48:45 rillig Exp $
 #
 # Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -117,6 +117,7 @@
 
 
 test_case all_messages
+test_case c11_generic_expression
 test_case c99_init_designator
 test_case d_alignof
 test_case d_bltinoffsetof
diff -r 40acc2de311c -r 28f98d5f0d85 usr.bin/xlint/lint1/main1.c
--- a/usr.bin/xlint/lint1/main1.c       Sun Jun 27 18:19:13 2021 +0000
+++ b/usr.bin/xlint/lint1/main1.c       Sun Jun 27 18:48:45 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main1.c,v 1.45 2021/04/18 22:51:24 rillig Exp $        */
+/*     $NetBSD: main1.c,v 1.46 2021/06/27 18:48:45 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: main1.c,v 1.45 2021/04/18 22:51:24 rillig Exp $");
+__RCSID("$NetBSD: main1.c,v 1.46 2021/06/27 18:48:45 rillig Exp $");
 #endif
 
 #include <sys/types.h>
@@ -208,7 +208,7 @@
                        if (strcmp(optarg, "c11") == 0) {
                                c11flag = true;
                                Sflag = true;
-                               sflag = true;
+                               sflag = false;
                        } else
                                usage();
                        break;



Home | Main Index | Thread Index | Old Index