public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: Predefine __STDCPP_THREADS__ in the compiler if thread model is not single
@ 2020-11-13 17:29 Jakub Jelinek
  2020-11-13 18:20 ` Jeff Law
  2020-11-13 19:20 ` Tom Tromey
  0 siblings, 2 replies; 12+ messages in thread
From: Jakub Jelinek @ 2020-11-13 17:29 UTC (permalink / raw)
  To: Jason Merrill, Jonathan Wakely, John David Anglin; +Cc: gcc-patches

Hi!

The following patch predefines __STDCPP_THREADS__ macro to 1 if c++11 or
later and thread model (e.g. printed by gcc -v) is not single.
There are two targets not handled by this patch, those that define
THREAD_MODEL_SPEC.  In one case - QNX - it looks just like a mistake
to me, instead of setting thread_model=posix in config.gcc it uses
THREAD_MODEL_SPEC macro to set it unconditionally to posix.
The other is hpux10, which uses -threads option to decide if threads
are enabled or not, but that option isn't really passed to the compiler.
I think that is something that really should be solved in config/pa/
instead, e.g. in the config/xxx/xxx-c.c targets usually set their own
predefined macros and it could handle this, and either pass the option
also to the compiler, or say predefine __STDCPP_THREADS__ if _DCE_THREADS
macro is defined already (or -D_DCE_THREADS found on the command line),
or whatever else.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 

2020-11-13  Jakub Jelinek  <jakub@redhat.com>

	* c-cppbuiltin.c: Include configargs.h.
	(c_cpp_builtins): For C++11 and later if THREAD_MODEL_SPEC is not
	defined, predefine __STDCPP_THREADS__ to 1 unless thread_model is
	"single".

--- gcc/c-family/c-cppbuiltin.c.jj	2020-10-22 10:37:25.890800306 +0200
+++ gcc/c-family/c-cppbuiltin.c	2020-11-13 12:34:25.290963074 +0100
@@ -32,6 +32,7 @@ along with GCC; see the file COPYING3.
 #include "debug.h"		/* For dwarf2out_do_cfi_asm.  */
 #include "common/common-target.h"
 #include "cppbuiltin.h"
+#include "configargs.h"
 
 #ifndef TARGET_OS_CPP_BUILTINS
 # define TARGET_OS_CPP_BUILTINS()
@@ -1033,6 +1034,12 @@ c_cpp_builtins (cpp_reader *pfile)
 	cpp_define (pfile, "__cpp_threadsafe_static_init=200806L");
       if (flag_char8_t)
         cpp_define (pfile, "__cpp_char8_t=201811L");
+#ifndef THREAD_MODEL_SPEC
+      /* Targets that define THREAD_MODEL_SPEC need to define
+	 __STDCPP_THREADS__ in their config/XXX/XXX-c.c themselves.  */
+      if (cxx_dialect >= cxx11 && strcmp (thread_model, "single") != 0)
+	cpp_define (pfile, "__STDCPP_THREADS__=1");
+#endif
     }
   /* Note that we define this for C as well, so that we know if
      __attribute__((cleanup)) will interface with EH.  */

	Jakub


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

* Re: [PATCH] c++: Predefine __STDCPP_THREADS__ in the compiler if thread model is not single
  2020-11-13 17:29 [PATCH] c++: Predefine __STDCPP_THREADS__ in the compiler if thread model is not single Jakub Jelinek
