From patchwork Fri Nov 17 15:24:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Schwinge X-Patchwork-Id: 166218 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp607678vqn; Fri, 17 Nov 2023 07:25:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IEXyJlYDi11w/2aoSkAN5l8zv40BozrcZ/VfqiOTmmevHwJZmGeQwiIQFyv9ZyiqxTVB5s1 X-Received: by 2002:a05:6214:30a:b0:65b:2660:f58b with SMTP id i10-20020a056214030a00b0065b2660f58bmr13178223qvu.12.1700234722409; Fri, 17 Nov 2023 07:25:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700234722; cv=pass; d=google.com; s=arc-20160816; b=QosLeN9lJoeUHyW90OfoAS3rUc9arUJyIAY15uiajgz+GKxZWa7sPof+H/45IJ7Qz1 Ef+fxDovyIHetqcHVS7D1gO7l2cCer86UDYlnCCB2LLwKckPHGw3MSp6r0/Nw1O0FLNn DBpzEgRjT6oGgJjwicf3BxBq0GnS34BsCT+4/Tflq7nxYGb3sPN3RcNAWWvC33ORS9Fw 4a3BANJLXIv+rQeEfRmYObKF/pIRqL+gSd/RMCqcYHO60GI7Clfffs4Ar5AHfL+IFweE AJb6ISzM2TFXMtjAoTjPuKDfietwPNHGOxZ35YeDwoz964mRSmlSdpWY3dAt2j+lKwlV bqXQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:message-id:date :user-agent:subject:to:from:ironport-sdr:arc-filter:dmarc-filter :delivered-to; bh=H+uRUxIPjgbWyWj/Axr2iyqRtUC6vTPW8XD3ndAxrLg=; fh=yeE/fgfjyvozsqW07dOG6igMiAmRYR/3M4icxF+Md7M=; b=gxzuqiy7+LtrxOIyKPk8/9CO6AH3JOaTEdrtKQZQEiP36FV2OaaIlPfnx91vRz2WbH LzBr7leWIPzr96FNQE9EpkpdclS+T3M+YxNOk62tVZ3muwthKpotY4urlhrnZFfyBRu4 Z33yttioXYqk89v+TGgOrcpZcJFRG3vZuxiNqSi6BdppDoJAYiHsAGG04dECk0NbU/KT KCSEEK8M9qzuS6tYVYa4Ii6vI+b/GU50lLzEZE1TUKojImA6U0oN/nnBmOOjvBjtPy96 FQ8IRKm4/FFyJYKzmLjwIJRnPM6VBf+EvbcrIqjgMbAgpTkhczS/rH3Sx0ebEM/Is3cQ MZ+w== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id c11-20020a05621401cb00b00658900baafasi1787139qvt.609.2023.11.17.07.25.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 07:25:22 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 300FA385828A for ; Fri, 17 Nov 2023 15:25:22 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 6DBE23858D1E for ; Fri, 17 Nov 2023 15:24:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6DBE23858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6DBE23858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=68.232.141.98 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700234698; cv=none; b=c8yxhOAaab43q6ig1CvPkBDAsmQAu+iSNo2zRr+pRtRRaZtJDBlcPDQlJ1+dY1x3gqPDvm8GZ3NkcNyZyzo23NiLcz8DBlBHPz56X17YEjU+zIwRweni2406pC3UYnwQVULrHz+2nXAhydas5WbmqM3YeBDeer3w9I+hdLqbDRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700234698; c=relaxed/simple; bh=84bRvUeOpwekbKL1NG57BFk0kw31ywT6ob1H6FR84a4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=TCn7lcPwVLykqh7m7FKd/idw+03X1h67uz3gjZjJrmVo5eX3ymr92vx0vACh/EtM5CR6c+gdzO7XjsOZ+tKtAzVRnvTjotz7qI6OdMdDuq+UGNUOJjonqDgoc0YBerT4054KIcz41hPqgwjiA+aCDiWeXvciNQR36CeDBjnPDzo= ARC-Authentication-Results: i=1; server2.sourceware.org X-CSE-ConnectionGUID: Mvqe8hYxQ5a9phfERmNacw== X-CSE-MsgGUID: A0eHwi5ZRdCiFxngWb4s1A== X-IronPort-AV: E=Sophos;i="6.04,206,1695715200"; d="scan'208,223";a="25803326" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 17 Nov 2023 07:24:52 -0800 IronPort-SDR: SlBrjml3aoOozzrnVDJHlRD/X54nnZaVBKtJ96IXunH8AEVgoCbfNNRh1gjX5zanasJywXeRym +22n8kV59aUxym93izdL9eHXRPrizqb3S4j2TAYg0xd0evYig9T1LeBnVR2Dlfrns+6AzXRUxd KwuJzaJyT/sFzF9NLhxdMrRYFPmIbvy5SNFeMb/RLqU8ovGVpgYVe322mm1jLbQwJuaVLIy2ky djC8Ylv23FMuKbPOvqVTpk+MkBF4IGE2wHDbz6f5L/JjGkQ816z+c6N98VNORPnId7qQ1mtkEH mKU= From: Thomas Schwinge To: Jakub Jelinek , Tobias Burnus , Subject: Add 'libgomp.c++/static-local-variable-1.C' User-Agent: Notmuch/0.29.3+94~g74c3f1b (https://notmuchmail.org) Emacs/28.2 (x86_64-pc-linux-gnu) Date: Fri, 17 Nov 2023 16:24:46 +0100 Message-ID: <87sf541jy9.fsf@euler.schwinge.homeip.net> MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-11.mgc.mentorg.com (139.181.222.11) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, URIBL_SBL_A, WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782825324342562372 X-GMAIL-MSGID: 1782825324342562372 Hi! I found that with GCC's '-fthreadsafe-statics' implementation (..., which is enabled by default) instrumented as follows: --- libstdc++-v3/libsupc++/guard.cc +++ libstdc++-v3/libsupc++/guard.cc @@ -271,6 +273,7 @@ namespace __cxxabiv1 extern "C" int __cxa_guard_acquire (__guard *g) { + asm("int3"); #ifdef __GTHREADS // If the target can reorder loads, we need to insert a read memory // barrier so that accesses to the guarded variable happen after the ..., there is only one single libgomp C++ test case where this triggers; 'libgomp.c++/taskloop-6.C': Thread 1 "a.out" received signal SIGTRAP, Trace/breakpoint trap. __cxxabiv1::__cxa_guard_acquire (g=0x60b228 (J)::i>) at [...]/source-gcc/libstdc++-v3/libsupc++/guard.cc:281 281 if (_GLIBCXX_GUARD_TEST_AND_ACQUIRE (g)) (gdb) bt #0 __cxxabiv1::__cxa_guard_acquire (g=0x60b228 (J)::i>) at [...]/source-gcc/libstdc++-v3/libsupc++/guard.cc:281 #1 0x0000000000404772 in f17<121> (j=...) at source-gcc/libgomp/testsuite/libgomp.c++/taskloop-6.C:300 #2 0x0000000000401e11 in main () at source-gcc/libgomp/testsuite/libgomp.c++/taskloop-6.C:411 That test case however isn't per se testing behavior of a C++ static local variable vs. OpenMP. OK to push the attached "Add 'libgomp.c++/static-local-variable-1.C'"? (Also, I'm happy to extend the test case to verify any additional features you think are userful to be tested there.) (With '-fno-threadsafe-statics', this fails, as expected.) Grüße Thomas ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 From d3140a1b4a649c5acb3735ef7fd04a4ebffe5e9a Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Fri, 17 Nov 2023 16:06:25 +0100 Subject: [PATCH] Add 'libgomp.c++/static-local-variable-1.C' A debug run may look as follows: int main() void f() S::S() void f() S::S()/ void f() void f()/ void f() void f()/ void f() void f()/ void f() void f()/ void f() void f()/ void f() void f()/ void f() void f()/ void f() void f()/ void f() void f()/ void f() void f()/ void f()/ void f()/ cSC = 1 cf = 12 int main()/ S::~S() S::~S()/ libgomp/ * testsuite/libgomp.c++/static-local-variable-1.C: New. --- .../libgomp.c++/static-local-variable-1.C | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 libgomp/testsuite/libgomp.c++/static-local-variable-1.C diff --git a/libgomp/testsuite/libgomp.c++/static-local-variable-1.C b/libgomp/testsuite/libgomp.c++/static-local-variable-1.C new file mode 100644 index 00000000000..3169ba77d8d --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/static-local-variable-1.C @@ -0,0 +1,95 @@ +// Test basic behavior of a C++ static local variable vs. OpenMP. + +#include +#include + +#define DEBUG_PRINTF //__builtin_printf + +static int state; + +static int cSC, cSD, cf; + +struct S +{ + S() + { + DEBUG_PRINTF("%s\n", __PRETTY_FUNCTION__); + + int c; +#pragma omp atomic capture + c = ++cSC; + if (c != 1) + __builtin_abort(); + + if (state++ != 1) + __builtin_abort(); + + DEBUG_PRINTF("%s/\n", __PRETTY_FUNCTION__); + } + + ~S() + { + DEBUG_PRINTF("%s\n", __PRETTY_FUNCTION__); + + int c; +#pragma omp atomic capture + c = ++cSD; + if (c != 1) + __builtin_abort(); + + if (state++ != 3) + __builtin_abort(); + + DEBUG_PRINTF("%s/\n", __PRETTY_FUNCTION__); + // Exit '0', now that we've verified all is OK. + _exit(0); + } +}; + +static void f() +{ + DEBUG_PRINTF("%s\n", __PRETTY_FUNCTION__); + +#pragma omp atomic + ++cf; + + // + static S s; + + DEBUG_PRINTF("%s/\n", __PRETTY_FUNCTION__); +} + +int main() +{ + DEBUG_PRINTF("%s\n", __PRETTY_FUNCTION__); + + if (state++ != 0) + __builtin_abort(); + + int nthreads; + +#pragma omp parallel + { +#pragma omp master + { + nthreads = omp_get_num_threads (); + } + + f(); + } + + DEBUG_PRINTF(" cSC = %d\n", cSC); + DEBUG_PRINTF(" cf = %d\n", cf); + if (cSC != 1) + __builtin_abort(); + if (cf != nthreads) + __builtin_abort(); + + if (state++ != 2) + __builtin_abort(); + + DEBUG_PRINTF("%s/\n", __PRETTY_FUNCTION__); + + // See '_exit(0);' elsewhere. + return 1; +} -- 2.34.1