From patchwork Thu Oct 31 10:37:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 99901 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7A3113857349 for ; Thu, 31 Oct 2024 10:38:19 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 98C903858D33 for ; Thu, 31 Oct 2024 10:37:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 98C903858D33 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 98C903858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730371061; cv=none; b=BR0VFizlLkvREIRiIBJwcE0jucbZAJalujfZ2Ifv6ByVmXo0E8OFIaqoy9tEZBQSxbt9c6KRIUqLjBSSzFPIRh+l01tOOG6ZDqAR1Val36rztsuqx9jrTEwbohD0tkO7DzL2TO5V0U76PAqN0tPPQKu2IQYYZC9sxFS7R/n5WY0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730371061; c=relaxed/simple; bh=xzqcaMDSVKMLMytNa1oIEBJgVY9Bc4sq7mFiAwqyvUU=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:From:To; b=CxM/nLu++QDkndmCphow6U/jbn5Ti/JEdL/cE4or5P9NJZJLiCQgnAD1qAiwoevA1Nl7ZDQs5bOCqVl1Yp2yKgnVRBd9KLFQ7idgRqiYCzvBzVciGlKYkkfuyKGxUdaWSoJnYb24JvpSlsm4C8GeFf4P/Mxq9wzspl0yTcV4vUs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-37d49ffaba6so554306f8f.0 for ; Thu, 31 Oct 2024 03:37:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1730371057; x=1730975857; darn=gcc.gnu.org; h=in-reply-to:content-language:references:to:from:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=V+nQNQ1KnVttBccWM6FaGyWnyj1L/vzNUQuGwfD2C4w=; b=sIMIrWFKFiwkmsIDtywyR9SUsEx5XJ+qBIqloXqna+lMFkF+DtBDpBMl2I3vCnuXp+ kUfKuG1eRA/3DdUcNhjd1A5bQTpqiMWQmuuj8Db9QPbRGtqtzgQPHAJ4ErHH/ubnfta7 GyLUzcdceQcz1PnMLxGgW3ZZRRRPGReoSv2trHORNO68R9Hzcevz4tLYWFWAUeTnBw9r vGxOeOaXYYvWOOP4ZxvZeN9ZRCiT+H2dydZQrOvnf9VmetAqOFZozcL2j/qMhHnkFf+j uB7zG3bKCyW563x8WWoi+3R1wbly3nX1Sv8WCuHJlLBF/oCrkn93edVGHJ4ZjXXO/0LE enMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730371057; x=1730975857; h=in-reply-to:content-language:references:to:from:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=V+nQNQ1KnVttBccWM6FaGyWnyj1L/vzNUQuGwfD2C4w=; b=Ca0JVrTTJ/M2WpRHRXYlv/10T3GNOHuNT53Ktr7eX7wQ8HFzoDYhhFkVrDlpfBDJrd xhxjnGVYO8kJyDlS9Lyi/NVHSKgsrwiBsyB+J8P4npZ3DSLKStta6f2Axp5lPH/ddVcw nLZJduacaxGgnpW7pnP2tlXbEQzE0SKn8iRyVryG+TcszaWoMLtUyLDZdK6P7UyMcIut c3l+NBQfC4wKMSp5XrymUEL04PIHstO85WLjAMFOkipMKcueE2MowTCP0hWC00IQLzn4 LNFkOsUORJV67+PeoRFutomNMg2psIXkVecCrytpfmEQ7I8P3waxJe1u0BfKra13Bwsf IuSw== X-Gm-Message-State: AOJu0YzhchtPGBjWI2TPDc3UmBMSSMm0B8pnNFC6R+m9vfkp8SAAeXEH LEcF9y9KgFSqUlu28Skz9bnACtaem2bnyF1QeZk9Wg70NlTe0FS2ANsQmSPEEowlBUTcO0oOnMN 5 X-Google-Smtp-Source: AGHT+IHGF7rNnmJvXpg1ZwBDbvoi7iERvKXv3o6kTqV6AfM9EoMbsgQ5pUdIzVT+04UzdT89iL+upw== X-Received: by 2002:a05:6000:4585:b0:37c:d11e:949 with SMTP id ffacd0b85a97d-381b708ae44mr4388537f8f.28.1730371057199; Thu, 31 Oct 2024 03:37:37 -0700 (PDT) Received: from [192.168.8.104] (tmo-084-76.customers.d1-online.com. [80.187.84.76]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c1189123sm1720308f8f.115.2024.10.31.03.37.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 31 Oct 2024 03:37:36 -0700 (PDT) Message-ID: Date: Thu, 31 Oct 2024 11:37:35 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: =?utf-8?q?=5Bcommitted=5D_=E2=80=94_was=3A_=5BPatch=5D_OpenMP/C++?= =?utf-8?q?=3A_Fix_declare_variant_with_reference-returning_functions?= From: Tobias Burnus To: gcc-patches , Jakub Jelinek References: <10446a42-bab7-4325-966c-f0dcabfb8658@baylibre.com> Content-Language: en-US In-Reply-To: <10446a42-bab7-4325-966c-f0dcabfb8658@baylibre.com> X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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~patchwork=sourceware.org@gcc.gnu.org Tobias Burnus wrote: > Before the patch, the included testcase fails with: > > declare-variant-9.C:4:29: error: could not find variant declaration > 4 | #pragma omp declare variant(variant_fn) match(user={condition(1)}) > | ^~~~~~~~~~ > > Comments, remarks, suggestions before I commit it? I realized that a template testcase was missing – hence, I extended the testcase; cf. attachment. → Committed as r15-4799-gf011f8908182fd BTW: Initially, the template testcase did not work; it turned out that I made a typo (tmpl vs templ) in the variant name, which GCC did/does not diagnose. I discussed with Jakub, who will take care of adding a diagnostic. Thanks! Tobias commit f011f8908182fd05ddd9a34881507b8584c44fb2 Author: Tobias Burnus Date: Thu Oct 31 11:28:57 2024 +0100 OpenMP/C++: Fix declare variant with reference-returning functions gcc/cp/ChangeLog: * decl.cc (omp_declare_variant_finalize_one): Strip indirect ref around variant-function call when processing a variant. gcc/testsuite/ChangeLog: * g++.dg/gomp/declare-variant-9.C: New test. diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 0bc320a2b39..b638f3af294 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -8375,6 +8375,9 @@ omp_declare_variant_finalize_one (tree decl, tree attr) if (variant == error_mark_node && !processing_template_decl) return true; + if (TREE_CODE (variant) == INDIRECT_REF) + variant = TREE_OPERAND (variant, 0); + variant = cp_get_callee_fndecl_nofold (variant); input_location = save_loc; diff --git a/gcc/testsuite/g++.dg/gomp/declare-variant-9.C b/gcc/testsuite/g++.dg/gomp/declare-variant-9.C new file mode 100644 index 00000000000..7e26d8b11ae --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/declare-variant-9.C @@ -0,0 +1,29 @@ +/* { dg-additional-options "-fdump-tree-gimple" } */ +int &variant_fn(); + +#pragma omp declare variant(variant_fn) match(user={condition(1)}) +int &bar(); + +void sub(int &a) +{ + bar(); + a = bar(); +} + +template +T &templ_var_fn(T x); + +#pragma omp declare variant(templ_var_fn) match(user={condition(1)}) +template +T &templ_base_fn(T x); + +void run(int &b) +{ + templ_base_fn(5); + b = templ_base_fn(7); +} + +/* { dg-final { scan-tree-dump " variant_fn \\(\\);" "gimple" } } */ +/* { dg-final { scan-tree-dump " _1 = variant_fn \\(\\);" "gimple" } } */ +/* { dg-final { scan-tree-dump " templ_var_fn \\(5\\);" "gimple" } } */ +/* { dg-final { scan-tree-dump " _1 = templ_var_fn \\(7\\);" "gimple" } } */