Bug 12789 - [tree-ssa] Miscompilation of small program
Summary: [tree-ssa] Miscompilation of small program
Status: RESOLVED DUPLICATE of bug 12751
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: tree-ssa
: P2 critical
Target Milestone: tree-ssa
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2003-10-27 14:33 UTC by Wolfgang Bangerth
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Wolfgang Bangerth 2003-10-27 14:33:36 UTC
This small program
---------------------------
#include <fstream>
#include <string>

void foo (const int i) {
  std::ifstream in("irrelevant");
  std::string line;
  if (i == 1) return;
  foo (1);
}

int main () {
  foo (0);
}
---------------------------
segfaults on running when compiled with the tree-ssa
branch from
  gcc version 3.5-tree-ssa 20031024 (merged 20031017)
It doesn't segfault with mainline from the same day, though.
Assuming that the code in libstdc++ is the same on the two
branches, this means that something is being miscompiled. This
could, theoretically also include a miscompilation in libstdc++
itself, since I can't get around using parts of it, but it 
strikes me as odd that I need the tail recursion in foo() to
actually trigger the bug in the program. Maybe it is just
some interaction of the tail recursion and the stack space/
constructors/exception handling details of the objects in use
in this function that make this happen, so this could actually
be simple to track down than it looks like.

W.
Comment 1 Andrew Pinski 2003-10-27 17:19:14 UTC
Most likely the same bug as PR 12751.
Comment 2 Wolfgang Bangerth 2003-10-28 18:02:20 UTC
This is indeed almost certainly the same bug. Here's something smaller: 
----------------------------- 
#include <cstdio> 
 
struct X 
{ 
    X()  { printf ("X::X\n"); } 
    ~X() { printf ("X::~X\n"); } 
}; 
 
void foo (const int i) { 
  X x1, x2; 
  if (i == 1) return; 
  foo (1); 
} 
 
int main () { 
  foo (0); 
} 
------------------------------ 
 
I get 4 calls to the ctor, and 5 to the dtor. 
 
W. 
Comment 3 Andrew Pinski 2003-10-30 04:51:02 UTC
It is a dup of bug 12751, as it works correctly with -fno-exception and it has nothing to do with 
tail recursion (or switch's), it is eh related.
Comment 4 Andrew Pinski 2003-10-30 04:53:05 UTC

*** This bug has been marked as a duplicate of 12751 ***
Comment 5 Wolfgang Bangerth 2003-11-14 16:50:46 UTC
Confirmed fixed with rth's patch to 12751. 
Thanks a lot!