Bug 4978 - invalid expression evaluation in gcc
Summary: invalid expression evaluation in gcc
Status: RESOLVED DUPLICATE of bug 11751
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2001-12-01 09:56 UTC by ggs
Modified: 2004-08-13 16:03 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ggs 2001-12-01 09:56:01 UTC
 configured with: /usr/local/src/add-on/gcc-3.0.2/configure 
 --prefix=/usr/add-on/gcc-3.0.2
 Description:	The values of the two occurrences of (tmpvar->num = tmpnum)
 		are not computed correctly; I think the compiler loses track
 		of which registers contain each value.  I also see the same
 		error in the IBM S390 version of the compiler.  The test
 		program should exit with status = 0 if the compilation is
 		valid, status = 1 if invalid.  The Sun WorkShop Compiler 5.0
 		compiles this code correctly.
 How-To-Repeat:	gcc -o gccerr gccerr.c; ./gccerr; echo $?
 Fix:		Simplify expression
 
 
 --==_Exmh_-1288580240
 Content-Type: text/plain ; name="gccerr.c"; charset=us-ascii
 Content-Description: gccerr.c
 Content-Disposition: attachment; filename="gccerr.c"
 
 typedef struct {
 	char	*str;		/* the actual str 		    */
 	int	len;		/* len of malloc'ed space 	    */
 	int	refcnt;		/* number of times this string in use */
 } STR, *STRP;
 
 typedef struct {
 	STRP	string;
 	double	num;	    	/* num if pss and used      	    */
 	char	cur;        	/* indication of current type	    */
 } VAR, *VARP;
 
 extern double atof();
 extern int strlen();
 extern void exit();
 
 STR	s_temp = { "asdf", 5, 1 };
 VAR	s_Au_temp = { &s_temp, 0.0, 1 };
 STR	s_zero = { "0.0", 4, 3 };
 VAR	s_Au_subs = { &s_zero, 0.0, 1 };
 VAR	s_Au_send = { &s_zero, 0.0, 1 };
 VAR	s_Au_slen = { &s_zero, 0.0, 1 };
 VARP    tmpvar;
 double  tmpnum;
 
 VARP	Au_temp = &s_Au_temp;
 VARP	Au_subs = &s_Au_subs;
 VARP	Au_send = &s_Au_send;
 VARP	Au_slen = &s_Au_slen;
 
 main()
 {
 	if (  (   (  Au_subs->cur & (1<<1) )
 	       || (  Au_subs->cur |= (1<<1)
 		   , Au_subs->num = atof(( Au_subs->string->str ) ) ) )
 	    , (  (  (  (tmpnum = ( (Au_subs->num + 255)  ))
 		     , (tmpvar = (  Au_send  ))
 		     , (tmpvar->cur = ((1<<1) | (1<<2) | (1<<3) ) ) )
 		  , (tmpvar->num = tmpnum) )
 	       > (  (  (tmpnum = (  ((double)strlen(( Au_temp->string->str ))) ))
 		     , (tmpvar = (  Au_slen  ))
 		     , (tmpvar->cur = ((1<<1) | (1<<2) | (1<<3)) ) )
 		  , (tmpvar->num = tmpnum)) ) )
 	{
 	    exit(0);	/* correct */
 	}
 	else
 	{
 	    exit(1);	/* invalid */
 	}
 }

Release:
unknown
Comment 1 Jakub Jelinek 2002-02-21 08:37:24 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: There is no sequence point in C after first operand of
    < operator, so your testcase has undefined behaviour.
    See ISO C99 Annex C, for example.
    There are sequence points after first operand of comma
    and at the end of if controlling expression, but there is
    nothing which requires < operands to be evaluated in any
    specific order.
Comment 2 Richard Henderson 2002-04-26 01:44:41 UTC
State-Changed-From-To: analyzed->closed
State-Changed-Why: Not a bug, as diagnosed by Jakub.
Comment 3 Wolfgang Bangerth 2004-08-13 16:01:33 UTC
Reopening to mark as a duplicate of... 
Comment 4 Wolfgang Bangerth 2004-08-13 16:03:22 UTC
...PR 11751. 

*** This bug has been marked as a duplicate of 11751 ***