From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id E114C385772F; Wed, 26 Apr 2023 08:37:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E114C385772F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682498261; bh=DcZyY2ok8aZjPmeFBZIerMtZGZb9Oyi/GBZuS0NNIrI=; h=From:To:Subject:Date:From; b=nbJmUXMsmdwhp13kRfRkTJi1HS6XeGsOpbkyKopV8P9sy90KE72IfT41j3j1MMpf1 aCRvhCg7ooSILjiVTuqix9XtyD2/I69Lghp9GXWN+zm/FMgeAzVFEQsrzSXtExySs+ /qX3UxdvxzqEqs4OoU3psEsE5vZcDRcf/7ZAo74o= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-7246] c: Avoid -Wenum-int-mismatch warning for redeclaration of builtin acc_on_device [PR107041] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-13 X-Git-Oldrev: 2295ad5898aabc652b247446be5769e4a43184f1 X-Git-Newrev: f8646b8dcb18721e776c39117f62aee7ee571f21 Message-Id: <20230426083741.E114C385772F@sourceware.org> Date: Wed, 26 Apr 2023 08:37:41 +0000 (GMT) List-Id: https://gcc.gnu.org/g:f8646b8dcb18721e776c39117f62aee7ee571f21 commit r13-7246-gf8646b8dcb18721e776c39117f62aee7ee571f21 Author: Jakub Jelinek Date: Thu Apr 20 19:26:17 2023 +0200 c: Avoid -Wenum-int-mismatch warning for redeclaration of builtin acc_on_device [PR107041] 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. 2023-04-20 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. (cherry picked from commit 3d7ab53d6c59499624aa41c8dea0664976820b3b) Diff: --- gcc/c/c-decl.cc | 9 ++++++++- gcc/testsuite/gcc.dg/goacc/pr107041.c | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index e537d33f398..1b53f2d0785 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -2219,7 +2219,14 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl, } /* 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 built-in redeclaration, + the built-in 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 " diff --git a/gcc/testsuite/gcc.dg/goacc/pr107041.c b/gcc/testsuite/gcc.dg/goacc/pr107041.c new file mode 100644 index 00000000000..ed7fb5a5b5d --- /dev/null +++ b/gcc/testsuite/gcc.dg/goacc/pr107041.c @@ -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); +}