User account creation filtered due to spam.

Bug 15662 - Segmentation fault (POWERPC ) when an exception is thrown - even if try catch is specified
Summary: Segmentation fault (POWERPC ) when an exception is thrown - even if try catch...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 3.3.1
: P1 normal
Target Milestone: 3.4.1
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2004-05-26 14:10 UTC by Rajan
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host:
Target: powerpc-*-linux
Build:
Known to work: 3.4.1 4.0.0
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rajan 2004-05-26 14:10:06 UTC
Consider the following:

#include <iostream.h>


class Exception{
  public:
    Exception() {}
    ~Exception() {}
};

std::string foo(bool throwException)
{
   if( throwException ) {
     throw Exception();
   } else {
     std:: string x = "hello world";
     return x;
  }
}

int main(int argc, char** argv)
{
  try {
    const std::string & str  = foo(true);
  } catch(...) {
    cout << "Caught an exception" << endl;
  }
  return 0;
}

Compiled it for POWERPC target and upon execution, it segmentation faults and 
dumps a core. From the core, it is trying to delete the std::string object 
pointed at by str (reference to string to be returned from foo) while unwinding 
the stack.

The same results are obtained if any of the STL classes are used. 

Everything works fine on x86 targets. 


It seems that the gcc compiler is breaching  ISO/ISE 14882:2003 12.2/5 upon 
throw of an exception.

Thanks
Comment 1 Andrew Pinski 2004-05-26 14:19:39 UTC
How is gcc configured?
And which PPC target, linux, or just elf?
Comment 2 Andrew Pinski 2004-05-26 14:23:41 UTC
I am going to assume eabi, if not please reopen this bug, other wise this is a dup of bug 10778 which I 
am closing this one.

*** This bug has been marked as a duplicate of 10778 ***
Comment 3 Wolfgang Bangerth 2004-05-26 14:26:25 UTC
BTW, you are trying to bind the const reference to a temporary. That 
doesn't sound very good... 
 
W. 
Comment 4 Rajan 2004-05-26 14:38:30 UTC
It is not the same as 10778. Host is linux on powerpc target machine. Compiled 
with options:

 -DLINUX -D_SVID_SOURCE=1 -D_BSD_SOURCE=1 -D_ISOC99_SOURCE=1 -D_GNU_SOURCE=1 
 -mpowerpc -pthread

As per ISO/ISE 14882:2003 12.2/5, when a reference is bound to temporary, the 
temporrary remains in scope till the reference is in scope. It would seem that 
the gcc 3.3.1 tries to delete the temporary object refered to by a const 
reference upon unwinding the stack - when it should not be attempting to delete 
that object. 

IMPORTANT NOTE: Happens only when STL is involved and on POWERPC only.
Comment 5 Andrew Pinski 2004-05-26 15:03:04 UTC
I should note this works on powerpc-apple-darwin.
Comment 6 Wolfgang Bangerth 2004-05-26 15:53:14 UTC
As Rajan correctly points out, the code is valid of course. Sorry for the 
confusing. 
W. 
Comment 7 Alan Modra 2004-06-10 12:24:35 UTC
testcase passes with 3.3-hammer, 3.4.1 and 3.5.0 powerpc-linux and powerpc64-linux
Comment 8 Andrew Pinski 2004-06-10 13:07:43 UTC
Closing as fixed then.