Module Name: src Committed By: rillig Date: Sat Mar 9 17:34:01 UTC 2024
Modified Files: src/tests/usr.bin/xlint/lint1: platform_ilp32_int.c platform_ilp32_long.c platform_lp64.c Log Message: tests/lint: demonstrate integer overflow on lp64 platforms To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/platform_lp64.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_ilp32_int.c diff -u src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c:1.3 src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c:1.4 --- src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c:1.3 Sat Mar 9 16:47:09 2024 +++ src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c Sat Mar 9 17:34:01 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: platform_ilp32_int.c,v 1.3 2024/03/09 16:47:09 rillig Exp $ */ +/* $NetBSD: platform_ilp32_int.c,v 1.4 2024/03/09 17:34:01 rillig Exp $ */ # 3 "platform_ilp32_int.c" /* @@ -28,24 +28,75 @@ convert_between_int_and_long(void) ul32 = u32; } -char ch; +unsigned char u8; +unsigned long long u64; +unsigned char u8_buf[20]; +unsigned long long u64_buf[20]; void array_index(void) { - static char buf[20]; + /* expect+1: warning: array subscript cannot be > 19: 16777215 [168] */ + u8 += u8_buf[0x00ffffff]; /* expect+1: warning: array subscript cannot be > 19: 2147483647 [168] */ - ch += buf[2147483647]; + u8 += u8_buf[0x7fffffff]; /* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */ /* expect+1: warning: array subscript cannot be negative: -2147483648 [167] */ - ch += buf[2147483648]; + u8 += u8_buf[2147483648]; /* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */ /* expect+1: warning: array subscript cannot be negative: -2147483648 [167] */ - ch += buf[0x80000000]; + u8 += u8_buf[0x80000000]; /* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */ /* expect+1: warning: array subscript cannot be negative: -1 [167] */ - ch += buf[0xffffffff]; + u8 += u8_buf[0xffffffff]; + /* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */ + /* expect+1: warning: array subscript cannot be negative: -2147483648 [167] */ + u8 += u8_buf[0x80000000]; + /* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */ + /* expect+1: warning: array subscript cannot be negative: -1 [167] */ + u8 += u8_buf[0xffffffff]; + /* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */ + /* expect+1: warning: array subscript cannot be negative: -1 [167] */ + u8 += u8_buf[0x00ffffffffffffff]; + /* expect+1: warning: array subscript cannot be negative: -1 [167] */ + u8 += u8_buf[0xffffffffffffffff]; + + /* expect+1: warning: array subscript cannot be > 19: 16777215 [168] */ + u64 += u64_buf[0x00ffffff]; + /* expect+2: warning: operator '*' produces integer overflow [141] */ + /* expect+1: warning: array subscript cannot be negative: -1 [167] */ + u64 += u64_buf[0x7fffffff]; + /* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */ + /* expect+1: warning: operator '*' produces integer overflow [141] */ + u64 += u64_buf[2147483648]; + /* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */ + /* expect+1: warning: operator '*' produces integer overflow [141] */ + u64 += u64_buf[0x80000000]; + /* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */ + /* expect+1: warning: array subscript cannot be negative: -1 [167] */ + u64 += u64_buf[0xffffffff]; + /* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */ + /* expect+1: warning: operator '*' produces integer overflow [141] */ + u64 += u64_buf[0x80000000]; + /* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */ + /* expect+1: warning: array subscript cannot be negative: -1 [167] */ + u64 += u64_buf[0xffffffff]; + /* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */ + /* expect+1: warning: array subscript cannot be negative: -1 [167] */ + u64 += u64_buf[0x00ffffffffffffff]; + /* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */ + /* expect+1: warning: array subscript cannot be negative: -1 [167] */ + u64 += u64_buf[0x0fffffffffffffff]; + /* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */ + /* expect+1: warning: array subscript cannot be negative: -1 [167] */ + u64 += u64_buf[0x1fffffffffffffff]; + /* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */ + /* expect+1: warning: array subscript cannot be negative: -1 [167] */ + u64 += u64_buf[0x3fffffffffffffff]; + /* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */ + /* expect+1: warning: array subscript cannot be negative: -1 [167] */ + u64 += u64_buf[0x7fffffffffffffff]; /* expect+1: warning: array subscript cannot be negative: -1 [167] */ - ch += buf[0xffffffffffffffff]; + u64 += u64_buf[0xffffffffffffffff]; } Index: src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c diff -u src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c:1.5 src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c:1.6 --- src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c:1.5 Sat Mar 9 16:47:09 2024 +++ src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c Sat Mar 9 17:34:01 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: platform_ilp32_long.c,v 1.5 2024/03/09 16:47:09 rillig Exp $ */ +/* $NetBSD: platform_ilp32_long.c,v 1.6 2024/03/09 17:34:01 rillig Exp $ */ # 3 "platform_ilp32_long.c" /* @@ -37,24 +37,75 @@ convert_between_int_and_long(void) ul32 = u32; } -char ch; +unsigned char u8; +unsigned long long u64; +unsigned char u8_buf[20]; +unsigned long long u64_buf[20]; void array_index(void) { - static char buf[20]; + /* expect+1: warning: array subscript cannot be > 19: 16777215 [168] */ + u8 += u8_buf[0x00ffffff]; /* expect+1: warning: array subscript cannot be > 19: 2147483647 [168] */ - ch += buf[2147483647]; + u8 += u8_buf[0x7fffffff]; /* expect+2: warning: conversion of 'long long' to 'long' is out of range [119] */ /* expect+1: warning: array subscript cannot be negative: -2147483648 [167] */ - ch += buf[2147483648]; + u8 += u8_buf[2147483648]; /* expect+2: warning: conversion of 'unsigned int' to 'long' is out of range [119] */ /* expect+1: warning: array subscript cannot be negative: -2147483648 [167] */ - ch += buf[0x80000000]; + u8 += u8_buf[0x80000000]; /* expect+2: warning: conversion of 'unsigned int' to 'long' is out of range [119] */ /* expect+1: warning: array subscript cannot be negative: -1 [167] */ - ch += buf[0xffffffff]; + u8 += u8_buf[0xffffffff]; + /* expect+2: warning: conversion of 'unsigned int' to 'long' is out of range [119] */ + /* expect+1: warning: array subscript cannot be negative: -2147483648 [167] */ + u8 += u8_buf[0x80000000]; + /* expect+2: warning: conversion of 'unsigned int' to 'long' is out of range [119] */ + /* expect+1: warning: array subscript cannot be negative: -1 [167] */ + u8 += u8_buf[0xffffffff]; + /* expect+2: warning: conversion of 'long long' to 'long' is out of range [119] */ + /* expect+1: warning: array subscript cannot be negative: -1 [167] */ + u8 += u8_buf[0x00ffffffffffffff]; + /* expect+1: warning: array subscript cannot be negative: -1 [167] */ + u8 += u8_buf[0xffffffffffffffff]; + + /* expect+1: warning: array subscript cannot be > 19: 16777215 [168] */ + u64 += u64_buf[0x00ffffff]; + /* expect+2: warning: operator '*' produces integer overflow [141] */ + /* expect+1: warning: array subscript cannot be negative: -1 [167] */ + u64 += u64_buf[0x7fffffff]; + /* expect+2: warning: conversion of 'long long' to 'long' is out of range [119] */ + /* expect+1: warning: operator '*' produces integer overflow [141] */ + u64 += u64_buf[2147483648]; + /* expect+2: warning: conversion of 'unsigned int' to 'long' is out of range [119] */ + /* expect+1: warning: operator '*' produces integer overflow [141] */ + u64 += u64_buf[0x80000000]; + /* expect+2: warning: conversion of 'unsigned int' to 'long' is out of range [119] */ + /* expect+1: warning: array subscript cannot be negative: -1 [167] */ + u64 += u64_buf[0xffffffff]; + /* expect+2: warning: conversion of 'unsigned int' to 'long' is out of range [119] */ + /* expect+1: warning: operator '*' produces integer overflow [141] */ + u64 += u64_buf[0x80000000]; + /* expect+2: warning: conversion of 'unsigned int' to 'long' is out of range [119] */ + /* expect+1: warning: array subscript cannot be negative: -1 [167] */ + u64 += u64_buf[0xffffffff]; + /* expect+2: warning: conversion of 'long long' to 'long' is out of range [119] */ + /* expect+1: warning: array subscript cannot be negative: -1 [167] */ + u64 += u64_buf[0x00ffffffffffffff]; + /* expect+2: warning: conversion of 'long long' to 'long' is out of range [119] */ + /* expect+1: warning: array subscript cannot be negative: -1 [167] */ + u64 += u64_buf[0x0fffffffffffffff]; + /* expect+2: warning: conversion of 'long long' to 'long' is out of range [119] */ + /* expect+1: warning: array subscript cannot be negative: -1 [167] */ + u64 += u64_buf[0x1fffffffffffffff]; + /* expect+2: warning: conversion of 'long long' to 'long' is out of range [119] */ + /* expect+1: warning: array subscript cannot be negative: -1 [167] */ + u64 += u64_buf[0x3fffffffffffffff]; + /* expect+2: warning: conversion of 'long long' to 'long' is out of range [119] */ + /* expect+1: warning: array subscript cannot be negative: -1 [167] */ + u64 += u64_buf[0x7fffffffffffffff]; /* expect+1: warning: array subscript cannot be negative: -1 [167] */ - ch += buf[0xffffffffffffffff]; + u64 += u64_buf[0xffffffffffffffff]; } Index: src/tests/usr.bin/xlint/lint1/platform_lp64.c diff -u src/tests/usr.bin/xlint/lint1/platform_lp64.c:1.8 src/tests/usr.bin/xlint/lint1/platform_lp64.c:1.9 --- src/tests/usr.bin/xlint/lint1/platform_lp64.c:1.8 Sat Mar 9 16:47:09 2024 +++ src/tests/usr.bin/xlint/lint1/platform_lp64.c Sat Mar 9 17:34:01 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: platform_lp64.c,v 1.8 2024/03/09 16:47:09 rillig Exp $ */ +/* $NetBSD: platform_lp64.c,v 1.9 2024/03/09 17:34:01 rillig Exp $ */ # 3 "platform_lp64.c" /* @@ -45,21 +45,58 @@ convert_128(void) u32 = u128; } -char ch; +unsigned char u8; +unsigned long long u64; +unsigned char u8_buf[20]; +unsigned long long u64_buf[20]; void array_index(void) { - static char buf[20]; + /* expect+1: warning: array subscript cannot be > 19: 16777215 [168] */ + u8 += u8_buf[0x00ffffff]; /* expect+1: warning: array subscript cannot be > 19: 2147483647 [168] */ - ch += buf[2147483647]; + u8 += u8_buf[0x7fffffff]; /* expect+1: warning: array subscript cannot be > 19: 2147483648 [168] */ - ch += buf[2147483648]; + u8 += u8_buf[2147483648]; /* expect+1: warning: array subscript cannot be > 19: 2147483648 [168] */ - ch += buf[0x80000000]; + u8 += u8_buf[0x80000000]; /* expect+1: warning: array subscript cannot be > 19: 4294967295 [168] */ - ch += buf[0xffffffff]; + u8 += u8_buf[0xffffffff]; + /* expect+1: warning: array subscript cannot be > 19: 2147483648 [168] */ + u8 += u8_buf[0x80000000]; + /* expect+1: warning: array subscript cannot be > 19: 4294967295 [168] */ + u8 += u8_buf[0xffffffff]; + /* expect+1: warning: array subscript cannot be > 19: 72057594037927935 [168] */ + u8 += u8_buf[0x00ffffffffffffff]; + /* expect+1: warning: array subscript cannot be negative: -1 [167] */ + u8 += u8_buf[0xffffffffffffffff]; + + /* expect+1: warning: array subscript cannot be > 19: 16777215 [168] */ + u64 += u64_buf[0x00ffffff]; + /* expect+1: warning: array subscript cannot be > 19: 2147483647 [168] */ + u64 += u64_buf[0x7fffffff]; + /* expect+1: warning: array subscript cannot be > 19: 2147483648 [168] */ + u64 += u64_buf[2147483648]; + /* expect+1: warning: array subscript cannot be > 19: 2147483648 [168] */ + u64 += u64_buf[0x80000000]; + /* expect+1: warning: array subscript cannot be > 19: 4294967295 [168] */ + u64 += u64_buf[0xffffffff]; + /* expect+1: warning: array subscript cannot be > 19: 2147483648 [168] */ + u64 += u64_buf[0x80000000]; + /* expect+1: warning: array subscript cannot be > 19: 4294967295 [168] */ + u64 += u64_buf[0xffffffff]; + /* expect+1: warning: array subscript cannot be > 19: 72057594037927935 [168] */ + u64 += u64_buf[0x00ffffffffffffff]; + /* expect+1: warning: array subscript cannot be > 19: 1152921504606846975 [168] */ + u64 += u64_buf[0x0fffffffffffffff]; + // FIXME: integer overflow + //u64 += u64_buf[0x1fffffffffffffff]; + // FIXME: integer overflow + //u64 += u64_buf[0x3fffffffffffffff]; + // FIXME: integer overflow + //u64 += u64_buf[0x7fffffffffffffff]; /* expect+1: warning: array subscript cannot be negative: -1 [167] */ - ch += buf[0xffffffffffffffff]; + u64 += u64_buf[0xffffffffffffffff]; }