From patchwork Fri Oct 20 06:51:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 155848 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp869374vqb; Thu, 19 Oct 2023 23:52:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEJcs4+m7UcuDFWUIxrZiDC8tVnjsBLhj+53rJle5QBcm8IbkopBOMpyYzS0GO1tGf9ihgi X-Received: by 2002:a05:622a:1ba5:b0:41c:c770:62be with SMTP id bp37-20020a05622a1ba500b0041cc77062bemr5322286qtb.33.1697784734514; Thu, 19 Oct 2023 23:52:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697784734; cv=pass; d=google.com; s=arc-20160816; b=AAeBgsZsamG6tfRmQFpCMbOr0VfKWBj32Z28E+n8rKd3yfEA/7pVuIyHVkxmEz2/ie xXtafEbwsUsKF/xdrTWvQca90wV29Hk6Irz+vUB5/Arn+5V94eUyHS4dk74U06+tP9vD QwXAhoccnGIbcm/RXbL/MzOFukAv5XvwKbredInk75yqwfQ1bCYWs0IZrnwG6pb0kxWV mu6SGHoMqryvibgTlOheZSfeYAyMbz526jTjIdBml8/8fTGtdEew7ODvSyCYDlOpmeft 4eJfDnZijkVxqGZojnFPNFPSzN9pSLq5opWnYzARQNfuFktQ8WUwMifjhZYK2bECt5R+ luHg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:user-agent :message-id:date:subject:to:from:dkim-signature:arc-filter :dmarc-filter:delivered-to; bh=W5pPkJkC+EHnGAnNqx+wRKseSXuEeT0qcaWMd4kB7RI=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=0VEhFcV0M8uAfKdQdYRcYduNFhFV2OK2jMX97U0Q76Ww0+EpKWhmGY9Ef4IkyNAxp0 uVHSp/5ajCeZQVnpFbOWQrQslt2JNyG/McIeB6EMtRAcflG1tdQZ7iRuvoHofvtm04Yq leWl3eaTwqVmw7ht2txj+5P5Iv7T/xZmnAY9B8W0u7NdZdXY6ga503ktVfAJk3moyCV0 VN5Lg4lTAwQspfqEh73EtwW4b5W5WXVQ2YLCeyOQC95UaIHhIFGK1vWuhw77/wNce7vU I5mO/zJycwbhBhmw+BCtIdLZ4gynKNKsXXweItZI+wpMMESnHidGFMBc9eXcoTCvoSLE YQoA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Yb945r6r; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id e9-20020ac85989000000b004197ddb7c07si818125qte.288.2023.10.19.23.52.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 23:52:14 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Yb945r6r; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 43DCF3856943 for ; Fri, 20 Oct 2023 06:52:14 +0000 (GMT) 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 A03A83858439 for ; Fri, 20 Oct 2023 06:51:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A03A83858439 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A03A83858439 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697784710; cv=none; b=dRN2ig8w079VAglDwi2ylFogpV0gyVmUKoWfD1HWMNC8mZFBlyVcCLnxR2jO3tSmvkGgM5vQFjPV1vE443Hq+wPy7ZEipgRghkvNA7UdbjgTECSxg7kCdM8y4ZXJxiFYLHg0aJrqHKty7y+CFoVVW/eCw2PW2F5hXasfeM/eSkg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697784710; c=relaxed/simple; bh=bKWqff2ZsipOgQXvNYQIFgEVvgq2kTFlyFUVfRx38+o=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=WVIwunIjSBXcTI8FJRHtd9WaHkCztu/njFU+T+2hd+QKbOugt8DkdaKXKOUiA/y9ByByYtNa/kHvA9oB409XVrJx+8ugaC5v/YoXjs6TaTdKZ1YkUuN1TNp3i6IDuonhs/WBnbp9g+cMm+FwZUOXdnow+zglvExHFalOMlp+5HM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697784709; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=W5pPkJkC+EHnGAnNqx+wRKseSXuEeT0qcaWMd4kB7RI=; b=Yb945r6r4pSR8MS62jNkVZrobT/RQL9R41zQiUJLKj+nomRzMX8JO48aYZDaFqaexOL19+ g8iyL430MblPLMCI0esL0+HnvFAjv6xt3jHpLilZvt+ZYe2QhFA/GZQvK5wHygl20/ncjc qW+gHxHdFAORrfBGli8RyWZT87QGW/c= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-21-ee3zsyJNPqyMINwY903MFQ-1; Fri, 20 Oct 2023 02:51:42 -0400 X-MC-Unique: ee3zsyJNPqyMINwY903MFQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6C13710201E0 for ; Fri, 20 Oct 2023 06:51:42 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.23]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 12419C15BB8 for ; Fri, 20 Oct 2023 06:51:41 +0000 (UTC) From: Florian Weimer To: gcc-patches@gcc.gnu.org Subject: [PATCH] c: -Wint-conversion should cover pointer/integer mismatches in ?: Date: Fri, 20 Oct 2023 08:51:40 +0200 Message-ID: <87y1fxzszn.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.3 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780256325696463219 X-GMAIL-MSGID: 1780256325696463219 gcc/c/ PR c/109827 PR other/44209 * c-typeck.cc (build_conditional_expr): Use OPT_Wint_conversion for pointer/integer mismatch warnings. gcc/testsuite/ * gcc.dg/Wint-conversion-3.c: New. --- gcc/c/c-typeck.cc | 4 ++-- gcc/testsuite/gcc.dg/Wint-conversion-3.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) base-commit: 8f4bbdc28df6e87a7ad5ec5ca191a7a836a4f016 diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index 6e044b4afbc..7e18f95891a 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -5580,7 +5580,7 @@ build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp, && (code2 == INTEGER_TYPE || code2 == BITINT_TYPE)) { if (!null_pointer_constant_p (orig_op2)) - pedwarn (colon_loc, 0, + pedwarn (colon_loc, OPT_Wint_conversion, "pointer/integer type mismatch in conditional expression"); else { @@ -5592,7 +5592,7 @@ build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp, && (code1 == INTEGER_TYPE || code1 == BITINT_TYPE)) { if (!null_pointer_constant_p (orig_op1)) - pedwarn (colon_loc, 0, + pedwarn (colon_loc, OPT_Wint_conversion, "pointer/integer type mismatch in conditional expression"); else { diff --git a/gcc/testsuite/gcc.dg/Wint-conversion-3.c b/gcc/testsuite/gcc.dg/Wint-conversion-3.c new file mode 100644 index 00000000000..4e514769c01 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wint-conversion-3.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "" } */ + +const char * +f1 (int flag) +{ + return flag ? "" : 1; /* { dg-warning "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" } */ +} + +const char * +f2 (int flag) +{ + return flag ? 1 : ""; /* { dg-warning "pointer/integer type mismatch in conditional expression \\\[-Wint-conversion\\\]" } */ +}