public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/48933] New: Infinite recursion in tr1/cmath functions with complex parameters
@ 2011-05-09 10:14 bisqwit at iki dot fi
  2011-05-09 10:46 ` [Bug libstdc++/48933] " paolo.carlini at oracle dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: bisqwit at iki dot fi @ 2011-05-09 10:14 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48933

           Summary: Infinite recursion in tr1/cmath functions with complex
                    parameters
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: bisqwit@iki.fi
                CC: warp@iki.fi


All of the function calls in this example code produce a stack overflow due to
infinite recursion, regardless of optimization level.
Compile with: g++ code.cc
Tested on the following gcc versions: 4.2.4  4.3.5  4.4.6  4.5.2  4.6.1
No compiler warnings or errors are emitted. (Tried even -Wall -W -pedantic
-ansi).

Does not happen on gcc 4.0.4, because tr1/cmath is unavailable.

#include <tr1/cmath>
#include <complex>
int main()
{
    std::tr1::tgamma( std::complex<double> (0.5, 0.0) );
    std::tr1::cbrt( std::complex<double> (0.5, 0.0) );
    std::tr1::asinh( std::complex<double> (0.5, 0.0) );
    std::tr1::acosh( std::complex<double> (1.5, 0.0) );
    std::tr1::atanh( std::complex<double> (0.5, 0.0) );
    std::tr1::erf( std::complex<double> (0.5, 0.0) );
    std::tr1::hypot( std::complex<double> (1.0, 0.0) ,
                     std::complex<double> (1.0, 0.0) );
    std::tr1::logb( std::complex<double> (0.5, 0.0) );
    std::tr1::round( std::complex<double> (0.5, 0.0) );
    std::tr1::trunc( std::complex<double> (0.5, 0.0) );
}

The bug can be traced to all functions in tr1/cmath that look like this:

  template<typename _Tp>
    inline typename __gnu_cxx::__promote<_Tp>::__type
    cbrt(_Tp __x) 
    {
      typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
      return cbrt(__type(__x)); // <-- infinite recursion here
    }


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libstdc++/48933] Infinite recursion in tr1/cmath functions with complex parameters
  2011-05-09 10:14 [Bug libstdc++/48933] New: Infinite recursion in tr1/cmath functions with complex parameters bisqwit at iki dot fi
@ 2011-05-09 10:46 ` paolo.carlini at oracle dot com
  2011-05-09 10:49 ` redi at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-05-09 10:46 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48933

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011.05.09 10:26:00
         AssignedTo|unassigned at gcc dot       |paolo.carlini at oracle dot
                   |gnu.org                     |com
     Ever Confirmed|0                           |1

--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-05-09 10:26:00 UTC ---
Apparently we need enable_ifs.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libstdc++/48933] Infinite recursion in tr1/cmath functions with complex parameters
  2011-05-09 10:14 [Bug libstdc++/48933] New: Infinite recursion in tr1/cmath functions with complex parameters bisqwit at iki dot fi
  2011-05-09 10:46 ` [Bug libstdc++/48933] " paolo.carlini at oracle dot com
@ 2011-05-09 10:49 ` redi at gcc dot gnu.org
  2011-05-09 11:00 ` bisqwit at iki dot fi
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2011-05-09 10:49 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48933

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-05-09 10:46:40 UTC ---
Yes, we should disable the TR1 math functions for anything that isn't integral
or floating point, because it happens with any non-integral, non-float type:

#include <tr1/cmath>

struct Foo { };

int main()
{
    std::tr1::acosh( Foo() );
}


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libstdc++/48933] Infinite recursion in tr1/cmath functions with complex parameters
  2011-05-09 10:14 [Bug libstdc++/48933] New: Infinite recursion in tr1/cmath functions with complex parameters bisqwit at iki dot fi
  2011-05-09 10:46 ` [Bug libstdc++/48933] " paolo.carlini at oracle dot com
  2011-05-09 10:49 ` redi at gcc dot gnu.org
@ 2011-05-09 11:00 ` bisqwit at iki dot fi
  2011-05-09 11:06 ` redi at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: bisqwit at iki dot fi @ 2011-05-09 11:00 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48933

--- Comment #4 from Joel Yliluoma <bisqwit at iki dot fi> 2011-05-09 10:51:28 UTC ---
There is, however, an asinh, a cbrt, a hypot etc. for complex types. I don't
know about standard, but mathematically they are well defined. (for example,
hypot(x,y) = sqrt(x*x + y*y), asinh(x) = log(x + sqrt(x*x + 1)))

For trunc & other rounding functions probably not so.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libstdc++/48933] Infinite recursion in tr1/cmath functions with complex parameters
  2011-05-09 10:14 [Bug libstdc++/48933] New: Infinite recursion in tr1/cmath functions with complex parameters bisqwit at iki dot fi
                   ` (2 preceding siblings ...)
  2011-05-09 11:00 ` bisqwit at iki dot fi
@ 2011-05-09 11:06 ` redi at gcc dot gnu.org
  2011-05-09 11:08 ` paolo.carlini at oracle dot com
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2011-05-09 11:06 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48933

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-05-09 10:57:06 UTC ---
They're in C++0x but I don't think they're in TR1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libstdc++/48933] Infinite recursion in tr1/cmath functions with complex parameters
  2011-05-09 10:14 [Bug libstdc++/48933] New: Infinite recursion in tr1/cmath functions with complex parameters bisqwit at iki dot fi
                   ` (3 preceding siblings ...)
  2011-05-09 11:06 ` redi at gcc dot gnu.org
