From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 68522 invoked by alias); 9 Dec 2018 11:05:15 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 68501 invoked by uid 89); 9 Dec 2018 11:05:14 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.9 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=fold, initializer 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 ESMTP; Sun, 09 Dec 2018 11:05:12 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 634AC3DE03 for ; Sun, 9 Dec 2018 11:05:11 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-117-214.ams2.redhat.com [10.36.117.214]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DF47A5D6AA; Sun, 9 Dec 2018 11:05:10 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id wB9B58WA004258; Sun, 9 Dec 2018 12:05:09 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id wB9B56Z7004257; Sun, 9 Dec 2018 12:05:06 +0100 Date: Sun, 09 Dec 2018 11:05:00 -0000 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Fix ICE with offsetof-like initializer (PR c++/88410) Message-ID: <20181209110506.GV12380@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.2 (2017-12-15) X-IsSubscribed: yes X-SW-Source: 2018-12/txt/msg00533.txt.bz2 Hi! The following testcase ICEs starting with my change to move offsetof-like expression handling from the parsing to cp_fold - if the base expression is not INTEGER_CST, but a constant VAR_DECL initialized with INTEGER_CST, then we don't fold it as offsetof-like expression and as we use recursive cp_fold only on functions, not initializers, we don't fold that VAR_DECL in there into INTEGER_CST and the middle-end ICEs on it trying to fold it. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2018-12-09 Jakub Jelinek PR c++/88410 * cp-gimplify.c (cp_fold) : For offsetof-like folding, call maybe_constant_value on val to see if it is INTEGER_CST. * g++.dg/cpp0x/pr88410.C: New test. --- gcc/cp/cp-gimplify.c.jj 2018-11-23 20:00:26.603273556 +0100 +++ gcc/cp/cp-gimplify.c 2018-12-08 11:39:03.983985326 +0100 @@ -2317,6 +2317,7 @@ cp_fold (tree x) { val = TREE_OPERAND (val, 0); STRIP_NOPS (val); + val = maybe_constant_value (val); if (TREE_CODE (val) == INTEGER_CST) return fold_offsetof (op0, TREE_TYPE (x)); } --- gcc/testsuite/g++.dg/cpp0x/pr88410.C.jj 2018-12-08 11:41:10.946927148 +0100 +++ gcc/testsuite/g++.dg/cpp0x/pr88410.C 2018-12-08 11:40:48.476291414 +0100 @@ -0,0 +1,7 @@ +// PR c++/88410 +// { dg-do compile { target c++11 } } + +typedef __UINTPTR_TYPE__ uintptr_t; +const uintptr_t a = 32; +struct C { int b; int c; }; +uintptr_t d { uintptr_t (&reinterpret_cast(a)->c) - a }; Jakub