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 [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 Content-Type: text/plain 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 List-Id: 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(-) 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\\\]" } */ +} base-commit: 8f4bbdc28df6e87a7ad5ec5ca191a7a836a4f016