@ 2011-05-09 11:08 ` paolo.carlini at oracle dot com
  2011-05-09 11:17 ` paolo.carlini at oracle dot com
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-05-09 11:08 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48933

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.7.0

--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-05-09 10:39:07 UTC ---
Note of course, those infinite recursions can at best transformed to hard
errors, there is no, eg, trunc, for std::complex types.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libstdc++/48933] Infinite recursion in tr1/cmath functions with complex parameters
  2011-05-09 10:14 [Bug libstdc++/48933] New: Infinite recursion in tr1/cmath functions with complex parameters bisqwit at iki dot fi
                   ` (4 preceding siblings ...)
  2011-05-09 11:08 ` paolo.carlini at oracle dot com
@ 2011-05-09 11:17 ` paolo.carlini at oracle dot com
  2011-05-09 15:46 ` paolo.carlini at oracle dot com
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-05-09 11:17 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48933

--- Comment #6 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-05-09 11:01:44 UTC ---
The way tr1/cmath is currently implemented, roughly speaking *when* an overload
does not exist anyway an infinite recursion can happen. Thus, this is just a
QoI issue. But it's easy to fix, I'll do that momentarily.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libstdc++/48933] Infinite recursion in tr1/cmath functions with complex parameters
  2011-05-09 10:14 [Bug libstdc++/48933] New: Infinite recursion in tr1/cmath functions with complex parameters bisqwit at iki dot fi
                   ` (5 preceding siblings ...)
  2011-05-09 11:17 ` paolo.carlini at oracle dot com
@ 2011-05-09 15:46 ` paolo.carlini at oracle dot com
  2011-05-09 15:48 ` paolo at gcc dot gnu.org
  2011-12-19  2:22 ` redi at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-05-09 15:46 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48933

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

--- Comment #8 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-05-09 15:42:17 UTC ---
Done.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libstdc++/48933] Infinite recursion in tr1/cmath functions with complex parameters
  2011-05-09 10:14 [Bug libstdc++/48933] New: Infinite recursion in tr1/cmath functions with complex parameters bisqwit at iki dot fi
                   ` (6 preceding siblings ...)
  2011-05-09 15:46 ` paolo.carlini at oracle dot com
@ 2011-05-09 15:48 ` paolo at gcc dot gnu.org
  2011-12-19  2:22 ` redi at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: paolo at gcc dot gnu.org @ 2011-05-09 15:48 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48933

--- Comment #7 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> 2011-05-09 15:38:25 UTC ---
Author: paolo
Date: Mon May  9 15:38:21 2011
New Revision: 173574

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173574
Log:
2011-05-09  Paolo Carlini  <paolo.carlini@oracle.com>

    PR libstdc++/48933
    * include/c_global/cmath (acosh, asinh, atanh, cbrt, copysign,
    erf, erfc, exp2, expm1, fdim, fma, fmax, hypot, ilogb, lgamma,
    llrint, llround, log1p, log2, logb, lrint, lround, nearbyint,
    nextafter, nexttoward, remainder, remquo, rint, round, scalbln,
    scalbn, tgamma, trunc): Use __enable_if on the return type.
    * include/tr1/cmath: Likewise.
    * testsuite/26_numerics/headers/cmath/overloads_c++0x_neg.cc: New.
    * testsuite/tr1/8_c_compatibility/cmath/overloads_neg.cc: Likewise.

Added:
   
trunk/libstdc++-v3/testsuite/26_numerics/headers/cmath/overloads_c++0x_neg.cc
    trunk/libstdc++-v3/testsuite/tr1/8_c_compatibility/cmath/overloads_neg.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/c_global/cmath
    trunk/libstdc++-v3/include/tr1/cmath


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libstdc++/48933] Infinite recursion in tr1/cmath functions with complex parameters
  2011-05-09 10:14 [Bug libstdc++/48933] New: Infinite recursion in tr1/cmath functions with complex parameters bisqwit at iki dot fi
                   ` (7 preceding siblings ...)
  2011-05-09 15:48 ` paolo at gcc dot gnu.org
@ 2011-12-19  2:22 ` redi at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2011-12-19  2:22 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48933

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-12-19 01:52:05 UTC ---
This has also been partially fixed for 4.6.3 by backporting the fix for bug
51083


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2011-12-19  1:52 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-09 10:14 [Bug libstdc++/48933] New: Infinite recursion in tr1/cmath functions with complex parameters bisqwit at iki dot fi
2011-05-09 10:46 ` [Bug libstdc++/48933] " paolo.carlini at oracle dot com
2011-05-09 10:49 ` redi at gcc dot gnu.org
2011-05-09 11:00 ` bisqwit at iki dot fi
2011-05-09 11:06 ` redi at gcc dot gnu.org
2011-05-09 11:08 ` paolo.carlini at oracle dot com
2011-05-09 11:17 ` paolo.carlini at oracle dot com
2011-05-09 15:46 ` paolo.carlini at oracle dot com
2011-05-09 15:48 ` paolo at gcc dot gnu.org
2011-12-19  2:22 ` redi at gcc dot gnu.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).