Module Name:    src
Committed By:   rillig
Date:           Sun Jun 27 18:48:45 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: main1.c
Added Files:
        src/tests/usr.bin/xlint/lint1: c11_generic_expression.c
            c11_generic_expression.exp

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.1065 -r1.1066 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.66 -r1.67 src/tests/usr.bin/xlint/lint1/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/c11_generic_expression.c \
    src/tests/usr.bin/xlint/lint1/c11_generic_expression.exp
cvs rdiff -u -r1.59 -r1.60 src/tests/usr.bin/xlint/lint1/t_integration.sh
cvs rdiff -u -r1.45 -r1.46 src/usr.bin/xlint/lint1/main1.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.1065 src/distrib/sets/lists/tests/mi:1.1066
--- src/distrib/sets/lists/tests/mi:1.1065	Sun Jun 27 12:11:10 2021
+++ src/distrib/sets/lists/tests/mi	Sun Jun 27 18:48:45 2021
@@ -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

Index: src/tests/usr.bin/xlint/lint1/Makefile
diff -u src/tests/usr.bin/xlint/lint1/Makefile:1.66 src/tests/usr.bin/xlint/lint1/Makefile:1.67
--- src/tests/usr.bin/xlint/lint1/Makefile:1.66	Sun Jun 27 09:22:31 2021
+++ src/tests/usr.bin/xlint/lint1/Makefile	Sun Jun 27 18:48:45 2021
@@ -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 @@ TESTSDIR=	${TESTSBASE}/usr.bin/xlint/lin
 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

Index: src/tests/usr.bin/xlint/lint1/t_integration.sh
diff -u src/tests/usr.bin/xlint/lint1/t_integration.sh:1.59 src/tests/usr.bin/xlint/lint1/t_integration.sh:1.60
--- src/tests/usr.bin/xlint/lint1/t_integration.sh:1.59	Sun Jun 27 10:14:43 2021
+++ src/tests/usr.bin/xlint/lint1/t_integration.sh	Sun Jun 27 18:48:45 2021
@@ -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()
 
 
 test_case all_messages
+test_case c11_generic_expression
 test_case c99_init_designator
 test_case d_alignof
 test_case d_bltinoffsetof

Index: src/usr.bin/xlint/lint1/main1.c
diff -u src/usr.bin/xlint/lint1/main1.c:1.45 src/usr.bin/xlint/lint1/main1.c:1.46
--- src/usr.bin/xlint/lint1/main1.c:1.45	Sun Apr 18 22:51:24 2021
+++ src/usr.bin/xlint/lint1/main1.c	Sun Jun 27 18:48:45 2021
@@ -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 @@ main(int argc, char *argv[])
 			if (strcmp(optarg, "c11") == 0) {
 				c11flag = true;
 				Sflag = true;
-				sflag = true;
+				sflag = false;
 			} else
 				usage();
 			break;

Added files:

Index: src/tests/usr.bin/xlint/lint1/c11_generic_expression.c
diff -u /dev/null src/tests/usr.bin/xlint/lint1/c11_generic_expression.c:1.1
--- /dev/null	Sun Jun 27 18:48:45 2021
+++ src/tests/usr.bin/xlint/lint1/c11_generic_expression.c	Sun Jun 27 18:48:45 2021
@@ -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 */
+}
Index: src/tests/usr.bin/xlint/lint1/c11_generic_expression.exp
diff -u /dev/null src/tests/usr.bin/xlint/lint1/c11_generic_expression.exp:1.1
--- /dev/null	Sun Jun 27 18:48:45 2021
+++ src/tests/usr.bin/xlint/lint1/c11_generic_expression.exp	Sun Jun 27 18:48:45 2021
@@ -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]

Reply via email to