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: demonstrate wrong erro...
details: https://anonhg.NetBSD.org/src/rev/98ea0105530d
branches: trunk
changeset: 366534:98ea0105530d
user: rillig <rillig%NetBSD.org@localhost>
date: Sun May 29 23:09:43 2022 +0000
description:
tests/lint: demonstrate wrong errors 'size/alignment of bit-field'
Since tree.c 1.444 from 2022-05-26, which added range and bit checks for
integer expressions, not taking into account that querying for the size
of a bit-field type triggers an error message.
diffstat:
tests/usr.bin/xlint/lint1/msg_132.c | 47 ++++++++++++++++++++++++++++++++++-
tests/usr.bin/xlint/lint1/msg_132.exp | 26 +++++++++++++++++++
2 files changed, 72 insertions(+), 1 deletions(-)
diffs (91 lines):
diff -r cbc9e75605ec -r 98ea0105530d tests/usr.bin/xlint/lint1/msg_132.c
--- a/tests/usr.bin/xlint/lint1/msg_132.c Sun May 29 22:26:21 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_132.c Sun May 29 23:09:43 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_132.c,v 1.13 2022/05/26 20:17:40 rillig Exp $ */
+/* $NetBSD: msg_132.c,v 1.14 2022/05/29 23:09:43 rillig Exp $ */
# 3 "msg_132.c"
// Test for message: conversion from '%s' to '%s' may lose accuracy [132]
@@ -194,3 +194,48 @@
/* expect+1: warning: conversion from 'unsigned long long' to 'unsigned int' may lose accuracy [132] */
return x;
}
+
+
+struct bit_fields {
+ unsigned bits_32: 32;
+ unsigned bits_5: 5;
+ unsigned bits_3: 3;
+};
+
+unsigned char
+test_bit_fields(struct bit_fields s, unsigned long m)
+{
+ /* expect+4: error: cannot take size/alignment of bit-field [145] */
+ /* expect+3: error: cannot take size/alignment of bit-field [145] */
+ /* expect+2: error: cannot take size/alignment of bit-field [145] */
+ /* expect+1: error: cannot take size/alignment of bit-field [145] */
+ s.bits_3 = s.bits_32 & m;
+
+ /* expect+9: error: cannot take size/alignment of bit-field [145] */
+ /* expect+8: error: cannot take size/alignment of bit-field [145] */
+ /* expect+7: error: cannot take size/alignment of bit-field [145] */
+ /* expect+6: error: cannot take size/alignment of bit-field [145] */
+ /* expect+5: error: cannot take size/alignment of bit-field [145] */
+ /* expect+4: error: cannot take size/alignment of bit-field [145] */
+ /* expect+3: error: cannot take size/alignment of bit-field [145] */
+ /* expect+2: error: cannot take size/alignment of bit-field [145] */
+ /* expect+1: warning: conversion from 'unsigned long' to 'unsigned int' may lose accuracy [132] */
+ s.bits_5 = s.bits_3 & m;
+
+ /* expect+9: error: cannot take size/alignment of bit-field [145] */
+ /* expect+8: error: cannot take size/alignment of bit-field [145] */
+ /* expect+7: error: cannot take size/alignment of bit-field [145] */
+ /* expect+6: error: cannot take size/alignment of bit-field [145] */
+ /* expect+5: error: cannot take size/alignment of bit-field [145] */
+ /* expect+4: error: cannot take size/alignment of bit-field [145] */
+ /* expect+3: error: cannot take size/alignment of bit-field [145] */
+ /* expect+2: error: cannot take size/alignment of bit-field [145] */
+ /* expect+1: warning: conversion from 'unsigned long' to 'unsigned int' may lose accuracy [132] */
+ s.bits_32 = s.bits_5 & m;
+
+ /* expect+4: error: cannot take size/alignment of bit-field [145] */
+ /* expect+3: error: cannot take size/alignment of bit-field [145] */
+ /* expect+2: error: cannot take size/alignment of bit-field [145] */
+ /* expect+1: warning: conversion from 'unsigned long' to 'unsigned char' may lose accuracy [132] */
+ return s.bits_32 & m;
+}
diff -r cbc9e75605ec -r 98ea0105530d tests/usr.bin/xlint/lint1/msg_132.exp
--- a/tests/usr.bin/xlint/lint1/msg_132.exp Sun May 29 22:26:21 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_132.exp Sun May 29 23:09:43 2022 +0000
@@ -27,3 +27,29 @@
msg_132.c(141): warning: conversion from 'unsigned long long' to 'int' may lose accuracy [132]
msg_132.c(193): warning: conversion from 'unsigned long long' to 'unsigned int' may lose accuracy [132]
msg_132.c(195): warning: conversion from 'unsigned long long' to 'unsigned int' may lose accuracy [132]
+msg_132.c(212): error: cannot take size/alignment of bit-field [145]
+msg_132.c(212): error: cannot take size/alignment of bit-field [145]
+msg_132.c(212): error: cannot take size/alignment of bit-field [145]
+msg_132.c(212): error: cannot take size/alignment of bit-field [145]
+msg_132.c(223): error: cannot take size/alignment of bit-field [145]
+msg_132.c(223): error: cannot take size/alignment of bit-field [145]
+msg_132.c(223): error: cannot take size/alignment of bit-field [145]
+msg_132.c(223): error: cannot take size/alignment of bit-field [145]
+msg_132.c(223): error: cannot take size/alignment of bit-field [145]
+msg_132.c(223): error: cannot take size/alignment of bit-field [145]
+msg_132.c(223): error: cannot take size/alignment of bit-field [145]
+msg_132.c(223): error: cannot take size/alignment of bit-field [145]
+msg_132.c(223): warning: conversion from 'unsigned long' to 'unsigned int' may lose accuracy [132]
+msg_132.c(234): error: cannot take size/alignment of bit-field [145]
+msg_132.c(234): error: cannot take size/alignment of bit-field [145]
+msg_132.c(234): error: cannot take size/alignment of bit-field [145]
+msg_132.c(234): error: cannot take size/alignment of bit-field [145]
+msg_132.c(234): error: cannot take size/alignment of bit-field [145]
+msg_132.c(234): error: cannot take size/alignment of bit-field [145]
+msg_132.c(234): error: cannot take size/alignment of bit-field [145]
+msg_132.c(234): error: cannot take size/alignment of bit-field [145]
+msg_132.c(234): warning: conversion from 'unsigned long' to 'unsigned int' may lose accuracy [132]
+msg_132.c(240): error: cannot take size/alignment of bit-field [145]
+msg_132.c(240): error: cannot take size/alignment of bit-field [145]
+msg_132.c(240): error: cannot take size/alignment of bit-field [145]
+msg_132.c(240): warning: conversion from 'unsigned long' to 'unsigned char' may lose accuracy [132]
Home |
Main Index |
Thread Index |
Old Index