public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/67090] New: [5/6 Regression] O2/O3 optimizes values away when different type pointers are typecasted
@ 2015-08-01 15:40 davispuh at gmail dot com
2015-08-01 15:42 ` [Bug c/67090] " davispuh at gmail dot com
2015-08-01 18:27 ` davispuh at gmail dot com
0 siblings, 2 replies; 3+ messages in thread
From: davispuh at gmail dot com @ 2015-08-01 15:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67090
Bug ID: 67090
Summary: [5/6 Regression] O2/O3 optimizes values away when
different type pointers are typecasted
Product: gcc
Version: 6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: davispuh at gmail dot com
Target Milestone: ---
GCC 5.2.0 and also latest trunk 6.0 (compiled from git commit 9b6b471, svn
r226241) using O2 or O3 generates invalid code by optimizing value away when
it's pointer is casted to different type pointer.
Here's a testcase, basically cast (double *) to (long *) and (long *) to
(double *)
#include <stdio.h>
int main(int argc, char **argv)
{
long l = 0xAA00133700BB00EE;
double d = (double)-2.190302448144169e-106;
volatile int i = 0; // this to prevent optimization, could be also argc-1
printf("%16lX\n%.15e\n", ((long*)&d)[i], ((double*)&l)[i]);
return 0;
}
Compiling it with gcc -O1 or with clang -O3 produces correct output:
AA00133700BB00EE
-2.190302448144169e-106
But when compiling with gcc -O2 (or -O3) produces incorrect output
0
6.952967796700164e-310
When compiled correctly with -O1
0x004004fa 48b8ee00bb00. movabs rax, -0x55ffecc8ff44ff12
0x00400504 4889442418 mov qword [rsp + 0x18], rax
0x00400509 f20f100dd700. movsd xmm1, qword [rip + 0xd7] ;
[0x4005e8:8]=0xaa00133700bb00ee
0x00400511 f20f114c2410 movsd qword [rsp + 0x10], xmm1
0x00400517 c744240c0000. mov dword [rsp + 0xc], 0
0x0040051f 8b54240c mov edx, dword [rsp + 0xc] ;
[0xc:4]=-1 ; 12
0x00400523 8b44240c mov eax, dword [rsp + 0xc] ;
[0xc:4]=-1 ; 12
0x00400527 4863d2 movsxd rdx, edx
0x0040052a f20f1044d418 movsd xmm0, qword [rsp + rdx*8 + 0x18]
; [0x18:8]=-1 ; 24
0x00400530 4898 cdqe
0x00400532 488b74c410 mov rsi, qword [rsp + rax*8 + 0x10] ;
[0x10:8]=-1 ; 16
0x00400537 bfd4054000 mov edi, str._16lX_n_.15e_n ;
"%16lX.%.15e." @ 0x4005d4
0x0040053c b801000000 mov eax, 1
0x00400541 e89afeffff call sym.imp.printf
;0x004003e0() ; sym.imp.printf
0x00400546 b800000000 mov eax, 0
0x0040054b 4883c428 add rsp, 0x28
0x0040054f c3 ret
memory at rsp (0x7ffea6ee18c0)
- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0x7ffea6ee18c0 5005 4000 0000 0000 1004 4000 0000 0000 P.@.......@.....
0x7ffea6ee18d0 ee00 bb00 3713 00aa ee00 bb00 3713 00aa ....7.......7... //
values here
0x7ffea6ee18e0 0000 0000 0000 0000 9037 5a02 437f 0000 .........7Z.C...
0x7ffea6ee18f0 c819 eea6 fe7f 0000 c819 eea6 fe7f 0000 ................
When compiled incorrectly with -O2
0x00400414 bfc4054000 mov edi, str._16lX_n_.15e_n ;
"%16lX.%.15e." @ 0x4005c4
0x00400419 c744240c0000. mov dword [rsp + 0xc], 0
0x00400421 486354240c movsxd rdx, dword [rsp + 0xc] ;
[0xc:4]=-1 ; 12
0x00400426 486344240c movsxd rax, dword [rsp + 0xc] ;
[0xc:4]=-1 ; 12
0x0040042b f20f1044d410 movsd xmm0, qword [rsp + rdx*8 + 0x10]
; [0x10:8]=-1 ; 16
0x00400431 488b74c418 mov rsi, qword [rsp + rax*8 + 0x18] ;
[0x18:8]=-1 ; 24
0x00400436 b801000000 mov eax, 1
0x0040043b e8a0ffffff call sym.imp.printf
;0x004003e0() ; sym.imp.printf
0x00400440 31c0 xor eax, eax
0x00400442 4883c428 add rsp, 0x28
0x00400446 c3 ret
memory at rsp (0x7ffd8ac419d0)
- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0x7ffd8ac419d0 4005 4000 0000 0000 5004 4000 0000 0000 @.@.....P.@.....
0x7ffd8ac419e0 d01a c48a fd7f 0000 0000 0000 0000 0000 ................ //
values aren't here
0x7ffd8ac419f0 0000 0000 0000 0000 90b7 be39 047f 0000 ...........9....
0x7ffd8ac41a00 d81a c48a fd7f 0000 d81a c48a fd7f 0000 ................
Running x86_64 Arch Linux, gcc -v
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/6.0.140195.9b6b471/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /mnt/AUR/gcc-multilib-trunk-git/src/gcc/configure
--prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,lto,objc,obj-c++ --enable-shared
--enable-threads=posix --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch
--disable-libssp --enable-gnu-unique-object --enable-linker-build-id
--enable-cloog-backend=isl --enable-lto --enable-plugin
--enable-install-libiberty --with-linker-hash-style=gnu --enable-multilib
--disable-werror --enable-checking=release : (reconfigured)
/mnt/AUR/gcc-multilib-trunk-git/src/gcc/configure --prefix=/usr
--libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,lto,objc,obj-c++ --enable-shared
--enable-threads=posix --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch
--disable-libssp --enable-gnu-unique-object --enable-linker-build-id
--enable-cloog-backend=isl --enable-lto --enable-plugin
--enable-install-libiberty --with-linker-hash-style=gnu --enable-multilib
--disable-werror --enable-checking=release
Thread model: posix
gcc version 6.0.140195.9b6b471 20150727 (experimental) (GCC)
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/67090] [5/6 Regression] O2/O3 optimizes values away when different type pointers are typecasted
2015-08-01 15:40 [Bug c/67090] New: [5/6 Regression] O2/O3 optimizes values away when different type pointers are typecasted davispuh at gmail dot com
@ 2015-08-01 15:42 ` davispuh at gmail dot com
2015-08-01 18:27 ` davispuh at gmail dot com
1 sibling, 0 replies; 3+ messages in thread
From: davispuh at gmail dot com @ 2015-08-01 15:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67090
--- Comment #1 from Dāvis <davispuh at gmail dot com> ---
Created attachment 36105
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36105&action=edit
Testcase
>From gcc-bugs-return-493874-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Sat Aug 01 15:49:12 2015
Return-Path: <gcc-bugs-return-493874-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 108864 invoked by alias); 1 Aug 2015 15:49:12 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 108837 invoked by uid 48); 1 Aug 2015 15:49:09 -0000
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/67090] [5/6 Regression] O2/O3 optimizes values away when different type pointers are typecasted
Date: Sat, 01 Aug 2015 15:49:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c
X-Bugzilla-Version: 6.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: pinskia at gcc dot gnu.org
X-Bugzilla-Status: RESOLVED
X-Bugzilla-Resolution: INVALID
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_status resolution
Message-ID: <bug-67090-4-MDRRTamrkJ@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-67090-4@http.gcc.gnu.org/bugzilla/>
References: <bug-67090-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-08/txt/msg00016.txt.bz2
Content-length: 583
https://gcc.gnu.org/bugzilla/show_bug.cgi?idg090
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is such an obvious violation of aliasing rules in c/c++.
Use memcpy or an Union (gcc extension) to get around the it. You can use
-fno-strict-aliasing too.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/67090] [5/6 Regression] O2/O3 optimizes values away when different type pointers are typecasted
2015-08-01 15:40 [Bug c/67090] New: [5/6 Regression] O2/O3 optimizes values away when different type pointers are typecasted davispuh at gmail dot com
2015-08-01 15:42 ` [Bug c/67090] " davispuh at gmail dot com
@ 2015-08-01 18:27 ` davispuh at gmail dot com
1 sibling, 0 replies; 3+ messages in thread
From: davispuh at gmail dot com @ 2015-08-01 18:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67090
--- Comment #3 from Dāvis <davispuh at gmail dot com> ---
(In reply to Andrew Pinski from comment #2)
> This is such an obvious violation of aliasing rules in c/c++.
> Use memcpy or an Union (gcc extension) to get around the it. You can use
> -fno-strict-aliasing too.
Then warning (or error) would be more appropriate than silently generating
invalid code as currently there's no warning even with -Wall
>From gcc-bugs-return-493878-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Sat Aug 01 18:33:38 2015
Return-Path: <gcc-bugs-return-493878-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 106916 invoked by alias); 1 Aug 2015 18:33:37 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 106888 invoked by uid 48); 1 Aug 2015 18:33:34 -0000
From: "trippels at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/67090] [5/6 Regression] O2/O3 optimizes values away when different type pointers are typecasted
Date: Sat, 01 Aug 2015 18:33:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c
X-Bugzilla-Version: 6.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: trippels at gcc dot gnu.org
X-Bugzilla-Status: RESOLVED
X-Bugzilla-Resolution: INVALID
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: cc
Message-ID: <bug-67090-4-2igYKRkq6T@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-67090-4@http.gcc.gnu.org/bugzilla/>
References: <bug-67090-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-08/txt/msg00020.txt.bz2
Content-length: 883
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67090
Markus Trippelsdorf <trippels at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |trippels at gcc dot gnu.org
--- Comment #4 from Markus Trippelsdorf <trippels at gcc dot gnu.org> ---
(In reply to Dāvis from comment #3)
> (In reply to Andrew Pinski from comment #2)
> > This is such an obvious violation of aliasing rules in c/c++.
> > Use memcpy or an Union (gcc extension) to get around the it. You can use
> > -fno-strict-aliasing too.
>
> Then warning (or error) would be more appropriate than silently generating
> invalid code as currently there's no warning even with -Wall
You'll get the warning with -Wstrict-aliasing=2 or -Wstrict-aliasing=1.
>From gcc-bugs-return-493879-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Sat Aug 01 18:38:02 2015
Return-Path: <gcc-bugs-return-493879-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 110266 invoked by alias); 1 Aug 2015 18:38:01 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 110077 invoked by uid 55); 1 Aug 2015 18:37:57 -0000
From: "pault at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/67091] Bad result for type-bound procedures returning pointers to the intrinsic function ASSOCIATED
Date: Sat, 01 Aug 2015 18:38:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: fortran
X-Bugzilla-Version: 6.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: pault at gcc dot gnu.org
X-Bugzilla-Status: NEW
X-Bugzilla-Resolution:
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: pault at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-67091-4-7m2ctyvBPF@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-67091-4@http.gcc.gnu.org/bugzilla/>
References: <bug-67091-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-08/txt/msg00021.txt.bz2
Content-length: 751
https://gcc.gnu.org/bugzilla/show_bug.cgi?idg091
--- Comment #1 from Paul Thomas <pault at gcc dot gnu.org> ---
Author: pault
Date: Sat Aug 1 18:37:25 2015
New Revision: 226464
URL: https://gcc.gnu.org/viewcvs?rev"6464&root=gcc&view=rev
Log:
2015-08-01 Paul Thomas <pault@gcc.gnu.org>
PR fortran/67091
* trans-intrinsic.c (gfc_conv_associated): Add the pre and post
blocks for the second argument to se.
2015-08-01 Paul Thomas <pault@gcc.gnu.org>
PR fortran/67091
* gfortran.dg/associated_target_6.f03: New test
Added:
trunk/gcc/testsuite/gfortran.dg/associated_target_6.f03
Modified:
trunk/gcc/fortran/ChangeLog
trunk/gcc/fortran/trans-intrinsic.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-08-01 18:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-01 15:40 [Bug c/67090] New: [5/6 Regression] O2/O3 optimizes values away when different type pointers are typecasted davispuh at gmail dot com
2015-08-01 15:42 ` [Bug c/67090] " davispuh at gmail dot com
2015-08-01 18:27 ` davispuh at gmail dot com
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).