@ 2020-11-13 18:20 ` Jeff Law
  2020-11-13 19:03   ` John David Anglin
  2020-11-13 19:20 ` Tom Tromey
  1 sibling, 1 reply; 12+ messages in thread
From: Jeff Law @ 2020-11-13 18:20 UTC (permalink / raw)
  To: Jakub Jelinek, Jason Merrill, Jonathan Wakely, John David Anglin
  Cc: gcc-patches


On 11/13/20 10:29 AM, Jakub Jelinek via Gcc-patches wrote:
> Hi!
>
> The following patch predefines __STDCPP_THREADS__ macro to 1 if c++11 or
> later and thread model (e.g. printed by gcc -v) is not single.
> There are two targets not handled by this patch, those that define
> THREAD_MODEL_SPEC.  In one case - QNX - it looks just like a mistake
> to me, instead of setting thread_model=posix in config.gcc it uses
> THREAD_MODEL_SPEC macro to set it unconditionally to posix.
> The other is hpux10, which uses -threads option to decide if threads
> are enabled or not, but that option isn't really passed to the compiler.
> I think that is something that really should be solved in config/pa/
> instead, e.g. in the config/xxx/xxx-c.c targets usually set their own
> predefined macros and it could handle this, and either pass the option
> also to the compiler, or say predefine __STDCPP_THREADS__ if _DCE_THREADS
> macro is defined already (or -D_DCE_THREADS found on the command line),
> or whatever else.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 
>
> 2020-11-13  Jakub Jelinek  <jakub@redhat.com>
>
> 	* c-cppbuiltin.c: Include configargs.h.
> 	(c_cpp_builtins): For C++11 and later if THREAD_MODEL_SPEC is not
> 	defined, predefine __STDCPP_THREADS__ to 1 unless thread_model is
> 	"single".

OK.  Note that hpux10 should be considered long dead.   I wouldn't let
that get in the way of anything.  One could argue we should remove
hpux10 and earlier, leaving just hpux11.


Jeff



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

* Re: [PATCH] c++: Predefine __STDCPP_THREADS__ in the compiler if thread model is not single
  2020-11-13 18:20 ` Jeff Law
@ 2020-11-13 19:03   ` John David Anglin
  2020-11-13 19:05     ` Jeff Law
  0 siblings, 1 reply; 12+ messages in thread
From: John David Anglin @ 2020-11-13 19:03 UTC (permalink / raw)
  To: Jeff Law, Jakub Jelinek, Jason Merrill, Jonathan Wakely; +Cc: gcc-patches

On 2020-11-13 1:20 p.m., Jeff Law wrote:
> On 11/13/20 10:29 AM, Jakub Jelinek via Gcc-patches wrote:
>> Hi!
>>
>> The following patch predefines __STDCPP_THREADS__ macro to 1 if c++11 or
>> later and thread model (e.g. printed by gcc -v) is not single.
>> There are two targets not handled by this patch, those that define
>> THREAD_MODEL_SPEC.  In one case - QNX - it looks just like a mistake
>> to me, instead of setting thread_model=posix in config.gcc it uses
>> THREAD_MODEL_SPEC macro to set it unconditionally to posix.
>> The other is hpux10, which uses -threads option to decide if threads
>> are enabled or not, but that option isn't really passed to the compiler.
>> I think that is something that really should be solved in config/pa/
>> instead, e.g. in the config/xxx/xxx-c.c targets usually set their own
>> predefined macros and it could handle this, and either pass the option
>> also to the compiler, or say predefine __STDCPP_THREADS__ if _DCE_THREADS
>> macro is defined already (or -D_DCE_THREADS found on the command line),
>> or whatever else.
>>
>> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 
>>
>> 2020-11-13  Jakub Jelinek  <jakub@redhat.com>
>>
>> 	* c-cppbuiltin.c: Include configargs.h.
>> 	(c_cpp_builtins): For C++11 and later if THREAD_MODEL_SPEC is not
>> 	defined, predefine __STDCPP_THREADS__ to 1 unless thread_model is
>> 	"single".
> OK.  Note that hpux10 should be considered long dead.   I wouldn't let
> that get in the way of anything.  One could argue we should remove
> hpux10 and earlier, leaving just hpux11.
In principle, I agree.  But there are some intereactions in the header defines and I have limited
time at the moment.

Regards,
Dave

-- 
John David Anglin  dave.anglin@bell.net


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

