Bug 15549 - [3.3 Regression] true !< 'a'
Summary: [3.3 Regression] true !< 'a'
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.3
: P2 normal
Target Milestone: 3.3.5
Assignee: Not yet assigned to anyone
URL:
Keywords: patch, wrong-code
Depends on:
Blocks:
 
Reported: 2004-05-20 04:54 UTC by Flash Sheridan
Modified: 2016-12-26 20:00 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 2.95.3, 3.4.0, 4.0.0
Known to fail: 3.0.4, 3.2.3, 3.3.3
Last reconfirmed: 2004-05-20 05:09:22


Attachments
Pre-processed source (2.14 KB, application/octet-stream)
2004-05-20 04:56 UTC, Flash Sheridan
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Flash Sheridan 2004-05-20 04:54:05 UTC
static volatile bool arg1__Bool_1475 = true;
	volatile const static uint_least8_t arg2_char_1479 = 'a';
	printf(  " \t %s %d \n " , "" ,  arg1__Bool_1475 < arg2_char_1479  );
 

gives 0, not 1, on GNU C version 3.3 20030304 (Apple Computer, Inc. build 1495).
Originally found in C99 mode, but also with default flags.
gcc version 2.96 20000731 (Red Hat Linux 7.2 2.96-112.7.2) behaves as expected.
(The extra %s and empty string are for alignment issues on another platform.)



Commands:
gcc ../c/noerror/bugfiles/gcc_bool_bug.c

 a.out 
  1 < 97 ( arg1__Bool_1475 < arg2_char_1479 ) : 
          0 


Full source:

#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>


 int main()	{
//...
	static volatile bool arg1__Bool_1475 = true;
//...
	volatile const static uint_least8_t arg2_char_1479 = 'a';
	printf(  " %s %d" , "" , arg1__Bool_1475  );
	printf(  "%s < %d ( arg1__Bool_1475 < arg2_char_1479 ) : \n " , "" , arg2_char_1479  );
	printf(  " \t %s %d \n " , "" ,  arg1__Bool_1475 < arg2_char_1479  );
//...
	return 42;
}


Pre-processed file to follow, once I figure out how; here's the session:

gcc -v -save-temps ../c/noerror/bugfiles/gcc_bool_bug.c
Reading specs from /usr/libexec/gcc/darwin/ppc/3.3/specs
Thread model: posix
gcc version 3.3 20030304 (Apple Computer, Inc. build 1495)
 /usr/libexec/gcc/darwin/ppc/3.3/cc1 -E -quiet -v -D__GNUC__=3 -D__GNUC_MINOR__=3 
-D__GNUC_PATCHLEVEL__=0 -D__APPLE_CC__=1495 -D__DYNAMIC__ ../c/noerror/bugfiles/
gcc_bool_bug.c -fPIC gcc_bool_bug.i
ignoring nonexistent directory "/usr/ppc-darwin/include"
ignoring nonexistent directory "/Local/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/include/gcc/darwin/3.3
 /usr/include
End of search list.
Framework search starts here:
 /System/Library/Frameworks
 /Library/Frameworks
End of framework search list.
 /usr/libexec/gcc/darwin/ppc/3.3/cc1 -fpreprocessed gcc_bool_bug.i -fPIC -quiet -dumpbase 
gcc_bool_bug.c -auxbase gcc_bool_bug -version -o gcc_bool_bug.s
GNU C version 3.3 20030304 (Apple Computer, Inc. build 1495) (ppc-darwin)
        compiled by GNU C version 3.3 20030304 (Apple Computer, Inc. build 1495).
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=131072
 /usr/libexec/gcc/darwin/ppc/as -arch ppc -o gcc_bool_bug.o gcc_bool_bug.s
 ld -arch ppc -dynamic -o a.out -lcrt1.o -lcrt2.o -L/usr/lib/gcc/darwin/3.3 -L/usr/lib/gcc/darwin -L/
usr/libexec/gcc/darwin/ppc/3.3/../../.. gcc_bool_bug.o -lgcc -lSystem |
 c++filt3
