From patchwork Sat Aug 27 13:52:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Jose E. Marchesi" X-Patchwork-Id: 802 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp662492wro; Sat, 27 Aug 2022 06:53:30 -0700 (PDT) X-Google-Smtp-Source: AA6agR4UNvbzTHEgfqUrU207OO2UkwAhuBWiSOmmTCSOzoIlM1I3ZOgkZg2Z8YOQRi0SPoWHgSOo X-Received: by 2002:a17:907:7f20:b0:73d:d54f:6571 with SMTP id qf32-20020a1709077f2000b0073dd54f6571mr7215404ejc.315.1661608410630; Sat, 27 Aug 2022 06:53:30 -0700 (PDT) Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ne25-20020a1709077b9900b0073cb9655c3esi58103ejc.371.2022.08.27.06.53.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Aug 2022 06:53:30 -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=miGN8Yn5; arc=fail (signature failed); 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 135D0381E080 for ; Sat, 27 Aug 2022 13:53:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 135D0381E080 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661608409; bh=3Pv5+C7XcQTwrh3cbd+wtS71rfXNI/GoLL4aJ7xo9ew=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=miGN8Yn5cJZBa4XMc/FAIqrtQNyYtCWAvUlMiyg592r11wNCS9Jtvybp687hx8cb1 qWptLYS8OmssFViQNqWRgnM9FDAaLx6zjFGAuBpDE7IkXNEE+4ux9xa8YeLSTymHcM tXIy1/J/WGINVlbNRQcBAFliv2BT8s3RAQnElO68= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 11801388DD25 for ; Sat, 27 Aug 2022 13:52:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 11801388DD25 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27RCZxfO006659; Sat, 27 Aug 2022 13:52:40 GMT Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3j79v0gkq6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 27 Aug 2022 13:52:38 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 27RCfOHH033468; Sat, 27 Aug 2022 13:52:37 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2169.outbound.protection.outlook.com [104.47.59.169]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3j79q06v7a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 27 Aug 2022 13:52:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Bkqrggn/lTW2bx/lZeeDDdlUDJNLbETyxH8UL79twhPcAH9cTmaxR1FnjzBf4y5Af2H8aINd4PoeUMgj1XCMy0gJHy8S5nw8F+7cq/y085t5vIlRk0f2rHQb3ndfwvqavfQAFNq1tKZz2a018KK2+x9AYKRRELpCwRVso4GaFQqvhUc4jAPPsHTMYCFlFftrTxK1tWkgVh5z1I4Aa7OW/GUqPAOBxdlT/xxUs6HZ5op6gb2GZLxYE2uA6zInCtZgraNp51jCmnekzWBzCGiuHZrQEcxSIE/788MK6UMa2efG1p50I9Em4wje3aBd0VSUx2pzaFftJAYCDnhlwdqiTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=3Pv5+C7XcQTwrh3cbd+wtS71rfXNI/GoLL4aJ7xo9ew=; b=bkaUNxSZkwxlihMGaDuCkFHVI3CbnTQBVrbwK7OXHAbp+Zw1Ur3ZD0T0sTG4vYBypPGv0xXRdroLRqWbkkIdLmWfRsS7mPEcoMrcodfS2KmzxOD8uYAajx8/ykBGfcDKccP2lJ6Zs/PpTbgiUOySlt814gPcxN8lgTuQfCaCygwK1WD32/sXaz/AJt1n9U/kal72xCsMXYjyOpwN1Jethiq28EfudsXwpTiRQmDttcxyGqVQr4P7SPd/wZ//bqrfsSEudsE+pWTGoRtpmvYrPQycAX9VLFVZY7TvUeQ0H6rN2dD6LN+q1yBtGeQPiCrC/2/IHLb/U/NQj197RyNcKg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none Received: from BYAPR10MB2888.namprd10.prod.outlook.com (2603:10b6:a03:88::32) by PH0PR10MB5563.namprd10.prod.outlook.com (2603:10b6:510:f2::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.15; Sat, 27 Aug 2022 13:52:34 +0000 Received: from BYAPR10MB2888.namprd10.prod.outlook.com ([fe80::6440:83d5:754:2daf]) by BYAPR10MB2888.namprd10.prod.outlook.com ([fe80::6440:83d5:754:2daf%5]) with mapi id 15.20.5546.023; Sat, 27 Aug 2022 13:52:34 +0000 To: gcc-patches@gcc.gnu.org Subject: [PATCH V3] Add warning options -W[no-]compare-distinct-pointer-types Date: Sat, 27 Aug 2022 15:52:09 +0200 Message-ID: <87pmgl94l2.fsf@oracle.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) X-ClientProxiedBy: FR3P281CA0176.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a0::11) To BYAPR10MB2888.namprd10.prod.outlook.com (2603:10b6:a03:88::32) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 450ffee1-6688-4ded-a757-08da8833650c X-MS-TrafficTypeDiagnostic: PH0PR10MB5563:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eg9F83FdreApHn+ynpm6OZZGq18RpwrQfB2qgOQ8sLGnA/sQsjaeO2yYV1vhhUXr7/m2sJnVqECknTbn4ZR7X074RijU4pM74r+k9JoensLFdBzF4ZEj3bj8woDOfYigfjn84DQ5bdrVAE/BQehRKxESuUMXADlX29x10vmHsVjQFdKie+eqOuKDGuYhxMND5qyq+8e383n/y3YuyReFb+hZKJOvpsZp4WjM46Zat+8IV6N1+IezISkcMQjgSgqaHdJP0pnrP9YuDbhct8DC9x8L/04+/ofU6rFq1MP2q367SGL3gC6VchY5lqG+bQSUebiCLLxpUSyRDT9yAk00iHm15KEiH/cdEqdcNSuSGq8E0nTushGOabZwJLjBFwN4DM0ov1Hskip8m3aBl6J2A1bdnmuttxwaQ3HxU29ZZy36GcREUHqfmK0W37v1A0d1O6oBRfHBnO18fKhC9LlIbImZvgHPl+1/NpLIoYtLIppBX1vyUjD2N9FNzkWs7zZRly6Y64pgJ+7rHsMMuOKYJW38jyfQEskO5D8l7kpxkD3JevWiU8pi4YLBSI7DDJEg2yc9m2QhEvd9nHWXkM7FvDnS4mL7RUA+M9qpOOWnLODXFVo2pmtI3osPKaP7/ZK3NGGh6Q2U9BifEleKUPWK4wbZ/X2Wl+kZ3P+PpmAhgAMxkw5AxyVNFQtVx0Fzav5GL72SZfgY4VOFk4eq3/EdEA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB2888.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(39860400002)(376002)(396003)(366004)(346002)(136003)(66556008)(38100700002)(8676002)(66476007)(5660300002)(4326008)(478600001)(6506007)(83380400001)(6666004)(26005)(41300700001)(186003)(66946007)(2616005)(316002)(6916009)(86362001)(6486002)(8936002)(36756003)(2906002)(6512007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?1UqiqZxlMYSh+jnRbEX5bxjttuQw?= =?utf-8?q?9Vxr3QWpg+I72qTRGafAgi/hjr/MCKvnGZkwNeqbDs7pNf6bDR3kbvYkokWMhR9uj?= =?utf-8?q?lXhCihya2OMTfbZeb6JhDTZSRfZNv7aW9oL8/A8+iTtsLWwa81SExAuZJo8m7oCgz?= =?utf-8?q?5IwZypaWMLBtCka3IOTM4b5gPoN/OGq4N1C2VhtnnMSe12DGvdBEpfcRsvKaPYK7/?= =?utf-8?q?MxrheNTSCj5sKTvPvdVK2wvnedVTMRqUqrKDCZxsBEbBNuqDaN6tiTz0XnfOJuweU?= =?utf-8?q?1p/BYjFIKLN0L3eXwpnwvslvAIO3R02/5d+eGnQu79onJlchCv8kAjd9XlMuiQEev?= =?utf-8?q?NoCLDYi1jE3b8Iv8oQ8tabt+8QAVgENVOi0R+7u9op03Sthzlo/r9Ul0/HhKR8e2K?= =?utf-8?q?0FHDk41k6vbHVXs6TDIOHQYl0ULYBdYtRzpQLnyt7IFlqHJGf9/Wq36hIBNubpuHn?= =?utf-8?q?lUHphjf+M1dJmQO60GDhBaviw6CqOnzl73RaBod7wjoai9tcVXKyAmAx1EXg0l4cs?= =?utf-8?q?Yl7MAa3+Q0HCvNjWvYPo44RakRovAJdWHkBOcS+Yk7BtQg1WvTk2Hz7ZPuBeQMlB3?= =?utf-8?q?tHj3g+27cuSSd+g2soTp+IW30wH2rQlw3eAOesoveCMLN+0ji0Q1Pg+1nmp6ENIVo?= =?utf-8?q?F5jaJDlDty4uKCQn90S9BiGq6/2Z3wUDpXBqXLlzZHfKN3qM1XqjNvQjyyM5+5USg?= =?utf-8?q?xlAi/Z0pdOtnNVC0ZSkQnAF+CSqD8b3WHdcp2Bt9ekjSn3x6mfjItifFb1mOUM0Kt?= =?utf-8?q?tdHfmlDFoOFLXeMptM/Cxm0WgRy5iUsgVF3Y2lnvFLD9cj+ox+FHXf+bjhRWxOMGh?= =?utf-8?q?c8F27jSaANWEFGBXo5DQHM7iZ6NfIydrtjvOpcvqdIKhQYM8ZDeB7I9omI8Rz4gAa?= =?utf-8?q?Oy+ForGQBVF6zwyp37dYfoiNZxK3Zp5q18p0VRPhXGgqcocdzYjz7f9C/BTiotgpz?= =?utf-8?q?VtiW1okd8GNzby/+8+cozYbsZXULxc/PStQrxdpbCMYidvdGp7npalYtYUAKPT0Kn?= =?utf-8?q?29sRwmMnnhM/xSsfgDUBtdL8RGKqV84IsKiJHeisdl765J7oS7mm7kqjO6jAL3dfJ?= =?utf-8?q?RnxJYztiE9nMi/6p2YjXawyAA3M9UmCbnPjBidlUPSkoMtInMX0eIA96rMFKW7mx4?= =?utf-8?q?Y8V0WqFxnIRAsDyvJ6OTJw+rWZPtnIcNabDUw6DM+EhOFSlAE4LVffdQ7bxqx94Rd?= =?utf-8?q?VT1Xeui0/szKGv8S3H3ayVQxLPmIUsSk8WJOUtuqQYEHwhU28okU7eM28GPH+ZR5C?= =?utf-8?q?bwHfb5mSE1LvK+jY6KcB9lwTx7GdpLmbgOnlJvbyqEdXgw9HSw9t6RCxNwrjNWbJl?= =?utf-8?q?uMCPNX49VL4r0rdwlPx9J7jlBm0EkwOcokF6mxPQ4E2jLtk62822U8MhFzTPL3+5a?= =?utf-8?q?qH2memoeUZZscH/6kUwA39TbFJgr5UXxU1nLj8ygkbtFXw9hOKWIe4rvW1NKcP2zI?= =?utf-8?q?+LljUZoc8L4I/dc4vL6+1Dhpe/NVGHP5YRph1N/b+AlIm2BqE0GWdcHV2sicIfT+o?= =?utf-8?q?QhEz7PNbpgViWaczTSnZA6i40D2c26C4Dw=3D=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 450ffee1-6688-4ded-a757-08da8833650c X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2888.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2022 13:52:34.7946 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: nxp3TI+/nlw+KVU6vGVm6Ncj4b5QUddtqmPA7dCSpZsU4I1TKsbfhCyHMNzP853eEXPP1HlKSzPPJKA2nmWL/lUaT7RcfocgHM83c7u4JdM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR10MB5563 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-27_08,2022-08-25_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 malwarescore=0 mlxscore=0 spamscore=0 mlxlogscore=999 phishscore=0 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208270056 X-Proofpoint-GUID: i4qvhgQN8n3-pL_9cw7M5hHYd8WDWe3s X-Proofpoint-ORIG-GUID: i4qvhgQN8n3-pL_9cw7M5hHYd8WDWe3s X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, 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: "Jose E. Marchesi via Gcc-patches" From: "Jose E. Marchesi" Reply-To: "Jose E. Marchesi" Cc: Joseph Myers 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?1742322700825227099?= X-GMAIL-MSGID: =?utf-8?q?1742322700825227099?= GCC emits pedwarns unconditionally when comparing pointers of different types, for example: int xdp_context (struct xdp_md *xdp) { void *data = (void *)(long)xdp->data; __u32 *metadata = (void *)(long)xdp->data_meta; __u32 ret; if (metadata + 1 > data) return 0; return 1; } /home/jemarch/foo.c: In function ‘xdp_context’: /home/jemarch/foo.c:15:20: warning: comparison of distinct pointer types lacks a cast 15 | if (metadata + 1 > data) | ^ LLVM supports an option -W[no-]compare-distinct-pointer-types that can be used in order to enable or disable the emission of such warnings. It is enabled by default. This patch adds the same options to GCC. Documentation and testsuite updated included. Regtested in x86_64-linu-gnu. No regressions observed. gcc/ChangeLog: PR c/106537 * doc/invoke.texi (Option Summary): Mention -Wcompare-distinct-pointer-types under `Warning Options'. (Warning Options): Document -Wcompare-distinct-pointer-types. gcc/c-family/ChangeLog: PR c/106537 * c.opt (Wcompare-distinct-pointer-types): New option. gcc/c/ChangeLog: PR c/106537 * c-typeck.cc (build_binary_op): Warning on comparing distinct pointer types only when -Wcompare-distinct-pointer-types. gcc/testsuite/ChangeLog: PR c/106537 * gcc.c-torture/compile/pr106537-1.c: New test. * gcc.c-torture/compile/pr106537-2.c: Likewise. * gcc.c-torture/compile/pr106537-3.c: Likewise. --- gcc/c-family/c.opt | 4 ++++ gcc/c/c-typeck.cc | 6 ++--- gcc/doc/invoke.texi | 6 +++++ .../gcc.c-torture/compile/pr106537-1.c | 23 +++++++++++++++++++ .../gcc.c-torture/compile/pr106537-2.c | 21 +++++++++++++++++ .../gcc.c-torture/compile/pr106537-3.c | 21 +++++++++++++++++ 6 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr106537-1.c create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr106537-2.c create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr106537-3.c diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index f776efd39d8..729b86c0287 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -1848,6 +1848,10 @@ Winvalid-imported-macros C++ ObjC++ Var(warn_imported_macros) Warning Warn about macros that have conflicting header units definitions. +Wcompare-distinct-pointer-types +C ObjC Var(warn_compare_distinct_pointer_types) Warning Init(1) +Warn if pointers of distinct types are compared without a cast. + flang-info-include-translate C++ Var(note_include_translate_yes) Note #include directives translated to import declarations. diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index ee891ee33c2..dc7e8514c47 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -12422,7 +12422,7 @@ build_binary_op (location_t location, enum tree_code code, else /* Avoid warning about the volatile ObjC EH puts on decls. */ if (!objc_ok) - pedwarn (location, 0, + pedwarn (location, OPT_Wcompare_distinct_pointer_types, "comparison of distinct pointer types lacks a cast"); if (result_type == NULL_TREE) @@ -12562,8 +12562,8 @@ build_binary_op (location_t location, enum tree_code code, int qual = ENCODE_QUAL_ADDR_SPACE (as_common); result_type = build_pointer_type (build_qualified_type (void_type_node, qual)); - pedwarn (location, 0, - "comparison of distinct pointer types lacks a cast"); + pedwarn (location, OPT_Wcompare_distinct_pointer_types, + "comparison of distinct pointer types lacks a cast"); } } else if (code0 == POINTER_TYPE && null_pointer_constant_p (orig_op1)) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 6131bfa7acf..5ef9dbe4bbe 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -341,6 +341,7 @@ Objective-C and Objective-C++ Dialects}. -Wcast-align -Wcast-align=strict -Wcast-function-type -Wcast-qual @gol -Wchar-subscripts @gol -Wclobbered -Wcomment @gol +-Wcompare-distinct-pointer-types @gol -Wconversion -Wno-coverage-mismatch -Wno-cpp @gol -Wdangling-else -Wdangling-pointer -Wdangling-pointer=@var{n} @gol -Wdate-time @gol @@ -8648,6 +8649,11 @@ programs. Warn for variables that might be changed by @code{longjmp} or @code{vfork}. This warning is also enabled by @option{-Wextra}. +@item -Wcompare-distinct-pointer-types +@opindex Wcompare-distinct-pointer-types +Warn if pointers of distinct types are compared without a cast. This +warning is enabled by default. + @item -Wconversion @opindex Wconversion @opindex Wno-conversion diff --git a/gcc/testsuite/gcc.c-torture/compile/pr106537-1.c b/gcc/testsuite/gcc.c-torture/compile/pr106537-1.c new file mode 100644 index 00000000000..56c8deeb4fe --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr106537-1.c @@ -0,0 +1,23 @@ +/* { dg-do compile } + { dg-options "" } + This testcase checks that warn_compare_distinct_pointer_types is enabled by + default. */ + +typedef int __u32; + +struct xdp_md +{ + char *data; + char *data_meta; +}; + +int xdp_context (struct xdp_md *xdp) +{ + void *data = (void *)(long)xdp->data; + __u32 *metadata = (void *)(long)xdp->data_meta; + __u32 ret; + + if (metadata + 1 > data) /* { dg-warning "comparison of distinct pointer types" } */ + return 0; + return 1; +} diff --git a/gcc/testsuite/gcc.c-torture/compile/pr106537-2.c b/gcc/testsuite/gcc.c-torture/compile/pr106537-2.c new file mode 100644 index 00000000000..7a9b2aec0b8 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr106537-2.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ +/* { dg-options "-Wcompare-distinct-pointer-types" } */ + +typedef int __u32; + +struct xdp_md +{ + char *data; + char *data_meta; +}; + +int xdp_context (struct xdp_md *xdp) +{ + void *data = (void *)(long)xdp->data; + __u32 *metadata = (void *)(long)xdp->data_meta; + __u32 ret; + + if (metadata + 1 > data) /* { dg-warning "comparison of distinct pointer types" } */ + return 0; + return 1; +} diff --git a/gcc/testsuite/gcc.c-torture/compile/pr106537-3.c b/gcc/testsuite/gcc.c-torture/compile/pr106537-3.c new file mode 100644 index 00000000000..dc5dd46e3cb --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr106537-3.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ +/* { dg-options "-Wno-compare-distinct-pointer-types" } */ + +typedef int __u32; + +struct xdp_md +{ + char *data; + char *data_meta; +}; + +int xdp_context (struct xdp_md *xdp) +{ + void *data = (void *)(long)xdp->data; + __u32 *metadata = (void *)(long)xdp->data_meta; + __u32 ret; + + if (metadata + 1 > data) /* There shouldn't be a warning here. */ + return 0; + return 1; +}