* Re: [PATCH] c++: Predefine __STDCPP_THREADS__ in the compiler if thread model is not single
  2020-11-13 19:03   ` John David Anglin
@ 2020-11-13 19:05     ` Jeff Law
  0 siblings, 0 replies; 12+ messages in thread
From: Jeff Law @ 2020-11-13 19:05 UTC (permalink / raw)
  To: John David Anglin, Jakub Jelinek, Jason Merrill, Jonathan Wakely
  Cc: gcc-patches


On 11/13/20 12:03 PM, John David Anglin wrote:
> On 2020-11-13 1:20 p.m., Jeff Law wrote:
>> On 11/13/20 10:29 AM, Jakub Jelinek via Gcc-patches wrote:
>>> Hi!
>>>
>>> The following patch predefines __STDCPP_THREADS__ macro to 1 if c++11 or
>>> later and thread model (e.g. printed by gcc -v) is not single.
>>> There are two targets not handled by this patch, those that define
>>> THREAD_MODEL_SPEC.  In one case - QNX - it looks just like a mistake
>>> to me, instead of setting thread_model=posix in config.gcc it uses
>>> THREAD_MODEL_SPEC macro to set it unconditionally to posix.
>>> The other is hpux10, which uses -threads option to decide if threads
>>> are enabled or not, but that option isn't really passed to the compiler.
>>> I think that is something that really should be solved in config/pa/
>>> instead, e.g. in the config/xxx/xxx-c.c targets usually set their own
>>> predefined macros and it could handle this, and either pass the option
>>> also to the compiler, or say predefine __STDCPP_THREADS__ if _DCE_THREADS
>>> macro is defined already (or -D_DCE_THREADS found on the command line),
>>> or whatever else.
>>>
>>> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 
>>>
>>> 2020-11-13  Jakub Jelinek  <jakub@redhat.com>
>>>
>>> 	* c-cppbuiltin.c: Include configargs.h.
>>> 	(c_cpp_builtins): For C++11 and later if THREAD_MODEL_SPEC is not
>>> 	defined, predefine __STDCPP_THREADS__ to 1 unless thread_model is
>>> 	"single".
>> OK.  Note that hpux10 should be considered long dead.   I wouldn't let
>> that get in the way of anything.  One could argue we should remove
>> hpux10 and earlier, leaving just hpux11.
> In principle, I agree.  But there are some intereactions in the header defines and I have limited
> time at the moment.

ACK.  I don't think removing the old hpux stuff is a high priority.   My
primary point was that I think hpux10 is dead and we shouldn't let it
get in the way of making progress on platforms that are still viable.


jeff


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

* Re: [PATCH] c++: Predefine __STDCPP_THREADS__ in the compiler if thread model is not single
  2020-11-13 17:29 [PATCH] c++: Predefine __STDCPP_THREADS__ in the compiler if thread model is not single Jakub Jelinek
  2020-11-13 18:20 ` Jeff Law
@ 2020-11-13 19:20 ` Tom Tromey
  2020-11-13 21:39   ` Jason Merrill
  2020-11-13 21:42   ` Jonathan Wakely
  1 sibling, 2 replies; 12+ messages in thread
From: Tom Tromey @ 2020-11-13 19:20 UTC (permalink / raw)
  To: Jakub Jelinek via Gcc-patches
  Cc: Jason Merrill, Jonathan Wakely, John David Anglin, Jakub Jelinek

>>>>> "Jakub" == Jakub Jelinek via Gcc-patches <gcc-patches@gcc.gnu.org> writes:

Jakub> 2020-11-13  Jakub Jelinek  <jakub@redhat.com>

Jakub> 	* c-cppbuiltin.c: Include configargs.h.
Jakub> 	(c_cpp_builtins): For C++11 and later if THREAD_MODEL_SPEC is not
Jakub> 	defined, predefine __STDCPP_THREADS__ to 1 unless thread_model is
Jakub> 	"single".

Note this is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63287

Tom

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

