Module Name: src Committed By: rillig Date: Sun Jan 10 11:24:43 UTC 2021
Modified Files: src/distrib/sets/lists/tests: mi src/tests/usr.bin/xlint/lint1: Makefile t_integration.sh Added Files: src/tests/usr.bin/xlint/lint1: d_c99_bool.c d_c99_bool.exp Log Message: lint: demonstrate wrong handling of conversion to _Bool To generate a diff of this commit: cvs rdiff -u -r1.1007 -r1.1008 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.25 -r1.26 src/tests/usr.bin/xlint/lint1/Makefile cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/d_c99_bool.c \ src/tests/usr.bin/xlint/lint1/d_c99_bool.exp cvs rdiff -u -r1.21 -r1.22 src/tests/usr.bin/xlint/lint1/t_integration.sh 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.1007 src/distrib/sets/lists/tests/mi:1.1008 --- src/distrib/sets/lists/tests/mi:1.1007 Sat Jan 2 10:22:42 2021 +++ src/distrib/sets/lists/tests/mi Sun Jan 10 11:24:42 2021 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1007 2021/01/02 10:22:42 rillig Exp $ +# $NetBSD: mi,v 1.1008 2021/01/10 11:24:42 rillig Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -5745,6 +5745,8 @@ ./usr/tests/usr.bin/xlint/lint1/d_bltinoffsetof.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/d_c99_anon_struct.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/d_c99_anon_union.c tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/xlint/lint1/d_c99_bool.c tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/xlint/lint1/d_c99_bool.exp tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/d_c99_complex_num.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/d_c99_complex_split.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/d_c99_compound_literal_comma.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.25 src/tests/usr.bin/xlint/lint1/Makefile:1.26 --- src/tests/usr.bin/xlint/lint1/Makefile:1.25 Sat Jan 2 10:22:42 2021 +++ src/tests/usr.bin/xlint/lint1/Makefile Sun Jan 10 11:24:42 2021 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.25 2021/01/02 10:22:42 rillig Exp $ +# $NetBSD: Makefile,v 1.26 2021/01/10 11:24:42 rillig Exp $ NOMAN= # defined @@ -11,6 +11,8 @@ TESTS_SH= t_integration FILESDIR= ${TESTSDIR} FILES+= d_alignof.c FILES+= d_bltinoffsetof.c +FILES+= d_c99_bool.c +FILES+= d_c99_bool.exp FILES+= d_c99_anon_struct.c FILES+= d_c99_anon_union.c FILES+= d_c99_complex_num.c Index: src/tests/usr.bin/xlint/lint1/t_integration.sh diff -u src/tests/usr.bin/xlint/lint1/t_integration.sh:1.21 src/tests/usr.bin/xlint/lint1/t_integration.sh:1.22 --- src/tests/usr.bin/xlint/lint1/t_integration.sh:1.21 Sat Jan 9 14:33:53 2021 +++ src/tests/usr.bin/xlint/lint1/t_integration.sh Sun Jan 10 11:24:42 2021 @@ -1,4 +1,4 @@ -# $NetBSD: t_integration.sh,v 1.21 2021/01/09 14:33:53 rillig Exp $ +# $NetBSD: t_integration.sh,v 1.22 2021/01/10 11:24:42 rillig Exp $ # # Copyright (c) 2008, 2010 The NetBSD Foundation, Inc. # All rights reserved. @@ -65,6 +65,7 @@ test_case() test_case bltinoffsetof test_case c99_anon_struct test_case c99_anon_union +test_case c99_bool test_case c99_compound_literal_comma test_case c99_decls_after_stmt2 test_case c99_flex_array_packed Added files: Index: src/tests/usr.bin/xlint/lint1/d_c99_bool.c diff -u /dev/null src/tests/usr.bin/xlint/lint1/d_c99_bool.c:1.1 --- /dev/null Sun Jan 10 11:24:43 2021 +++ src/tests/usr.bin/xlint/lint1/d_c99_bool.c Sun Jan 10 11:24:42 2021 @@ -0,0 +1,49 @@ +/* $NetBSD: d_c99_bool.c,v 1.1 2021/01/10 11:24:42 rillig Exp $ */ +# 3 "d_bool.c" + +/* + * C99 6.3.1.2 says: "When any scalar value is converted to _Bool, the result + * is 0 if the value compares equal to 0; otherwise the result is 1." + * + * This is different from the other integer types, which get truncated or + * invoke undefined behavior. + */ + +/* Below, the wrong assertions produce warning 20. */ + +int int_0_converts_to_false[(_Bool)0 ? -1 : 1]; +int int_0_converts_to_true_[(_Bool)0 ? 1 : -1]; + +int int_1_converts_to_false[(_Bool)1 ? -1 : 1]; +int int_1_converts_to_true_[(_Bool)1 ? 1 : -1]; + +int int_2_converts_to_false[(_Bool)2 ? -1 : 1]; +int int_2_converts_to_true_[(_Bool)2 ? 1 : -1]; + +int int_256_converts_to_false[(_Bool)256 ? -1 : 1]; // FIXME +int int_256_converts_to_true_[(_Bool)256 ? 1 : -1]; // FIXME + +int null_pointer_converts_to_false[(_Bool)(void *)0 ? -1 : 1]; +int null_pointer_converts_to_true_[(_Bool)(void *)0 ? 1 : -1]; + +int nonnull_pointer_converts_to_false[(_Bool)"not null" ? -1 : 1]; // FIXME 133 +int nonnull_pointer_converts_to_true_[(_Bool)"not null" ? 1 : -1]; // FIXME 133 + +int double_minus_1_0_converts_to_false[(_Bool)-1.0 ? -1 : 1]; // FIXME 119 +int double_minus_1_0_converts_to_true_[(_Bool)-1.0 ? 1 : -1]; // FIXME 20, 119 + +int double_minus_0_5_converts_to_false[(_Bool)-0.5 ? -1 : 1]; // FIXME 119 +int double_minus_0_5_converts_to_true_[(_Bool)-0.5 ? 1 : -1]; // FIXME 20, 119 + +int double_minus_0_0_converts_to_false[(_Bool)-0.0 ? -1 : 1]; +int double_minus_0_0_converts_to_true_[(_Bool)-0.0 ? 1 : -1]; + +int double_0_0_converts_to_false[(_Bool)0.0 ? -1 : 1]; +int double_0_0_converts_to_true_[(_Bool)0.0 ? 1 : -1]; + +/* The C99 rationale explains in 6.3.1.2 why (_Bool)0.5 is true. */ +int double_0_5_converts_to_false[(_Bool)0.5 ? -1 : 1]; // FIXME 20 +int double_0_5_converts_to_true_[(_Bool)0.5 ? 1 : -1]; // FIXME 20 + +int double_1_0_converts_to_false[(_Bool)1.0 ? -1 : 1]; +int double_1_0_converts_to_true_[(_Bool)1.0 ? 1 : -1]; Index: src/tests/usr.bin/xlint/lint1/d_c99_bool.exp diff -u /dev/null src/tests/usr.bin/xlint/lint1/d_c99_bool.exp:1.1 --- /dev/null Sun Jan 10 11:24:43 2021 +++ src/tests/usr.bin/xlint/lint1/d_c99_bool.exp Sun Jan 10 11:24:42 2021 @@ -0,0 +1,17 @@ +d_bool.c(15): negative array dimension (-1) [20] +d_bool.c(17): negative array dimension (-1) [20] +d_bool.c(20): negative array dimension (-1) [20] +d_bool.c(24): negative array dimension (-1) [20] +d_bool.c(27): negative array dimension (-1) [20] +d_bool.c(29): warning: conversion of pointer to '_Bool' loses bits [133] +d_bool.c(30): warning: conversion of pointer to '_Bool' loses bits [133] +d_bool.c(32): warning: conversion of 'double' to '_Bool' is out of range [119] +d_bool.c(33): warning: conversion of 'double' to '_Bool' is out of range [119] +d_bool.c(33): negative array dimension (-1) [20] +d_bool.c(35): warning: conversion of 'double' to '_Bool' is out of range [119] +d_bool.c(36): warning: conversion of 'double' to '_Bool' is out of range [119] +d_bool.c(36): negative array dimension (-1) [20] +d_bool.c(39): negative array dimension (-1) [20] +d_bool.c(42): negative array dimension (-1) [20] +d_bool.c(46): negative array dimension (-1) [20] +d_bool.c(48): negative array dimension (-1) [20]