From patchwork Thu Oct 16 17:20:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 400339 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 AAAC814007D for ; Fri, 17 Oct 2014 04:21:00 +1100 (AEDT) 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:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=q0DhpRyuuGNWJB9vq p3vBhq2xygeB0la9RXFXDnADQJRrjSkJCse8LD0GPxi3taGwhfOnf5r8SG2kv7CE VQXxxBHFsLiwZxHSaCufFaoc8HjY0MbvdXCcL/qk5W3DhbmunMbyHxJX5yBZDMGw icMD7s1NIP2xtsyuymrYqpSgzA= 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:references:mime-version :content-type:in-reply-to; s=default; bh=1Ri0f4iNKGG62/TiS6KHSSf JZus=; b=sMSywlI/Up51AUA48ggsCWYLFMdfncmlevj64VCFNmvjEd8940UufsL awBcJEM8R1Ry7e/LBDCcUIszLPR7lmXBic8+jzZI9ynbdP6BmSbmbmPFvnJAkZmo rVY6oRIaATgfd11KEMjevNd9CIxzaxTAEH2ywWD6vGMS5/uCDRvY= Received: (qmail 29669 invoked by alias); 16 Oct 2014 17:20:44 -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 29609 invoked by uid 89); 16 Oct 2014 17:20:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 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; Thu, 16 Oct 2014 17:20:42 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s9GHKcvr016519 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 16 Oct 2014 13:20:39 -0400 Received: from redhat.com (ovpn-116-16.ams2.redhat.com [10.36.116.16]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s9GHKVdd005544 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Thu, 16 Oct 2014 13:20:36 -0400 Date: Thu, 16 Oct 2014 19:20:30 +0200 From: Marek Polacek To: "Joseph S. Myers" Cc: GCC Patches Subject: Re: [C PATCH] Clamp down "incomplete type" error (PR c/63543) Message-ID: <20141016172030.GM10501@redhat.com> References: <20141015172244.GE10501@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) On Wed, Oct 15, 2014 at 09:46:20PM +0000, Joseph S. Myers wrote: > On Wed, 15 Oct 2014, Marek Polacek wrote: > > > We've got a complaint that the "dereferencing pointer to incomplete > > type" error is printed for all occurrences of the incomplete type, > > which is too verbose. Also it'd be nicer to print the type as well. > > This patch fixes this; if we find an incomplete type, mark it with error > > node, then we don't print the error message more than once. > > I don't like this approach of modifying the type; type nodes are shared > objects and this could affect all sorts of other logic subsequently > working with the type. I think there should be some sort of annotation of > the type (either in the type itself, or on the side) that *only* means an > error has been given for the type being incomplete, rather than inserting > error_mark_node into the type. I'm sorry. Here is another version, which uses a lang flag to distinguish whether a "dereferencing incomplete..." error message has been given. One could argue that I should've named the lang flag e.g. C_TYPE_INCOMPLETE_ERROR_REPORTED, but I hope it can be reused in the future for some similar purpose. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2014-10-16 Marek Polacek PR c/63543 * c-tree.h (C_TYPE_ERROR_REPORTED): Define. * c-typeck.c (build_indirect_ref): Don't print the "dereferencing..." error multiple times. Print the type. * gcc.dg/pr63543.c: New test. * gcc.dg/array-8.c: Remove dg-error. * gcc.dg/pr48552-1.c: Remove and adjust dg-error. * gcc.dg/pr48552-2.c: Likewise. Marek diff --git gcc/c/c-tree.h gcc/c/c-tree.h index e6aca01..5ff9d9c 100644 --- gcc/c/c-tree.h +++ gcc/c/c-tree.h @@ -56,6 +56,9 @@ along with GCC; see the file COPYING3. If not see This is used for -Wc++-compat. */ #define C_TYPE_DEFINED_IN_STRUCT(TYPE) TYPE_LANG_FLAG_2 (TYPE) +/* Record whether an "incomplete type" error was given for the type. */ +#define C_TYPE_ERROR_REPORTED(TYPE) TYPE_LANG_FLAG_3 (TYPE) + /* Record whether a typedef for type `int' was actually `signed int'. */ #define C_TYPEDEF_EXPLICITLY_SIGNED(EXP) DECL_LANG_FLAG_1 (EXP) diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c index 5c0697a..0f363f5 100644 --- gcc/c/c-typeck.c +++ gcc/c/c-typeck.c @@ -2378,7 +2378,12 @@ build_indirect_ref (location_t loc, tree ptr, ref_operator errstring) if (!COMPLETE_OR_VOID_TYPE_P (t) && TREE_CODE (t) != ARRAY_TYPE) { - error_at (loc, "dereferencing pointer to incomplete type"); + if (!C_TYPE_ERROR_REPORTED (TREE_TYPE (ptr))) + { + error_at (loc, "dereferencing pointer to incomplete type " + "%qT", t); + C_TYPE_ERROR_REPORTED (TREE_TYPE (ptr)) = 1; + } return error_mark_node; } if (VOID_TYPE_P (t) && c_inhibit_evaluation_warnings == 0) diff --git gcc/testsuite/gcc.dg/array-8.c gcc/testsuite/gcc.dg/array-8.c index d469a80..2872985 100644 --- gcc/testsuite/gcc.dg/array-8.c +++ gcc/testsuite/gcc.dg/array-8.c @@ -45,5 +45,4 @@ g (void) sip[0]; /* { dg-error "invalid use of undefined type 'struct si'" } */ /* { dg-error "dereferencing pointer to incomplete type" "incomplete" { target *-*-* } 45 } */ 0[sip]; /* { dg-error "invalid use of undefined type 'struct si'" } */ - /* { dg-error "dereferencing pointer to incomplete type" "incomplete" { target *-*-* } 47 } */ } diff --git gcc/testsuite/gcc.dg/pr48552-1.c gcc/testsuite/gcc.dg/pr48552-1.c index 877c4c2..4b833fb 100644 --- gcc/testsuite/gcc.dg/pr48552-1.c +++ gcc/testsuite/gcc.dg/pr48552-1.c @@ -49,5 +49,5 @@ f7 (struct S *x) void f8 (struct S *x) { - __asm volatile ("" : "=r" (*x)); /* { dg-error "dereferencing pointer to incomplete type" "incomplete" } */ -} /* { dg-error "invalid lvalue in asm output 0" "invalid lvalue" { target *-*-* } 52 } */ + __asm volatile ("" : "=r" (*x)); /* { dg-error "invalid lvalue in asm output 0" } */ +} diff --git gcc/testsuite/gcc.dg/pr48552-2.c gcc/testsuite/gcc.dg/pr48552-2.c index a796983..954c411 100644 --- gcc/testsuite/gcc.dg/pr48552-2.c +++ gcc/testsuite/gcc.dg/pr48552-2.c @@ -49,5 +49,5 @@ f7 (struct S *x) void f8 (struct S *x) { - __asm ("" : "=r" (*x)); /* { dg-error "dereferencing pointer to incomplete type" "incomplete" } */ -} /* { dg-error "invalid lvalue in asm output 0" "invalid lvalue" { target *-*-* } 52 } */ + __asm ("" : "=r" (*x)); /* { dg-error "invalid lvalue in asm output 0" } */ +} diff --git gcc/testsuite/gcc.dg/pr63543.c gcc/testsuite/gcc.dg/pr63543.c index e69de29..215b62e 100644 --- gcc/testsuite/gcc.dg/pr63543.c +++ gcc/testsuite/gcc.dg/pr63543.c @@ -0,0 +1,21 @@ +/* PR c/63543 */ +/* { dg-do compile } */ + +struct S; +union U; + +int +f1 (struct S *s) +{ + return s->a /* { dg-error "dereferencing pointer to incomplete type .struct S." } */ + + s->b + + s->c; +} + +int +f2 (union U *u) +{ + return u->a /* { dg-error "dereferencing pointer to incomplete type .union U." } */ + + u->a + + u->a; +}