public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/18084] New: setfill coupled with inline function: incorrect results on Linux x86
@ 2004-10-20 16:37 knutejunk at austin dot rr dot com
2004-10-20 17:09 ` [Bug rtl-optimization/18084] [3.4 only]setfill " pinskia at gcc dot gnu dot org
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: knutejunk at austin dot rr dot com @ 2004-10-20 16:37 UTC (permalink / raw)
To: gcc-bugs
The problem...
The following program produces incorrect results on a Linux x86 system when
compiled with gcc v3.4.2 (and 3.4.1) with full optimizations. The program is
supposed to print 0xFFFF, but instead produces random results (seems to be a
stack corruption problem).
The source...
#include <inttypes.h>
#include <iostream>
#include <iomanip>
#define BUG
using namespace std;
class A
{
public:
A () :
valid_mask_(0x00000000FFFFFFFFull),
size_(0x000000000000FFFFull)
{}
uint64_t calc(uint64_t value) const {
#ifdef BUG
return valid_mask_ & (value | size_);
#else
// This code will never expose the bug
uint64_t tmp = valid_mask_ & (value | size_);
return tmp;
#endif
}
private:
uint64_t valid_mask_;
uint64_t size_;
};
uint32_t CheckStuff()
{
A a;
uint64_t value = a.calc(0);
#ifdef BUG
// This code will expose the bug iff BUG is defined for calc()
cout << "0x" << hex << setfill('0') << value << endl;
#else
// This code will never expose the bug
cout << "0x" << hex << value << endl;
#endif
if(value == 0xffff) {
return 0;
}
else {
return 1;
}
}
int main()
{
return CheckStuff();
}
The build line...
gcc-3.4.1 -v -W -Wall -O3 -g2 gcc_bug.cpp
The results (it's purely random, but here's an example)...
0x8048978bfffbb68
What it should print...
0xFFFF
Observations...
- Take out the -O3 (-O0) and it works
- This program works just fine on Solaris no matter how you compile it
- This program works with gcc 3.3.X, gcc 3.2.X and (shudder) 2.95
- Take out setfill('0') and it works
- Keep setfill('0') in the cout statement and return a tmp for the inline
calc() function and it works
Compiler/system info...
system type:
Linux x86 (RedHat Enterprise 3)
gcc -v output:
--enable-shared --with-ld=/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-
linux2.4/bin/ld
--with-as=/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/bin/as
--with-nm=/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/bin/nm
--enable-languages=c,c++,java --disable-nls
Thread model: posix
gcc version 3.4.1
/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/libexec/gcc/i686-pc-
linux-gnu/3.4
.1/cc1plus -quiet -v -D_GNU_SOURCE gcc_bug.cpp -quiet -dumpbase gcc_bug.cpp
-mtune=pentiumpro -auxbase gcc_bug -g2 -O0 -W -Wall -version -o /tmp/cc82jgXc.s
ignoring nonexistent directory
"/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/lib/gcc/i686-pc-linux-
gnu/3.4.1/
../../../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/lib/gcc/i686-pc-linux-
gnu/3.4.1/.
./../../../include/c++/3.4.1
/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/lib/gcc/i686-pc-linux-
gnu/3.4.1/.
./../../../include/c++/3.4.1/i686-pc-linux-gnu
/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/lib/gcc/i686-pc-linux-
gnu/3.4.1/.
./../../../include/c++/3.4.1/backward
/usr/local/include
/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/include
/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/lib/gcc/i686-pc-linux-
gnu/3.4.1/i
nclude
/usr/include
End of search list.
GNU C++ version 3.4.1 (i686-pc-linux-gnu)
compiled by GNU C version 3.4.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/bin/as -V -Qy -o /tmp/
cc15JK08.o
/tmp/cc82jgXc.s
GNU assembler version 2.13.2.1 (i686-pc-linux-gnu) using BFD version 2.13.2.1
/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/libexec/gcc/i686-pc-
linux-gnu/3.4
.1/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -rpath
/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/lib /usr/lib/crt1.o
/usr/lib/crti.o
/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/lib/gcc/i686-pc-linux-
gnu/3.4.1/c
rtbegin.o
-L/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/lib/gcc/i686-pc-
linux-gnu/3.4.1
-L/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/lib/gcc/i686-pc-
linux-gnu/3.4.1
/../../../../i686-pc-linux-gnu/lib
-L/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/lib/gcc/i686-pc-
linux-gnu/3.4.1
/../../.. /tmp/cc15JK08.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/lib/gcc/i686-pc-linux-
gnu/3.4.1/c
rtend.o /usr/lib/crtn.o
--
Summary: setfill coupled with inline function: incorrect results
on Linux x86
Product: gcc
Version: 3.4.2
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: knutejunk at austin dot rr dot com
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18084
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug rtl-optimization/18084] [3.4 only]setfill coupled with inline function: incorrect results on Linux x86
2004-10-20 16:37 [Bug c++/18084] New: setfill coupled with inline function: incorrect results on Linux x86 knutejunk at austin dot rr dot com
@ 2004-10-20 17:09 ` pinskia at gcc dot gnu dot org
2004-10-20 18:00 ` bangerth at dealii dot org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-20 17:09 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-10-20 17:09 -------
It works on the mainline but not on 3.4.0 and I don't know if this is a regression.
But I should note that -O2 is enough and -O2 -fno-gcse works.
--
What |Removed |Added
----------------------------------------------------------------------------
Component|c++ |rtl-optimization
Keywords| |wrong-code
Known to fail| |3.4.0
Known to work| |4.0.0
Summary|setfill coupled with inline |[3.4 only]setfill coupled
|function: incorrect results |with inline function:
|on Linux x86 |incorrect results on Linux
| |x86
Target Milestone|--- |3.4.3
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18084
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug rtl-optimization/18084] [3.4 only]setfill coupled with inline function: incorrect results on Linux x86
2004-10-20 16:37 [Bug c++/18084] New: setfill coupled with inline function: incorrect results on Linux x86 knutejunk at austin dot rr dot com
2004-10-20 17:09 ` [Bug rtl-optimization/18084] [3.4 only]setfill " pinskia at gcc dot gnu dot org
@ 2004-10-20 18:00 ` bangerth at dealii dot org
2004-10-25 14:24 ` bangerth at dealii dot org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: bangerth at dealii dot org @ 2004-10-20 18:00 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-10-20 18:00 -------
Here's something slightly smaller:
------------------
#include <inttypes.h>
#include <iostream>
#include <iomanip>
uint64_t mask1, mask2;
uint64_t calc() {
return mask1 & mask2;
}
int main()
{
mask1 = 0x00000000FFFFFFFFull;
mask2 = 0x000000000000FFFFull;
uint64_t value = calc();
std::cout << std::setfill('0');
if(value != calc())
abort ();
}
------------------------------
g/x> /home/bangerth/bin/gcc-3.4.3-pre/bin/c++ -O3 x.cc ; ./a.out
Aborted
I'll keep working on reducing this.
W.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18084
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug rtl-optimization/18084] [3.4 only]setfill coupled with inline function: incorrect results on Linux x86
2004-10-20 16:37 [Bug c++/18084] New: setfill coupled with inline function: incorrect results on Linux x86 knutejunk at austin dot rr dot com
2004-10-20 17:09 ` [Bug rtl-optimization/18084] [3.4 only]setfill " pinskia at gcc dot gnu dot org
2004-10-20 18:00 ` bangerth at dealii dot org
@ 2004-10-25 14:24 ` bangerth at dealii dot org
2004-10-25 14:57 ` [Bug rtl-optimization/18084] [3.4 regression]setfill " pinskia at gcc dot gnu dot org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: bangerth at dealii dot org @ 2004-10-25 14:24 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-10-25 14:24 -------
Here is a short testcase:
----------------------
struct X {
bool init;
void foo() { if (!init) init = true; }
void bar() { foo(); }
};
typedef unsigned long long int uint64_t;
uint64_t mask1, mask2;
uint64_t calc() {
return mask1 & mask2;
}
int main()
{
mask1 = 0x00000000FFFFFFFFull;
mask2 = 0x000000000000FFFFull;
uint64_t value = calc();
X().bar();
if(value != calc())
abort ();
}
------------------------------
g/x> /home/bangerth/bin/gcc-3.4.3-pre/bin/c++ y.cc && ./a.out
g/x> /home/bangerth/bin/gcc-3.4.3-pre/bin/c++ -O3 y.cc && ./a.out
Aborted
g/x> /home/bangerth/bin/gcc-3.3.4-pre/bin/c++ -O3 y.cc && ./a.out
g/x> /home/bangerth/bin/gcc-4.0-pre/bin/c++ -O3 y.cc && ./a.out
Thus, the problem is confined to the 3.4 branch (which does not mean,
of course, that the bug isn't latent on mainline as well).
W.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed| |1
Last reconfirmed|0000-00-00 00:00:00 |2004-10-25 14:24:46
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18084
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug rtl-optimization/18084] [3.4 regression]setfill coupled with inline function: incorrect results on Linux x86
2004-10-20 16:37 [Bug c++/18084] New: setfill coupled with inline function: incorrect results on Linux x86 knutejunk at austin dot rr dot com
` (2 preceding siblings ...)
2004-10-25 14:24 ` bangerth at dealii dot org
@ 2004-10-25 14:57 ` pinskia at gcc dot gnu dot org
2004-10-30 22:58 ` cvs-commit at gcc dot gnu dot org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-25 14:57 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-10-25 14:56 -------
It also works in 3.3.3.
--
What |Removed |Added
----------------------------------------------------------------------------
Known to work|4.0.0 |4.0.0 3.3.3
Summary|[3.4 only]setfill coupled |[3.4 regression]setfill
|with inline function: |coupled with inline
|incorrect results on Linux |function: incorrect results
|x86 |on Linux x86
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18084
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug rtl-optimization/18084] [3.4 regression]setfill coupled with inline function: incorrect results on Linux x86
2004-10-20 16:37 [Bug c++/18084] New: setfill coupled with inline function: incorrect results on Linux x86 knutejunk at austin dot rr dot com
` (3 preceding siblings ...)
2004-10-25 14:57 ` [Bug rtl-optimization/18084] [3.4 regression]setfill " pinskia at gcc dot gnu dot org
@ 2004-10-30 22:58 ` cvs-commit at gcc dot gnu dot org
2004-10-30 23:06 ` pinskia at gcc dot gnu dot org
2004-10-31 1:57 ` cvs-commit at gcc dot gnu dot org
6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-10-30 22:58 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From cvs-commit at gcc dot gnu dot org 2004-10-30 22:58 -------
Subject: Bug 18084
CVSROOT: /cvs/gcc
Module name: gcc
Changes by: sayle@gcc.gnu.org 2004-10-30 22:58:49
Modified files:
gcc/testsuite : ChangeLog
Added files:
gcc/testsuite/g++.dg/opt: pr18084-1.C
Log message:
PR rtl-optimization/18084
* g++.dg/opt/pr18084-1.C: New testcase.
Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4525&r2=1.4526
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/opt/pr18084-1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18084
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug rtl-optimization/18084] [3.4 regression]setfill coupled with inline function: incorrect results on Linux x86
2004-10-20 16:37 [Bug c++/18084] New: setfill coupled with inline function: incorrect results on Linux x86 knutejunk at austin dot rr dot com
` (4 preceding siblings ...)
2004-10-30 22:58 ` cvs-commit at gcc dot gnu dot org
@ 2004-10-30 23:06 ` pinskia at gcc dot gnu dot org
2004-10-31 1:57 ` cvs-commit at gcc dot gnu dot org
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-30 23:06 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-10-30 23:06 -------
*** This bug has been marked as a duplicate of 17581 ***
--
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |DUPLICATE
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18084
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug rtl-optimization/18084] [3.4 regression]setfill coupled with inline function: incorrect results on Linux x86
2004-10-20 16:37 [Bug c++/18084] New: setfill coupled with inline function: incorrect results on Linux x86 knutejunk at austin dot rr dot com
` (5 preceding siblings ...)
2004-10-30 23:06 ` pinskia at gcc dot gnu dot org
@ 2004-10-31 1:57 ` cvs-commit at gcc dot gnu dot org
6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-10-31 1:57 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From cvs-commit at gcc dot gnu dot org 2004-10-31 01:57 -------
Subject: Bug 18084
CVSROOT: /cvs/gcc
Module name: gcc
Branch: gcc-3_4-branch
Changes by: sayle@gcc.gnu.org 2004-10-31 01:57:39
Modified files:
gcc/testsuite : ChangeLog
Added files:
gcc/testsuite/g++.dg/opt: pr18084-1.C
Log message:
PR rtl-optimization/18084
* g++.dg/opt/pr18084-1.C: New testcase.
Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.301&r2=1.3389.2.302
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/opt/pr18084-1.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18084
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2004-10-31 1:57 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-20 16:37 [Bug c++/18084] New: setfill coupled with inline function: incorrect results on Linux x86 knutejunk at austin dot rr dot com
2004-10-20 17:09 ` [Bug rtl-optimization/18084] [3.4 only]setfill " pinskia at gcc dot gnu dot org
2004-10-20 18:00 ` bangerth at dealii dot org
2004-10-25 14:24 ` bangerth at dealii dot org
2004-10-25 14:57 ` [Bug rtl-optimization/18084] [3.4 regression]setfill " pinskia at gcc dot gnu dot org
2004-10-30 22:58 ` cvs-commit at gcc dot gnu dot org
2004-10-30 23:06 ` pinskia at gcc dot gnu dot org
2004-10-31 1:57 ` 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).