public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/21297] New: buf[i+i]=0 stores buf[i] when -O2
@ 2005-04-30 15:54 akr at m17n dot org
  2005-04-30 16:00 ` [Bug middle-end/21297] [4.0/4.1 Regression] " pinskia at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: akr at m17n dot org @ 2005-04-30 15:54 UTC (permalink / raw)
  To: gcc-bugs

gcc 4.0.0 optimization seems to have a problem.
In the f function in following source, buf[i+i] = '\0' stores '\0' to buf[2].
But it should store to buf[4]. 

% cat t.c
extern int printf (__const char *__restrict __format, ...);

void
f(char *buf)
{
  int i;
  for (i = 0; i < 2; i++) ;
  printf("i=%d\n", i);
  buf[i+i] = '\0';
}

int main(int argc, char **argv)
{
  char buf[] = "0123456789";
  f(buf);
  printf("%s\n", buf);
  return 0;
}
% gcc -v -O2 t.c
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.0.0/configure --prefix=/home/src/gcc
Thread model: posix
gcc version 4.0.0
 /home/src/gcc/libexec/gcc/i686-pc-linux-gnu/4.0.0/cc1 -quiet -v t.c -quiet
-dumpbase t.c -mtune=pentiumpro -auxbase t -O2 -version -o /tmp/ccKF4bLU.s
ignoring nonexistent directory
"/home/src/gcc/lib/gcc/i686-pc-linux-gnu/4.0.0/../../../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /home/src/gcc/include
 /home/src/gcc/lib/gcc/i686-pc-linux-gnu/4.0.0/include
 /usr/include
End of search list.
GNU C version 4.0.0 (i686-pc-linux-gnu)
        compiled by GNU C version 4.0.0.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
 as -V -Qy -o /tmp/ccm6JTQG.o /tmp/ccKF4bLU.s
GNU assembler version 2.15 (i386-linux) using BFD version 2.15
 /home/src/gcc/libexec/gcc/i686-pc-linux-gnu/4.0.0/collect2 --eh-frame-hdr -m
elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o
/home/src/gcc/lib/gcc/i686-pc-linux-gnu/4.0.0/crtbegin.o
-L/home/src/gcc/lib/gcc/i686-pc-linux-gnu/4.0.0
-L/home/src/gcc/lib/gcc/i686-pc-linux-gnu/4.0.0/../../.. /tmp/ccm6JTQG.o -lgcc
--as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed
/home/src/gcc/lib/gcc/i686-pc-linux-gnu/4.0.0/crtend.o /usr/lib/crtn.o
% ./a.out 
i=2
01

The binary produces "01".  But it should be "0123".
If gcc 3.3.5 is used, the binary produces "0123".

-- 
           Summary: buf[i+i]=0 stores buf[i] when -O2
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: akr at m17n dot org
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21297


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/21297] [4.0/4.1 Regression] buf[i+i]=0 stores buf[i] when -O2
  2005-04-30 15:54 [Bug c/21297] New: buf[i+i]=0 stores buf[i] when -O2 akr at m17n dot org
@ 2005-04-30 16:00 ` pinskia at gcc dot gnu dot org
  2005-05-02 13:04 ` [Bug target/21297] " jakub at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-04-30 16:00 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-04-30 16:00 -------
This is another expand issue:
;; *((char *) (unsigned int) (i + i) + buf) = 0
(insn 27 25 0 (set (mem:QI (plus:SI (mult:SI (reg/v:SI 60 [ i ])
                    (const_int 1 [0x1]))
                (reg/v/f:SI 61 [ buf ])) [0 S1 A8])
        (const_int 0 [0x0])) -1 (nil)
    (nil))

Why is it multiplying by one and not by two.

Confirmed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
          Component|c                           |middle-end
     Ever Confirmed|                            |1
           Keywords|                            |wrong-code
   Last reconfirmed|0000-00-00 00:00:00         |2005-04-30 16:00:20
               date|                            |
            Summary|buf[i+i]=0 stores buf[i]    |[4.0/4.1 Regression]
                   |when -O2                    |buf[i+i]=0 stores buf[i]
                   |                            |when -O2
   Target Milestone|---                         |4.0.1


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21297


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug target/21297] [4.0/4.1 Regression] buf[i+i]=0 stores buf[i] when -O2
  2005-04-30 15:54 [Bug c/21297] New: buf[i+i]=0 stores buf[i] when -O2 akr at m17n dot org
  2005-04-30 16:00 ` [Bug middle-end/21297] [4.0/4.1 Regression] " pinskia at gcc dot gnu dot org
