/*
* On ILP32 platforms, the integer constant 2147483648 cannot be represented
* as 'int' or 'long', therefore it becomes 'long long'. This would
* influence the type names in the diagnostics.
*/
/* lint1-only-if: lp64 */
/*
* C99 6.4.4.1p5 defines that decimal integer constants without suffix get
* one of the signed integer types. On the other hand, octal and hexadecimal
* constants get either a signed or unsigned type, whichever fits first.
*/
void
fold_uplus(void)
{
take_int(+(0));
take_int(+(2147483647));
/* expect+1: warning: conversion of 'long' to 'int' is out of range, arg #1 [295] */
take_int(+(2147483648));
/* expect+1: warning: conversion of 'long' to 'int' is out of range, arg #1 [295] */
take_int(+(4294967295));
/*
* Hexadecimal constants and constants with the suffix 'U' get either
* a signed or an unsigned integer type, so no warning here.
*/
take_uint(+(2147483648U));
take_uint(+(0x80000000));
take_uint(+(0x80000000U));
}
/* The '-' is an operator, it is not part of the integer constant. */
take_int(-2147483648);
/* expect+1: warning: '2147483647 + 1' overflows 'int' [141] */
take_int(-(2147483647 + 1));
/* expect+1: warning: '-(-2147483648)' overflows 'int' [141] */
take_int(-(-2147483647 - 1));
/* expect+1: warning: conversion of 'long' to 'int' is out of range, arg #1 [295] */
take_int(-(4294967295));
take_uint(-(0));
/* expect+1: warning: conversion of negative constant -2147483647 to unsigned type 'unsigned int', arg #1 [296] */
take_uint(-(2147483647));
/* expect+1: warning: conversion of negative constant -2147483648 to unsigned type 'unsigned int', arg #1 [296] */
take_uint(-(2147483648));
/* expect+1: warning: conversion of negative constant -4294967295 to unsigned type 'unsigned int', arg #1 [296] */
take_uint(-(4294967295));
}
void
fold_compl(void)
{
take_int(~(0));
take_int(~(2147483647));
/* expect+1: warning: conversion of 'long' to 'int' is out of range, arg #1 [295] */
take_int(~(2147483648));
/* expect+1: warning: conversion of 'long' to 'int' is out of range, arg #1 [295] */
take_int(~(4294967295));
/* expect+1: warning: conversion of negative constant -1 to unsigned type 'unsigned int', arg #1 [296] */
take_uint(~(0));
/* expect+1: warning: conversion of negative constant -2147483648 to unsigned type 'unsigned int', arg #1 [296] */
take_uint(~(2147483647));
/* expect+1: warning: conversion of negative constant -2147483649 to unsigned type 'unsigned int', arg #1 [296] */
take_uint(~(2147483648));
/* expect+1: warning: conversion of negative constant -4294967296 to unsigned type 'unsigned int', arg #1 [296] */
take_uint(~(4294967295));
}
/*
* No overflow since one of the operands is unsigned, therefore the
* other operand is converted to unsigned as well.
* See C99 6.3.1.8p1, paragraph 8 of 10.
*/
/* wrong integer overflow warning before tree.c 1.338 from 2021-08-19 */
take_uint(2147483647 + 1U);
/* wrong integer overflow warning before tree.c 1.338 from 2021-08-19 */
take_uint(2147483647U + 1);
}
/*
* The following expression originated in vndcompress.c 1.29 from 2017-07-29,
* where line 310 contained a seemingly harmless compile-time assertion that
* expanded to a real monster expression.
*
* __CTASSERT(MUL_OK(uint64_t, MAX_N_BLOCKS, MAX_BLOCKSIZE));
*
* Before tree.c 1.345 from 2021-08-22, lint wrongly assumed that the result
* of all binary operators were the common arithmetic type, but that was
* wrong for the comparison operators. The expression '1ULL < 2ULL' does not
* have type 'unsigned long long' but 'int' in default mode, or '_Bool' in
* strict bool mode.
*/
struct ctassert5_struct {
unsigned int member:
0xfffffffeU
<=
((1ULL << 63) + 1 < 1 ? ~(1ULL << 63) : ~0ULL) / 0xfffffe00U
? 1
: -1;
};
/*
* Since Makefile.inc 1.21 from 2022-04-08 (which added -ftrapv) and before
* tree.c 1.436 from 2022-04-20, lint crashed with an integer overflow when
* calculating '-(uint64_t)INT64_MIN' in val_t.u.integer.
*/
void
unary_minus_overflow(unsigned long long val)
{
if (val > -(unsigned long long)(-0x7fffffffffffffffL - 1))
return;
}