From patchwork Thu Feb 13 21:31:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1237759 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-519502-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=ZnaxcxlT; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=UNh8qcws; dkim-atps=neutral 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 48JV8H3Bpgz9sP7 for ; Fri, 14 Feb 2020 08:31:57 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:content-type :content-transfer-encoding; q=dns; s=default; b=PmfzpH+GD9uKfQ24 xaoQHg/jeSjQzgInqmAlppOjYgwcxavpaWsJ4cbCPiknNne/u9qR6demXf1CKkH4 RwoNpeJGFh1R6Cm01WT9bBa0ffHEToFGiFbZydzgPsRTI3F+RmGbY0whYYid6Anc /7HfUyTLbWeyKbkz+jjMDVyXdCU= 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:from :to:subject:date:message-id:content-type :content-transfer-encoding; s=default; bh=HqnFsEd+Xpjwf9aN7o4mCc DrCIQ=; b=ZnaxcxlT5NcWUcSkPO+PSMvYWGD7RJ5jcnEK9afA178KeS+CZd6pSv lFERST1Bf7k+T/LM9ZmVwTs+THIPQdrHKRpmhN7gwVaWmRVVHFxHv/6pihCKQqSE /ozLBhgUMSDHbWfVVHcrOBk74hi5VHn4t1Ya2ic9SqYI2C0n/WUuw= Received: (qmail 108769 invoked by alias); 13 Feb 2020 21:31:50 -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 108739 invoked by uid 89); 13 Feb 2020 21:31:49 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=determination X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (207.211.31.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 13 Feb 2020 21:31:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581629507; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=HcqIlLPnwF/P2LBZ8ydsPYG7de+p3h7LNOrM4cyF1oc=; b=UNh8qcwsmP/PAiuoxigQzoPSbHmSt5aylb3aPv2icJkWZqsrfN817B1m9NsIQc+fEFZVMY a8FmLEHo0XaGaG3NowBgfhB512wwJx6BndJlKgtFKUr9a8ult/nyQaeAqz+Z2UKS/gHvB+ WdIAJs6IS50LEhXGGGu3WoGzRwc3C04= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-59-tXn2W5ItOuGPdxjSyurSpQ-1; Thu, 13 Feb 2020 16:31:45 -0500 Received: by mail-wr1-f70.google.com with SMTP id s13so2957793wrb.21 for ; Thu, 13 Feb 2020 13:31:45 -0800 (PST) Received: from barrymore.redhat.com ([193.85.242.99]) by smtp.gmail.com with ESMTPSA id w22sm4338366wmk.34.2020.02.13.13.31.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2020 13:31:42 -0800 (PST) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [comitted] c++: Fix static local vars in extern "C". Date: Thu, 13 Feb 2020 22:31:41 +0100 Message-Id: <20200213213141.9373-1-jason@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-IsSubscribed: yes Since my patch for PR 91476 moved visibility determination sooner, a local static in a vague linkage function now gets TREE_PUBLIC set before retrofit_lang_decl calls set_decl_linkage, which was making decl_linkage think that it has external linkage. It still has no linkage according to the standard. Tested x86_64-pc-linux-gnu, applying to trunk. gcc/cp/ChangeLog 2020-02-13 Jason Merrill PR c++/93643 PR c++/91476 * tree.c (decl_linkage): Always lk_none for locals. --- gcc/cp/tree.c | 9 +++---- .../g++.dg/lookup/extern-c-static1.C | 27 +++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/lookup/extern-c-static1.C base-commit: 613c932f5e5c0cc2e4b88e21d9870fa7b1a6ce5d diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 736ef6fe667..72b3a720ee8 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -5266,6 +5266,10 @@ decl_linkage (tree decl) if (TREE_CODE (decl) == FIELD_DECL) return lk_none; + /* Things in local scope do not have linkage. */ + if (decl_function_context (decl)) + return lk_none; + /* Things that are TREE_PUBLIC have external linkage. */ if (TREE_PUBLIC (decl)) return lk_external; @@ -5285,11 +5289,6 @@ decl_linkage (tree decl) if (TREE_CODE (decl) == CONST_DECL) return decl_linkage (TYPE_NAME (DECL_CONTEXT (decl))); - /* Things in local scope do not have linkage, if they don't have - TREE_PUBLIC set. */ - if (decl_function_context (decl)) - return lk_none; - /* Members of the anonymous namespace also have TREE_PUBLIC unset, but are considered to have external linkage for language purposes, as do template instantiations on targets without weak symbols. DECLs really diff --git a/gcc/testsuite/g++.dg/lookup/extern-c-static1.C b/gcc/testsuite/g++.dg/lookup/extern-c-static1.C new file mode 100644 index 00000000000..0ba8d67ba15 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/extern-c-static1.C @@ -0,0 +1,27 @@ +// PR c++/93643 + +void* callback(const char* name); + +extern "C" { + + inline void f1() + { + static void (*f)(); + f = (void(*)()) callback("f1"); + f(); + } + + inline void f2() + { + static void (*f)(); + f = (void(*)()) callback("f2"); + f(); + } + +} // extern "C" + +int main() +{ + f1(); + f2(); +}