From patchwork Tue Feb 13 17:31:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 1898357 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=OyFV0bKt; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TZ7fb1ylxz23j4 for ; Wed, 14 Feb 2024 04:31:35 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1859F3858033 for ; Tue, 13 Feb 2024 17:31:33 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-yw1-x112c.google.com (mail-yw1-x112c.google.com [IPv6:2607:f8b0:4864:20::112c]) by sourceware.org (Postfix) with ESMTPS id 32D3038582B1 for ; Tue, 13 Feb 2024 17:31:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 32D3038582B1 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 32D3038582B1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::112c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707845470; cv=none; b=UTy35PyD9MXsbxHT6yMzJYe9W8vdaDvmhJqaSiGrrTxPnPrqS6cCMvgWj7kBNtt3q2QesNx2Pf7D6hmpprjL79unndG310qJsps9eEKmLdSSiLWGGTZnN2lxq/Dy4QprxPLwtYmsyEaWoUYDl1thPuN2tABWjOG5vpFQDMK8f40= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707845470; c=relaxed/simple; bh=lYkq6a9hr57xZxK5913Y5tFY34HHKDCQ+uN0X+1Dn6g=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=I38GTu4jAfSYvX8pEmmm3JQRHLiPWv5/IC9J2LK4DuQRa488tQHlOVv8Mw7VrB1JKPmJM5TdP9Q0UdD4bD99WvE2992MPtvNzcwfUz8zxNGfvmxY0g2kRACEwnTfapZb016r1G8H2pH3CDDjf1WlmS2Mq++GKEe8qXHHRMnLXx8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x112c.google.com with SMTP id 00721157ae682-604ac794c01so8103257b3.2 for ; Tue, 13 Feb 2024 09:31:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1707845465; x=1708450265; darn=gcc.gnu.org; h=in-reply-to:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=UOULhJcGNXxEUDZ1g9cvHgg9tKI7taItJhvt3q0ZwGs=; b=OyFV0bKtLfLzolluaHhhW92mM+NUEI+0UrNYCxja5hBlCpajXbxiv9wk+3vbgrTiw/ 9e8jIxuSC2egWctGM9FbZC4vmx5jXnOor62R6cBY6ePlhF3q6k1qjwrnm8nUgNfbehOx rPp/9YV4W3A+Cq82vqQgiRTHJB6Bn2Hk8m9KstV2yb91qtgs4BGXSd1uOSnxcPsnsuxQ zIGf5NHVnplr2rDCkccepIi8cYSBJEqC3N8nXJX6TypDjA4hmRr8XD+lbz+Qp/GPUK7L u4ds1tHEXvtFgv8bTfJyYOAuANl89IRCXeGdsD3JorG8L52dN1vw2+ddtl/8ejdITPvi XtKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707845465; x=1708450265; h=in-reply-to:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=UOULhJcGNXxEUDZ1g9cvHgg9tKI7taItJhvt3q0ZwGs=; b=AmRiu/hwVhkATLeyneHuE25bs2Mqu3/ZNIc53IKASdMp9q6uax/68yx7wuMm46PW99 gdsQf5KvoJW/E7GisfW8hsw7avZ/yU9hpFJi5nbioq+tN09B1GuJRBNQtw0bXCroTiAS DzFQdf/YBcpct9l4zBPuyzErw5qSooHgZ3L3M/nW1RGCMKvMpl79A/lDHDa1Z6DQPVc4 DNa0YZZaGaz3RGakXYiTAxFBnZbXLP7DPaf8poMCIFzgB0KeDwIX58X/gUjVVGixubDh 71QFBuh3VXXaU9IKI/VeCqx4AbYuKH+q3vIbgm8kC4FpeyrsyWBZxQz9M4+zg1fajcH5 SUeQ== X-Gm-Message-State: AOJu0YyobiXPw20VtXBYzoAPdNJdIvVZuh4L6R7M87IRrhWVzMouaEYL u6fDUVT0LSsn0lVDpLTP0hFB1y5eyqxoQqi1AgvsGKzxdroVAKqdaA4lcWy9EAw= X-Google-Smtp-Source: AGHT+IFm4oWmRbpSEbU2XMig9Ohcq1ZW65t3Hll+NwsEingz8sySDpxQrQEOJIbLUwDb18HvdYx4sg== X-Received: by 2002:a0d:eb16:0:b0:607:85b3:b52f with SMTP id u22-20020a0deb16000000b0060785b3b52fmr14794ywe.22.1707845465197; Tue, 13 Feb 2024 09:31:05 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWCKwxgPZlpfJyJFp/r8K5MPME77+LQLHmfUA3Ehg8Rn3NA4r1VPQeXU6EIVPQTjrLktXgHoggcY9jETP2DHnyr0mAi0HXnW93Yy6cDqSdnW4Fe7g2pxgbQeg== 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 c184-20020a0dc1c1000000b00604a2e45cf2sm1808084ywd.140.2024.02.13.09.31.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 13 Feb 2024 09:31:04 -0800 (PST) Message-ID: <06aeb43f-f767-4302-b85e-dd956868e987@baylibre.com> Date: Tue, 13 Feb 2024 18:31:02 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [Patch] OpenMP: Reject non-const 'condition' trait in Fortran (was: [Patch] OpenMP: Handle DECL_ASSEMBLER_NAME with 'declare variant') Content-Language: en-US To: Jakub Jelinek Cc: gcc-patches , Paul-Antoine Arras References: <5637ae04-8e34-4a30-bd7f-6dba45f3663d@baylibre.com> From: Tobias Burnus In-Reply-To: X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, HTML_MESSAGE, 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Jakub Jelinek wrote: > Isn't all this caused just by the missing check that condition trait has a > constant expression? > > IMHO that is the way to handle it in GCC 14. Concur – how about the following patch? Tobias PS: See PR113904 for follow up tasks. / Instead of '.AND.' etc. I could have also used some more '==', '<' etc. expressions in the modified examples (as should have Sandra in the initial version), but, fortunately, there is at least one '=='. OpenMP: Reject non-const 'condition' trait in Fortran OpenMP 5.0 only permits constant expressions for the 'condition' trait in context selectors; this is relaxed in 5.2 but not implemented. In order to avoid wrong code, it is now rejected. Additionally, in Fortran, 'condition' should not accept an integer expression, which is now ensured. Additionally, as 'device_num' should be a conforming device number, there is now a check on the value. PR middle-end/113904 gcc/c/ChangeLog: * c-parser.cc (c_parser_omp_context_selector): Handle splitting of OMP_TRAIT_PROPERTY_EXPR into OMP_TRAIT_PROPERTY_{DEV_NUM,BOOL}_EXPR. gcc/cp/ChangeLog: * parser.cc (cp_parser_omp_context_selector): Handle splitting of OMP_TRAIT_PROPERTY_EXPR into OMP_TRAIT_PROPERTY_{DEV_NUM,BOOL}_EXPR. gcc/fortran/ChangeLog: * openmp.cc (gfc_match_omp_context_selector): * trans-openmp.cc (gfc_trans_omp_declare_variant): Handle splitting of OMP_TRAIT_PROPERTY_EXPR into OMP_TRAIT_PROPERTY_{DEV_NUM,BOOL}_EXPR. gcc/ChangeLog: * omp-general.cc (struct omp_ts_info): Update for splitting of OMP_TRAIT_PROPERTY_EXPR into OMP_TRAIT_PROPERTYDEV_NUM,BOOL}_EXPR. * omp-selectors.h (enum omp_tp_type): Replace OMP_TRAIT_PROPERTY_EXPR by OMP_TRAIT_PROPERTY_{DEV_NUM,BOOL}_EXPR. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/declare-variant-1.f90: Change 'condition' trait's argument from integer to a logical expression. * gfortran.dg/gomp/declare-variant-11.f90: Likewise. * gfortran.dg/gomp/declare-variant-12.f90: Likewise. * gfortran.dg/gomp/declare-variant-13.f90: Likewise. * gfortran.dg/gomp/declare-variant-2.f90: Likewise. * gfortran.dg/gomp/declare-variant-2a.f90: Likewise. * gfortran.dg/gomp/declare-variant-3.f90: Likewise. * gfortran.dg/gomp/declare-variant-4.f90: Likewise. * gfortran.dg/gomp/declare-variant-6.f90: Likewise. * gfortran.dg/gomp/declare-variant-8.f90: Likewise. * gfortran.dg/gomp/declare-variant-20.f90: New test. gcc/c/c-parser.cc | 3 +- gcc/cp/parser.cc | 3 +- gcc/fortran/openmp.cc | 30 ++++++++++--- gcc/fortran/trans-openmp.cc | 3 +- gcc/omp-general.cc | 4 +- gcc/omp-selectors.h | 3 +- .../gfortran.dg/gomp/declare-variant-1.f90 | 4 +- .../gfortran.dg/gomp/declare-variant-11.f90 | 4 +- .../gfortran.dg/gomp/declare-variant-12.f90 | 12 ++--- .../gfortran.dg/gomp/declare-variant-13.f90 | 2 +- .../gfortran.dg/gomp/declare-variant-2.f90 | 8 ++-- .../gfortran.dg/gomp/declare-variant-20.f90 | 51 ++++++++++++++++++++++ .../gfortran.dg/gomp/declare-variant-2a.f90 | 4 +- .../gfortran.dg/gomp/declare-variant-3.f90 | 8 ++-- .../gfortran.dg/gomp/declare-variant-4.f90 | 8 ++-- .../gfortran.dg/gomp/declare-variant-6.f90 | 14 +++--- .../gfortran.dg/gomp/declare-variant-8.f90 | 2 +- 17 files changed, 119 insertions(+), 44 deletions(-) diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index c31349dae2f..3be91d666a5 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -24656,7 +24656,8 @@ c_parser_omp_context_selector (c_parser *parser, enum omp_tss_code set, } while (1); break; - case OMP_TRAIT_PROPERTY_EXPR: + case OMP_TRAIT_PROPERTY_DEV_NUM_EXPR: + case OMP_TRAIT_PROPERTY_BOOL_EXPR: t = c_parser_expr_no_commas (parser, NULL).value; if (t != error_mark_node) { diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index f0c8f9c4005..68ab74d70b9 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -47984,7 +47984,8 @@ cp_parser_omp_context_selector (cp_parser *parser, enum omp_tss_code set, } while (1); break; - case OMP_TRAIT_PROPERTY_EXPR: + case OMP_TRAIT_PROPERTY_DEV_NUM_EXPR: + case OMP_TRAIT_PROPERTY_BOOL_EXPR: /* FIXME: this is bogus, the expression need not be constant. */ t = cp_parser_constant_expression (parser); diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc index 0af80d54fad..d8cce6922b0 100644 --- a/gcc/fortran/openmp.cc +++ b/gcc/fortran/openmp.cc @@ -5790,19 +5790,39 @@ gfc_match_omp_context_selector (gfc_omp_set_selector *oss) } while (1); break; - case OMP_TRAIT_PROPERTY_EXPR: + case OMP_TRAIT_PROPERTY_DEV_NUM_EXPR: + case OMP_TRAIT_PROPERTY_BOOL_EXPR: if (gfc_match_expr (&otp->expr) != MATCH_YES) { gfc_error ("expected expression at %C"); return MATCH_ERROR; } if (!gfc_resolve_expr (otp->expr) - || (otp->expr->ts.type != BT_LOGICAL + || (property_kind == OMP_TRAIT_PROPERTY_BOOL_EXPR + && otp->expr->ts.type != BT_LOGICAL) + || (property_kind == OMP_TRAIT_PROPERTY_DEV_NUM_EXPR && otp->expr->ts.type != BT_INTEGER) - || otp->expr->rank != 0) + || otp->expr->rank != 0 + || otp->expr->expr_type != EXPR_CONSTANT) { - gfc_error ("property must be constant integer or logical " - "expression at %C"); + if (property_kind == OMP_TRAIT_PROPERTY_BOOL_EXPR) + gfc_error ("property must be a constant logical expression " + "at %C"); + else + gfc_error ("property must be a constant integer expression " + "at %C"); + return MATCH_ERROR; + } + /* Device number must be conforming, which includes + omp_initial_device (-1) and omp_invalid_device (-4). */ + if (property_kind == OMP_TRAIT_PROPERTY_DEV_NUM_EXPR + && otp->expr->expr_type == EXPR_CONSTANT + && mpz_sgn (otp->expr->value.integer) < 0 + && mpz_cmp_si (otp->expr->value.integer, -1) != 0 + && mpz_cmp_si (otp->expr->value.integer, -4) != 0) + { + gfc_error ("property must be a conforming device number " + "at %C"); return MATCH_ERROR; } break; diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc index 9599521b97c..a2bf15665b3 100644 --- a/gcc/fortran/trans-openmp.cc +++ b/gcc/fortran/trans-openmp.cc @@ -8426,7 +8426,8 @@ gfc_trans_omp_declare_variant (gfc_namespace *ns) { switch (otp->property_kind) { - case OMP_TRAIT_PROPERTY_EXPR: + case OMP_TRAIT_PROPERTY_DEV_NUM_EXPR: + case OMP_TRAIT_PROPERTY_BOOL_EXPR: { gfc_se se; gfc_init_se (&se, NULL); diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc index 2e31a3f9290..2c095200d5b 100644 --- a/gcc/omp-general.cc +++ b/gcc/omp-general.cc @@ -1163,7 +1163,7 @@ struct omp_ts_info omp_ts_map[] = }, { "device_num", (1 << OMP_TRAIT_SET_TARGET_DEVICE), - OMP_TRAIT_PROPERTY_EXPR, false, + OMP_TRAIT_PROPERTY_DEV_NUM_EXPR, false, NULL }, { "vendor", @@ -1208,7 +1208,7 @@ struct omp_ts_info omp_ts_map[] = }, { "condition", (1 << OMP_TRAIT_SET_USER), - OMP_TRAIT_PROPERTY_EXPR, true, + OMP_TRAIT_PROPERTY_BOOL_EXPR, true, NULL }, { "target", diff --git a/gcc/omp-selectors.h b/gcc/omp-selectors.h index 78b810d5215..c61808ec0ad 100644 --- a/gcc/omp-selectors.h +++ b/gcc/omp-selectors.h @@ -64,7 +64,8 @@ enum omp_tp_type { OMP_TRAIT_PROPERTY_NONE, OMP_TRAIT_PROPERTY_ID, OMP_TRAIT_PROPERTY_NAME_LIST, - OMP_TRAIT_PROPERTY_EXPR, + OMP_TRAIT_PROPERTY_DEV_NUM_EXPR, + OMP_TRAIT_PROPERTY_BOOL_EXPR, OMP_TRAIT_PROPERTY_CLAUSE_LIST, OMP_TRAIT_PROPERTY_EXTENSION }; diff --git a/gcc/testsuite/gfortran.dg/gomp/declare-variant-1.f90 b/gcc/testsuite/gfortran.dg/gomp/declare-variant-1.f90 index 50d7e41613f..9b68397d190 100644 --- a/gcc/testsuite/gfortran.dg/gomp/declare-variant-1.f90 +++ b/gcc/testsuite/gfortran.dg/gomp/declare-variant-1.f90 @@ -20,11 +20,11 @@ module main !$omp & match (construct={parallel,do}, & !$omp & device={isa(avx512f,avx512vl),kind(host,cpu)}, & !$omp & implementation={vendor(score(0):gnu),unified_shared_memory}, & - !$omp & user={condition(score(0):0)}) + !$omp & user={condition(score(0):.false.)}) !$omp declare variant (bar) & !$omp & match (device={arch(x86_64,powerpc64),isa(avx512f,popcntb)}, & !$omp & implementation={atomic_default_mem_order(seq_cst),made_up_selector("foo", 13, "bar")}, & - !$omp & user={condition(3-3)}) + !$omp & user={condition(.true. .AND. (.not. .true.))}) ! { dg-warning "unknown selector 'made_up_selector'" "" { target *-*-* } .-2 } end function diff --git a/gcc/testsuite/gfortran.dg/gomp/declare-variant-11.f90 b/gcc/testsuite/gfortran.dg/gomp/declare-variant-11.f90 index 3593c9a5bb3..15b6901a02e 100644 --- a/gcc/testsuite/gfortran.dg/gomp/declare-variant-11.f90 +++ b/gcc/testsuite/gfortran.dg/gomp/declare-variant-11.f90 @@ -49,8 +49,8 @@ contains subroutine f13 () !$omp declare variant (f10) match (device={isa("avx512f")}) - !$omp declare variant (f11) match (user={condition(1)},device={isa(avx512f)},implementation={vendor(gnu)}) - !$omp declare variant (f12) match (user={condition(2 + 1)},device={isa(avx512f)}) + !$omp declare variant (f11) match (user={condition(.true.)},device={isa(avx512f)},implementation={vendor(gnu)}) + !$omp declare variant (f12) match (user={condition(.true. .NEQV. .false.)},device={isa(avx512f)}) end subroutine subroutine f14 () diff --git a/gcc/testsuite/gfortran.dg/gomp/declare-variant-12.f90 b/gcc/testsuite/gfortran.dg/gomp/declare-variant-12.f90 index 2fd8abd0dc7..f1b4a2280ec 100644 --- a/gcc/testsuite/gfortran.dg/gomp/declare-variant-12.f90 +++ b/gcc/testsuite/gfortran.dg/gomp/declare-variant-12.f90 @@ -17,7 +17,7 @@ contains subroutine f04 () !$omp declare variant (f01) match (device={isa("avx512f","avx512vl")}) ! 16 !$omp declare variant (f02) match (implementation={vendor(score(15):gnu)}) - !$omp declare variant (f03) match (user={condition(score(11):1)}) + !$omp declare variant (f03) match (user={condition(score(11):.true.)}) end subroutine subroutine f05 () @@ -32,7 +32,7 @@ contains subroutine f08 () !$omp declare variant (f05) match (device={isa(avx512f,avx512vl)}) ! 16 !$omp declare variant (f06) match (implementation={vendor(score(15):gnu)}) - !$omp declare variant (f07) match (user={condition(score(17):1)}) + !$omp declare variant (f07) match (user={condition(score(17):.true.)}) end subroutine subroutine f09 () @@ -48,7 +48,7 @@ contains end subroutine subroutine f13 () - !$omp declare variant (f09) match (device={arch(x86_64)},user={condition(score(65):1)}) ! 64+65 + !$omp declare variant (f09) match (device={arch(x86_64)},user={condition(score(65):.true.)}) ! 64+65 !$omp declare variant (f10) match (implementation={vendor(score(127):"gnu")}) !$omp declare variant (f11) match (device={isa(ssse3)}) ! 128 !$omp declare variant (f12) match (implementation={atomic_default_mem_order(score(126):seq_cst)}) @@ -65,7 +65,7 @@ contains subroutine f17 () !$omp declare variant (f14) match (construct={teams,parallel,do}) ! 16+8+4 - !$omp declare variant (f15) match (construct={parallel},user={condition(score(19):1)}) ! 8+19 + !$omp declare variant (f15) match (construct={parallel},user={condition(score(19):.true.)}) ! 8+19 !$omp declare variant (f16) match (implementation={atomic_default_mem_order(score(27):seq_cst)}) end subroutine @@ -80,7 +80,7 @@ contains subroutine f21 () !$omp declare variant (f18) match (construct={teams,parallel,do}) ! 16+8+4 - !$omp declare variant (f19) match (construct={do},user={condition(score(25):1)}) ! 4+25 + !$omp declare variant (f19) match (construct={do},user={condition(score(25):.true.)}) ! 4+25 !$omp declare variant (f20) match (implementation={atomic_default_mem_order(score(28):seq_cst)}) end subroutine @@ -110,7 +110,7 @@ contains subroutine f29 () !$omp declare variant (f26) match (construct={parallel,do}) ! 2+1 - !$omp declare variant (f27) match (construct={do},user={condition(1)}) ! 4 + !$omp declare variant (f27) match (construct={do},user={condition(.true.)}) ! 4 !$omp declare variant (f28) match (implementation={atomic_default_mem_order(score(3):seq_cst)}) end subroutine diff --git a/gcc/testsuite/gfortran.dg/gomp/declare-variant-13.f90 b/gcc/testsuite/gfortran.dg/gomp/declare-variant-13.f90 index 91648f9bcf4..97484a63d0b 100644 --- a/gcc/testsuite/gfortran.dg/gomp/declare-variant-13.f90 +++ b/gcc/testsuite/gfortran.dg/gomp/declare-variant-13.f90 @@ -30,7 +30,7 @@ contains !$omp declare variant (f01) match (device={isa("avx512f")}) ! 4 or 8 !$omp declare variant (f02) match (implementation={vendor(score(3):gnu)},device={kind(cpu)}) ! (1 or 2) + 3 - !$omp declare variant (f03) match (user={condition(score(9):1)}) + !$omp declare variant (f03) match (user={condition(score(9):.true.)}) !$omp declare variant (f04) match (implementation={vendor(score(6):gnu)},device={kind(host)}) ! (1 or 2) + 6 f05 = x end function diff --git a/gcc/testsuite/gfortran.dg/gomp/declare-variant-2.f90 b/gcc/testsuite/gfortran.dg/gomp/declare-variant-2.f90 index cbb29f87302..7fc5071feff 100644 --- a/gcc/testsuite/gfortran.dg/gomp/declare-variant-2.f90 +++ b/gcc/testsuite/gfortran.dg/gomp/declare-variant-2.f90 @@ -15,7 +15,7 @@ contains !$omp declare variant () ! { dg-error "" } end subroutine subroutine f5 () - !$omp declare variant match(user={condition(0)}) ! { dg-error "expected '\\(' at .1." } + !$omp declare variant match(user={condition(.false.)}) ! { dg-error "expected '\\(' at .1." } end subroutine subroutine f6 () !$omp declare variant (f1) ! { dg-error "expected 'match' at .1." } @@ -66,7 +66,7 @@ contains !$omp declare variant (f1) match(user={condition(f1)}) ! { dg-error "expected expression at .1." } end subroutine subroutine f22 () - !$omp declare variant (f1) match(user={condition(1, 2, 3)}) ! { dg-error "expected '\\)' at .1." } + !$omp declare variant (f1) match(user={condition(.false., .true., .false.)}) ! { dg-error "expected '\\)' at .1." } end subroutine subroutine f23 () !$omp declare variant (f1) match(construct={master}) ! { dg-warning "unknown selector 'master' for context selector set 'construct'" } @@ -189,9 +189,9 @@ contains !$omp declare variant (f1) match(implementation={atomic_default_mem_order("relaxed")}) ! { dg-error "expected identifier at .1." } end subroutine subroutine f77 () - !$omp declare variant (f1) match(user={condition(score(f76):1)}) ! { dg-error ".score. argument must be constant integer expression at .1." } + !$omp declare variant (f1) match(user={condition(score(f76):.true.)}) ! { dg-error ".score. argument must be constant integer expression at .1." } end subroutine subroutine f78 () - !$omp declare variant (f1) match(user={condition(score(-130):1)}) ! { dg-error ".score. argument must be non-negative" } + !$omp declare variant (f1) match(user={condition(score(-130):.true.)}) ! { dg-error ".score. argument must be non-negative" } end subroutine end module 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..17fdcb7e8bc --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/declare-variant-20.f90 @@ -0,0 +1,51 @@ +! PR middle-end/113904 + +module m + implicit none (type, external) + logical, parameter :: parameter_true = .false. + logical :: false_flag = .false. + integer :: my_dev_num +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 variant4() result(res) + res = 4 + end function + + integer function variant5() result(res) + res = 4 + end function + + integer function variant6() result(res) + res = 4 + end function + + integer function foo() result(res) + ! 'condition' + !$omp declare variant(variant1) match(user={condition(parameter_true)},construct={teams}) ! OK + ! Below: OK since OpenMP 5.1 - but not yet supported: PR middle-end/113904 + !$omp declare variant(variant2) match(user={condition(false_flag)},construct={parallel}) ! { dg-error "property must be a constant logical expression" } + !$omp declare variant(variant3) match(user={condition(1)},construct={target}) ! { dg-error "property must be a constant logical expression" } + + ! 'device_num' + !$omp declare variant(variant4) match(target_device={device_num(0)}) ! OK + !$omp declare variant(variant4) match(target_device={device_num(2)}) ! OK - assuming there are two non-host devices. + !$omp declare variant(variant5) match(target_device={device_num(-1)}) ! OK - omp_initial_device + !$omp declare variant(variant5) match(target_device={device_num(-4)}) ! OK - omp_invalid_device (will never match) + ! OK - but not handled -> PR middle-end/113904 + !$omp declare variant(variant5) match(target_device={device_num(my_device)}) ! { dg-error "property must be a constant integer expression" } + !$omp declare variant(variant5) match(target_device={device_num(-2)}) ! { dg-error "property must be a conforming device number" } + + res = 99 + end +end module m diff --git a/gcc/testsuite/gfortran.dg/gomp/declare-variant-2a.f90 b/gcc/testsuite/gfortran.dg/gomp/declare-variant-2a.f90 index edc9b27f884..b44322ac02a 100644 --- a/gcc/testsuite/gfortran.dg/gomp/declare-variant-2a.f90 +++ b/gcc/testsuite/gfortran.dg/gomp/declare-variant-2a.f90 @@ -10,10 +10,10 @@ contains !$omp declare variant (f1) match(construct={parallel},construct={parallel}) ! { dg-error "selector set 'construct' specified more than once" } end subroutine subroutine f30 () - !$omp declare variant (f1) match(user={condition(0)},construct={target},user={condition(0)}) ! { dg-error "selector set 'user' specified more than once" } + !$omp declare variant (f1) match(user={condition(.false.)},construct={target},user={condition(.false.)}) ! { dg-error "selector set 'user' specified more than once" } end subroutine subroutine f31 () - !$omp declare variant (f1) match(user={condition(0)},user={condition(1)}) ! { dg-error "selector set 'user' specified more than once" } + !$omp declare variant (f1) match(user={condition(.false.)},user={condition(.true.)}) ! { dg-error "selector set 'user' specified more than once" } end subroutine subroutine f37 () !$omp declare variant (f1) match(device={kind(unknown)}) ! { dg-warning "unknown property 'unknown' of 'kind' selector" } diff --git a/gcc/testsuite/gfortran.dg/gomp/declare-variant-3.f90 b/gcc/testsuite/gfortran.dg/gomp/declare-variant-3.f90 index c62622b607b..6b23d40e410 100644 --- a/gcc/testsuite/gfortran.dg/gomp/declare-variant-3.f90 +++ b/gcc/testsuite/gfortran.dg/gomp/declare-variant-3.f90 @@ -210,13 +210,13 @@ contains !$omp& vendor(score(22):gnu),unified_address,extension(score(22):foobar)}) ! { dg-warning "unknown property 'foobar' of 'extension' selector" "" { target *-*-* } .-1 } end subroutine subroutine f72 () - !$omp declare variant (f13) match (user={condition(0)}) + !$omp declare variant (f13) match (user={condition(.false.)}) end subroutine subroutine f73 () - !$omp declare variant (f13) match (user={condition(272-272*1)}) + !$omp declare variant (f13) match (user={condition(.true..and..not..true.)}) end subroutine subroutine f74 () - !$omp declare variant (f13) match (user={condition(score(25):1)}) + !$omp declare variant (f13) match (user={condition(score(25):.true.)}) end subroutine subroutine f75 () !$omp declare variant (f13) match (device={kind(any,"any")}) @@ -231,7 +231,7 @@ contains !$omp declare variant (f13) match (implementation={vendor(nvidia)}) end subroutine subroutine f79 () - !$omp declare variant (f13) match (user={condition(score(0):0)}) + !$omp declare variant (f13) match (user={condition(score(0):.false.)}) end subroutine end module diff --git a/gcc/testsuite/gfortran.dg/gomp/declare-variant-4.f90 b/gcc/testsuite/gfortran.dg/gomp/declare-variant-4.f90 index bc4f41647b4..5c7fee23504 100644 --- a/gcc/testsuite/gfortran.dg/gomp/declare-variant-4.f90 +++ b/gcc/testsuite/gfortran.dg/gomp/declare-variant-4.f90 @@ -44,10 +44,10 @@ contains end function end interface - !$omp declare variant (f1) match (user={condition(1)}) - !$omp declare variant (f2) match (user={condition(score(1):1)}) - !$omp declare variant (f3) match (user={condition(score(3):1)}) - !$omp declare variant (f4) match (user={condition(score(2):1)}) + !$omp declare variant (f1) match (user={condition(.true.)}) + !$omp declare variant (f2) match (user={condition(score(1):.true.)}) + !$omp declare variant (f3) match (user={condition(score(3):.true.)}) + !$omp declare variant (f4) match (user={condition(score(2):.true.)}) !$omp declare variant (f5) match (implementation={vendor(gnu)}) f6 = z + x + y diff --git a/gcc/testsuite/gfortran.dg/gomp/declare-variant-6.f90 b/gcc/testsuite/gfortran.dg/gomp/declare-variant-6.f90 index 3f33f38b9bc..63a8bd8744a 100644 --- a/gcc/testsuite/gfortran.dg/gomp/declare-variant-6.f90 +++ b/gcc/testsuite/gfortran.dg/gomp/declare-variant-6.f90 @@ -24,7 +24,7 @@ contains integer, intent(in) :: x integer (kind = 8), intent(in) :: y real :: z - !$omp declare variant (f1) match (user={condition(0)},construct={parallel}) + !$omp declare variant (f1) match (user={condition(.false.)},construct={parallel}) f3 = 0.0 end function @@ -33,7 +33,7 @@ contains integer, intent(in) :: x integer (kind = 8), intent(in) :: y real :: z - !$omp declare variant (f1) match (construct={parallel},user={condition(score(1):1)}) + !$omp declare variant (f1) match (construct={parallel},user={condition(score(1):.true.)}) f4 = 0.0 end function @@ -50,7 +50,7 @@ contains integer, intent(in) :: x integer (kind = 8), intent(in) :: y real :: z - !$omp declare variant (f5) match (user={condition(0)}) ! { dg-error "'f5' used as a variant with incompatible 'construct' selector sets" } + !$omp declare variant (f5) match (user={condition(.false.)}) ! { dg-error "'f5' used as a variant with incompatible 'construct' selector sets" } f6 = 0.0 end function @@ -59,7 +59,7 @@ contains integer, intent(in) :: x integer (kind = 8), intent(in) :: y real :: z - !$omp declare variant (f5) match (construct={parallel},user={condition(score(1):1)}) + !$omp declare variant (f5) match (construct={parallel},user={condition(score(1):.true.)}) f7 = 0.0 end function @@ -76,7 +76,7 @@ contains integer, intent(in) :: x integer (kind = 8), intent(in) :: y real :: z - !$omp declare variant (f8) match (user={condition(0)},construct={do}) ! { dg-error "'f8' used as a variant with incompatible 'construct' selector sets" } + !$omp declare variant (f8) match (user={condition(.false.)},construct={do}) ! { dg-error "'f8' used as a variant with incompatible 'construct' selector sets" } f9 = 0.0 end function @@ -85,7 +85,7 @@ contains integer, intent(in) :: x integer (kind = 8), intent(in) :: y real :: z - !$omp declare variant (f8) match (user={condition(1)}) + !$omp declare variant (f8) match (user={condition(.true.)}) f10 = 0.0 end function @@ -111,7 +111,7 @@ contains integer, intent(in) :: x integer (kind = 8), intent(in) :: y real :: z - !$omp declare variant (f11) match (user={condition(score(1):1)},construct={target,teams,parallel,do}) ! { dg-error "'f11' used as a variant with incompatible 'construct' selector sets" } + !$omp declare variant (f11) match (user={condition(score(1):.true.)},construct={target,teams,parallel,do}) ! { dg-error "'f11' used as a variant with incompatible 'construct' selector sets" } f13 = 0.0 end function diff --git a/gcc/testsuite/gfortran.dg/gomp/declare-variant-8.f90 b/gcc/testsuite/gfortran.dg/gomp/declare-variant-8.f90 index c751489a5db..d69e552eeb7 100644 --- a/gcc/testsuite/gfortran.dg/gomp/declare-variant-8.f90 +++ b/gcc/testsuite/gfortran.dg/gomp/declare-variant-8.f90 @@ -23,7 +23,7 @@ contains end subroutine subroutine f06 () - !$omp declare variant (f05) match (user={condition(1)},implementation={atomic_default_mem_order(relaxed)}) + !$omp declare variant (f05) match (user={condition(.true.)},implementation={atomic_default_mem_order(relaxed)}) end subroutine subroutine f07 ()