From patchwork Fri Feb 26 14:43:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 589063 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 01E5A1402D6 for ; Sat, 27 Feb 2016 01:43:57 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=HFBPVth+; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=vSg3ZHE3XKk0VLVVtNLaogzZqA99a /0Rk/zFPteCTleEGQcmEpAirErQykYH2bdjv/8wYT8Qesn+EZp0vRmCQw1wlbrU1 RKwLrM2mzvpJOsZj9QLLEFREa9ys6RX8/ud6eMEK4wBHhcWwFkXe14xUQYtACP0p WhN0BfJtbcRq8c= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=rm2T/LZawuwOzh6nzBoY4hO2WiU=; b=HFB PVth+tbA74fPI5R9K3HsPpvNMbi8pZJwC/8FdAomifCopbM7qxfcAg6AT+Zs07eK VNdjnNr9OoFZiCiYYVYm94EyLa2zOgDGLmcUu2RtzB63b7be+MCwhQC7wK1tW7k+ k4suzsBoBnTVtZXk+yPkVxnXA5yDSDxlFpBTl99c= Received: (qmail 81745 invoked by alias); 26 Feb 2016 14:43:47 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 81690 invoked by uid 89); 26 Feb 2016 14:43:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=isn, Parse, parse, 69 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 26 Feb 2016 14:43:43 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 0FDB78E67F; Fri, 26 Feb 2016 14:43:42 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-113-25.phx2.redhat.com [10.3.113.25]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1QEhekA027014 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 26 Feb 2016 09:43:41 -0500 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id u1QEhcx8030914; Fri, 26 Feb 2016 15:43:39 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id u1QEhaGX030913; Fri, 26 Feb 2016 15:43:36 +0100 Date: Fri, 26 Feb 2016 15:43:36 +0100 From: Jakub Jelinek To: "Joseph S. Myers" , Marek Polacek Cc: gcc-patches@gcc.gnu.org Subject: [C PATCH] Fix C error-recovery (PR c/69796, PR c/69974) Message-ID: <20160226144336.GC3017@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes Hi! Already PR69483 and these two further PRs show that it is really a bad idea to set TREE_TYPE of decls with incomplete types to error_mark_node, there are lots of places in the middle-end that don't expect error_mark_nodes appearing so late. I've bootstrapped/regtested on x86_64-linux and i686-linux following patch which just doesn't do anything with the type, we don't emit the error multiple times, because if the FE emits errors, cgraphunit doesn't attempt to assemble variables or compile functions (just gimplifies them) if seen_error (). Attached is then untested alternative, set the type to something that should hopefully not cause ICEs nor further errors/warnings during the error-recovery. Ok for trunk, or shall I test the other patch instead? 2016-02-26 Jakub Jelinek PR c/69796 PR c/69974 * c-parser.c (c_parser_translation_unit): Don't change TREE_TYPE of incomplete decls to error_mark_node. * gcc.dg/pr69796.c: New test. * gcc.dg/pr69974.c: New test. Jakub 2016-02-26 Jakub Jelinek PR c/69796 PR c/69974 * c-parser.c (c_parser_translation_unit): For incomplete decls set type to char_type_node instead of error_mark_node. * gcc.dg/pr69796.c: New test. * gcc.dg/pr69974.c: New test. --- gcc/c/c-parser.c.jj 2016-02-24 09:33:37.000000000 +0100 +++ gcc/c/c-parser.c 2016-02-26 13:04:16.416657335 +0100 @@ -1438,7 +1438,10 @@ c_parser_translation_unit (c_parser *par if (DECL_SIZE (decl) == NULL_TREE && TREE_TYPE (decl) != error_mark_node) { error ("storage size of %q+D isn%'t known", decl); - TREE_TYPE (decl) = error_mark_node; + /* Don't set the type to error_mark_node, the middle-end is unprepared + to see error_mark_node type appearing so late in the IL, + so using some other type is better for error recovery. */ + TREE_TYPE (decl) = char_type_node; } } --- gcc/testsuite/gcc.dg/pr69796.c.jj 2016-02-26 13:16:32.352323768 +0100 +++ gcc/testsuite/gcc.dg/pr69796.c 2016-02-26 13:16:16.000000000 +0100 @@ -0,0 +1,10 @@ +/* PR c/69796 */ +/* { dg-do compile } */ + +struct S s; /* { dg-error "storage size of 's' isn't known" } */ + +void +foo () +{ + s a; /* { dg-error "expression statement has incomplete type|expected" } */ +} --- gcc/testsuite/gcc.dg/pr69974.c.jj 2016-02-26 13:13:40.239740046 +0100 +++ gcc/testsuite/gcc.dg/pr69974.c 2016-02-26 13:13:29.000000000 +0100 @@ -0,0 +1,13 @@ +/* PR c/69974 */ +/* { dg-do compile } */ + +struct S; +char foo (struct S *); +struct S a; /* { dg-error "storage size of 'a' isn't known" } */ +int b; + +void +bar () +{ + b &= foo (&a); +} --- gcc/c/c-parser.c.jj 2016-02-24 09:33:37.000000000 +0100 +++ gcc/c/c-parser.c 2016-02-26 13:31:00.947133760 +0100 @@ -1436,10 +1436,7 @@ c_parser_translation_unit (c_parser *par tree decl; FOR_EACH_VEC_ELT (incomplete_record_decls, i, decl) if (DECL_SIZE (decl) == NULL_TREE && TREE_TYPE (decl) != error_mark_node) - { - error ("storage size of %q+D isn%'t known", decl); - TREE_TYPE (decl) = error_mark_node; - } + error ("storage size of %q+D isn%'t known", decl); } /* Parse an external declaration (C90 6.7, C99 6.9). --- gcc/testsuite/gcc.dg/pr69796.c.jj 2016-02-26 13:16:32.352323768 +0100 +++ gcc/testsuite/gcc.dg/pr69796.c 2016-02-26 13:16:16.000000000 +0100 @@ -0,0 +1,10 @@ +/* PR c/69796 */ +/* { dg-do compile } */ + +struct S s; /* { dg-error "storage size of 's' isn't known" } */ + +void +foo () +{ + s a; /* { dg-error "expression statement has incomplete type|expected" } */ +} --- gcc/testsuite/gcc.dg/pr69974.c.jj 2016-02-26 13:13:40.239740046 +0100 +++ gcc/testsuite/gcc.dg/pr69974.c 2016-02-26 13:13:29.000000000 +0100 @@ -0,0 +1,13 @@ +/* PR c/69974 */ +/* { dg-do compile } */ + +struct S; +char foo (struct S *); +struct S a; /* { dg-error "storage size of 'a' isn't known" } */ +int b; + +void +bar () +{ + b &= foo (&a); +}