Date: Tue, 28 Aug 2001 23:15:58 -0700 (PDT) From: Petr Lampa <lampa@fee.vutbr.cz> To: freebsd-gnats-submit@FreeBSD.org Subject: gnu/30181: gcc-2.95.3 -O2 optimalization bug Message-ID: <200108290615.f7T6FwW24091@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 30181 >Category: gnu >Synopsis: gcc-2.95.3 -O2 optimalization bug >Confidential: no >Severity: serious >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Tue Aug 28 23:20:00 PDT 2001 >Closed-Date: >Last-Modified: >Originator: Petr Lampa >Release: 4.3-RELEASE,4.3-STABLE,4.4-RC1 >Organization: Dept. of Computer Science FEECS BUT >Environment: FreeBSD boco.fee.vutbr.cz 4.3-STABLE FreeBSD 4.3-STABLE #1: Thu Jul 19 08:48:56 CEST 2001 lampa@boco.fee.vutbr.cz:/src/sys/sys-44/compile/BOCO i386 >Description: gcc-2.95.3 (both FreeBSD port and original GNU version) generates bad code for long long operations in some cases when -O2 is on: #include <sys/types.h> #include <netinet/in.h> extern off_t rfc1035NamePack(char *buf, size_t sz, const char *name); static off_t rfc1035QuestionPack(char *buf, size_t sz, const char *name, unsigned short type, unsigned short class) { off_t off = 0; <-- this is long long unsigned short s; off += rfc1035NamePack(buf, sz, name); s = class; memcpy(buf + off, &s, sizeof(s)); assert(off <= sz); return off; } The code is taken from squid-2.3.STABLE5, it's minimized to demonstrate bug. gcc -v -O2 -S t.c Using builtin specs. gcc version 2.95.3 [FreeBSD] 20010315 (release) /usr/libexec/cpp -lang-c -v -D__GNUC__=2 -D__GNUC_MINOR__=95 -Di386 -D__FreeBSD __=4 -D__FreeBSD_cc_version=440000 -Dunix -D__i386__ -D__FreeBSD__=4 -D__FreeBSD _cc_version=440000 -D__unix__ -D__i386 -D__unix -Acpu(i386) -Amachine(i386) -Asy stem(unix) -Asystem(FreeBSD) -D__OPTIMIZE__ -Acpu(i386) -Amachine(i386) -Di386 - D__i386 -D__i386__ -D__ELF__ t.c /tmp/ccvoKazy.i GNU CPP version 2.95.3 [FreeBSD] 20010315 (release) (i386 FreeBSD/ELF) #include "..." search starts here: #include <...> search starts here: /usr/include /usr/include End of search list. The following default directories have been omitted from the search path: /usr/include/g++ End of omitted list. /usr/libexec/cc1 /tmp/ccvoKazy.i -quiet -dumpbase t.c -O2 -version -o t.s GNU C version 2.95.3 [FreeBSD] 20010315 (release) (i386-unknown-freebsd) compile d by GNU C version 2.95.3 [FreeBSD] 20010315 (release). .file "t.c" .version "01.01" gcc2_compiled.: .text .p2align 2,0x90 .type rfc1035QuestionPack,@function rfc1035QuestionPack: pushl %ebp movl %esp,%ebp subl $16,%esp pushl %edi pushl %esi movl 8(%ebp),%esi movl 12(%ebp),%eax xorl %edx,%edx <---- this should be long long (%eax,%edx) movl %eax,12(%ebp) <---- 2nd argument overwritten movl %edx,16(%ebp) <---- 3rd argument overwritten movl 24(%ebp),%edi addl $-4,%esp pushl 16(%ebp) pushl %eax pushl %esi call rfc1035NamePack movl %eax,-8(%ebp) movl %edx,-4(%ebp) movl -8(%ebp),%eax movw %di,(%eax,%esi) addl $-12,%esp xorl %ecx,%ecx movl 12(%ebp),%eax movl 16(%ebp),%edx addl $16,%esp cmpl %edx,-4(%ebp) jg .L3 jne .L4 cmpl %eax,-8(%ebp) ja .L3 .L4: movl $1,%ecx .L3: pushl %ecx call assert movl -8(%ebp),%eax movl -4(%ebp),%edx leal -24(%ebp),%esp popl %esi popl %esi popl %edi leave ret .Lfe1: .size rfc1035QuestionPack,.Lfe1-rfc1035QuestionPack .ident "GCC: (GNU) c 2.95.3 [FreeBSD] 20010315 (release)" >How-To-Repeat: gcc -O2 t.c >Fix: Use -O optimalization only. This error may manifest anywhere where long long type is used (distribution, ports). This should be mentioned in release notes. gcc-3.0.1 seems to be fixed. >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200108290615.f7T6FwW24091>