From patchwork Thu Dec 21 15:51:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 852023 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-469723-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="A7rxuiz9"; 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 3z2bkk3MHVz9s81 for ; Fri, 22 Dec 2017 02:52:45 +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:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=sB4WHR+xpQbQESzX I2z9JmGfdwDWT1j4TMnbRcWetzrSEq4/r9qEeUXNlyQKmZ+LX8YvCroE5D8TpQRj AGC8VKxQTPZsnPWZczCUalbn7QXDPD/QZu6HLA4L3guqN0kPr86Fv0QbBbCEcOUr qVisnNxaTeKeIMBlnI5xsea6Zgc= 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:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=RyksDoGcWA41O/jcY1Fpg3 Udvog=; b=A7rxuiz9U7EzZM2Uq4oPG78s30+nhUDRGtXAAGHjqe1Ear2qXvMIUI aHb/d+TF9NsvRTskoJ8YdSXT4CVyzeDcdb0cG/eE7NhLGBMjWYK829UFQ3yLIO/z KMiRb3bLh+Edzl3UD6RLd9awkXxL5k+U8hBa1Z1BqyYAuBS54SQp4= Received: (qmail 94097 invoked by alias); 21 Dec 2017 15:52:38 -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 94086 invoked by uid 89); 21 Dec 2017 15:52:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 21 Dec 2017 15:52:36 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id DD4D781850 for ; Thu, 21 Dec 2017 16:52:32 +0100 (CET) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QaOSr0Rgapab for ; Thu, 21 Dec 2017 16:52:32 +0100 (CET) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id B51F88152A for ; Thu, 21 Dec 2017 16:52:32 +0100 (CET) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [patch] Fix PR C++/82872 Date: Thu, 21 Dec 2017 16:51:40 +0100 Message-ID: <2618637.dVWshZqFx6@polaris> User-Agent: KMail/4.14.10 (Linux/3.16.7-53-desktop; KDE/4.14.9; x86_64; ; ) MIME-Version: 1.0 Hi, this is an ICE in the C++ FE on an offsetof construct with __PTRDIFF_MAX__ and it happens only with this specific index: In file included from pr82872.c:4: pr82872.c: In function 'size_t foo()': pr82872.c:10:10: internal compiler error: in ignore_overflows, at cp/cvt.c:583 return offsetof (struct S, a[__PTRDIFF_MAX__]); ^~~~~~~~ 0x65ef7f ignore_overflows /home/eric/svn/gcc/gcc/cp/cvt.c:583 0x661bcc ocp_convert(tree_node*, tree_node*, int, int, int) /home/eric/svn/gcc/gcc/cp/cvt.c:817 0x6636e0 convert(tree_node*, tree_node*) /home/eric/svn/gcc/gcc/cp/cvt.c:1580 0x882b62 fold_offsetof(tree_node*) /home/eric/svn/gcc/gcc/c-family/c-common.c:6282 0x801c0c finish_offsetof(tree_node*, tree_node*, unsigned int) /home/eric/svn/gcc/gcc/cp/semantics.c:4041 0x74596b cp_parser_builtin_offsetof /home/eric/svn/gcc/gcc/cp/parser.c:9828 The C++ FE is quite picky about constant integer overflow during conversion operations and checks that they can only _introduce_ overflows and never make them disappear, the latter case occuring here in convert_to_integer_1. Tested on x86_64-suse-linux, OK for the mainline? 2017-12-21 Eric Botcazou PR C++/82872 * convert.c (convert_to_integer_1) : Do not return the shared zero if the input has overflowed. 2017-12-21 Eric Botcazou * c-c++-common/pr82872.c: New test. Index: convert.c =================================================================== --- convert.c (revision 255850) +++ convert.c (working copy) @@ -671,7 +671,7 @@ convert_to_integer_1 (tree type, tree ex { case POINTER_TYPE: case REFERENCE_TYPE: - if (integer_zerop (expr)) + if (integer_zerop (expr) && !TREE_OVERFLOW (expr)) return build_int_cst (type, 0); /* Convert to an unsigned integer of the correct width first, and from