From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id DF0E239450ED for ; Fri, 13 Nov 2020 17:29:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DF0E239450ED Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-224-JTMI-wetNS2jfoHAgw46-A-1; Fri, 13 Nov 2020 12:29:50 -0500 X-MC-Unique: JTMI-wetNS2jfoHAgw46-A-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E6CFC1899423; Fri, 13 Nov 2020 17:29:49 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-113-127.ams2.redhat.com [10.36.113.127]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 852DD55793; Fri, 13 Nov 2020 17:29:49 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 0ADHTlnu3478462 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 13 Nov 2020 18:29:47 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 0ADHTjx43478461; Fri, 13 Nov 2020 18:29:45 +0100 Date: Fri, 13 Nov 2020 18:29:45 +0100 From: Jakub Jelinek To: Jason Merrill , Jonathan Wakely , John David Anglin Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Predefine __STDCPP_THREADS__ in the compiler if thread model is not single Message-ID: <20201113172945.GH3788@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-6.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Nov 2020 17:29:54 -0000 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 * 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