@ 2005-05-02 13:04 ` jakub at gcc dot gnu dot org
  2005-05-02 13:42 ` jakub at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu dot org @ 2005-05-02 13:04 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jakub at gcc dot gnu dot org  2005-05-02 13:04 -------
This is a target bug.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |jakub at gcc dot gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED
          Component|middle-end                  |target
   Last reconfirmed|2005-04-30 16:00:20         |2005-05-02 13:04:19
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21297


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug target/21297] [4.0/4.1 Regression] buf[i+i]=0 stores buf[i] when -O2
  2005-04-30 15:54 [Bug c/21297] New: buf[i+i]=0 stores buf[i] when -O2 akr at m17n dot org
  2005-04-30 16:00 ` [Bug middle-end/21297] [4.0/4.1 Regression] " pinskia at gcc dot gnu dot org
  2005-05-02 13:04 ` [Bug target/21297] " jakub at gcc dot gnu dot org
@ 2005-05-02 13:42 ` jakub at gcc dot gnu dot org
  2005-05-03 13:04 ` cvs-commit at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu dot org @ 2005-05-02 13:42 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jakub at gcc dot gnu dot org  2005-05-02 13:42 -------
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2005-05/msg00073.html>

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21297


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug target/21297] [4.0/4.1 Regression] buf[i+i]=0 stores buf[i] when -O2
  2005-04-30 15:54 [Bug c/21297] New: buf[i+i]=0 stores buf[i] when -O2 akr at m17n dot org
                   ` (2 preceding siblings ...)
  2005-05-02 13:42 ` jakub at gcc dot gnu dot org
@ 2005-05-03 13:04 ` cvs-commit at gcc dot gnu dot org
  2005-05-04  7:25 ` [Bug target/21297] [4.0 " cvs-commit at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-05-03 13:04 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2005-05-03 13:01 -------
Subject: Bug 21297

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	jakub@gcc.gnu.org	2005-05-03 12:58:13

Modified files:
	gcc            : ChangeLog 
	gcc/config/i386: i386.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.c-torture/execute: 20050502-2.c 

Log message:
	PR target/21297
	* config/i386/i386.c (legitimize_address): When canonicalizing
	ASHIFT into MULT, multiply by 1 << shift_count instead of
	1 << log2 (shift_count).
	
	* gcc.c-torture/execute/20050502-2.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.8572&r2=2.8573
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/i386/i386.c.diff?cvsroot=gcc&r1=1.816&r2=1.817
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5433&r2=1.5434
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/20050502-2.c.diff?cvsroot=gcc&r1=NONE&r2=1.1



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21297


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug target/21297] [4.0 Regression] buf[i+i]=0 stores buf[i] when -O2
  2005-04-30 15:54 [Bug c/21297] New: buf[i+i]=0 stores buf[i] when -O2 akr at m17n dot org
                   ` (3 preceding siblings ...)
  2005-05-03 13:04 ` cvs-commit at gcc dot gnu dot org
@ 2005-05-04  7:25 ` cvs-commit at gcc dot gnu dot org
  2005-05-04  8:16 ` giovannibajo at libero dot it
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-05-04  7:25 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2005-05-04 07:24 -------
Subject: Bug 21297

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	jakub@gcc.gnu.org	2005-05-04 07:24:34

Modified files:
	gcc            : ChangeLog 
	gcc/testsuite  : ChangeLog 
	gcc/config/i386: i386.c 
Added files:
	gcc/testsuite/gcc.c-torture/execute: 20050502-2.c 

