From patchwork Sat Dec 5 23:07:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 553062 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 83E2114031E for ; Sun, 6 Dec 2015 10:07:30 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=a+C96xft; 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 :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=vCuFrFtMSpaekYiJITYkpMnEhh1BcYHGGCWwIpS0gpuqre PeNk4S1VCaGWGfcsyoGwK83+BIDDplhUR9iPcMcFWKMos5LC7ir7dsnNiIxyVe+w UfiFf3Kee1w4d9+SDJyuY1cpVXRfcL4StQtOCTiGTjsMSbOjIfADrFMSAQJdg= 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:subject:content-type; s= default; bh=2ikzxGQrH91DjP0Cz2391q3KERA=; b=a+C96xftZyuHWu1r/q2t wDL2OyuzmA+LsbcxIjTmsD+QC3EWYcd2dMO8nBT5Vyh/aRM9BEyAJj8tMwYyHcBG L4cQVB4kE46cwu2PCO4YhMp0QDOvwz0yZUsCBRTz6aykg10zoBaOxWtDOiRHfh8u 7nOb8HtMHo+7W9ccbl7/AKo= Received: (qmail 121110 invoked by alias); 5 Dec 2015 23:07:23 -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 121100 invoked by uid 89); 5 Dec 2015 23:07:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-qk0-f172.google.com Received: from mail-qk0-f172.google.com (HELO mail-qk0-f172.google.com) (209.85.220.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sat, 05 Dec 2015 23:07:22 +0000 Received: by qkcb135 with SMTP id b135so9930476qkc.3 for ; Sat, 05 Dec 2015 15:07:20 -0800 (PST) X-Received: by 10.55.72.23 with SMTP id v23mr27626591qka.24.1449356839973; Sat, 05 Dec 2015 15:07:19 -0800 (PST) Received: from [192.168.0.26] (97-124-162-152.hlrn.qwest.net. [97.124.162.152]) by smtp.gmail.com with ESMTPSA id c67sm8513775qgd.29.2015.12.05.15.07.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 05 Dec 2015 15:07:19 -0800 (PST) Message-ID: <56636E25.6000303@gmail.com> Date: Sat, 05 Dec 2015 16:07:17 -0700 From: Martin Sebor User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Gcc Patch List , Jason Merrill Subject: [PATCH] c++/68711 - [5 regression] SEGV on an invalid offsetof of a member of a virtual base X-IsSubscribed: yes The attached patch restores the "invalid access to non-static data member" error for invalid offsetof-like expressions involving members of virtually derived base classes that was inadvertently made ineffective as a result of the merge of the C++ delayed folding branch. Martin gcc/testsuite/ChangeLog: 2015-12-05 Martin Sebor PR c++/68711 * g++.dg/other/offsetof8.C: New test. gcc/cp/ChangeLog: 2015-12-05 Martin Sebor PR c++/68711 * typeck.c (build_class_member_access_expr): Strip NOPs before testing a potentially null operand for equality to zero. Index: gcc/cp/typeck.c =================================================================== --- gcc/cp/typeck.c (revision 231314) +++ gcc/cp/typeck.c (working copy) @@ -2358,8 +2358,14 @@ int type_quals; tree member_type; - null_object_p = (INDIRECT_REF_P (object) - && integer_zerop (TREE_OPERAND (object, 0))); + if (INDIRECT_REF_P (object)) + { + tree oper = TREE_OPERAND (object, 0); + STRIP_NOPS (oper); + null_object_p = integer_zerop (oper); + } + else + null_object_p = false; /* Convert OBJECT to the type of MEMBER. */ if (!same_type_p (TYPE_MAIN_VARIANT (object_type), Index: gcc/testsuite/g++.dg/other/offsetof8.C =================================================================== --- gcc/testsuite/g++.dg/other/offsetof8.C (revision 0) +++ gcc/testsuite/g++.dg/other/offsetof8.C (working copy) @@ -0,0 +1,12 @@ +// PR c++/68711 - [5 regression] SEGV on an invalid offsetof of a member +// of a virtual base +// { dg-do compile } + +struct A { int i; }; + +struct B: virtual A { }; + +int a[] = { + !&((B*)0)->i, // { dg-error "invalid access to non-static data member" } + __builtin_offsetof (B, i) // { dg-error "invalid access to non-static" } +};