🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #1029

bug fix for my Aug 7 patch (GCC 2.2.2 does not warn about `1<=i<=N')

#1029
From: Paul Eggert
Date: Sun, 30 Aug 1992 00:07
80 lines
3151 bytes
On Aug 7 I submitted a patch to make GCC 2.2.2 warn about C expressions like
`1<=i<=N', which have a different meaning than in traditional mathematics.
Unfortunately, the patch has a bug that sometimes causes gcc -O -W to issue a
warning when it shouldn't.  For a program like

	struct tree_common
	{
	  int code : 8;
	  unsigned public_flag : 1;
	};
	static int
	gen_decl (decl)
	     struct tree_common *decl;
	{
	  if (( (decl)->code)  == 10 && !((decl)->public_flag) )
	    return 3;
	  return -2;
	}

GCC 2.2.2 (-O -W, sparc, SunOS 4.1.2, with my patch) wrongly complains:

	x.c:10: warning: comparisons like X<=Y<=Z do not have the usual meaning

Roughly speaking, the problem is that the patched GCC internally optimizes the
&& to an ==, and then wrongly complains about the transformed expression.

Here is a fix.  The c-typeck.c patch is with respect to GCC 2.2.2.  The
invoke.texi patch has not changed since Aug 7, but I'm including it to make
this report self-contained.

Sat Aug 29 23:55:12 1992  Paul Eggert  (eggert@twinsun.com)

	* c-typeck.c (parser_build_binary_op): Don't get confused by bit-field
	merging when warning about expressions like `1<=i<=N'.

Fri Aug  7 22:34:20 1992  Paul Eggert  (eggert@twinsun.com)

	* c-typeck.c (parser_build_binary_op): Warn about expressions like
	`1<=i<=N'.
	* invoke.texi: Document warning.

===================================================================
RCS file: c-typeck.c,v
retrieving revision 2.2
diff -c -r2.2 c-typeck.c
*** c-typeck.c	1992/05/28 05:20:58	2.2
--- c-typeck.c	1992/08/29 23:55:12
***************
*** 2128,2133 ****
--- 2128,2139 ----
  	}
      }
  
+   /* Similarly, check for cases like 1<=i<=10 that are probably errors.  */
+   if (extra_warnings
+       && TREE_CODE_CLASS (code) == '<'
+       && (TREE_CODE_CLASS (code1) == '<' || TREE_CODE_CLASS (code2) == '<'))
+     warning ("comparisons like X<=Y<=Z do not have the usual meaning");
+ 
    class = TREE_CODE_CLASS (TREE_CODE (result));
  
    /* Record the code that was specified in the source,
===================================================================
RCS file: invoke.texi,v
retrieving revision 2.2.2.1
diff -c2 -r2.2.2.1 invoke.texi
*** invoke.texi	1992/08/01 03:27:09	2.2.2.1
--- invoke.texi	1992/08/07 22:22:36
***************
*** 616,619 ****
--- 616,624 ----
  
  @item
+ A comparison like @samp{x<=y<=z} appears; this is equivalent to
+ @samp{(x<=y ? 1 : 0) <= z}, which is a different interpretation than
+ ordinary mathmatics.
+ 
+ @item
  A storage-class specifier like @code{static} appears other than
  at the beginning of a declaration.  According to the C Standard,
Technical Details
Message-ID: <9208300007.AA02511@shadow.twinsun.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!shadow.TWinsun.COM!eggert

Show Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!shadow.TWinsun.COM!eggert
From: eggert@shadow.TWinsun.COM (Paul Eggert)
Subject: bug fix for my Aug 7 patch (GCC 2.2.2 does not warn about `1<=i<=N')
Message-ID: <9208300007.AA02511@shadow.twinsun.com>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Sun, 30 Aug 1992 00:07:57 GMT
Approved: bug-gcc@prep.ai.mit.edu
Lines: 81