From patchwork Thu Jun 5 17:28:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 356554 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C53E114008D for ; Fri, 6 Jun 2014 03:28:55 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=FTlIJQH9sPCHxQPUhXtVcKnp+cEOwGmerKzoQ+pts7nhKA ShWZFlH/FhuAsFjKC8l7Kai5kYg912qdjuvkmNNPUFS6zcuoT72v4tXhuglcxkgh 0HuDE6zEUrAB139e+AC8c39HauAaZgYV5N/LynFyHCqv+VKsxf9zAI18qf5Zs= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=f0IATtPQ0l9t/JwTEODmiBmU7aA=; b=tNM5V3fFQty1Jlr9c/ga KANdUztk3VPK9O1A3RdL3c5ifsCpcc0xuXMvuFsE9YKU2th/6PTP8mjRoC/qfNi+ ERUTwwN5HPo4eIgvUQrVpQJL8bi3QMvq/UDa6+YlejEHaw6v0FGqzuLMy4yvdn0r xnh7Zi4hcvqyPCJIQjtZgcQ= Received: (qmail 8086 invoked by alias); 5 Jun 2014 17:28:47 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 8068 invoked by uid 89); 5 Jun 2014 17:28:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.2 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 05 Jun 2014 17:28:37 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s55HSZFG029300 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 5 Jun 2014 13:28:36 -0400 Received: from [10.10.116.18] ([10.10.116.18]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s55HSZ3I030995 for ; Thu, 5 Jun 2014 13:28:35 -0400 Message-ID: <5390A8C3.6030009@redhat.com> Date: Thu, 05 Jun 2014 13:28:35 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/61343 (missing init for thread_local) The bug here was that we were setting DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P for a variable where the explicitly written initializer is constant, but becomes a non-constant constructor call. Fixed thus. Tested x86_64-pc-linux-gnu, applying to trunk. commit 210aa8e75e0827163fd3041890404d39d485d23d Author: Jason Merrill Date: Wed Jun 4 13:28:38 2014 -0400 PR c++/61343 * decl.c (check_initializer): Maybe clear DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 3d4058c..b068df8 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -5856,6 +5856,13 @@ check_initializer (tree decl, tree init, int flags, vec **cleanups) if (init && init != error_mark_node) init_code = build2 (INIT_EXPR, type, decl, init); + if (init_code) + { + /* We might have set these in cp_finish_decl. */ + DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = false; + TREE_CONSTANT (decl) = false; + } + if (init_code && DECL_IN_AGGR_P (decl)) { static int explained = 0; diff --git a/gcc/testsuite/g++.dg/tls/thread_local9.C b/gcc/testsuite/g++.dg/tls/thread_local9.C new file mode 100644 index 0000000..c75528a --- /dev/null +++ b/gcc/testsuite/g++.dg/tls/thread_local9.C @@ -0,0 +1,23 @@ +// PR c++/61343 + +// { dg-do run { target c++11 } } +// { dg-add-options tls } +// { dg-require-effective-target tls_runtime } + +struct Foo { + int value; + + Foo() noexcept { + value = 12; + } +}; + +static thread_local Foo a{}; + +static __attribute__((noinline)) void UseA() { + if (a.value != 12) __builtin_abort(); +} + +int main() { + UseA(); +}