From patchwork Tue Feb 13 14:54:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 200459 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp589050dyb; Tue, 13 Feb 2024 06:55:10 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWsPTXsfzuTfF2VBZ+tp4b/1GXvOfttuDiAvx/6IyWZ+WBtnCTKLUqXBEBi4Qa15/DlxlbDPibytHNQYpE4tq554x7tdA== X-Google-Smtp-Source: AGHT+IHucdaN/jSXBVwavM8OXq+4jVk97CUi6cb+a8Ie4p3YOP9d8c01CAsjXg0f++suQeu514lC X-Received: by 2002:a05:620a:1022:b0:785:d3a9:ab22 with SMTP id a2-20020a05620a102200b00785d3a9ab22mr5594714qkk.16.1707836109918; Tue, 13 Feb 2024 06:55:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707836109; cv=pass; d=google.com; s=arc-20160816; b=g7412qUie7SWs1BfHzkvhtJrGLMuYpE3T2bi97ju4SNuRh1QAzfenUcBLa1Dv2nHbW Irw3DSk3BE1kS0D+UKQw8x+l113NuheLzSJQo7cQKC7HblEACXGvSgy4cjTH7wH079U6 iWZCDFjwLQ0NGm6Tlh7UaYBDB0nBm3w3R/WIMI82ZRtC7g3K333jztX/SkNsNzxa6mTo QFW9bICVEGofrIe+wIsTPaw3qmjhaIXvDaD5jpwjnxv2ca3CXlaGkRziAbZFrZyo9xQd GHHtbqY51N3a5X9RMUJakVbfUkw2H+DLv/Vd4qZ5prodGv+jwDWKghX1tUnuD4fa2cbF 7VFQ== 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:subject:from:cc:to :content-language:user-agent:mime-version:date:message-id :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=27Nrx1qkF2sKgxcnpnbShQ3H2epPRbYJXml1K+v7srE=; fh=E9t2bXj4fEu37PAEzpQaVKAJ5p1BP8meyieQLjPsgto=; b=ENZFB/kRYKUchNupQOjCBk+uX9re2TRkp6YiwFpbSPicY+dQliOcTbWOZx2Xi85AuK 6zWVGgkzrAYdnJnB76rjdL0m2hg+d+4mErRNoeQnSKk7DrxBEXojVBDMBiWcAYqEn3cZ HtoWQz/LXs1QfLL4Bso0uNV+ywpK/f940o8Jdohyz3Obsy3Ruyv5w9wG/8t7ozCucBoH +Fn5fw7Y9cs6I0gba2q7IM4DB/gxYaWPU0Ldl4endO1jeYIa6ujyFOFf/uIA6J+3y709 Lgeg34qZavB670rk/BeeS1ji6jrDVHtXjOuVjb5iQ0bKrwvMfRQ4ZX4KkQ+dYT1Ug6qN kDbQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b="hy3u4dn/"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" X-Forwarded-Encrypted: i=2; AJvYcCXECIubfEZCA5V79BYWal6PhD/CzCSLVfnUL5nSCGsQ4odVTHnx15Xo1/6+aIBMvskPcf18krFRO5YKG5voayohS5ZvcA== Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id d13-20020a05620a158d00b007871daec488si1335430qkk.25.2024.02.13.06.55.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 06:55:09 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b="hy3u4dn/"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 9675D38582BA for ; Tue, 13 Feb 2024 14:55:09 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id 1E57B3858412 for ; Tue, 13 Feb 2024 14:54:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1E57B3858412 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=baylibre.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1E57B3858412 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::334 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707836073; cv=none; b=v6iJaXjfnMxEF/vNH0gOZCHpM94K5Y3jLhC3iYLTk0etJMKT87+fmtgiW6EwLHApJk9I86JSJzco3+hCmk6F7pcftyawYOLulMDXjYEDjmgJX4YCaw94qrkPI3GmmoOa6819wwu8gGizJIxN80rguKW27pjtndrZau5Oi91eGvs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707836073; c=relaxed/simple; bh=g1YpGfezq1I1qnNgly8eFCD6/8P7qqjM4H1ol6Vt67k=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=RdgmlP2LR9lWRZcXYJxJFecp7u0mVgSe64qBUS893VyJrYVWhOpQFxo/V0/h/rFnnd7CI/Kun3afNkdH4awcsCjSOlOVzhBgeNM+4EVP+xzPz+Y+WR2oiy+lRC+1bAhgB/C8wS/wLy7ZSZi2bfTy3dmBSmr6ie7yDLWg6tbXrQA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-411c2f76308so4322675e9.3 for ; Tue, 13 Feb 2024 06:54:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1707836070; x=1708440870; darn=gcc.gnu.org; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=27Nrx1qkF2sKgxcnpnbShQ3H2epPRbYJXml1K+v7srE=; b=hy3u4dn/oWprWlNaHornRWp6sFVhk8Pb8pcNevovJW6QI1XWIgRjMIaUBBaqKt9eKu j8EJv/GXY4EXYbhVanUOXTyUZtHNPzwWsUYj/wi1A+PnFnJ8hKw9iTt0BCLIwbtVJhQn Wg5IEWe7E31rx2/M5d4lSzCiqeQoc9OZgGSMXgME2pvrzzRqWbzbUVPEPianT+/Oq767 UzraOX3wATqPW9RrpnP+Qwrz6kvz6VHvCPxJWdrk1uAfpmblsLjkED/trj1n5t63xE2T OOtv4XQCCkYLa9EIoG6hwPd/+oOz+Xmt3UfOhcPFryHr+2fXKeByRv0gRC/siU+tNFmU lzow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707836070; x=1708440870; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=27Nrx1qkF2sKgxcnpnbShQ3H2epPRbYJXml1K+v7srE=; b=q+UrhGbvCyNgV43XYgYizWmj4+5BuwokD5ge7E5qX+wyrS14ekYW7FjOv8s6CnmGVi K2HHsflt2y95bEkfy2th0E5gQl3vudB/NEI0FOhR1RF6W3Qr1Z2x5IGISc74E8rJC6dB pL/eWlrPWEZ21ICgCsdNE0vECfpmn03yMlHx5A/dBhMJYyh+s9nrp2cSoV5KarowodHA 9WnUC3TfJR55acuarkXctQa2KLwL3OhsUx6mu8gOc1+DqRxTUZSWnQMqpOaSNluGtwjJ vxvXLktvPoxfb9S+S92epItYvDA2Pj6qxeL5DgHemMiDGFoM4rW2HBdg/RDABLx/DboY C6tg== X-Gm-Message-State: AOJu0YxyR6MlpXyV1EgzlAXJ15j8PFhATaRx8mab7ZTcYWQeV4PepK4T J7caiuB+CyJwhSaw9QRi6LVv6dtfS/ueTqUqrcsoMZzPxgaiJoFk1F46H7lH1cB1kBamGnBCFkz 8I90= X-Received: by 2002:a05:600c:3b21:b0:40f:dd7e:4a4d with SMTP id m33-20020a05600c3b2100b0040fdd7e4a4dmr8848930wms.31.1707836069877; Tue, 13 Feb 2024 06:54:29 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVSxkPLhh+6czsyw7/dYLktiaeEQ6/Y9LKtmtncOgCNbkzSO4gFySUjzQsOyyC6iMIr+m6YyLggNLRqAlS3LJdgr9gOVYEhA6rPXmqL4zCeuGoxyGTl3Q== Received: from ?IPV6:2001:16b8:2af0:3c00:14f5:1aa4:590b:2a32? (200116b82af03c0014f51aa4590b2a32.dip.versatel-1u1.de. [2001:16b8:2af0:3c00:14f5:1aa4:590b:2a32]) by smtp.gmail.com with ESMTPSA id s21-20020a05600c45d500b0040fd1629443sm12065488wmo.18.2024.02.13.06.54.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 13 Feb 2024 06:54:29 -0800 (PST) Message-ID: <5637ae04-8e34-4a30-bd7f-6dba45f3663d@baylibre.com> Date: Tue, 13 Feb 2024 15:54:28 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: gcc-patches , Jakub Jelinek Cc: Paul-Antoine Arras From: Tobias Burnus Subject: [Patch] OpenMP: Handle DECL_ASSEMBLER_NAME with 'declare variant' X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: 1790795957146697731 X-GMAIL-MSGID: 1790795957146697731 Inomp_resolve_declare_variant, a code path generates a new decl for the base function – in doing so, it ignores the assembler name. As the included Fortran example shows, this will lead to a linker error. Solution: Also copy over the assembler name. Comments, suggestions, remarks before I commit it? Tobias PS: As a fallout of some testing, motivated by the original testcase, I have filled a couple of declare-variant and context-selector PRs: 113904 (dyn. user={condition(...)}), 113905 (multiple users of variant funcs), 113906 (construct={...} lacks constructs). OpenMP: Handle DECL_ASSEMBLER_NAME with 'declare variant' gcc/ChangeLog: * omp-general.cc (omp_resolve_declare_variant): When building the decl for the base variant, honor also the assembler name. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/declare-variant-20.f90: New test. gcc/omp-general.cc | 2 + .../gfortran.dg/gomp/declare-variant-20.f90 | 62 ++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc index 2e31a3f9290..bc92a170e96 100644 --- a/gcc/omp-general.cc +++ b/gcc/omp-general.cc @@ -2630,6 +2630,8 @@ omp_resolve_declare_variant (tree base) (*slot)->variants = entry.variants; tree alt = build_decl (DECL_SOURCE_LOCATION (base), FUNCTION_DECL, DECL_NAME (base), TREE_TYPE (base)); + if (DECL_ASSEMBLER_NAME_SET_P (base)) + SET_DECL_ASSEMBLER_NAME (alt, DECL_ASSEMBLER_NAME (base)); DECL_ARTIFICIAL (alt) = 1; DECL_IGNORED_P (alt) = 1; TREE_STATIC (alt) = 1; diff --git a/gcc/testsuite/gfortran.dg/gomp/declare-variant-20.f90 b/gcc/testsuite/gfortran.dg/gomp/declare-variant-20.f90 new file mode 100644 index 00000000000..c7050a22365 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/declare-variant-20.f90 @@ -0,0 +1,62 @@ +! { dg-additional-options "-fdump-tree-gimple-asmname" } + +! This tests that mangled names, i.e. DECL_NAME != DECL_ASSEMBLER_NAME +! are properly handled + +! This test case failed before with: +! undefined reference to `foo' +! as the actual symbol is __m_MOD_foo + +! NOTE 1: This test relies on late resolution of condition, +! which is here enforced via the always_false_flag variable. +! +! NOTE 2: Using a variable is an OpenMP 5.1 feature that is/was not supported +! when this test case was created, cf. PR middle-end/113904 + +module m + implicit none (type, external) + logical :: always_false_flag = .false. +contains + integer function variant1() result(res) + res = 1 + end function + + integer function variant2() result(res) + res = 2 + end function + + integer function variant3() result(res) + res = 3 + end function + + integer function foo() result(res) + !$omp declare variant(variant1) match(construct={teams}) + !$omp declare variant(variant2) match(construct={parallel}) + !$omp declare variant(variant3) match(user={condition(always_false_flag)},construct={target}) + res = 99 + end +end module m + +program main + use m + implicit none (type, external) + integer :: r1, r2, r3 + + r1 = foo() + if (r1 /= 99) stop 1 + + !$omp parallel if (.false.) + r2 = foo() + if (r2 /= 2) stop 2 + !$omp end parallel + + !$omp teams num_teams(1) + r3 = foo() + if (r3 /= 1) stop 3 + !$omp end teams + +end program + +! { dg-final { scan-tree-dump-times "r1 = __m_MOD_foo \\(\\);" 1 "gimple" } } +! { dg-final { scan-tree-dump-times "r2 = __m_MOD_variant2 \\(\\);" 1 "gimple" } } +! { dg-final { scan-tree-dump-times "r3 = __m_MOD_variant1 \\(\\);" 1 "gimple" } }