From patchwork Fri Jan 31 12:10:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 315567 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 141D42C00CE for ; Fri, 31 Jan 2014 23:10:42 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=cA1a8JPCU+I5NfwwvB3H1kEd0IHk5jl0taKP4xrRWgo Ckvx0O2Q58fDFVmkjRgvM3PllN1nrbmj3unLN+C3wL/xVivd5rneyRC7ZMcrvF8Y 2SWbQDL/8BDisu//GCW2fCMZkx1ZnUvxaoEpYBPyzKkDvgpb2AbkBiE2DzkfnCBA = 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 :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=1sR0/8+gP8FMpZgoEdIW8Ap6jiM=; b=Vy6QbmILnjp7vuWh7 Kr43Y7QKlXLff6ERj8W5eoZn++oQfjylrYUTY8FddtIQIrWcJDNYKUhDbEnDAxkw lp67p3Foj1e5mRtuDoOHqPloDh+zzXFg6NCpRXJOkTu6cf2u2yIcB2nZ5u+M4ntX qlDzBfXFyAYRMSpabbTiIoUjMQ= Received: (qmail 27666 invoked by alias); 31 Jan 2014 12:10:35 -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 27645 invoked by uid 89); 31 Jan 2014 12:10:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.4 required=5.0 tests=AWL, BAYES_00, FSL_NEW_HELO_USER, RP_MATCHES_RCVD, SPF_PASS autolearn=no version=3.3.2 X-HELO: userp1040.oracle.com Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Fri, 31 Jan 2014 12:10:33 +0000 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s0VCAUhG005529 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 31 Jan 2014 12:10:31 GMT Received: from userz7021.oracle.com (userz7021.oracle.com [156.151.31.85]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s0VCAPCa008657 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Fri, 31 Jan 2014 12:10:28 GMT Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by userz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s0VCAPf2000489; Fri, 31 Jan 2014 12:10:25 GMT Received: from [192.168.1.4] (/79.33.222.195) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 31 Jan 2014 04:10:25 -0800 Message-ID: <52EB92AE.1070500@oracle.com> Date: Fri, 31 Jan 2014 13:10:22 +0100 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: [C++ Patch] PR 59082 X-IsSubscribed: yes Hi, in this ICE on invalid regression we emit a sensible error message about the duplicate base and then we ICE when we process the function, because TYPE_VFIELD (type) is null in build_vfield_ref. My changes just check for the offending situation and return early from build_base_path (fold_build_pointer_plus would crash for an error_mark_node). Tested x86_64-linux. Thanks, Paolo. //////////////////// /cp 2014-01-31 Paolo Carlini PR c++/59082 * class.c (build_vfield_ref): Early return error_mark_node if TYPE_VFIELD (type) is null. (build_base_path): Check return value of build_vfield_ref. /testsuite 2014-01-31 Paolo Carlini PR c++/59082 * g++.dg/inherit/crash4.C: New. Index: cp/class.c =================================================================== --- cp/class.c (revision 207336) +++ cp/class.c (working copy) @@ -431,6 +431,9 @@ build_base_path (enum tree_code code, v_offset = build_vfield_ref (cp_build_indirect_ref (expr, RO_NULL, complain), TREE_TYPE (TREE_TYPE (expr))); + + if (v_offset == error_mark_node) + return error_mark_node; v_offset = fold_build_pointer_plus (v_offset, BINFO_VPTR_FIELD (v_binfo)); v_offset = build1 (NOP_EXPR, @@ -625,7 +628,9 @@ build_vfield_ref (tree datum, tree type) { tree vfield, vcontext; - if (datum == error_mark_node) + if (datum == error_mark_node + /* Can happen in case of duplicate base types (c++/59082). */ + || !TYPE_VFIELD (type)) return error_mark_node; /* First, convert to the requested type. */ Index: testsuite/g++.dg/inherit/crash4.C =================================================================== --- testsuite/g++.dg/inherit/crash4.C (revision 0) +++ testsuite/g++.dg/inherit/crash4.C (working copy) @@ -0,0 +1,10 @@ +// PR c++/59082 + +struct A {}; + +struct B : virtual A, A {}; // { dg-error "duplicate base type" } + +A foo(const B &b) +{ + return b; +}