From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22487 invoked by alias); 27 Dec 2002 13:56:04 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 22317 invoked by uid 71); 27 Dec 2002 13:56:01 -0000 Resent-Date: 27 Dec 2002 13:56:01 -0000 Resent-Message-ID: <20021227135601.22316.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, bsg@uniyar.ac.ru Received: (qmail 22206 invoked by uid 61); 27 Dec 2002 13:55:32 -0000 Message-Id: <20021227135532.22205.qmail@sources.redhat.com> Date: Fri, 27 Dec 2002 05:56:00 -0000 From: bsg@uniyar.ac.ru Reply-To: bsg@uniyar.ac.ru To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version: gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: c/9065: FAIL with gcc.c-torture/execute/loop-2e.c test with gcc-3.2.1 (wrong instruction generation) X-SW-Source: 2002-12/txt/msg01311.txt.bz2 List-Id: >Number: 9065 >Category: c >Synopsis: FAIL with gcc.c-torture/execute/loop-2e.c test with gcc-3.2.1 (wrong instruction generation) >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: wrong-code >Submitter-Id: net >Arrival-Date: Fri Dec 27 05:56:01 PST 2002 >Closed-Date: >Last-Modified: >Originator: Igor Zhbanov >Release: 2.3.1 >Organization: >Environment: GCC version is: gcc-3.2.1 (GNU CPP version 3.2.1 (cpplib) (i386 Linux/ELF)) My system is Linux-2.2.19 on i586 (i586-pc-linux-gnu) with glibc-2.2.3. Options to comile gcc: ../gcc-3.2.1/configure --enable-shared --prefix=/usr --enable-threads >Description: I have found a bug when compiling test file gcc.c-torture/execute/loop-2e.c This is a minimalized version of test file gcc/testsuite/gcc.c-torture/execute/loop-2e.c: --- begin void f (int *p, int **q) { /* Correct behaviour with: */ unsigned int i; /* Incorrect behaviour with: */ /* int i; */ for (i = 0; i < 40; i++) *q++ = &p[i]; } --- end GCC command line: /root/tmp/compile/gcc/gcc/cc1 exp.c -Os -Wall -W -o exp.s If you set type of variable `i' to signed int (instead of unsigned) in function `f()' and use optimization for size (`-Os' option) then the compiler will produce wrong assembly output as shown below: --- begin .file "exp.c" .text .globl f .type f,@function f: pushl %ebp movl %esp, %ebp movl 8(%ebp), %eax # p, p movl 12(%ebp), %ecx # q, q movl %eax, %edx # p, p addl $156, %eax .L6: movl %edx, (%ecx) # p, * q addl $4, %ecx # q addl $4, %edx # p cmpl %eax, %edx # p # Here is a bug. # Correct instruction: jbe .L6 # Incorrect instruction: # jle .L6 popl %ebp ret .Lfe1: .size f,.Lfe1-f --- end This bug happens when gcc decided to eliminate induction variable `i' and replace it with pointers comparison. The bug consts in unexpected loop termination when one of the pointers `*p' or `*q' (function arguments) is above 0x80000000 while another pointer is below 0x80000000. The problem is that the type of jump instruction (`jbe' or `jle') depends on the type of variable `i' (unsigned or signed). That is wrong because in the example above we use instruction `cmpl %eax, %edx' to compare pointers, not integers. And the pointers should always be compared as unsigned numbers (i.e. `jbe' instruction should be used). This example fails when one of the pointers `*p' or `*q' is above 0x8000000 while another pointer is below 0x80000000. Such a values can not be compared correctly as signed integers. >How-To-Repeat: void f (int *p, int **q) { /* Incorrect behaviour with: */ int i; for (i = 0; i < 40; i++) *q++ = &p[i]; } GCC command line: /root/tmp/compile/gcc/gcc/cc1 exp.c -Os -Wall -W -o exp.s >Fix: >Release-Note: >Audit-Trail: >Unformatted: