From patchwork Sat Jul 20 20:42:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sandra Loosemore X-Patchwork-Id: 94269 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 5C6183861034 for ; Sat, 20 Jul 2024 20:44:18 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-il1-x129.google.com (mail-il1-x129.google.com [IPv6:2607:f8b0:4864:20::129]) by sourceware.org (Postfix) with ESMTPS id 1F21C385E82D for ; Sat, 20 Jul 2024 20:42:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1F21C385E82D 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 1F21C385E82D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::129 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721508177; cv=none; b=TgLnR4HGBZSd5utilgvFZ7bu87dgRzbLLPmDJcDemxqcx9+46GFkhdTOk3CG7lSvX6QOx0nNSo60oELDurGIlZQsDpvsTjmdqImyitzPASSP/Ct5FjTMnqmgWb1PXj2ubmfbAffmQOL3gtEYU2HFsoZSQDzAp++OtE9hyvHH+7E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721508177; c=relaxed/simple; bh=bg5X2Ew5J2QgdMguuBU6e9F12bU5v9YW9Fh+8AmEDl8=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=obf2usZoE7GGAak+blg0cw3z60IUDApA4ZiG09tndvdNOwohz1SG3x4jshNwJesfkyQJrlCEOYsboL9BkqLm+7fmf50CW2rKgMuQt7aGB9Q+yVqCkq2py+aKIL0NcI0XiVLPNE1kSMF4dj4tJpjjtOL+ctSv1asCDysTLp2LoZI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-il1-x129.google.com with SMTP id e9e14a558f8ab-3993f5d75bbso3145625ab.3 for ; Sat, 20 Jul 2024 13:42:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1721508171; x=1722112971; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=esnKbem1lQPc0ACFztNSd63vKJTCydItPE+fJEq5vYM=; b=2vuqK63/wATLIFFibrV9NqL4qPOjdIPq4B3UTAJeWkkCMxVCL9Y2E++G+KnOvPz+0b Twp3/UAEd2bdOTa39aMZF74fsEo60+Td0mBuFPnIcAjEt/i06uME0O+v7neDj8IWvZwG 2zq4Hw0vraa3ql/53w9BAn11Fz0ElQ33qP2U31LJf6ut2hopYdi0fZ9QyKFZVDf0RNm5 zaAezhASi0O+OXF63LrDk6N63dcnhhar97fA9V4cOg27Mz3uUZVOfZ+lWFOhqb5WUYSu NcHI8G76rTJ6K7IFsB8TsYpultB4zy7QVQwqry8dwJ4vFHS4BRH18aNcU7l+qU6yt1tY OthQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721508171; x=1722112971; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=esnKbem1lQPc0ACFztNSd63vKJTCydItPE+fJEq5vYM=; b=opBt1CiPmfK5zcsRjHRaDjYKOSv3SReoDzbZ1443qNzzgND1pcCAx69RRtIij4TBAd iEi1boyzZqF145BfqhzKbLpiJNrzY6NGW1L95eAAKryZaembCOvnYg/zO84DEBo9Uaxr q8r1GSZTVOADF70X6DyOLNE69tEcXT/8JpvSd+GtSbfwbh1ZXEEvV9ICrg9gD+kwzDVk u4j+tEZiP+a4U/Yu9QwqosQLtzlNDEc/Cts1WACdoUq2bzozBmGsSoB5KGDPyVDvtaVi mxGgWILVMkMqbHFXBhTQOiv1SBXeNd2NzD6ElXFJeN7MvhJ36IFmh9bAwvptFQkTKvF4 dKnQ== X-Gm-Message-State: AOJu0YxNCeXV3O4dXDzeS1Z1ipihOiIPYl4VW0x3piC9IXptmZ/S9MFx DdYKa7VyjASu+/iGVf48aXlQFbQnKiAqPeA02mbxAei6dl2m+OhyGvV3GmYFgZqzzzwY3EIPzlP aZDQ= X-Google-Smtp-Source: AGHT+IGOEQEXDrrlbSqzLChAUwvi62m5BHbPHHcrCX0jbolDhk6ng/AKylPkyw8vz5UOpOTWGmjj+g== X-Received: by 2002:a05:6e02:1fed:b0:374:9957:7328 with SMTP id e9e14a558f8ab-398e5855d1cmr55425655ab.15.1721508171517; Sat, 20 Jul 2024 13:42:51 -0700 (PDT) Received: from pondscum.hsd1.co.comcast.net ([2601:281:d901:5620:ee50:43b7:d7db:ddf2]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-397f5c2b74esm13133105ab.35.2024.07.20.13.42.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jul 2024 13:42:51 -0700 (PDT) From: Sandra Loosemore To: gcc-patches@gcc.gnu.org Cc: jakub@redhat.com, tburnus@baylibre.com Subject: [PATCH v3 08/12] OpenMP: Reject other properties with kind(any) Date: Sat, 20 Jul 2024 14:42:27 -0600 Message-Id: <20240720204231.2229891-9-sloosemore@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240720204231.2229891-1-sloosemore@baylibre.com> References: <20240720204231.2229891-1-sloosemore@baylibre.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, 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 The OpenMP spec says: "If trait-property any is specified in the kind trait-selector of the device selector set or the target_device selector sets, no other trait-property may be specified in the same selector set." GCC was not previously enforcing this restriction and several testcases included such valid constructs. This patch fixes it. gcc/ChangeLog * omp-general.cc (omp_check_context_selector): Reject other properties in the same selector set with kind(any). gcc/testsuite/ChangeLog * c-c++-common/gomp/declare-variant-10.c: Fix broken tests. * c-c++-common/gomp/declare-variant-3.c: Likewise. * c-c++-common/gomp/declare-variant-9.c: Likewise. * c-c++-common/gomp/declare-variant-any.c: New. * gfortran.dg/gomp/declare-variant-10.f90: Fix broken tests. * gfortran.dg/gomp/declare-variant-3.f90: Likewise. * gfortran.dg/gomp/declare-variant-9.f90: Likewise. * gfortran.dg/gomp/declare-variant-any.f90: Likewise. --- gcc/omp-general.cc | 31 +++++++++++++++++++ .../c-c++-common/gomp/declare-variant-10.c | 4 +-- .../c-c++-common/gomp/declare-variant-3.c | 10 ++---- .../c-c++-common/gomp/declare-variant-9.c | 4 +-- .../c-c++-common/gomp/declare-variant-any.c | 10 ++++++ .../gfortran.dg/gomp/declare-variant-10.f90 | 4 +-- .../gfortran.dg/gomp/declare-variant-3.f90 | 12 ++----- .../gfortran.dg/gomp/declare-variant-9.f90 | 2 +- .../gfortran.dg/gomp/declare-variant-any.f90 | 28 +++++++++++++++++ 9 files changed, 82 insertions(+), 23 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/gomp/declare-variant-any.c create mode 100644 gcc/testsuite/gfortran.dg/gomp/declare-variant-any.f90 diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc index 87a245ec8b3..12f178c5a2d 100644 --- a/gcc/omp-general.cc +++ b/gcc/omp-general.cc @@ -1288,6 +1288,8 @@ omp_check_context_selector (location_t loc, tree ctx, bool metadirective_p) for (tree tss = ctx; tss; tss = TREE_CHAIN (tss)) { enum omp_tss_code tss_code = OMP_TSS_CODE (tss); + bool saw_any_prop = false; + bool saw_other_prop = false; /* FIXME: not implemented yet. */ if (!metadirective_p && tss_code == OMP_TRAIT_SET_TARGET_DEVICE) @@ -1325,6 +1327,27 @@ omp_check_context_selector (location_t loc, tree ctx, bool metadirective_p) else ts_seen[ts_code] = true; + + /* If trait-property "any" is specified in the "kind" + trait-selector of the "device" selector set or the + "target_device" selector sets, no other trait-property + may be specified in the same selector set. */ + if (ts_code == OMP_TRAIT_DEVICE_KIND) + for (tree p = OMP_TS_PROPERTIES (ts); p; p = TREE_CHAIN (p)) + { + const char *prop = omp_context_name_list_prop (p); + if (!prop) + continue; + else if (strcmp (prop, "any") == 0) + saw_any_prop = true; + else + saw_other_prop = true; + } + else if (ts_code == OMP_TRAIT_DEVICE_ARCH + || ts_code == OMP_TRAIT_DEVICE_ISA + || ts_code == OMP_TRAIT_DEVICE_NUM) + saw_other_prop = true; + if (omp_ts_map[ts_code].valid_properties == NULL) continue; @@ -1377,6 +1400,14 @@ omp_check_context_selector (location_t loc, tree ctx, bool metadirective_p) break; } } + + if (saw_any_prop && saw_other_prop) + { + error_at (loc, + "no other trait-property may be specified " + "in the same selector set with %"); + return error_mark_node; + } } return ctx; } diff --git a/gcc/testsuite/c-c++-common/gomp/declare-variant-10.c b/gcc/testsuite/c-c++-common/gomp/declare-variant-10.c index 2b8a39425b1..e77693430d1 100644 --- a/gcc/testsuite/c-c++-common/gomp/declare-variant-10.c +++ b/gcc/testsuite/c-c++-common/gomp/declare-variant-10.c @@ -7,7 +7,7 @@ void f01 (void); #pragma omp declare variant (f01) match (device={isa(avx512f,avx512bw)}) void f02 (void); void f03 (void); -#pragma omp declare variant (f03) match (device={kind("any"),arch(x86_64),isa(avx512f,avx512bw)}) +#pragma omp declare variant (f03) match (device={arch(x86_64),isa(avx512f,avx512bw)}) void f04 (void); void f05 (void); #pragma omp declare variant (f05) match (device={kind(gpu)}) @@ -28,7 +28,7 @@ void f15 (void); #pragma omp declare variant (f15) match (device={isa(sse4,ssse3),arch(i386)}) void f16 (void); void f17 (void); -#pragma omp declare variant (f17) match (device={kind(any,fpga)}) +#pragma omp declare variant (f17) match (device={kind(fpga)}) void f18 (void); #pragma omp declare target diff --git a/gcc/testsuite/c-c++-common/gomp/declare-variant-3.c b/gcc/testsuite/c-c++-common/gomp/declare-variant-3.c index f5d7797f458..0d772d7aaab 100644 --- a/gcc/testsuite/c-c++-common/gomp/declare-variant-3.c +++ b/gcc/testsuite/c-c++-common/gomp/declare-variant-3.c @@ -29,13 +29,13 @@ void f17 (void); void f18 (void); #pragma omp declare variant (f13) match (device={kind(fpga)}) void f19 (void); -#pragma omp declare variant (f13) match (device={kind(any,any)}) +#pragma omp declare variant (f13) match (device={kind(any)}) void f20 (void); #pragma omp declare variant (f13) match (device={kind(host,nohost)}) void f21 (void); #pragma omp declare variant (f13) match (device={kind("cpu","gpu","fpga")}) void f22 (void); -#pragma omp declare variant (f13) match (device={kind(any,cpu,nohost)}) +#pragma omp declare variant (f13) match (device={kind(cpu,nohost)}) void f23 (void); #pragma omp declare variant (f13) match (device={isa(avx)}) void f24 (void); @@ -139,12 +139,8 @@ void f72 (void); void f73 (void); #pragma omp declare variant (f13) match (user={condition(score(25):1)}) void f74 (void); -#pragma omp declare variant (f13) match (device={kind(any,"any")}) +#pragma omp declare variant (f13) match (device={kind("any")}) void f75 (void); -#pragma omp declare variant (f13) match (device={kind("any","any")}) -void f76 (void); -#pragma omp declare variant (f13) match (device={kind("any",any)}) -void f77 (void); #pragma omp declare variant (f13) match (implementation={vendor(nvidia)}) void f78 (void); #pragma omp declare variant (f13) match (user={condition(score(0):0)}) diff --git a/gcc/testsuite/c-c++-common/gomp/declare-variant-9.c b/gcc/testsuite/c-c++-common/gomp/declare-variant-9.c index 5ee75892f2d..da96c81eb6f 100644 --- a/gcc/testsuite/c-c++-common/gomp/declare-variant-9.c +++ b/gcc/testsuite/c-c++-common/gomp/declare-variant-9.c @@ -7,7 +7,7 @@ void f01 (void); #pragma omp declare variant (f01) match (device={isa("avx512f",avx512bw)}) void f02 (void); void f03 (void); -#pragma omp declare variant (f03) match (device={kind(any),arch(x86_64),isa("avx512f","avx512bw")}) +#pragma omp declare variant (f03) match (device={arch(x86_64),isa("avx512f","avx512bw")}) void f04 (void); void f05 (void); #pragma omp declare variant (f05) match (device={kind(gpu)}) @@ -28,7 +28,7 @@ void f15 (void); #pragma omp declare variant (f15) match (device={isa(sse4,ssse3),arch(i386)}) void f16 (void); void f17 (void); -#pragma omp declare variant (f17) match (device={kind("any","fpga")}) +#pragma omp declare variant (f17) match (device={kind("fpga")}) void f18 (void); void diff --git a/gcc/testsuite/c-c++-common/gomp/declare-variant-any.c b/gcc/testsuite/c-c++-common/gomp/declare-variant-any.c new file mode 100644 index 00000000000..ad932109077 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/declare-variant-any.c @@ -0,0 +1,10 @@ +extern int f1 (int); +extern int f2 (int); +extern int f3 (int); +extern int f4 (int); + +#pragma omp declare variant (f1) match (device={kind(any,gpu)}) /* { dg-error "no other trait-property may be specified" } */ +#pragma omp declare variant (f2) match (device={kind(cpu,"any")}) /* { dg-error "no other trait-property may be specified" } */ +#pragma omp declare variant (f3) match (device={kind("any"),arch(x86_64)}) /* { dg-error "no other trait-property may be specified" } */ +#pragma omp declare variant (f4) match (device={arch(x86_64),kind(any)}) /* { dg-error "no other trait-property may be specified" } */ +int f (int); diff --git a/gcc/testsuite/gfortran.dg/gomp/declare-variant-10.f90 b/gcc/testsuite/gfortran.dg/gomp/declare-variant-10.f90 index 2f09146a10d..01f59c52808 100644 --- a/gcc/testsuite/gfortran.dg/gomp/declare-variant-10.f90 +++ b/gcc/testsuite/gfortran.dg/gomp/declare-variant-10.f90 @@ -15,7 +15,7 @@ contains subroutine f03 () end subroutine subroutine f04 () - !$omp declare variant (f03) match (device={kind("any"),arch(x86_64),isa(avx512f,avx512bw)}) + !$omp declare variant (f03) match (device={arch(x86_64),isa(avx512f,avx512bw)}) end subroutine subroutine f05 () end subroutine @@ -50,7 +50,7 @@ contains subroutine f17 () end subroutine subroutine f18 () - !$omp declare variant (f17) match (device={kind(any,fpga)}) + !$omp declare variant (f17) match (device={kind(fpga)}) end subroutine subroutine test1 () diff --git a/gcc/testsuite/gfortran.dg/gomp/declare-variant-3.f90 b/gcc/testsuite/gfortran.dg/gomp/declare-variant-3.f90 index 6b23d40e410..30733209e14 100644 --- a/gcc/testsuite/gfortran.dg/gomp/declare-variant-3.f90 +++ b/gcc/testsuite/gfortran.dg/gomp/declare-variant-3.f90 @@ -51,7 +51,7 @@ contains !$omp declare variant (f13) match (device={kind(fpga)}) end subroutine subroutine f20 () - !$omp declare variant (f13) match (device={kind(any,any)}) + !$omp declare variant (f13) match (device={kind(any)}) end subroutine subroutine f21 () !$omp declare variant (f13) match (device={kind(host,nohost)}) @@ -60,7 +60,7 @@ contains !$omp declare variant (f13) match (device={kind("cpu","gpu","fpga")}) end subroutine subroutine f23 () - !$omp declare variant (f13) match (device={kind(any,cpu,nohost)}) + !$omp declare variant (f13) match (device={kind(cpu,nohost)}) end subroutine subroutine f24 () !$omp declare variant (f13) match (device={isa(avx)}) @@ -219,13 +219,7 @@ contains !$omp declare variant (f13) match (user={condition(score(25):.true.)}) end subroutine subroutine f75 () - !$omp declare variant (f13) match (device={kind(any,"any")}) - end subroutine - subroutine f76 () - !$omp declare variant (f13) match (device={kind("any","any")}) - end subroutine - subroutine f77 () - !$omp declare variant (f13) match (device={kind("any",any)}) + !$omp declare variant (f13) match (device={kind("any")}) end subroutine subroutine f78 () !$omp declare variant (f13) match (implementation={vendor(nvidia)}) diff --git a/gcc/testsuite/gfortran.dg/gomp/declare-variant-9.f90 b/gcc/testsuite/gfortran.dg/gomp/declare-variant-9.f90 index ebd066609f3..297bff97d5e 100644 --- a/gcc/testsuite/gfortran.dg/gomp/declare-variant-9.f90 +++ b/gcc/testsuite/gfortran.dg/gomp/declare-variant-9.f90 @@ -38,7 +38,7 @@ contains subroutine f17 () end subroutine subroutine f18 () - !$omp declare variant (f17) match (device={kind("any","fpga")}) + !$omp declare variant (f17) match (device={kind("fpga")}) end subroutine subroutine test1 () diff --git a/gcc/testsuite/gfortran.dg/gomp/declare-variant-any.f90 b/gcc/testsuite/gfortran.dg/gomp/declare-variant-any.f90 new file mode 100644 index 00000000000..01540008724 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/declare-variant-any.f90 @@ -0,0 +1,28 @@ +integer function f1 (x) + integer, intent(in) :: x + f1 = x + 1 +end function +integer function f2 (x) + integer, intent(in) :: x + f2 = x + 2 +end function +integer function f3 (x) + integer, intent(in) :: x + f3 = x + 3 +end function +integer function f4 (x) + integer, intent(in) :: x + f4 = x + 4 +end function + +integer function f (x) + integer, intent(in) :: x + + !$omp declare variant (f1) match (device={kind(any,gpu)}) ! { dg-error "no other trait-property may be specified" } + !$omp declare variant (f2) match (device={kind(cpu,"any")}) ! { dg-error "no other trait-property may be specified" } + !$omp declare variant (f3) match (device={kind("any"),arch(x86_64)}) ! { dg-error "no other trait-property may be specified" } + !$omp declare variant (f4) match (device={arch(x86_64),kind(any)}) ! { dg-error "no other trait-property may be specified" } + + f = x +end function +