Module Name: src Committed By: rillig Date: Sat Aug 28 20:51:10 UTC 2021
Modified Files: src/tests/usr.bin/xlint/lint1: lex_integer.c lex_integer.exp Log Message: tests/lint: test parsing of integer constants The previous version of this test did not focus on the integer constants but instead on conversions of function arguments. The current test covers several corner cases, such as non-decimal bases and all combinations of suffixes. This test does not cover lex_integer_constant completely since several code paths are only reachable on 32-bit target platforms. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/lex_integer.c cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/lex_integer.exp Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/usr.bin/xlint/lint1/lex_integer.c diff -u src/tests/usr.bin/xlint/lint1/lex_integer.c:1.7 src/tests/usr.bin/xlint/lint1/lex_integer.c:1.8 --- src/tests/usr.bin/xlint/lint1/lex_integer.c:1.7 Sat Aug 21 11:50:57 2021 +++ src/tests/usr.bin/xlint/lint1/lex_integer.c Sat Aug 28 20:51:10 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lex_integer.c,v 1.7 2021/08/21 11:50:57 rillig Exp $ */ +/* $NetBSD: lex_integer.c,v 1.8 2021/08/28 20:51:10 rillig Exp $ */ # 3 "lex_integer.c" /* @@ -9,60 +9,137 @@ /* lint1-only-if: lp64 */ -void sinki(int); -void sinku(unsigned int); +long signed_long; +unsigned long long unsigned_long_long_var; + +struct s { + int member; +}; +/* + * When lint tries to convert the argument to 'struct s', it prints the + * actual type of the argument as a side effect. + */ +void print_type(struct s); -/* All platforms supported by lint have 32-bit int in two's complement. */ void -test_signed_int(void) +no_suffix(void) { - sinki(0); - - sinki(-1); + /* expect+1: passing 'int' */ + print_type(0); + /* The '-' is not part of the constant, it's a unary operator. */ + /* expect+1: passing 'int' */ + print_type(-1); + /* expect+1: passing 'int' */ + print_type(2147483647); + /* expect+1: passing 'int' */ + print_type(0x7fffffff); + + /* expect+1: passing 'unsigned int' */ + print_type(0x80000000); + /* expect+1: passing 'unsigned int' */ + print_type(0xffffffff); + + /* expect+1: passing 'long' */ + print_type(2147483648); + /* expect+1: passing 'long' */ + print_type(0x0000000100000000); + /* expect+1: passing 'long' */ + print_type(0x7fffffffffffffff); + + /* expect+1: passing 'unsigned long' */ + print_type(0x8000000000000000); + /* expect+1: passing 'unsigned long' */ + print_type(0xffffffffffffffff); + + /* expect+2: warning: integer constant out of range [252] */ + /* expect+1: warning: passing 'unsigned long' */ + print_type(0x00010000000000000000); +} - sinki(2147483647); +void +suffix_u(void) +{ + /* expect+1: passing 'unsigned int' */ + print_type(3U); + /* expect+1: passing 'unsigned int' */ + print_type(3u); + + /* expect+1: passing 'unsigned int' */ + print_type(4294967295U); + /* expect+1: passing 'unsigned long' */ + print_type(4294967296U); +} - /* expect+2: converted from 'long' to 'int' due to prototype */ - /* expect+1: conversion of 'long' to 'int' is out of range */ - sinki(2147483648); +void +suffix_l(void) +{ + /* expect+1: passing 'long' */ + print_type(3L); - sinki(-2147483647); + /* expect+1: passing 'long' */ + print_type(3l); +} - /* expect+1: converted from 'long' to 'int' due to prototype */ - sinki(-2147483648); +void +suffix_ul(void) +{ + /* expect+1: passing 'unsigned long' */ + print_type(3UL); + /* expect+1: passing 'unsigned long' */ + print_type(3LU); } void -test_unsigned_int(void) +suffix_ll(void) { - sinku(0); + /* expect+1: passing 'long long' */ + print_type(3LL); - sinku(4294967295U); + /* The 'Ll' must not use mixed case. Checked by the compiler. */ + /* expect+1: passing 'long long' */ + print_type(3Ll); - /* expect+2: from 'unsigned long' to 'unsigned int' due to prototype */ - /* expect+1: conversion of 'unsigned long' to 'unsigned int' is out of range */ - sinku(4294967296U); + /* expect+1: passing 'long long' */ + print_type(3ll); } -void sinkull(unsigned long long); - void -suffixes(void) +suffix_ull(void) { - sinkull(3u); - sinkull(3ll); - sinkull(3llu); - sinkull(3Ull); + /* expect+1: passing 'unsigned long long' */ + print_type(3llu); + /* expect+1: passing 'unsigned long long' */ + print_type(3Ull); /* The 'LL' must not be split. Checked by the compiler. */ - sinkull(3lul); - /* The 'Ll' must not used mixed case. Checked by the compiler. */ - sinkull(3ULl); + /* expect+1: passing 'unsigned long long' */ + print_type(3lul); + + /* The 'Ll' must not use mixed case. Checked by the compiler. */ + /* expect+1: passing 'unsigned long long' */ + print_type(3ULl); +} + +void +suffix_too_many(void) +{ + /* expect+2: warning: malformed integer constant [251] */ + /* expect+1: passing 'long long' */ + print_type(3LLL); + + /* expect+2: warning: malformed integer constant [251] */ + /* expect+1: passing 'unsigned int' */ + print_type(3uu); } /* https://gcc.gnu.org/onlinedocs/gcc/Binary-constants.html */ void binary_literal(void) { - sinku(0b1111000001011010); + /* This is a GCC extension, but lint doesn't know that. */ + /* expect+1: passing 'int' */ + print_type(0b1111000001011010); + + /* expect+1: passing 'unsigned int' */ + print_type(0b11110000111100001111000011110000); } Index: src/tests/usr.bin/xlint/lint1/lex_integer.exp diff -u src/tests/usr.bin/xlint/lint1/lex_integer.exp:1.2 src/tests/usr.bin/xlint/lint1/lex_integer.exp:1.3 --- src/tests/usr.bin/xlint/lint1/lex_integer.exp:1.2 Sun Jun 27 10:14:43 2021 +++ src/tests/usr.bin/xlint/lint1/lex_integer.exp Sat Aug 28 20:51:10 2021 @@ -1,5 +1,34 @@ -lex_integer.c(27): warning: argument #1 is converted from 'long' to 'int' due to prototype [259] -lex_integer.c(27): warning: conversion of 'long' to 'int' is out of range, arg #1 [295] -lex_integer.c(32): warning: argument #1 is converted from 'long' to 'int' due to prototype [259] -lex_integer.c(44): warning: argument #1 is converted from 'unsigned long' to 'unsigned int' due to prototype [259] -lex_integer.c(44): warning: conversion of 'unsigned long' to 'unsigned int' is out of range, arg #1 [295] +lex_integer.c(28): warning: passing 'int' to incompatible 'struct s', arg #1 [155] +lex_integer.c(31): warning: passing 'int' to incompatible 'struct s', arg #1 [155] +lex_integer.c(33): warning: passing 'int' to incompatible 'struct s', arg #1 [155] +lex_integer.c(35): warning: passing 'int' to incompatible 'struct s', arg #1 [155] +lex_integer.c(38): warning: passing 'unsigned int' to incompatible 'struct s', arg #1 [155] +lex_integer.c(40): warning: passing 'unsigned int' to incompatible 'struct s', arg #1 [155] +lex_integer.c(43): warning: passing 'long' to incompatible 'struct s', arg #1 [155] +lex_integer.c(45): warning: passing 'long' to incompatible 'struct s', arg #1 [155] +lex_integer.c(47): warning: passing 'long' to incompatible 'struct s', arg #1 [155] +lex_integer.c(50): warning: passing 'unsigned long' to incompatible 'struct s', arg #1 [155] +lex_integer.c(52): warning: passing 'unsigned long' to incompatible 'struct s', arg #1 [155] +lex_integer.c(56): warning: integer constant out of range [252] +lex_integer.c(56): warning: passing 'unsigned long' to incompatible 'struct s', arg #1 [155] +lex_integer.c(63): warning: passing 'unsigned int' to incompatible 'struct s', arg #1 [155] +lex_integer.c(65): warning: passing 'unsigned int' to incompatible 'struct s', arg #1 [155] +lex_integer.c(68): warning: passing 'unsigned int' to incompatible 'struct s', arg #1 [155] +lex_integer.c(70): warning: passing 'unsigned long' to incompatible 'struct s', arg #1 [155] +lex_integer.c(77): warning: passing 'long' to incompatible 'struct s', arg #1 [155] +lex_integer.c(80): warning: passing 'long' to incompatible 'struct s', arg #1 [155] +lex_integer.c(87): warning: passing 'unsigned long' to incompatible 'struct s', arg #1 [155] +lex_integer.c(89): warning: passing 'unsigned long' to incompatible 'struct s', arg #1 [155] +lex_integer.c(96): warning: passing 'long long' to incompatible 'struct s', arg #1 [155] +lex_integer.c(100): warning: passing 'long long' to incompatible 'struct s', arg #1 [155] +lex_integer.c(103): warning: passing 'long long' to incompatible 'struct s', arg #1 [155] +lex_integer.c(110): warning: passing 'unsigned long long' to incompatible 'struct s', arg #1 [155] +lex_integer.c(112): warning: passing 'unsigned long long' to incompatible 'struct s', arg #1 [155] +lex_integer.c(116): warning: passing 'unsigned long long' to incompatible 'struct s', arg #1 [155] +lex_integer.c(120): warning: passing 'unsigned long long' to incompatible 'struct s', arg #1 [155] +lex_integer.c(128): warning: malformed integer constant [251] +lex_integer.c(128): warning: passing 'long long' to incompatible 'struct s', arg #1 [155] +lex_integer.c(132): warning: malformed integer constant [251] +lex_integer.c(132): warning: passing 'unsigned int' to incompatible 'struct s', arg #1 [155] +lex_integer.c(141): warning: passing 'int' to incompatible 'struct s', arg #1 [155] +lex_integer.c(144): warning: passing 'unsigned int' to incompatible 'struct s', arg #1 [155]