Module Name:    src
Committed By:   rillig
Date:           Mon May 30 07:19:28 UTC 2022

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

Log Message:
lint: fix assertion failure in '(unsigned long)(ptr) >> 12'

Since tree.c 1.449 from 2022-05-26.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/tests/usr.bin/xlint/lint1/msg_132.c
cvs rdiff -u -r1.14 -r1.15 src/tests/usr.bin/xlint/lint1/msg_132.exp
cvs rdiff -u -r1.450 -r1.451 src/usr.bin/xlint/lint1/tree.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_132.c
diff -u src/tests/usr.bin/xlint/lint1/msg_132.c:1.15 src/tests/usr.bin/xlint/lint1/msg_132.c:1.16
--- src/tests/usr.bin/xlint/lint1/msg_132.c:1.15	Sun May 29 23:24:09 2022
+++ src/tests/usr.bin/xlint/lint1/msg_132.c	Mon May 30 07:19:28 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_132.c,v 1.15 2022/05/29 23:24:09 rillig Exp $	*/
+/*	$NetBSD: msg_132.c,v 1.16 2022/05/30 07:19:28 rillig Exp $	*/
 # 3 "msg_132.c"
 
 // Test for message: conversion from '%s' to '%s' may lose accuracy [132]
@@ -214,3 +214,11 @@ test_bit_fields(struct bit_fields s, uns
 	/* expect+1: warning: conversion from 'unsigned long' to 'unsigned char' may lose accuracy [132] */
 	return s.bits_32 & m;
 }
+
+
+unsigned int
+convert_pointer_to_smaller_integer(void *ptr)
+{
+	/* expect+1: warning: conversion from 'unsigned long' to 'unsigned int' may lose accuracy [132] */
+	return (unsigned long)(ptr) >> 12;
+}

Index: src/tests/usr.bin/xlint/lint1/msg_132.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_132.exp:1.14 src/tests/usr.bin/xlint/lint1/msg_132.exp:1.15
--- src/tests/usr.bin/xlint/lint1/msg_132.exp:1.14	Sun May 29 23:24:09 2022
+++ src/tests/usr.bin/xlint/lint1/msg_132.exp	Mon May 30 07:19:28 2022
@@ -29,3 +29,4 @@ msg_132.c(193): warning: conversion from
 msg_132.c(195): warning: conversion from 'unsigned long long' to 'unsigned int' may lose accuracy [132]
 msg_132.c(209): warning: conversion from 'unsigned long' to 'unsigned int' may lose accuracy [132]
 msg_132.c(215): warning: conversion from 'unsigned long' to 'unsigned char' may lose accuracy [132]
+msg_132.c(223): warning: conversion from 'unsigned long' to 'unsigned int' may lose accuracy [132]

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.450 src/usr.bin/xlint/lint1/tree.c:1.451
--- src/usr.bin/xlint/lint1/tree.c:1.450	Sun May 29 23:24:09 2022
+++ src/usr.bin/xlint/lint1/tree.c	Mon May 30 07:19:28 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.450 2022/05/29 23:24:09 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.451 2022/05/30 07:19:28 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.450 2022/05/29 23:24:09 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.451 2022/05/30 07:19:28 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -255,10 +255,14 @@ ic_expr(const tnode_t *tn)
 {
 	integer_constraints lc, rc;
 
+	lint_assert(is_integer(tn->tn_type->t_tspec));
+
 	switch (tn->tn_op) {
 	case CON:
 		return ic_con(tn->tn_type, tn->tn_val);
 	case CVT:
+		if (!is_integer(tn->tn_left->tn_type->t_tspec))
+			return ic_any(tn->tn_type);
 		lc = ic_expr(tn->tn_left);
 		return ic_cvt(tn->tn_type, tn->tn_left->tn_type, lc);
 	case SHL:

Reply via email to