Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 154079

Summary: [4.1/bad-code] gcc 4.1.1 has broken (signed char) to (signed int) conversion
Product: Gentoo Linux Reporter: Stian Skjelstad <stian>
Component: [OLD] Core systemAssignee: Gentoo Toolchain Maintainers <toolchain>
Status: RESOLVED WORKSFORME    
Severity: major CC: rhill
Priority: High    
Version: unspecified   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---
Attachments: gcc-4.1.1-bug154079.patch

Description Stian Skjelstad 2006-11-04 15:42:14 UTC
I haven't tryied gcc vanilla yet, so I don't know if this is a gcc bug, or a gentoo-patchset bug. This is the simple test-case:

#include <stdio.h>
int main(int arg, char *argv[])
{
        int j;
        for (j=0; j<256; j++)
        {
                signed char j2=(signed char)j;
                printf("%d\n", (signed int)j2);
        }
        return 0;
}

For gcc 3.4.6 this generates 0 to 127 and -128 to -1, as expected. But on gcc 4.1.1 with -O or -O1 or higher, it generates 0 to 255, which is wrong. This can (and does) brake some applications
Comment 1 Ryan Hill (RETIRED) gentoo-dev 2006-11-04 15:54:10 UTC
4.0.3 works.  4.1.1-r1 fails.  4.1 branch svn works.  i don't have a vanilla 4.1.1 available.
Comment 2 Ryan Hill (RETIRED) gentoo-dev 2006-11-04 18:42:49 UTC
vanilla 4.1.1 fails.  works with -fwrapv though.
Comment 3 SpanKY gentoo-dev 2006-11-04 23:30:13 UTC
well feel free to do binary diffs with the 4.1 branch to see what changed fixed things ... or we can just wait for 4.1.2 ;)
Comment 4 Stian Skjelstad 2006-11-05 06:54:18 UTC
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29725
Comment 5 SpanKY gentoo-dev 2006-11-05 13:30:57 UTC
you're not supposed to file PR's with gcc when they've already been fixed

the "it's fixed in the 4.1 branch but not in any 4.1.x release" is not a valid argument
Comment 6 Stian Skjelstad 2006-11-05 22:01:18 UTC
Just though this to be a serious issue, since you actually get a program that runs, but misbehaves.
Comment 7 SpanKY gentoo-dev 2006-11-05 23:32:54 UTC
upstream has already fixed the problem, they dont care anymore
Comment 8 Stian Skjelstad 2006-11-06 13:03:47 UTC
http://gcc.gnu.org/ml/gcc-patches/2006-05/msg01032.html

A bit big patch perhaps?




The most vital part seems to be

Index: tree-chrec.c
===================================================================
--- tree-chrec.c        (revision 113852)
+++ tree-chrec.c        (working copy)
@@ -1150,7 +1150,7 @@ chrec_convert (tree type, tree chrec, tr
         1, 2, ..., 127, -128, ...  The result should not be
         {(schar)1, +, (schar)1}_x, but instead, we should keep the
         conversion: (schar) {(uchar)1, +, (uchar)1}_x.  */
-      if (scev_probably_wraps_p (type, base, step, at_stmt, loop,
+      if (scev_probably_wraps_p (ct, base, step, at_stmt, loop,
                                 &dummy, &dummy))
        goto failed_to_convert;
Comment 9 Ryan Hill (RETIRED) gentoo-dev 2006-11-12 00:40:30 UTC
Created attachment 101714 [details, diff]
gcc-4.1.1-bug154079.patch

that looks like the patch that went into trunk.  this is what got checked into the 4.1 branch (remove changelog hunk to apply).

if there's nothing specific in portage broken by this i suggest waiting for 4.1.2.
Comment 10 SpanKY gentoo-dev 2006-11-12 01:32:15 UTC
yeah, the proposed changes for the upstream PR seems more than what i'd like to try and add to gcc
Comment 11 Ryan Hill (RETIRED) gentoo-dev 2006-11-12 21:42:50 UTC
the 4.1.2 release process was set into motion today, so it shouldn't be long now.

http://permalink.gmane.org/gmane.comp.gcc.devel/83394
Comment 12 SpanKY gentoo-dev 2006-11-14 12:14:58 UTC
yeah, i'll just wait on 4.1.2 unless something critical comes up (and i think we would have seen it by now ...)
Comment 13 Stian Skjelstad 2006-11-14 13:49:38 UTC
I hit the bug in a program not in portage. I got some wierd sound in a sound-filter :-p   not hard find programs that have been broken because of this either, since it compiles and run. This doesn't need to be a crashing bug.

But yeah, gcc 4.1.2 is around the corner