Comment 1 Flash Sheridan 2004-05-20 04:56:05 UTC
Created attachment 6346 [details]
Pre-processed source
Comment 2 Andrew Pinski 2004-05-20 05:09:21 UTC
Confirmed, a regression from 2.95.3 for 3.3.x but not for 3.4.0 and 3.5.0.
Comment 3 Falk Hueffner 2004-05-27 14:14:24 UTC
Test case:

void abort(void);

__attribute__((noinline))
int lt (_Bool b, unsigned char c) { return b < c; } 

int main () { 
  if (!lt(1, 'a'))
    abort ();
} 

This is already broken in .00.rtl, which tries to do lt as (c != 0) & (b == 0),
which would be correct if c was also a bool.
Comment 4 Josef Zlomek 2004-06-01 15:52:48 UTC
The following patch fixes the problem on mainline and 3.4 branch:

2003-08-19  Mark Mitchell  <mark@codesourcery.com>
        
        PR c++/11946
        * convert.c (convert_to_integer): Use CONVERT_EXPR (instead of             
        NOP_EXPR) when necessary.

http://gcc.gnu.org/ml/gcc-patches/2004-06/msg00055.html
Comment 5 GCC Commits 2004-06-01 16:10:18 UTC
Subject: Bug 15549

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	hammer-3_3-branch
Changes by:	zlomek@gcc.gnu.org	2004-06-01 16:10:10

Modified files:
	gcc            : ChangeLog.hammer convert.c 

Log message:
	PR c/15549
	Backport from mainline:
	
	2003-08-19  Mark Mitchell  <mark@codesourcery.com>
	
	PR c++/11946
	* convert.c (convert_to_integer): Use CONVERT_EXPR (instead of
	NOP_EXPR) when necessary.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.hammer.diff?cvsroot=gcc&only_with_tag=hammer-3_3-branch&r1=1.1.2.405&r2=1.1.2.406
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/convert.c.diff?cvsroot=gcc&only_with_tag=hammer-3_3-branch&r1=1.19.12.5&r2=1.19.12.6

Comment 6 GCC Commits 2004-06-02 05:29:07 UTC
Subject: Bug 15549

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	hammer-3_3-branch
Changes by:	zlomek@gcc.gnu.org	2004-06-02 05:29:04

Modified files:
	gcc/testsuite  : ChangeLog.hammer 
	gcc/testsuite/gcc.dg: c99-bool-1.c 

Log message:
	PR c/15549
	Backport from mainline
	2003-08-19  Mark Mitchell  <mark@codesourcery.com>
	
	PR c++/11946.C
	* gcc.dg/c99-bool-1.c: Remove bogus warning.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.hammer.diff?cvsroot=gcc&only_with_tag=hammer-3_3-branch&r1=1.1.2.17&r2=1.1.2.18
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/c99-bool-1.c.diff?cvsroot=gcc&only_with_tag=hammer-3_3-branch&r1=1.3&r2=1.3.2.1

Comment 7 GCC Commits 2004-06-28 08:03:55 UTC
Subject: Bug 15549

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	zlomek@gcc.gnu.org	2004-06-28 08:03:48

Modified files:
	gcc            : ChangeLog convert.c 
	gcc/testsuite  : ChangeLog 
	gcc/testsuite/gcc.dg: c99-bool-1.c 

Log message:
	PR c/15549
	Backport from mainline
	2003-08-19  Mark Mitchell  <mark@codesourcery.com>
	
	PR c++/11946
	* convert.c (convert_to_integer): Use CONVERT_EXPR (instead of
	NOP_EXPR) when necessary.
	
	PR c/15549
	Backport from mainline
	2003-08-19  Mark Mitchell  <mark@codesourcery.com>
	
	PR c++/11946.C
	* gcc.dg/c99-bool-1.c: Remove bogus warning.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.16114.2.991&r2=1.16114.2.992
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/convert.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.19&r2=1.19.14.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.379&r2=1.2261.2.380
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/c99-bool-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.3&r2=1.3.4.1

Comment 8 Andrew Pinski 2004-08-31 03:45:46 UTC
Fixed.