From patchwork Sun Dec 9 11:05:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1009931 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-491959-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="hqheiPRu"; dkim-atps=neutral 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 43CNfG3DC8z9s3Z for ; Sun, 9 Dec 2018 22:05:23 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=awe93h/tAjf6QnFAJ6P+4dudRhvA5 DoCqjflQQnGNqQZy7F+yfDZRZ9OayueGCbcf0YJI4sy3AGlbB3wO/rGCmusY/70v SAlPj2mnUVZcogwEv5UvhNlO6FiEtgapxvqcPYKorGST63jnuTn1gqUISbA3NWsN jmq8AAUFFTg21k= 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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=UOhy0RTVnoYIWYfFMAQyJKVS0lY=; b=hqh eiPRuKN5Ojou4RJCP4Cy3H7oSB2akS//6CEWSojj5T44kCo7w4ABs7GYJeRko4CM 4qy6Sw7kTB06VbbzYGjvE6qj+GVkFIA2qHjwXhHMjUSwUSbtRvviEGniHPXOxNlo O2o9+tr00/6c6ad7D3fTfludIC0jql1AOiSGPYeo= 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-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 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, 9 Dec 2018 12:05:06 +0100 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-Disposition: inline User-Agent: Mutt/1.9.2 (2017-12-15) X-IsSubscribed: yes 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. Jakub --- 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 };