🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #270

gcc-2.2.2 generates incorrect warning message

#270
From: Thomas E. Shields
Date: Wed, 05 Aug 1992 10:54
157 lines
4775 bytes
* GCC version: gcc-2.2.2
* Hardware: Intel System 302 (25 MHz 386/387)
* OS: Interactive Unix System V/386 Release 3.2 Version 3.0

* Configuration (config.status):
	# GCC was configured as follows:
	../gcc-2.2/configure --srcdir=../gcc-2.2 i386-isc

* Description:

	The following example results in the warning message:

		warning: comparison is always 1 due to limited range of data type

	although the generated assembly code (both with and without optimization)
	looks just fine to me

Tom Shields

===================== source file (gcc.bug.c) ============================
/* example derived from function "zdomap" in vftovp.c, as generated by
   web2c version 5.851c (May 14 1992), from the Web/Pascal original, so
   don't give me any grief about this stupid code */

int map ( c )
unsigned char c ; 
{
    if ( ( ( c >= 0 ) && ( c <= 127 ) ) || ( ( c >= 128 ) && ( c <= 131 ) ) 
    || ( ( c >= 133 ) && ( c <= 136 ) ) ) 
        return 1;
    else
        return 2;
}
=================== end source file (gcc.bug.c) ==========================

==================== compile with gcc (no opt) ===========================
%  gcc -v -g -S gcc.bug.c
Reading specs from /usr/local/lib/gcc-lib/i386-isc/2.2.2/specs
gcc version 2.2.2
 /usr/local/lib/gcc-lib/i386-isc/2.2.2/cpp -lang-c -v -undef -D__GNUC__=2 -Dunix
 -Di386 -D__unix__ -D__i386__ -D__unix -D__i386 -g gcc.bug.c /usr/tmp/cca13201.i
GNU CPP version 2.2.2 (80386, ATT syntax)
 /usr/local/lib/gcc-lib/i386-isc/2.2.2/cc1 /usr/tmp/cca13201.i -quiet -dumpbase
gcc.bug.c -g -version -o gcc.bug.s
GNU C version 2.2.2 (80386, ATT syntax) compiled by GNU C version 2.2.2.
gcc.bug.c: In function `map':
gcc.bug.c:4: warning: comparison is always 1 due to limited range of data type
================== end compile with gcc (no opt) =========================

=============== assembly source (gcc.bug.s, no opt) ======================
	.file	"gcc.bug.c"
gcc2_compiled.:
.text
	.align 4
	.def	map;	.val	map;	.scl	2;	.type	044;	.endef
.globl map
map:
	pushl %ebp
	movl %esp,%ebp
	movb 8(%ebp),%dl
	movb %dl,8(%ebp)
	.def	.bf;	.val	.;	.scl	101;	.line	3;	.endef
	.def	c;	.val	8;	.scl	9;	.type	014;	.endef
	.def	c;	.val	8;	.scl	1;	.type	014;	.endef
	.ln	2
	cmpb $127,8(%ebp)
	jbe .L3
	cmpb $127,8(%ebp)
	jbe .L4
	cmpb $131,8(%ebp)
	jbe .L3
	jmp .L4
	.align 4
.L4:
	cmpb $132,8(%ebp)
	jbe .L2
	cmpb $136,8(%ebp)
	jbe .L3
	jmp .L2
	.align 4
.L3:
	.ln	4
	movl $1,%eax
	jmp .L1
	.align 4
	jmp .L5
	.align 4
.L2:
	.ln	6
	movl $2,%eax
	jmp .L1
	.align 4
.L5:
	.ln	7
	.ln	7
.L1:
	.def	.ef;	.val	.;	.scl	101;	.line	7;	.endef
	leave
	ret
	.def	map;	.val	.;	.scl	-1;	.endef
============= end assembly source (gcc.bug.s, no opt) ====================

====================== compile with gcc (opt) ============================
% gcc -v -g -O -S gcc.bug.c
Reading specs from /usr/local/lib/gcc-lib/i386-isc/2.2.2/specs
gcc version 2.2.2
 /usr/local/lib/gcc-lib/i386-isc/2.2.2/cpp -lang-c -v -undef
-D__GNUC__=2 -Dunix -Di386 -D__unix__ -D__i386__ -D__unix -D__i386
-D__OPTIMIZE__ -g gcc.bug.c /usr/tmp/cca13217.i
GNU CPP version 2.2.2 (80386, ATT syntax)
 /usr/local/lib/gcc-lib/i386-isc/2.2.2/cc1 /usr/tmp/cca13217.i -quiet
-dumpbase gcc.bug.c -g -O -version -o gcc.bug.s
GNU C version 2.2.2 (80386, ATT syntax) compiled by GNU C version 2.2.2.
gcc.bug.c: In function `map':
gcc.bug.c:4: warning: comparison is always 1 due to limited range of data type
==================== end compile with gcc (opt) ==========================

================= assembly source (gcc.bug.s, opt) =======================
% cat gcc.bug.s
	.file	"gcc.bug.c"
gcc2_compiled.:
.text
	.align 4
	.def	map;	.val	map;	.scl	2;	.type	044;	.endef
.globl map
map:
	pushl %ebp
	movl %esp,%ebp
	movb 8(%ebp),%al
	.def	.bf;	.val	.;	.scl	101;	.line	3;	.endef
	.def	c;	.val	8;	.scl	9;	.type	04;	.endef
	.def	c;	.val	0;	.scl	4;	.type	014;	.endef
	.ln	2
	cmpb $127,%al
	jbe .L3
	cmpb $131,%al
	jbe .L3
	cmpb $132,%al
	jbe .L2
	cmpb $136,%al
	ja .L2
.L3:
	.ln	4
	movl $1,%eax
	leave
	ret
	.align 4
.L2:
	.ln	6
	movl $2,%eax
	.ln	7
	leave
	ret
	.align 4
	.def	.ef;	.val	.;	.scl	101;	.line	7;	.endef
	.def	map;	.val	.;	.scl	-1;	.endef
=============== end assembly source (gcc.bug.s, opt) =====================
Technical Details
Message-ID: <480.713040854@oriole>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!stars.reston.unisys.com!shields

Show Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!stars.reston.unisys.com!shields
From: shields@stars.reston.unisys.com (Thomas E. Shields)
Subject: gcc-2.2.2 generates incorrect warning message
Message-ID: <480.713040854@oriole>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Wed, 5 Aug 1992 10:54:14 GMT
Approved: bug-gcc@prep.ai.mit.edu
Lines: 158