* Re: [PATCH] c++: Predefine __STDCPP_THREADS__ in the compiler if thread model is not single
  2020-11-13 19:20 ` Tom Tromey
@ 2020-11-13 21:39   ` Jason Merrill
  2020-11-13 21:46     ` Jakub Jelinek
  2020-11-13 21:42   ` Jonathan Wakely
  1 sibling, 1 reply; 12+ messages in thread
From: Jason Merrill @ 2020-11-13 21:39 UTC (permalink / raw)
  To: Tom Tromey, Jakub Jelinek via Gcc-patches
  Cc: Jonathan Wakely, John David Anglin, Jakub Jelinek

On 11/13/20 2:20 PM, Tom Tromey wrote:
>>>>>> "Jakub" == Jakub Jelinek via Gcc-patches <gcc-patches@gcc.gnu.org> writes:
> 
> Jakub> 2020-11-13  Jakub Jelinek  <jakub@redhat.com>
> 
> Jakub> 	* c-cppbuiltin.c: Include configargs.h.
> Jakub> 	(c_cpp_builtins): For C++11 and later if THREAD_MODEL_SPEC is not
> Jakub> 	defined, predefine __STDCPP_THREADS__ to 1 unless thread_model is
> Jakub> 	"single".
> 
> Note this is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63287

Any opinions about the relative advantage of doing this in the compiler 
vs. doing it in the library, as in Jonathan's patch in the PR?

Jason


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

* Re: [PATCH] c++: Predefine __STDCPP_THREADS__ in the compiler if thread model is not single
  2020-11-13 19:20 ` Tom Tromey
  2020-11-13 21:39   ` Jason Merrill
@ 2020-11-13 21:42   ` Jonathan Wakely
  1 sibling, 0 replies; 12+ messages in thread
From: Jonathan Wakely @ 2020-11-13 21:42 UTC (permalink / raw)
  To: gcc-patches

>>>>>> "Jakub" == Jakub Jelinek via Gcc-patches <gcc-patches@gcc.gnu.org> writes:
>
>Jakub> 	* c-cppbuiltin.c: Include configargs.h.
>Jakub> 	(c_cpp_builtins): For C++11 and later if THREAD_MODEL_SPEC is not
>Jakub> 	defined, predefine __STDCPP_THREADS__ to 1 unless thread_model is
>Jakub> 	"single".
>
>Note this is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63287

And FTR the QNX case that Jakub mentioned is now:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97815


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

* Re: [PATCH] c++: Predefine __STDCPP_THREADS__ in the compiler if thread model is not single
  2020-11-13 21:39   ` Jason Merrill
@ 2020-11-13 21:46     ` Jakub Jelinek
  2020-11-13 21:50       ` Jason Merrill
                         ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Jakub Jelinek @ 2020-11-13 21:46 UTC (permalink / raw)
  To: Jason Merrill
  Cc: Tom Tromey, Jakub Jelinek via Gcc-patches, Jonathan Wakely,
	John David Anglin

On Fri, Nov 13, 2020 at 04:39:25PM -0500, Jason Merrill wrote:
> On 11/13/20 2:20 PM, Tom Tromey wrote:
> > > > > > > "Jakub" == Jakub Jelinek via Gcc-patches <gcc-patches@gcc.gnu.org> writes:
> > 
> > Jakub> 2020-11-13  Jakub Jelinek  <jakub@redhat.com>
> > 
> > Jakub> 	* c-cppbuiltin.c: Include configargs.h.
> > Jakub> 	(c_cpp_builtins): For C++11 and later if THREAD_MODEL_SPEC is not
> > Jakub> 	defined, predefine __STDCPP_THREADS__ to 1 unless thread_model is
> > Jakub> 	"single".
> > 
> > Note this is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63287
> 
> Any opinions about the relative advantage of doing this in the compiler vs.
> doing it in the library, as in Jonathan's patch in the PR?

