From patchwork Wed Oct 28 17:01:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Wilson X-Patchwork-Id: 537474 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 3E396140D24 for ; Thu, 29 Oct 2015 04:01:52 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=DJ+Vk39S; 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 :mime-version:date:message-id:subject:from:to:content-type; q= dns; s=default; b=MotBUpAGoxfg29m1CLMEGIY8uc3fCsiPz4As3zOUp1t2rM 3C/t4GPuCeTWlci/WX/FOfrgOAtVaxCrwZRkljYu/HOiltCzkkUG5xtpBdUgHQiF IN6QpRwNCvN4SFPI5LEGI5E1sYyJ3qLd8dU+Yp24mjL0pjRSEqYHAuMLABoAY= 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 :mime-version:date:message-id:subject:from:to:content-type; s= default; bh=YZT++N+VzsBOSlKOvKTXNcanXHM=; b=DJ+Vk39SfTv8kB4t6N3r QKtI8XMhrCsXay/FQ+jHjZvlMzxHU8bLOxnAkUUd3/gQ5p7hGl9OZM/Fs9a7yYnA eyiAWCN0qgtECTXcWt4Xgkq31xXp5cky2IHJ32f5oxbUubvAY1Qq7V27o+mV2pCp UZd6rEZKg7FvTXOuaPqIFdA= Received: (qmail 46923 invoked by alias); 28 Oct 2015 17:01:45 -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 46853 invoked by uid 89); 28 Oct 2015 17:01:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-oi0-f51.google.com Received: from mail-oi0-f51.google.com (HELO mail-oi0-f51.google.com) (209.85.218.51) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 28 Oct 2015 17:01:41 +0000 Received: by oies66 with SMTP id s66so8298898oie.1 for ; Wed, 28 Oct 2015 10:01:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-type; bh=yqFWPc5qiAsYdPX/ZW+ruhJtY3CWez8u0osgBoPk1P0=; b=gEP3YEmRgjO3dkQSFGrq12fliTCXA7s5ohiQakIJXQg26G4XB8OV2cQ/zMEIrQb407 fG5/wQiZHeBoLFfz+fBfmRBXD2aKKaW+VnT/jdSrY84Mtb+bEZmc8htUJUDDr4SwqVEt CNp6Hnq8GmDrZ0wKHq6CN3bn7MQmbvU2QWtVvfAPjZTygThC3b30E3SZUnGND4z5v2hr mnybE25qU1MMjjONzWeT2R/0JRmSm/f1gpSAjkUAlVZwZGJfiBtqOaRdM/Uy1YnWIvmK ZWCF8wRXnqFl8uzfMQfZkDZMSIegCebwa2fh0UwC0sveW+a0pGP1wgUfSKA40b6Mywea 4whA== X-Gm-Message-State: ALoCoQnnpBHBymbUzw1vgUKCTs+9JxrkRxwi/CLkNfHr1T8tgyBrngeCd4r2o8InxYvTFHgiOYNv MIME-Version: 1.0 X-Received: by 10.202.190.10 with SMTP id o10mr10740643oif.23.1446051698298; Wed, 28 Oct 2015 10:01:38 -0700 (PDT) Received: by 10.76.172.136 with HTTP; Wed, 28 Oct 2015 10:01:38 -0700 (PDT) Date: Wed, 28 Oct 2015 10:01:38 -0700 Message-ID: Subject: [PATCH] [C] fix for ICE with -g From: Jim Wilson To: "gcc-patches@gcc.gnu.org" Compiling a simple testcase that defines an incomplete struct/union and then a variant of that type and then completes the struct/union gives an ICE in verify_type. palantir:2257$ cat tmp.c struct S a; const struct S b; struct S { }; palantir:2258$ ./xgcc -B./ -O -g tmp.c tmp.c:5:1: error: type variant has different TYPE_VFIELD }; ^ ... tmp.c:5:1: internal compiler error: verify_type failed ... The problem is in the C front end. It uses TYPE_VFIELD to keep track of incomplete types via C_TYPE_INCOMPLETE_VARS. This is only valid on the type main variant, and is cleared when the type main variant is completed. When we create a variant type, this field is being copied to the variant along with all other type fields. Since we never look at this field on variant types, it never gets cleared, and we end up with dangling pointers that trigger the ICE in verify_type. So this should be fixed by clearing the field when creating a variant type. Attached is a patch that does this clearing, and adds a testcase. This was tested with an x86_64 linux bootstrap and make check, and also a gdb make check. With this patch, some of the hacks in type_verify to work around the C front-end problem may no longer be necessary. I haven't looked at that. Jim Index: gcc/c/ChangeLog =================================================================== --- gcc/c/ChangeLog (revision 229395) +++ gcc/c/ChangeLog (working copy) @@ -1,3 +1,9 @@ +2015-10-26 Jim Wilson + + PR debug/66068 + * c-typeck.c (c_build_qualified_type): Clear C_TYPE_INCOMPLETE_VARS + after calling build_qualified_type. + 2015-10-22 Richard Biener * c-typeck.c (c_finish_omp_clauses): Properly convert operands Index: gcc/c/c-typeck.c =================================================================== --- gcc/c/c-typeck.c (revision 229395) +++ gcc/c/c-typeck.c (working copy) @@ -13090,6 +13090,8 @@ c_finish_transaction (location_t loc, tree block, tree c_build_qualified_type (tree type, int type_quals) { + tree var_type; + if (type == error_mark_node) return type; @@ -13146,7 +13148,13 @@ c_build_qualified_type (tree type, int type_quals) type_quals &= ~TYPE_QUAL_RESTRICT; } - return build_qualified_type (type, type_quals); + var_type = build_qualified_type (type, type_quals); + /* A variant type does not inherit the list of incomplete vars from the + type main variant. */ + if (TREE_CODE (var_type) == RECORD_TYPE + || TREE_CODE (var_type) == UNION_TYPE) + C_TYPE_INCOMPLETE_VARS (var_type) = 0; + return var_type; } /* Build a VA_ARG_EXPR for the C parser. */ Index: gcc/testsuite/ChangeLog =================================================================== --- gcc/testsuite/ChangeLog (revision 229395) +++ gcc/testsuite/ChangeLog (working copy) @@ -1,3 +1,8 @@ +2015-10-26 Jim Wilson + + PR debug/66068 + * gcc.dg/debug/pr66068.c: New test. + 2015-10-26 Louis Krupp PR fortran/66056 Index: gcc/testsuite/gcc.dg/debug/pr66068.c =================================================================== --- gcc/testsuite/gcc.dg/debug/pr66068.c (revision 0) +++ gcc/testsuite/gcc.dg/debug/pr66068.c (working copy) @@ -0,0 +1,13 @@ +/* { dg-do compile } */ + +struct S a; +const struct S b; +struct S +{ +}; + +union U c; +const union U d; +union U +{ +};