Log message:
	PR target/21297
	* config/i386/i386.c (legitimize_address): When canonicalizing
	ASHIFT into MULT, multiply by 1 << shift_count instead of
	1 << log2 (shift_count).
	
	* gcc.c-torture/execute/20050502-2.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=2.7592.2.214&r2=2.7592.2.215
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.157&r2=1.5084.2.158
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/i386/i386.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.795.6.6&r2=1.795.6.7
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/20050502-2.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21297


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug target/21297] [4.0 Regression] buf[i+i]=0 stores buf[i] when -O2
  2005-04-30 15:54 [Bug c/21297] New: buf[i+i]=0 stores buf[i] when -O2 akr at m17n dot org
                   ` (4 preceding siblings ...)
  2005-05-04  7:25 ` [Bug target/21297] [4.0 " cvs-commit at gcc dot gnu dot org
@ 2005-05-04  8:16 ` giovannibajo at libero dot it
  2005-05-26 17:54 ` cvs-commit at gcc dot gnu dot org
  2005-05-29 16:03 ` cvs-commit at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: giovannibajo at libero dot it @ 2005-05-04  8:16 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From giovannibajo at libero dot it  2005-05-04 08:16 -------
Fixed!

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21297


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug target/21297] [4.0 Regression] buf[i+i]=0 stores buf[i] when -O2
  2005-04-30 15:54 [Bug c/21297] New: buf[i+i]=0 stores buf[i] when -O2 akr at m17n dot org
                   ` (5 preceding siblings ...)
  2005-05-04  8:16 ` giovannibajo at libero dot it
@ 2005-05-26 17:54 ` cvs-commit at gcc dot gnu dot org
  2005-05-29 16:03 ` cvs-commit at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-05-26 17:54 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2005-05-26 17:50 -------
Subject: Bug 21297

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-rhl-branch
Changes by:	jakub@gcc.gnu.org	2005-05-26 17:49:50

Modified files:
	gcc            : ChangeLog 
	gcc/config/i386: i386.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.c-torture/execute: 20050502-2.c 

Log message:
	PR target/21297
	* config/i386/i386.c (legitimize_address): When canonicalizing
	ASHIFT into MULT, multiply by 1 << shift_count instead of
	1 << log2 (shift_count).
	
	* gcc.c-torture/execute/20050502-2.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-rhl-branch&r1=2.2326.2.399.2.78&r2=2.2326.2.399.2.79
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/i386/i386.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-rhl-branch&r1=1.635.2.8.2.11&r2=1.635.2.8.2.12
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-rhl-branch&r1=1.3389.2.170.2.49&r2=1.3389.2.170.2.50
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/20050502-2.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-rhl-branch&r1=NONE&r2=1.1.8.1



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21297


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug target/21297] [4.0 Regression] buf[i+i]=0 stores buf[i] when -O2
  2005-04-30 15:54 [Bug c/21297] New: buf[i+i]=0 stores buf[i] when -O2 akr at m17n dot org
                   ` (6 preceding siblings ...)
  2005-05-26 17:54 ` cvs-commit at gcc dot gnu dot org
@ 2005-05-29 16:03 ` cvs-commit at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-05-29 16:03 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2005-05-29 16:02 -------
Subject: Bug 21297

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	pault@gcc.gnu.org	2005-05-29 16:02:11

Modified files:
	gcc/fortran    : trans-array.c trans-expr.c 

Log message:
	2005-05-29 Paul Thomas  <pault@gcc.gnu.org>
	
	PR fortran/16939
	PR fortran/17192
	PR fortran/17193
	PR fortran/17202
	PR fortran/18689
	PR fortran/18890
	PR fortran/21297
	* fortran/trans-array.c (gfc_conv_resolve_dependencies): Add string
	length to temp_ss for character pointer array assignments.
	* fortran/trans-expr.c (gfc_conv_variable): Correct errors in
	dereferencing of characters and character pointers.
	* fortran/trans-expr.c (gfc_conv_function_call): Provide string
	length as return argument for various kinds of handling of return.
	Return a char[]* temporary for character pointer functions and
	dereference the temporary upon return.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/trans-array.c.diff?cvsroot=gcc&r1=1.45&r2=1.46
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/trans-expr.c.diff?cvsroot=gcc&r1=1.44&r2=1.45



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21297


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2005-05-29 16:03 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-30 15:54 [Bug c/21297] New: buf[i+i]=0 stores buf[i] when -O2 akr at m17n dot org
2005-04-30 16:00 ` [Bug middle-end/21297] [4.0/4.1 Regression] " pinskia at gcc dot gnu dot org
2005-05-02 13:04 ` [Bug target/21297] " jakub at gcc dot gnu dot org
2005-05-02 13:42 ` jakub at gcc dot gnu dot org
2005-05-03 13:04 ` cvs-commit at gcc dot gnu dot org
2005-05-04  7:25 ` [Bug target/21297] [4.0 " cvs-commit at gcc dot gnu dot org
2005-05-04  8:16 ` giovannibajo at libero dot it
2005-05-26 17:54 ` cvs-commit at gcc dot gnu dot org
2005-05-29 16:03 ` cvs-commit at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).