From patchwork Thu Jun 24 10:11:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1496477 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=O61Y8APV; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G9bXT5qMBz9sX1 for ; Thu, 24 Jun 2021 20:12:09 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1838A3AA980D for ; Thu, 24 Jun 2021 10:12:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1838A3AA980D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1624529527; bh=KIZ0cNxjAWpQAfAyjpkaZDPNTDsL/hozG0f9eZfRWIs=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=O61Y8APVGvT+3Zg985uAgyseSaql2MGULxZUkLVc47eNcbZDFnaHKCuMOnSgVXVyo Hl+h+oKLPH3PxiuBD8KODbnmdIusxb5Vtw0TfA7+gokMCB3rNzacuf0v/ugQR4wn4Z zGZtUoi4LeUDIKaaNBzYtllKNPPxUVjv1ajyt04U= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id E0EA23AA9830 for ; Thu, 24 Jun 2021 10:11:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E0EA23AA9830 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-237-7dhSsvTCNSOqzSvZGJSuyw-1; Thu, 24 Jun 2021 06:11:32 -0400 X-MC-Unique: 7dhSsvTCNSOqzSvZGJSuyw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D3E1B8C5EC4; Thu, 24 Jun 2021 10:11:30 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-112-143.ams2.redhat.com [10.36.112.143]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1F47610023B5; Thu, 24 Jun 2021 10:11:26 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 15OABOVQ1295425 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 24 Jun 2021 12:11:24 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 15OABNUK1295424; Thu, 24 Jun 2021 12:11:23 +0200 Date: Thu, 24 Jun 2021 12:11:23 +0200 To: "Joseph S. Myers" , Marek Polacek Subject: [PATCH] c: Fix C cast error-recovery [PR101171] Message-ID: <20210624101123.GO7746@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-5.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi! The following testcase ICEs during error-recovery, as build_c_cast calls note_integer_operands on error_mark_node and that wraps it into C_MAYBE_CONST_EXPR which is unexpected and causes ICE later on. Seems most other callers of note_integer_operands check early if something is error_mark_node and return before calling note_integer_operands on it. The following patch fixes it by not calling on error_mark_node, another possibility would be to handle error_mark_node in note_integer_operands and just return it. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2021-06-24 Jakub Jelinek PR c/101171 * c-typeck.c (build_c_cast): Don't call note_integer_operands on error_mark_node. * gcc.dg/pr101171.c: New test. Jakub --- gcc/c/c-typeck.c.jj 2021-06-23 13:33:00.375434219 +0200 +++ gcc/c/c-typeck.c 2021-06-23 17:51:17.501401208 +0200 @@ -6131,6 +6131,7 @@ build_c_cast (location_t loc, tree type, return value reflects this. */ if (int_operands && INTEGRAL_TYPE_P (type) + && value != error_mark_node && !EXPR_INT_CONST_OPERANDS (value)) value = note_integer_operands (value); --- gcc/testsuite/gcc.dg/pr101171.c.jj 2021-06-23 17:56:53.409896019 +0200 +++ gcc/testsuite/gcc.dg/pr101171.c 2021-06-23 17:56:28.668227851 +0200 @@ -0,0 +1,13 @@ +/* PR c/101171 */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +extern void foo (void); +int x = 0x1234; + +void +bar (void) +{ + if (x != (sizeof ((enum T) 0x1234))) /* { dg-error "conversion to incomplete type" } */ + foo (); +}