If it is done in the library, it will be defined only if any of the library
headers are included.
The https://eel.is/c++draft/cpp.predefined wording doesn't look like it
would allow defining it only if certain headers are included
(unlike e.g. the __cpp_lib_* macros which have associated list of headers
that should define those).

	Jakub


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

* Re: [PATCH] c++: Predefine __STDCPP_THREADS__ in the compiler if thread model is not single
  2020-11-13 21:46     ` Jakub Jelinek
@ 2020-11-13 21:50       ` Jason Merrill
  2020-11-13 22:52       ` Jonathan Wakely
  2020-11-16 16:23       ` Tom Tromey
  2 siblings, 0 replies; 12+ messages in thread
From: Jason Merrill @ 2020-11-13 21:50 UTC (permalink / raw)
  To: Jakub Jelinek
  Cc: Tom Tromey, Jakub Jelinek via Gcc-patches, Jonathan Wakely,
	John David Anglin

On 11/13/20 4:46 PM, Jakub Jelinek wrote:
> On Fri, Nov 13, 2020 at 04:39:25PM -0500, Jason Merrill wrote:
>> On 11/13/20 2:20 PM, Tom Tromey wrote:
>>>>>>>> "Jakub" == Jakub Jelinek via Gcc-patches <gcc-patches@gcc.gnu.org> writes:
>>>
>>> Jakub> 2020-11-13  Jakub Jelinek  <jakub@redhat.com>
>>>
>>> Jakub> 	* c-cppbuiltin.c: Include configargs.h.
>>> Jakub> 	(c_cpp_builtins): For C++11 and later if THREAD_MODEL_SPEC is not
>>> Jakub> 	defined, predefine __STDCPP_THREADS__ to 1 unless thread_model is
>>> Jakub> 	"single".
>>>
>>> Note this is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63287
>>
>> Any opinions about the relative advantage of doing this in the compiler vs.
>> doing it in the library, as in Jonathan's patch in the PR?
> 
> If it is done in the library, it will be defined only if any of the library
> headers are included.
> The https://eel.is/c++draft/cpp.predefined wording doesn't look like it
> would allow defining it only if certain headers are included
> (unlike e.g. the __cpp_lib_* macros which have associated list of headers
> that should define those).

Then the patch is OK.

Jason


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

* Re: [PATCH] c++: Predefine __STDCPP_THREADS__ in the compiler if thread model is not single
  2020-11-13 21:46     ` Jakub Jelinek
  2020-11-13 21:50       ` Jason Merrill
@ 2020-11-13 22:52       ` Jonathan Wakely
  2020-11-16 16:23       ` Tom Tromey
  2 siblings, 0 replies; 12+ messages in thread
From: Jonathan Wakely @ 2020-11-13 22:52 UTC (permalink / raw)
  To: Jakub Jelinek
  Cc: Jason Merrill, Tom Tromey, Jakub Jelinek via Gcc-patches,
	John David Anglin

On 13/11/20 22:46 +0100, Jakub Jelinek wrote:
>On Fri, Nov 13, 2020 at 04:39:25PM -0500, Jason Merrill wrote:
>> On 11/13/20 2:20 PM, Tom Tromey wrote:
>> > > > > > > "Jakub" == Jakub Jelinek via Gcc-patches <gcc-patches@gcc.gnu.org> writes:
>> >
>> > Jakub> 2020-11-13  Jakub Jelinek  <jakub@redhat.com>
>> >
>> > Jakub> 	* c-cppbuiltin.c: Include configargs.h.
>> > Jakub> 	(c_cpp_builtins): For C++11 and later if THREAD_MODEL_SPEC is not
>> > Jakub> 	defined, predefine __STDCPP_THREADS__ to 1 unless thread_model is
>> > Jakub> 	"single".
>> >
>> > Note this is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63287
>>
>> Any opinions about the relative advantage of doing this in the compiler vs.
>> doing it in the library, as in Jonathan's patch in the PR?
>
>If it is done in the library, it will be defined only if any of the library
>headers are included.
>The https://eel.is/c++draft/cpp.predefined wording doesn't look like it
>would allow defining it only if certain headers are included
>(unlike e.g. the __cpp_lib_* macros which have associated list of headers
>that should define those).

