lint: demonstrate wrong handling of conversion to _Bool
This commit is contained in:
parent
dadf0f419e
commit
e107438c00
@ -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
|
||||
|
@ -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
|
||||
|
49
tests/usr.bin/xlint/lint1/d_c99_bool.c
Normal file
49
tests/usr.bin/xlint/lint1/d_c99_bool.c
Normal file
@ -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];
|
17
tests/usr.bin/xlint/lint1/d_c99_bool.exp
Normal file
17
tests/usr.bin/xlint/lint1/d_c99_bool.exp
Normal file
@ -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]
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user