Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/usr.bin/xlint/lint1 tests/lint: test parsing of intege...
details: https://anonhg.NetBSD.org/src/rev/d4c4f354a41a
branches: trunk
changeset: 1023186:d4c4f354a41a
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Aug 28 20:51:10 2021 +0000
description:
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.
diffstat:
tests/usr.bin/xlint/lint1/lex_integer.c | 143 +++++++++++++++++++++++------
tests/usr.bin/xlint/lint1/lex_integer.exp | 39 +++++++-
2 files changed, 144 insertions(+), 38 deletions(-)
diffs (222 lines):
diff -r d6859ca01188 -r d4c4f354a41a tests/usr.bin/xlint/lint1/lex_integer.c
--- a/tests/usr.bin/xlint/lint1/lex_integer.c Sat Aug 28 19:49:28 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/lex_integer.c Sat Aug 28 20:51:10 2021 +0000
@@ -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;
-/* All platforms supported by lint have 32-bit int in two's complement. */
-void
-test_signed_int(void)
-{
- sinki(0);
-
- sinki(-1);
+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);
- sinki(2147483647);
+void
+no_suffix(void)
+{
+ /* 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+2: converted from 'long' to 'int' due to prototype */
- /* expect+1: conversion of 'long' to 'int' is out of range */
- sinki(2147483648);
+ /* expect+1: passing 'unsigned int' */
+ print_type(0x80000000);
+ /* expect+1: passing 'unsigned int' */
+ print_type(0xffffffff);
- sinki(-2147483647);
+ /* expect+1: passing 'long' */
+ print_type(2147483648);
+ /* expect+1: passing 'long' */
+ print_type(0x0000000100000000);
+ /* expect+1: passing 'long' */
+ print_type(0x7fffffffffffffff);
- /* expect+1: converted from 'long' to 'int' due to prototype */
- sinki(-2147483648);
+ /* 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);
}
void
-test_unsigned_int(void)
+suffix_u(void)
{
- sinku(0);
+ /* 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);
+}
- sinku(4294967295U);
+void
+suffix_l(void)
+{
+ /* expect+1: passing 'long' */
+ print_type(3L);
- /* 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' */
+ print_type(3l);
+}
+
+void
+suffix_ul(void)
+{
+ /* expect+1: passing 'unsigned long' */
+ print_type(3UL);
+ /* expect+1: passing 'unsigned long' */
+ print_type(3LU);
}
-void sinkull(unsigned long long);
+void
+suffix_ll(void)
+{
+ /* expect+1: passing 'long long' */
+ print_type(3LL);
+
+ /* The 'Ll' must not use mixed case. Checked by the compiler. */
+ /* expect+1: passing 'long long' */
+ print_type(3Ll);
+
+ /* expect+1: passing 'long long' */
+ print_type(3ll);
+}
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);
}
diff -r d6859ca01188 -r d4c4f354a41a tests/usr.bin/xlint/lint1/lex_integer.exp
--- a/tests/usr.bin/xlint/lint1/lex_integer.exp Sat Aug 28 19:49:28 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/lex_integer.exp Sat Aug 28 20:51:10 2021 +0000
@@ -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]
Home |
Main Index |
Thread Index |
Old Index