Right, the standard says "The values of the predefined macros (except
for __FILE__ and __LINE__) remain constant throughout the translation
unit."

Libc++ defines it in the library, and I added a testcase showing why
that's non-conforming to https://bugs.llvm.org/show_bug.cgi?id=33230#c11


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

* Re: [PATCH] c++: Predefine __STDCPP_THREADS__ in the compiler if thread model is not single
  2020-11-13 21:46     ` Jakub Jelinek
  2020-11-13 21:50       ` Jason Merrill
  2020-11-13 22:52       ` Jonathan Wakely
@ 2020-11-16 16:23       ` Tom Tromey
  2020-11-16 16:49         ` Jonathan Wakely
  2 siblings, 1 reply; 12+ messages in thread
From: Tom Tromey @ 2020-11-16 16:23 UTC (permalink / raw)
  To: Jakub Jelinek via Gcc-patches
  Cc: Jason Merrill, Jakub Jelinek, Jonathan Wakely, Tom Tromey,
	John David Anglin

Jakub> If it is done in the library, it will be defined only if any of the library
Jakub> headers are included.
Jakub> The https://eel.is/c++draft/cpp.predefined wording doesn't look like it
Jakub> would allow defining it only if certain headers are included
Jakub> (unlike e.g. the __cpp_lib_* macros which have associated list of headers
Jakub> that should define those).

Also I was wondering if there's a C analogue.
I found http://www.open-std.org/jtc1/sc22/WG14/www/docs/n2069.pdf but I
have no idea whether this is just a paper or was adopted.

Tom

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

* Re: [PATCH] c++: Predefine __STDCPP_THREADS__ in the compiler if thread model is not single
  2020-11-16 16:23       ` Tom Tromey
@ 2020-11-16 16:49         ` Jonathan Wakely
  0 siblings, 0 replies; 12+ messages in thread
From: Jonathan Wakely @ 2020-11-16 16:49 UTC (permalink / raw)
  To: Tom Tromey
  Cc: Jakub Jelinek via Gcc-patches, Jason Merrill, Jakub Jelinek,
	John David Anglin

On 16/11/20 09:23 -0700, Tom Tromey wrote:
>Jakub> If it is done in the library, it will be defined only if any of the library
>Jakub> headers are included.
>Jakub> The https://eel.is/c++draft/cpp.predefined wording doesn't look like it
>Jakub> would allow defining it only if certain headers are included
>Jakub> (unlike e.g. the __cpp_lib_* macros which have associated list of headers
>Jakub> that should define those).
>
>Also I was wondering if there's a C analogue.
>I found http://www.open-std.org/jtc1/sc22/WG14/www/docs/n2069.pdf but I
>have no idea whether this is just a paper or was adopted.

C11 and later say:

_ _STDC_NO_THREADS_ _ The integer constant 1, intended to indicate that the
implementation does not support the <threads.h> header.

You can probably guess how useful it is in practice:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53769



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

end of thread, other threads:[~2020-11-16 16:49 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-13 17:29 [PATCH] c++: Predefine __STDCPP_THREADS__ in the compiler if thread model is not single Jakub Jelinek
2020-11-13 18:20 ` Jeff Law
2020-11-13 19:03   ` John David Anglin
2020-11-13 19:05     ` Jeff Law
2020-11-13 19:20 ` Tom Tromey
2020-11-13 21:39   ` Jason Merrill
2020-11-13 21:46     ` Jakub Jelinek
2020-11-13 21:50       ` Jason Merrill
2020-11-13 22:52       ` Jonathan Wakely
2020-11-16 16:23       ` Tom Tromey
2020-11-16 16:49         ` Jonathan Wakely
2020-11-13 21:42   ` Jonathan Wakely

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).