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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 5BFCC3858C2C for ; Thu, 30 Sep 2021 15:49:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5BFCC3858C2C Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-303-Hqus91XrNA-fyLlcUHIz6w-1; Thu, 30 Sep 2021 11:49:06 -0400 X-MC-Unique: Hqus91XrNA-fyLlcUHIz6w-1 Received: by mail-qt1-f198.google.com with SMTP id c21-20020ac85195000000b002a540bbf1caso12296905qtn.2 for ; Thu, 30 Sep 2021 08:49:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=2gOUGwZMXvmP5biGkrP+4RcNuh9lSnlZjrCkdpLL0iw=; b=HOBpMc0wuTFdf/gNMcFLjMw9c+zLaI3uOssZs7qpsag+2cFrGpkfFOzMeTdYvp9TNv /2EHWNLarnqhmuaSkzIVt4R1KilkMOlf+sl4MyxosOL1zfEjXji9QCQgPitZm131clwl gq8uY1JxzwQLls1M39edUbBICxBYh8XiDZvu2E+Tei79uDDNiqZc4JgWldbKwg4idQhO oiyi8DXXPyOA4fa+etiN9+kbv0Yv+DrelNr17wsCro13A/kfiaN3fuyYaWDf2XFZZhhQ lDZvoAMFcgHm1GFslL9tKkP5i0j+u+41OeNuEGbGshvk6EhKoJu03rTBcGaZBnSd3w3I Tj0w== X-Gm-Message-State: AOAM5317+SApT/fnxEkY5IQKKq5jiR4z42MqFYStRnV5p6Yc/uao0ftb /JlbmSkCtnaQUdEdjjZ4r3Ufmf5zrJE61Yov3LmuPAlS7FmdZ9GpfxZbYOu/rCEbKvwqXaPwCAp u8ubIYjoWOk+Cn/WwBw== X-Received: by 2002:a37:a215:: with SMTP id l21mr5415352qke.74.1633016945796; Thu, 30 Sep 2021 08:49:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDUGp+fDK8e4UBOSbouJpys0JPZbxSprCEA7BT730jUDr27mHXHsoq1GJCUoO7zP8uCAQF/A== X-Received: by 2002:a37:a215:: with SMTP id l21mr5415323qke.74.1633016945408; Thu, 30 Sep 2021 08:49:05 -0700 (PDT) Received: from [192.168.1.149] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id k10sm1662841qkk.124.2021.09.30.08.49.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 30 Sep 2021 08:49:04 -0700 (PDT) Message-ID: Date: Thu, 30 Sep 2021 11:49:04 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.2 Subject: Re: [PATCH] c++: Fix handling of __thread/thread_local extern vars declared at function scope [PR102496] To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org References: <20210929083640.GL304296@tucnak> <20210930154512.GC304296@tucnak> From: Jason Merrill In-Reply-To: <20210930154512.GC304296@tucnak> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Thu, 30 Sep 2021 15:49:09 -0000 On 9/30/21 11:45, Jakub Jelinek wrote: > On Thu, Sep 30, 2021 at 08:06:52AM -0400, Jason Merrill wrote: >> Hmm, what if decl has the tls_model attribute? >> >> We could decide not to push the alias for a thread-local variable when >> processing_template_decl, like we don't if the type is dependent; in either >> case we'll push it at instantiation time. > > So like this (assuming it passes full bootstrap/regtest, so far it passed > tls.exp)? OK. > 2021-09-28 Jakub Jelinek > > PR c++/102496 > * name-lookup.c (push_local_extern_decl_alias): Return early even for > tls vars with non-dependent type when processing_template_decl. For > CP_DECL_THREAD_LOCAL_P vars call set_decl_tls_model on alias. > > * g++.dg/tls/pr102496-1.C: New test. > * g++.dg/tls/pr102496-2.C: New test. > > --- gcc/cp/name-lookup.c.jj 2021-09-29 10:07:28.838061585 +0200 > +++ gcc/cp/name-lookup.c 2021-09-30 17:30:46.010100552 +0200 > @@ -3375,7 +3375,10 @@ set_decl_context_in_fn (tree ctx, tree d > void > push_local_extern_decl_alias (tree decl) > { > - if (dependent_type_p (TREE_TYPE (decl))) > + if (dependent_type_p (TREE_TYPE (decl)) > + || (processing_template_decl > + && VAR_P (decl) > + && CP_DECL_THREAD_LOCAL_P (decl))) > return; > /* EH specs were not part of the function type prior to c++17, but > we still can't go pushing dependent eh specs into the namespace. */ > @@ -3471,6 +3474,8 @@ push_local_extern_decl_alias (tree decl) > push_nested_namespace (ns); > alias = do_pushdecl (alias, /* hiding= */true); > pop_nested_namespace (ns); > + if (VAR_P (decl) && CP_DECL_THREAD_LOCAL_P (decl)) > + set_decl_tls_model (alias, DECL_TLS_MODEL (decl)); > } > } > > --- gcc/testsuite/g++.dg/tls/pr102496-1.C.jj 2021-09-30 17:22:47.867769063 +0200 > +++ gcc/testsuite/g++.dg/tls/pr102496-1.C 2021-09-30 17:22:47.867769063 +0200 > @@ -0,0 +1,20 @@ > +// PR c++/102496 > +// { dg-do link { target c++11 } } > +// { dg-require-effective-target tls } > +// { dg-add-options tls } > +// { dg-additional-sources pr102496-2.C } > + > +template > +int > +foo () > +{ > + extern __thread int t1; > + return t1; > +} > + > +int > +main () > +{ > + extern __thread int t2; > + return foo <0> () + t2; > +} > --- gcc/testsuite/g++.dg/tls/pr102496-2.C.jj 2021-09-30 17:22:47.867769063 +0200 > +++ gcc/testsuite/g++.dg/tls/pr102496-2.C 2021-09-30 17:22:47.867769063 +0200 > @@ -0,0 +1,6 @@ > +// PR c++/102496 > +// { dg-do compile { target c++11 } } > +// { dg-require-effective-target tls } > + > +__thread int t1; > +__thread int t2; > > > Jakub >