From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 097EF3853C02 for ; Fri, 23 Jul 2021 08:10:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 097EF3853C02 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-529-O2nNPJyDP5GvaVsNnuWmOA-1; Fri, 23 Jul 2021 04:10:51 -0400 X-MC-Unique: O2nNPJyDP5GvaVsNnuWmOA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 28101107ACF5 for ; Fri, 23 Jul 2021 08:10:50 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-112-143.ams2.redhat.com [10.36.112.143]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CA1735C1D5 for ; Fri, 23 Jul 2021 08:10:49 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 16N8Alc81599850 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT) for ; Fri, 23 Jul 2021 10:10:48 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 16N8Al1r1599849 for gcc-patches@gcc.gnu.org; Fri, 23 Jul 2021 10:10:47 +0200 Date: Fri, 23 Jul 2021 10:10:47 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [committed] openmp: Add support for __has_attribute(omp::directive) and __has_attribute(omp::sequence) Message-ID: <20210723081047.GA2380545@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Jul 2021 08:10:55 -0000 Hi! Now that the C++ FE supports these attributes, but not through registering them in the attributes tables (they work quite differently from other attributes), this teaches c_common_has_attributes about those. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 2021-07-23 Jakub Jelinek * c-lex.c (c_common_has_attribute): Call canonicalize_attr_name also on attr_id. Return 1 for omp::directive or omp::sequence in C++11 and later. * c-c++-common/gomp/attrs-1.c: New test. * c-c++-common/gomp/attrs-2.c: New test. * c-c++-common/gomp/attrs-3.c: New test. --- gcc/c-family/c-lex.c.jj 2021-05-21 10:34:09.046563955 +0200 +++ gcc/c-family/c-lex.c 2021-07-22 15:16:37.340412532 +0200 @@ -338,7 +338,20 @@ c_common_has_attribute (cpp_reader *pfil tree attr_id = get_identifier ((const char *) cpp_token_as_text (pfile, nxt_token)); - attr_name = build_tree_list (attr_ns, attr_id); + attr_id = canonicalize_attr_name (attr_id); + if (c_dialect_cxx ()) + { + /* OpenMP attributes need special handling. */ + if ((flag_openmp || flag_openmp_simd) + && is_attribute_p ("omp", attr_ns) + && (is_attribute_p ("directive", attr_id) + || is_attribute_p ("sequence", attr_id))) + result = 1; + } + if (result) + attr_name = NULL_TREE; + else + attr_name = build_tree_list (attr_ns, attr_id); } else { --- gcc/testsuite/c-c++-common/gomp/attrs-1.c.jj 2021-07-22 14:34:26.718586059 +0200 +++ gcc/testsuite/c-c++-common/gomp/attrs-1.c 2021-07-22 15:16:00.389926789 +0200 @@ -0,0 +1,146 @@ +/* { dg-do compile } */ +/* { dg-options "-fopenmp" } */ + +#if __has_attribute(omp::directive) +#ifndef __cplusplus +#error omp::directive supported in C +#endif +#else +#ifdef __cplusplus +#error omp::directive not supported in C++ +#endif +#endif + +#if __has_attribute(omp::sequence) +#ifndef __cplusplus +#error omp::sequence supported in C +#endif +#else +#ifdef __cplusplus +#error omp::sequence not supported in C++ +#endif +#endif + +#if __has_attribute(omp::unknown) +#error omp::unknown supported +#endif + +#if __has_cpp_attribute(omp::directive) +#ifndef __cplusplus +#error omp::directive supported in C +#endif +#else +#ifdef __cplusplus +#error omp::directive not supported in C++ +#endif +#endif + +#if __has_cpp_attribute(omp::sequence) +#ifndef __cplusplus +#error omp::sequence supported in C +#endif +#else +#ifdef __cplusplus +#error omp::sequence not supported in C++ +#endif +#endif + +#if __has_cpp_attribute(omp::unknown) +#error omp::unknown supported +#endif + +#if __has_attribute(__omp__::__directive__) +#ifndef __cplusplus +#error __omp__::__directive__ supported in C +#endif +#else +#ifdef __cplusplus +#error __omp__::__directive__ not supported in C++ +#endif +#endif + +#if __has_attribute(__omp__::__sequence__) +#ifndef __cplusplus +#error __omp__::__sequence__ supported in C +#endif +#else +#ifdef __cplusplus +#error __omp__::__sequence__ not supported in C++ +#endif +#endif + +#if __has_attribute(__omp__::__unknown__) +#error __omp__::__unknown__ supported +#endif + +#if __has_cpp_attribute(__omp__::__directive__) +#ifndef __cplusplus +#error __omp__::__directive__ supported in C +#endif +#else +#ifdef __cplusplus +#error __omp__::__directive__ not supported in C++ +#endif +#endif + +#if __has_cpp_attribute(__omp__::__sequence__) +#ifndef __cplusplus +#error __omp__::__sequence__ supported in C +#endif +#else +#ifdef __cplusplus +#error __omp__::__sequence__ not supported in C++ +#endif +#endif + +#if __has_cpp_attribute(__omp__::__unknown__) +#error __omp__::__unknown__ supported +#endif + +#if __has_attribute(omp::__directive__) +#ifndef __cplusplus +#error omp::__directive__ supported in C +#endif +#else +#ifdef __cplusplus +#error omp::__directive__ not supported in C++ +#endif +#endif + +#if __has_attribute(__omp__::sequence) +#ifndef __cplusplus +#error __omp__::sequence supported in C +#endif +#else +#ifdef __cplusplus +#error __omp__::sequence not supported in C++ +#endif +#endif + +#if __has_attribute(omp::__unknown__) +#error omp::__unknown__ supported +#endif + +#if __has_cpp_attribute(__omp__::directive) +#ifndef __cplusplus +#error __omp__::directive supported in C +#endif +#else +#ifdef __cplusplus +#error __omp__::directive not supported in C++ +#endif +#endif + +#if __has_cpp_attribute(omp::__sequence__) +#ifndef __cplusplus +#error omp::__sequence__ supported in C +#endif +#else +#ifdef __cplusplus +#error omp::__sequence__ not supported in C++ +#endif +#endif + +#if __has_cpp_attribute(__omp__::unknown) +#error __omp__::unknown supported +#endif --- gcc/testsuite/c-c++-common/gomp/attrs-2.c.jj 2021-07-22 14:34:34.508477846 +0200 +++ gcc/testsuite/c-c++-common/gomp/attrs-2.c 2021-07-22 15:16:18.635672852 +0200 @@ -0,0 +1,146 @@ +/* { dg-do compile } */ +/* { dg-options "-fno-openmp -fopenmp-simd" } */ + +#if __has_attribute(omp::directive) +#ifndef __cplusplus +#error omp::directive supported in C +#endif +#else +#ifdef __cplusplus +#error omp::directive not supported in C++ +#endif +#endif + +#if __has_attribute(omp::sequence) +#ifndef __cplusplus +#error omp::sequence supported in C +#endif +#else +#ifdef __cplusplus +#error omp::sequence not supported in C++ +#endif +#endif + +#if __has_attribute(omp::unknown) +#error omp::unknown supported +#endif + +#if __has_cpp_attribute(omp::directive) +#ifndef __cplusplus +#error omp::directive supported in C +#endif +#else +#ifdef __cplusplus +#error omp::directive not supported in C++ +#endif +#endif + +#if __has_cpp_attribute(omp::sequence) +#ifndef __cplusplus +#error omp::sequence supported in C +#endif +#else +#ifdef __cplusplus +#error omp::sequence not supported in C++ +#endif +#endif + +#if __has_cpp_attribute(omp::unknown) +#error omp::unknown supported +#endif + +#if __has_attribute(__omp__::__directive__) +#ifndef __cplusplus +#error __omp__::__directive__ supported in C +#endif +#else +#ifdef __cplusplus +#error __omp__::__directive__ not supported in C++ +#endif +#endif + +#if __has_attribute(__omp__::__sequence__) +#ifndef __cplusplus +#error __omp__::__sequence__ supported in C +#endif +#else +#ifdef __cplusplus +#error __omp__::__sequence__ not supported in C++ +#endif +#endif + +#if __has_attribute(__omp__::__unknown__) +#error __omp__::__unknown__ supported +#endif + +#if __has_cpp_attribute(__omp__::__directive__) +#ifndef __cplusplus +#error __omp__::__directive__ supported in C +#endif +#else +#ifdef __cplusplus +#error __omp__::__directive__ not supported in C++ +#endif +#endif + +#if __has_cpp_attribute(__omp__::__sequence__) +#ifndef __cplusplus +#error __omp__::__sequence__ supported in C +#endif +#else +#ifdef __cplusplus +#error __omp__::__sequence__ not supported in C++ +#endif +#endif + +#if __has_cpp_attribute(__omp__::__unknown__) +#error __omp__::__unknown__ supported +#endif + +#if __has_attribute(omp::__directive__) +#ifndef __cplusplus +#error omp::__directive__ supported in C +#endif +#else +#ifdef __cplusplus +#error omp::__directive__ not supported in C++ +#endif +#endif + +#if __has_attribute(__omp__::sequence) +#ifndef __cplusplus +#error __omp__::sequence supported in C +#endif +#else +#ifdef __cplusplus +#error __omp__::sequence not supported in C++ +#endif +#endif + +#if __has_attribute(omp::__unknown__) +#error omp::__unknown__ supported +#endif + +#if __has_cpp_attribute(__omp__::directive) +#ifndef __cplusplus +#error __omp__::directive supported in C +#endif +#else +#ifdef __cplusplus +#error __omp__::directive not supported in C++ +#endif +#endif + +#if __has_cpp_attribute(omp::__sequence__) +#ifndef __cplusplus +#error omp::__sequence__ supported in C +#endif +#else +#ifdef __cplusplus +#error omp::__sequence__ not supported in C++ +#endif +#endif + +#if __has_cpp_attribute(__omp__::unknown) +#error __omp__::unknown supported +#endif --- gcc/testsuite/c-c++-common/gomp/attrs-3.c.jj 2021-07-22 14:34:56.393173843 +0200 +++ gcc/testsuite/c-c++-common/gomp/attrs-3.c 2021-07-22 14:58:17.525708003 +0200 @@ -0,0 +1,74 @@ +/* { dg-do compile } */ +/* { dg-options "-fno-openmp -fno-openmp-simd" } */ + +#if __has_attribute(omp::directive) +#error omp::directive supported even when -fno-openmp{,-simd} +#endif + +#if __has_attribute(omp::sequence) +#error omp::sequence supported even when -fno-openmp{,-simd} +#endif + +#if __has_attribute(omp::unknown) +#error omp::unknown supported +#endif + +#if __has_cpp_attribute(omp::directive) +#error omp::directive supported even when -fno-openmp{,-simd} +#endif + +#if __has_cpp_attribute(omp::sequence) +#error omp::sequence supported even when -fno-openmp{,-simd} +#endif + +#if __has_cpp_attribute(omp::unknown) +#error omp::unknown supported +#endif + +#if __has_attribute(__omp__::__directive__) +#error __omp__::__directive__ supported even when -fno-openmp{,-simd} +#endif + +#if __has_attribute(__omp__::__sequence__) +#error __omp__::__sequence__ supported even when -fno-openmp{,-simd} +#endif + +#if __has_attribute(__omp__::__unknown__) +#error __omp__::__unknown__ supported +#endif + +#if __has_cpp_attribute(__omp__::__directive__) +#error __omp__::__directive__ supported even when -fno-openmp{,-simd} +#endif + +#if __has_cpp_attribute(__omp__::__sequence__) +#error __omp__::__sequence__ supported even when -fno-openmp{,-simd} +#endif + +#if __has_cpp_attribute(__omp__::__unknown__) +#error __omp__::__unknown__ supported +#endif + +#if __has_attribute(omp::__directive__) +#error omp::__directive__ supported even when -fno-openmp{,-simd} +#endif + +#if __has_attribute(__omp__::sequence) +#error __omp__::sequence supported even when -fno-openmp{,-simd} +#endif + +#if __has_attribute(omp::__unknown__) +#error omp::__unknown__ supported +#endif + +#if __has_cpp_attribute(__omp__::directive) +#error __omp__::directive supported even when -fno-openmp{,-simd} +#endif + +#if __has_cpp_attribute(omp::__sequence__) +#error omp::__sequence__ supported even when -fno-openmp{,-simd} +#endif + +#if __has_cpp_attribute(__omp__::unknown) +#error __omp__::unknown supported +#endif Jakub