From patchwork Wed Apr 19 09:02:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 85266 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp231776vqo; Wed, 19 Apr 2023 02:03:53 -0700 (PDT) X-Google-Smtp-Source: AKy350bCloWXvigeHy9yvb/xFLQTqUXUHRYbWqNcTyRARWYrUCRS8WRU1RX0qEzO+df7gfmHZckg X-Received: by 2002:a17:906:32c6:b0:953:4481:3301 with SMTP id k6-20020a17090632c600b0095344813301mr2318616ejk.59.1681895033574; Wed, 19 Apr 2023 02:03:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681895033; cv=none; d=google.com; s=arc-20160816; b=cWI4ZtR1UqDryX2BpGAZo52LAmdfMdMngki4hORDTSG+SZABk0GjJRmvEa5Y+ajl6X iGMb/SzG/iT48uy+CFeROf4YuCz//q4Ilfn/RvL3ysXCy8+FFw3f9TXwWEDL/CxWOjGR 9XzFNE9VuKq5P5vymi90Jn4TWQCEMgwhIAjNmAJepCoRgvPc0yIQV/KRAcqbOePOsDHu kPC7nyimGSEa91qNaQW7xv99fQoe1gMJDGP2Y+kQ/0rIlJ7z8MjPHtY8CfmhbMqRemC4 UODt08Fv4WZYlUUXAyGZS/1quxVDEuIIVSxb+IlRFssCdg+CVOxfk2XdBH64DtnPAibU O0MQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=XSLdfe684skdWn7qvbGxCHed6AisH2q+da0cAP2kpa0=; b=H8WafsubCCjn3+qyFYgVeLQ/edeWjyQiFb0vBxil1uCKWtiMjsBmwOfaycmpOBx3Eg vxY7+k7BPqjIJM8Yd6TTee4xKpZZRSQlEYRX3THsR7jji39hPweYuNVjdQsxPmmSF7gQ Ed2CXKQtFoHxlmz5SktlMsYrIWRPhcz9xGntyPhO61mba8IKputXtZgL8y6aI1hRchCa MzZEdkfPwa8RYXRE4c2luKAFFVrsvfCu/sWmjY5yFKtf5XWQ+WtRjkDGDTAFcPMWZK2T YAoDQaO+FN5yj32gvYHvy1ojOERsV5LZJMWVHsHPZaOzHECj7KW4zHL3mgvJIh31z0Yh 5Zdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UwWNcTIS; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id bo10-20020a0564020b2a00b00506a75034ebsi6206930edb.87.2023.04.19.02.03.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 02:03:53 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UwWNcTIS; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6C4773858288 for ; Wed, 19 Apr 2023 09:03:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6C4773858288 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681895032; bh=XSLdfe684skdWn7qvbGxCHed6AisH2q+da0cAP2kpa0=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=UwWNcTISjXxOtGrp/40xczTBAL59+TzXidjCEO1pNBa8HFdwgJTUz882mISHID95m iBEa+Iy1XUpiTz4OCNa6z8bJulGcwU+TBeAHqocddd//rm/QNwibWj2yr1hJMWl7i+ IDknDuId+RzSsdnv87KJEBjBW9JFJD49phPZgWPU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 4A37A3858D1E for ; Wed, 19 Apr 2023 09:02:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4A37A3858D1E Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-571-nBOcsiPcMoqX-6UGR6-yYg-1; Wed, 19 Apr 2023 05:02:57 -0400 X-MC-Unique: nBOcsiPcMoqX-6UGR6-yYg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4066029AA2D9; Wed, 19 Apr 2023 09:02:57 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ED6F1492B06; Wed, 19 Apr 2023 09:02:56 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 33J92scj2593655 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 19 Apr 2023 11:02:54 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 33J92rBw2593654; Wed, 19 Apr 2023 11:02:53 +0200 Date: Wed, 19 Apr 2023 11:02:53 +0200 To: "Joseph S. Myers" , Marek Polacek , Thomas Schwinge Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c: Avoid -Wenum-int-mismatch warning for redeclaration of builtin acc_on_device [PR107041] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763594766830936799?= X-GMAIL-MSGID: =?utf-8?q?1763594766830936799?= Hi! The new -Wenum-int-mismatch warning triggers with -Wsystem-headers in , for obvious reasons the builtin acc_on_device uses int type argument rather than enum which isn't defined yet when the builtin is created, while the OpenACC spec requires it to have acc_device_t enum argument. The header makes sure it has int underlying type by using negative and __INT_MAX__ enumerators. I've tried to make the builtin typegeneric or just varargs, but that changes behavior e.g. when one calls it with some C++ class which has cast operator to acc_device_t, so the following patch instead disables the warning for this builtin. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk and 13.2? 2023-04-19 Jakub Jelinek PR c/107041 * c-decl.cc (diagnose_mismatched_decls): Avoid -Wenum-int-mismatch warning on acc_on_device declaration. * gcc.dg/goacc/pr107041.c: New test. Jakub --- gcc/c/c-decl.cc.jj 2023-03-10 10:10:17.918387120 +0100 +++ gcc/c/c-decl.cc 2023-04-18 10:29:33.340793562 +0200 @@ -2219,7 +2219,14 @@ diagnose_mismatched_decls (tree newdecl, } /* Warn about enum/integer type mismatches. They are compatible types (C2X 6.7.2.2/5), but may pose portability problems. */ - else if (enum_and_int_p && TREE_CODE (newdecl) != TYPE_DECL) + else if (enum_and_int_p + && TREE_CODE (newdecl) != TYPE_DECL + /* Don't warn about about acc_on_device builtin redeclaration, + the builtin is declared with int rather than enum because + the enum isn't intrinsic. */ + && !(TREE_CODE (olddecl) == FUNCTION_DECL + && fndecl_built_in_p (olddecl, BUILT_IN_ACC_ON_DEVICE) + && !C_DECL_DECLARED_BUILTIN (olddecl))) warned = warning_at (DECL_SOURCE_LOCATION (newdecl), OPT_Wenum_int_mismatch, "conflicting types for %q+D due to enum/integer " --- gcc/testsuite/gcc.dg/goacc/pr107041.c.jj 2023-04-18 10:18:07.039754258 +0200 +++ gcc/testsuite/gcc.dg/goacc/pr107041.c 2023-04-18 10:17:21.252418797 +0200 @@ -0,0 +1,23 @@ +/* PR c/107041 */ +/* { dg-do compile } */ +/* { dg-additional-options "-Wenum-int-mismatch" } */ + +typedef enum acc_device_t { + acc_device_current = -1, + acc_device_none = 0, + acc_device_default = 1, + acc_device_host = 2, + acc_device_not_host = 4, + acc_device_nvidia = 5, + acc_device_radeon = 8, + _ACC_highest = __INT_MAX__ +} acc_device_t; + +int acc_on_device (acc_device_t); /* { dg-bogus "conflicting types for 'acc_on_device' due to enum/integer mismatch; have 'int\\\(acc_device_t\\\)'" } */ +int acc_on_device (acc_device_t); + +int +foo (void) +{ + return acc_on_device (acc_device_host); +}