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 35BA23886C47 for ; Tue, 29 Mar 2022 20:53:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 35BA23886C47 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-251-gGC4YNEoPf-QocEj8qUWPg-1; Tue, 29 Mar 2022 16:53:25 -0400 X-MC-Unique: gGC4YNEoPf-QocEj8qUWPg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5879B3C13A04 for ; Tue, 29 Mar 2022 20:53:25 +0000 (UTC) Received: from pdp-11.redhat.com (unknown [10.22.10.220]) by smtp.corp.redhat.com (Postfix) with ESMTP id 39AA61121314; Tue, 29 Mar 2022 20:53:25 +0000 (UTC) From: Marek Polacek To: GCC Patches , Jason Merrill Subject: [PATCH] c-family: ICE with -Wconversion and A ?: B [PR101030] Date: Tue, 29 Mar 2022 16:53:21 -0400 Message-Id: <20220329205321.90251-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.0 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_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Tue, 29 Mar 2022 20:53:30 -0000 This patch fixes a crash in conversion_warning on a null expression. It is null because the testcase uses the GNU A ?: B extension. We could also use op0 instead of op1 in this case, but it doesn't seem to be necessary. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? PR c++/101030 gcc/c-family/ChangeLog: * c-warn.cc (conversion_warning) : Don't call conversion_warning when OP1 is null. gcc/testsuite/ChangeLog: * g++.dg/ext/cond5.C: New test. --- gcc/c-family/c-warn.cc | 2 +- gcc/testsuite/g++.dg/ext/cond5.C | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/ext/cond5.C diff --git a/gcc/c-family/c-warn.cc b/gcc/c-family/c-warn.cc index 9025fc1c20e..f24ac5d0539 100644 --- a/gcc/c-family/c-warn.cc +++ b/gcc/c-family/c-warn.cc @@ -1300,7 +1300,7 @@ conversion_warning (location_t loc, tree type, tree expr, tree result) tree op1 = TREE_OPERAND (expr, 1); tree op2 = TREE_OPERAND (expr, 2); - return (conversion_warning (loc, type, op1, result) + return ((op1 && conversion_warning (loc, type, op1, result)) || conversion_warning (loc, type, op2, result)); } diff --git a/gcc/testsuite/g++.dg/ext/cond5.C b/gcc/testsuite/g++.dg/ext/cond5.C new file mode 100644 index 00000000000..a92f28998f9 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/cond5.C @@ -0,0 +1,13 @@ +// PR c++/101030 +// { dg-do compile { target { c++11 } } } +// { dg-options "-Wconversion" } + +template +struct jj { + int ii[N ?: 1]; + char c = N ?: 1; // { dg-warning "conversion from .int. to .char. changes value from .300. to " } +}; + +int main() { + jj<300> kk; +} base-commit: 69db6e7f4e1d07bf8f33e93a29139cc16c1e0a2f -- 2.35.1