Module Name: src Committed By: rillig Date: Sun Dec 15 07:43:53 UTC 2024
Modified Files: src/tests/usr.bin/xlint/lint1: msg_222.c Log Message: tests/lint: test negative constant and unsigned type for all operators To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/msg_222.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/msg_222.c diff -u src/tests/usr.bin/xlint/lint1/msg_222.c:1.7 src/tests/usr.bin/xlint/lint1/msg_222.c:1.8 --- src/tests/usr.bin/xlint/lint1/msg_222.c:1.7 Sun Dec 15 05:56:18 2024 +++ src/tests/usr.bin/xlint/lint1/msg_222.c Sun Dec 15 07:43:53 2024 @@ -1,43 +1,105 @@ -/* $NetBSD: msg_222.c,v 1.7 2024/12/15 05:56:18 rillig Exp $ */ +/* $NetBSD: msg_222.c,v 1.8 2024/12/15 07:43:53 rillig Exp $ */ # 3 "msg_222.c" // Test for message: conversion of negative constant %lld to unsigned type '%s' [222] +// +// See also: +// msg_162.c: comparison of unsigned type with negative constant +// msg_164.c: assignment of negative constant to unsigned type +// msg_221.c: initialization of unsigned type with negative constant +// msg_296.c: conversion of negative constant to unsigned type in call /* lint1-extra-flags: -X 351 */ -/* expect+1: warning: initialization of unsigned type 'unsigned int' with negative constant -1 [221] */ -unsigned int global = -1; +unsigned int u32; +signed char sc; +unsigned char uc; +_Bool b; -void take_unsigned_int(unsigned int); void -function(signed char *scp, unsigned char *ucp) +convert_negative_constant(void) { - /* expect+1: warning: initialization of unsigned type 'unsigned int' with negative constant -1 [221] */ - unsigned int local = -1; - - /* expect+1: warning: conversion of negative constant -1 to unsigned type 'unsigned int', arg #1 [296] */ - take_unsigned_int(-1); - - if (local & -1) - return; + u32 = !-8; + u32 = ~-8; + /* expect+1: warning: assignment of negative constant -8 to unsigned type 'unsigned int' [164] */ + u32 = +-8; + u32 = - -8; + + /* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */ + u32 = u32 * -8; + /* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */ + u32 = -8 * u32; + /* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */ + u32 = u32 / -8; + /* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */ + u32 = -8 / u32; + /* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */ + u32 = u32 % -8; + /* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */ + u32 = -8 / u32; + /* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */ + u32 = u32 + -8; + /* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */ + u32 = -8 + u32; + /* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */ + u32 = u32 - -8; + /* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */ + u32 = -8 - u32; + /* expect+1: warning: negative shift [121] */ + u32 = u32 << -8; + u32 = -8 << u32; + /* expect+1: warning: negative shift [121] */ + u32 = u32 >> -8; + u32 = -8 >> u32; /* expect+1: warning: operator '<' compares 'unsigned int' with 'negative constant' [162] */ - if (local < -1) - return; - - local &= -1; - - /* expect+1: warning: conversion of negative constant -1 to unsigned type 'unsigned int' [222] */ - local += -1; + b = u32 < -8; + /* expect+1: warning: operator '<=' compares 'unsigned int' with 'negative constant' [162] */ + b = u32 <= -8; + /* expect+1: warning: operator '>' compares 'unsigned int' with 'negative constant' [162] */ + b = u32 > -8; + /* expect+1: warning: operator '>=' compares 'unsigned int' with 'negative constant' [162] */ + b = u32 >= -8; + /* expect+1: warning: operator '==' compares 'unsigned int' with 'negative constant' [162] */ + b = u32 == -8; + /* expect+1: warning: operator '!=' compares 'unsigned int' with 'negative constant' [162] */ + b = u32 != -8; + + u32 = u32 & -8; + u32 = u32 ^ -8; + u32 = u32 | -8; + b = u32 && -8; + b = u32 || -8; + + /* expect+1: warning: assignment of negative constant -8 to unsigned type 'unsigned int' [164] */ + u32 = -8; + /* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */ + u32 *= -8; + /* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */ + u32 /= -8; + /* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */ + u32 %= -8; + /* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */ + u32 += -8; + /* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */ + u32 -= -8; + // XXX: missing 'negative shift' warning + u32 <<= -8; + // XXX: missing 'negative shift' warning + u32 >>= -8; + u32 &= -8; + /* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */ + u32 ^= -8; + u32 |= -8; - *scp += 'A' - 'a'; - *scp -= 'A' - 'a'; + sc += 'A' - 'a'; + sc -= 'A' - 'a'; // XXX: It's perfectly fine to effectively subtract a constant from // XXX: an unsigned type. /* expect+1: warning: conversion of negative constant -32 to unsigned type 'unsigned char' [222] */ - *ucp += 'A' - 'a'; + uc += 'A' - 'a'; /* expect+1: warning: conversion of negative constant -32 to unsigned type 'unsigned char' [222] */ - *ucp -= 'A' - 'a'; + uc -= 'A' - 'a'; }