This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/32677] New: optimizer fails properly accessing argument
- From: "attardi at di dot unipi dot it" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 8 Jul 2007 17:59:30 -0000
- Subject: [Bug c++/32677] New: optimizer fails properly accessing argument
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The problem occurs when using flags -O3 (or -O2) in gcc 4.0, 4.1 and 4.2.0.
The following program exhibits the bug:
#include <iostream>
inline void store4(char* dst, char* src) {
*(unsigned*)dst = *(unsigned*)src;
}
void set(char* dst, long value) {
store4(dst, (char*)&value);
}
int main(int argc, char* argv[])
{
int value = 0;
char* data = (char*)&value;
set(data, 1);
std::cerr << value << std::endl;
}
Command line for showing the bug:
> c++ -o gccBug -O3 gccBug.cpp ; gccBug
0
> c++ -o gccBug -O gccBug.cpp ; gccBug
1
The bug also disappears when compiling with option -m32.
>From the assembly code for set(), the -O3 optimized version is:
_Z3setPcl:
.LFB1462:
movl -8(%rsp), %eax
movl %eax, (%rdi)
ret
instead the -O version is:
_Z3setPcl:
.LFB1462:
movq %rsi, -8(%rsp)
movl -8(%rsp), %eax
movl %eax, (%rdi)
ret
-- Giuseppe Attardi
University of Pisa
Italy
--
Summary: optimizer fails properly accessing argument
Product: gcc
Version: 4.2.0
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: attardi at di dot unipi dot it
GCC build triplet: 4.2.0
GCC host triplet: x86_64 GNU/Linux
GCC target triplet: x86_64-redhat-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32677