Module Name: src
Committed By: rillig
Date: Wed Feb 7 07:42:50 UTC 2024
Modified Files:
src/tests/usr.bin/xlint/lint1: platform_lp64_trad.c
src/usr.bin/xlint/lint1: lex.c
Log Message:
lint: unify rules for determining the type of an integer constant
Previously, in traditional C mode, large decimal numbers were treated as
unsigned, which disagreed with the book from 1978.
To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/platform_lp64_trad.c
cvs rdiff -u -r1.213 -r1.214 src/usr.bin/xlint/lint1/lex.c
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/platform_lp64_trad.c
diff -u src/tests/usr.bin/xlint/lint1/platform_lp64_trad.c:1.3 src/tests/usr.bin/xlint/lint1/platform_lp64_trad.c:1.4
--- src/tests/usr.bin/xlint/lint1/platform_lp64_trad.c:1.3 Sun Jan 28 08:17:27 2024
+++ src/tests/usr.bin/xlint/lint1/platform_lp64_trad.c Wed Feb 7 07:42:50 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: platform_lp64_trad.c,v 1.3 2024/01/28 08:17:27 rillig Exp $ */
+/* $NetBSD: platform_lp64_trad.c,v 1.4 2024/02/07 07:42:50 rillig Exp $ */
# 3 "platform_lp64_trad.c"
/*
@@ -29,10 +29,12 @@ void *lex_integer[] = {
9223372036854775807,
/* expect+1: ... integer 'long' ... */
0x7fffffffffffffff,
+ /* expect+2: warning: integer constant out of range [252] */
/* expect+1: ... integer 'long' ... */
9223372036854775808,
/* expect+1: ... integer 'long' ... */
0x8000000000000000,
+ /* expect+2: warning: integer constant out of range [252] */
/* expect+1: ... integer 'long' ... */
18446744073709551615,
/* expect+1: ... integer 'long' ... */
Index: src/usr.bin/xlint/lint1/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.213 src/usr.bin/xlint/lint1/lex.c:1.214
--- src/usr.bin/xlint/lint1/lex.c:1.213 Sat Feb 3 20:10:10 2024
+++ src/usr.bin/xlint/lint1/lex.c Wed Feb 7 07:42:50 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.213 2024/02/03 20:10:10 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.214 2024/02/07 07:42:50 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: lex.c,v 1.213 2024/02/03 20:10:10 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.214 2024/02/07 07:42:50 rillig Exp $");
#endif
#include <ctype.h>
@@ -508,41 +508,7 @@ integer_constant_type(tspec_t t, uint64_
return UINT;
if (ui <= TARG_LONG_MAX)
return LONG;
- if (ui <= TARG_ULONG_MAX && base != 10 && allow_c90)
- return ULONG;
- if (ui <= TARG_ULONG_MAX && !allow_c90)
- return LONG;
- if (!allow_c99) {
- if (!warned)
- /* integer constant out of range */
- warning(252);
- return allow_c90 ? ULONG : LONG;
- }
- if (ui <= TARG_LLONG_MAX)
- return LLONG;
- if (ui <= TARG_ULLONG_MAX && base != 10)
- return ULLONG;
- if (!warned)
- /* integer constant out of range */
- warning(252);
- return ULLONG;
- case UINT:
- if (ui <= TARG_UINT_MAX)
- return UINT;
- if (ui <= TARG_ULONG_MAX)
- return ULONG;
- if (!allow_c99) {
- if (!warned)
- /* integer constant out of range */
- warning(252);
- return ULONG;
- }
- if (ui <= TARG_ULLONG_MAX)
- return ULLONG;
- if (!warned)
- /* integer constant out of range */
- warning(252);
- return ULLONG;
+ /* FALLTHROUGH */
case LONG:
if (ui <= TARG_LONG_MAX)
return LONG;
@@ -554,14 +520,20 @@ integer_constant_type(tspec_t t, uint64_
warning(252);
return allow_c90 ? ULONG : LONG;
}
+ /* FALLTHROUGH */
+ case LLONG:
if (ui <= TARG_LLONG_MAX)
return LLONG;
if (ui <= TARG_ULLONG_MAX && base != 10)
- return ULLONG;
+ return allow_c90 ? ULLONG : LLONG;
if (!warned)
/* integer constant out of range */
warning(252);
- return ULLONG;
+ return allow_c90 ? ULLONG : LLONG;
+ case UINT:
+ if (ui <= TARG_UINT_MAX)
+ return UINT;
+ /* FALLTHROUGH */
case ULONG:
if (ui <= TARG_ULONG_MAX)
return ULONG;
@@ -571,21 +543,7 @@ integer_constant_type(tspec_t t, uint64_
warning(252);
return ULONG;
}
- if (ui <= TARG_ULLONG_MAX)
- return ULLONG;
- if (!warned)
- /* integer constant out of range */
- warning(252);
- return ULLONG;
- case LLONG:
- if (ui <= TARG_LLONG_MAX)
- return LLONG;
- if (ui <= TARG_ULLONG_MAX && base != 10)
- return allow_c90 ? ULLONG : LLONG;
- if (!warned)
- /* integer constant out of range */
- warning(252);
- return allow_c90 ? ULLONG : LLONG;
+ /* FALLTHROUGH */
default:
if (ui <= TARG_ULLONG_MAX)
return ULLONG;