public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/51146] New: The name clog for a global variable triggers a segfault inside std::pow
@ 2011-11-15 19:53 alpha_lc at hotmail dot com
  2011-11-15 20:09 ` [Bug libstdc++/51146] " pinskia at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: alpha_lc at hotmail dot com @ 2011-11-15 19:53 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 51146
           Summary: The name clog for a global variable triggers a
                    segfault inside std::pow
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: alpha_lc@hotmail.com


Adding a global variable to the code with a name like clog, while using
std::pow on a std::complex<double> triggers a segfault when std::pow is
reached. A simple example ( http://codepad.org/4Ekpgj91 ):

#include <iostream>
#include <complex>
#include <cmath>

int clog=0;

int main()
{
    std::cout<<"test1"<<std::endl;
    std::complex<double> b(1,-1);
    std::cout<<"test "<<std::pow(b,2.0)<<std::endl;
    std::cout<<"test2"<<std::endl;
}

This behavior has first been noticed on MinGW with gcc 4.5.2, but as soon as I
found out where the bug came from it was checked on codepad, and from various
gcc users in irc.freenode.net . I rate this bug as major because there might be
something deeper behind it.


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

* [Bug libstdc++/51146] The name clog for a global variable triggers a segfault inside std::pow
  2011-11-15 19:53 [Bug c++/51146] New: The name clog for a global variable triggers a segfault inside std::pow alpha_lc at hotmail dot com
@ 2011-11-15 20:09 ` pinskia at gcc dot gnu.org
  2011-11-15 20:13 ` alpha_lc at hotmail dot com
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-11-15 20:09 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c++                         |libstdc++
           Severity|major                       |normal

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-11-15 19:52:04 UTC ---
Well the issue is clog is a C99 name for complex log.  I don't have my C++
standard in front of me but I do know some names are reserved even at the top
level.


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

* [Bug libstdc++/51146] The name clog for a global variable triggers a segfault inside std::pow
  2011-11-15 19:53 [Bug c++/51146] New: The name clog for a global variable triggers a segfault inside std::pow alpha_lc at hotmail dot com
  2011-11-15 20:09 ` [Bug libstdc++/51146] " pinskia at gcc dot gnu.org
