Module Name:    src
Committed By:   rillig
Date:           Sun May 29 23:09:43 UTC 2022

Modified Files:
        src/tests/usr.bin/xlint/lint1: msg_132.c msg_132.exp

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/tests/usr.bin/xlint/lint1/msg_132.c
cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/xlint/lint1/msg_132.exp

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_132.c
diff -u src/tests/usr.bin/xlint/lint1/msg_132.c:1.13 src/tests/usr.bin/xlint/lint1/msg_132.c:1.14
--- src/tests/usr.bin/xlint/lint1/msg_132.c:1.13	Thu May 26 20:17:40 2022
+++ src/tests/usr.bin/xlint/lint1/msg_132.c	Sun May 29 23:09:43 2022
@@ -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 @@ test_ic_shr(u64_t x)
 	/* 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;
+}

Index: src/tests/usr.bin/xlint/lint1/msg_132.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_132.exp:1.12 src/tests/usr.bin/xlint/lint1/msg_132.exp:1.13
--- src/tests/usr.bin/xlint/lint1/msg_132.exp:1.12	Thu May 26 20:17:40 2022
+++ src/tests/usr.bin/xlint/lint1/msg_132.exp	Sun May 29 23:09:43 2022
@@ -27,3 +27,29 @@ msg_132.c(125): warning: function 'cover
 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]

Reply via email to