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: 55708 Delivered-To: patch@linaro.org Received: by 10.112.61.134 with SMTP id p6csp67732lbr; Wed, 28 Oct 2015 10:01:57 -0700 (PDT) X-Received: by 10.107.184.70 with SMTP id i67mr26289269iof.42.1446051717265; Wed, 28 Oct 2015 10:01:57 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id p81si34697147ioi.159.2015.10.28.10.01.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Oct 2015 10:01:57 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-411850-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-return-411850-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-411850-patch=linaro.org@gcc.gnu.org; dkim=pass header.i=@gcc.gnu.org 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=S2+RuQrp9ixDMt3Xrv4s2UdXhp0N54SjwUyH9uHGVpeRjV zC0kIsXO4x+Ws8aEJWy6Ma8fSadwPo8YOjbID2QLzZ6Fwbm2zfIeFPr2iQHgrZ67 7LhqP96oQrdZQPcduHMn8hAz/nyTQEE1E3QUhYm47o8lciEDtWkiWbh+DQz/8= 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=G215Yf83NuqEvRW2YtDd IUp3aa6Rl+qJJYFauc2Dipv0pdnS7U5XJPbwFO1/4GSF65LNU897NgGW5aH6XDg+ YBv8KhZPm21qgMeGjEeY9S0r6hWQqpLtxKuggDESROD3bVQFe6+KB7lAfa/+YElG 4qEZ1DrELxGZQqlMFKXF/FQ= 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 +{ +};