@ 2011-11-15 20:13 ` alpha_lc at hotmail dot com
  2011-11-15 20:21 ` [Bug c++/51146] " paolo.carlini at oracle dot com
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: alpha_lc at hotmail dot com @ 2011-11-15 20:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from alpha_lc at hotmail dot com 2011-11-15 19:56:15 UTC ---
(In reply to comment #1)
> Well the issue is clog is a C99 name for complex log.  I don't have my C++
> standard in front of me but I do know some names are reserved even at the top
> level.

In case it helps on that side, I've asked a VC++ user to try this code and it
worked perfectly.


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

* [Bug c++/51146] The name clog for a global variable triggers a segfault inside std::pow
  2011-11-15 19:53 [Bug c++/51146] New: The name clog for a global variable triggers a segfault inside std::pow alpha_lc at hotmail dot com
  2011-11-15 20:09 ` [Bug libstdc++/51146] " pinskia at gcc dot gnu.org
  2011-11-15 20:13 ` alpha_lc at hotmail dot com
@ 2011-11-15 20:21 ` paolo.carlini at oracle dot com
  2011-11-15 20:33 ` pinskia at gcc dot gnu.org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-11-15 20:21 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|libstdc++                   |c++

--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-11-15 20:07:35 UTC ---
For sure in the library there is nothing to fix, note in particular that the
implementation does not include <complex.h>, neither names clog, only
__builtin_clog.


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

* [Bug c++/51146] The name clog for a global variable triggers a segfault inside std::pow
  2011-11-15 19:53 [Bug c++/51146] New: The name clog for a global variable triggers a segfault inside std::pow alpha_lc at hotmail dot com
                   ` (3 preceding siblings ...)
  2011-11-15 20:33 ` pinskia at gcc dot gnu.org
@ 2011-11-15 20:33 ` paolo.carlini at oracle dot com
  2011-11-15 22:44 ` joseph at codesourcery dot com
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-11-15 20:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-11-15 20:26:23 UTC ---
I suppose, yes.


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

* [Bug c++/51146] The name clog for a global variable triggers a segfault inside std::pow
  2011-11-15 19:53 [Bug c++/51146] New: The name clog for a global variable triggers a segfault inside std::pow alpha_lc at hotmail dot com
                   ` (2 preceding siblings ...)
  2011-11-15 20:21 ` [Bug c++/51146] " paolo.carlini at oracle dot com
@ 2011-11-15 20:33 ` pinskia at gcc dot gnu.org
  2011-11-15 20:33 ` paolo.carlini at oracle dot com
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-11-15 20:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-11-15 20:20:48 UTC ---
(In reply to comment #3)
> For sure in the library there is nothing to fix, note in particular that the
> implementation does not include <complex.h>, neither names clog, only
> __builtin_clog.

But __builtin_clog always expands to extern "C" clog.  There is not much to be
done in the compiler here or libstdc++ really.  Just have to understand clog is
a reserved name under C99.


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

* [Bug c++/51146] The name clog for a global variable triggers a segfault inside std::pow
  2011-11-15 19:53 [Bug c++/51146] New: The name clog for a global variable triggers a segfault inside std::pow alpha_lc at hotmail dot com
                   ` (4 preceding siblings ...)
  2011-11-15 20:33 ` paolo.carlini at oracle dot com
@ 2011-11-15 22:44 ` joseph at codesourcery dot com
  2011-11-15 23:11 ` paolo.carlini at oracle dot com
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: joseph at codesourcery dot com @ 2011-11-15 22:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from joseph at codesourcery dot com <joseph at codesourcery dot com> 2011-11-15 22:28:38 UTC ---
I think this is really a duplicate of an issue discussed in various places 
before: libstdc++ relies on C library symbols that are not necessarily 
reserved by the selected version of standard C++, and in particular it 
relies on them in inline code in headers.  This means (a) g++ predefines 
_GNU_SOURCE, causing headers included by the user to make visible symbols 
the user didn't want and (b) the use of symbols in the headers conflicts 
with any symbols of the same name defined by the user.  Fixing this would 
be pretty involved and require close cooperation with libc to provide 
implementation-namespace versions of every such symbol the library needs, 
as I said in bug 36231; a lot of work to get this exactly in accordance 
with the various standards.


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

* [Bug c++/51146] The name clog for a global variable triggers a segfault inside std::pow
  2011-11-15 19:53 [Bug c++/51146] New: The name clog for a global variable triggers a segfault inside std::pow alpha_lc at hotmail dot com
                   ` (5 preceding siblings ...)
  2011-11-15 22:44 ` joseph at codesourcery dot com
@ 2011-11-15 23:11 ` paolo.carlini at oracle dot com
  2011-11-15 23:29 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-11-15 23:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-11-15 23:05:17 UTC ---
I just want to reiterate that the c++ library headers never name clog, only
__builtin_clog (and of course only when the underlying libc provides the
corresponding clog, in case runtime library calls are actually required). I
don't see why this way of using a __builtin* facility should give problems.
Would it be difficult to change the compiler to decouple completely, eg,
__builtin_clog from clog, in such a way that if the user or anything else
fiddles with the latter, the former is not affected, as if it were a completely
different, unrelated, name?


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

* [Bug c++/51146] The name clog for a global variable triggers a segfault inside std::pow
  2011-11-15 19:53 [Bug c++/51146] New: The name clog for a global variable triggers a segfault inside std::pow alpha_lc at hotmail dot com
                   ` (6 preceding siblings ...)
  2011-11-15 23:11 ` paolo.carlini at oracle dot com
@ 2011-11-15 23:29 ` redi at gcc dot gnu.org
  2011-11-16  0:13 ` paolo.carlini at oracle dot com
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2011-11-15 23:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-11-15 23:10:37 UTC ---
(N.B. we do name clog, but only for std::clog, the standard ostream ;)

If you link dynamically to libm.so then the clog symbol can be replaced by
symbol interposition. If a user does that and the symbol isn't the right type,
it goes boom.


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

* [Bug c++/51146] The name clog for a global variable triggers a segfault inside std::pow
  2011-11-15 19:53 [Bug c++/51146] New: The name clog for a global variable triggers a segfault inside std::pow alpha_lc at hotmail dot com
                   ` (7 preceding siblings ...)
  2011-11-15 23:29 ` redi at gcc dot gnu.org
@ 2011-11-16  0:13 ` paolo.carlini at oracle dot com
  2021-09-30  9:14 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-11-16  0:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-11-15 23:27:43 UTC ---
Jon, I think I understand what you are saying, but then we have one more reason
to not consider this sort of issue as <library>, because linking libm, with a
clog in user code with a different meaning, etc, can certainly happen even with
no headers included.


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

* [Bug c++/51146] The name clog for a global variable triggers a segfault inside std::pow
  2011-11-15 19:53 [Bug c++/51146] New: The name clog for a global variable triggers a segfault inside std::pow alpha_lc at hotmail dot com
                   ` (8 preceding siblings ...)
  2011-11-16  0:13 ` paolo.carlini at oracle dot com
@ 2021-09-30  9:14 ` pinskia at gcc dot gnu.org
  2021-09-30 10:02 ` redi at gcc dot gnu.org
  2021-09-30 10:04 ` redi at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-30  9:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51146

--- Comment #10 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Starting in GCC 8, we warn about this:
<source>:5:5: warning: built-in function 'clog' declared as non-function
[-Wbuiltin-declaration-mismatch]
 int clog=0;
     ^~~~


I noticed that LLVM's libc++ does not call clog but just log.

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

* [Bug c++/51146] The name clog for a global variable triggers a segfault inside std::pow
  2011-11-15 19:53 [Bug c++/51146] New: The name clog for a global variable triggers a segfault inside std::pow alpha_lc at hotmail dot com
                   ` (9 preceding siblings ...)
  2021-09-30  9:14 ` pinskia at gcc dot gnu.org
@ 2021-09-30 10:02 ` redi at gcc dot gnu.org
  2021-09-30 10:04 ` redi at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2021-09-30 10:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51146

--- Comment #11 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Libc++ uses complex<_Tp>(log(abs(__x)), arg(__x));

Even for C++11, which is based on C99, ::clog is not a reserved name in C++
because C++ specifies that <complex.h> just includes the C++ <complex> header,
so defines std::complex and none of the C99 complex routines exist in C++. This
is not a universally popular feature of C++. But it does mean that a strictly
conforming C++ program can use ::clog for whatever purpose it wants.

However, in practice, our implementation doesn't exist in a vacuum and depends
on an underlying system library (which is usually based on POSIX) and so those
symbols are essentially reserved too, even if the C++ standard doesn't say so.

E.g. if you define a symbol called ::fdopen or ::open you're asking for
trouble, even though those are not in ISO C++.

If you want a pure ISO C++ environment that doesn't rely on additional features
of POSIX and C99, maybe you need to look elsewhere.

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

* [Bug c++/51146] The name clog for a global variable triggers a segfault inside std::pow
  2011-11-15 19:53 [Bug c++/51146] New: The name clog for a global variable triggers a segfault inside std::pow alpha_lc at hotmail dot com
                   ` (10 preceding siblings ...)
  2021-09-30 10:02 ` redi at gcc dot gnu.org
@ 2021-09-30 10:04 ` redi at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2021-09-30 10:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51146

--- Comment #12 from Jonathan Wakely <redi at gcc dot gnu.org> ---
tl;dr I'm tempted to close this as WONTFIX.

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

end of thread, other threads:[~2021-09-30 10:04 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-15 19:53 [Bug c++/51146] New: The name clog for a global variable triggers a segfault inside std::pow alpha_lc at hotmail dot com
2011-11-15 20:09 ` [Bug libstdc++/51146] " pinskia at gcc dot gnu.org
2011-11-15 20:13 ` alpha_lc at hotmail dot com
2011-11-15 20:21 ` [Bug c++/51146] " paolo.carlini at oracle dot com
2011-11-15 20:33 ` pinskia at gcc dot gnu.org
2011-11-15 20:33 ` paolo.carlini at oracle dot com
2011-11-15 22:44 ` joseph at codesourcery dot com
2011-11-15 23:11 ` paolo.carlini at oracle dot com
2011-11-15 23:29 ` redi at gcc dot gnu.org
2011-11-16  0:13 ` paolo.carlini at oracle dot com
2021-09-30  9:14 ` pinskia at gcc dot gnu.org
2021-09-30 10:02 ` redi at gcc dot gnu.org
2021-09-30 10:04 ` 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).