From patchwork Mon Feb 12 19:18:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 872341 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-473097-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="IgprQzV8"; 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 3zgFpY0XyKz9rxj for ; Tue, 13 Feb 2018 06:19:16 +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:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=rKNKzeKQXcibn/xqdqKn+cHtUHaspVURtZlQMYd46xLrYb7Vjn pcdKgqxr8Ek7Tqz/EoNHIaeq26MTIMOG5xey35JW6CoiKybbeD6nTbrFxjZo8GbI 88FGEgumFNJYlzprCG8nNPY4Q0xqW74ehJSd3BHti4cicfHBSwFD0/Iq8= 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:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=kQxiK9sPxbdYuLOBNroXxN2l53k=; b=IgprQzV8X0V8MiMXJDM0 GDx6Wu4Xt9dJzgKhzttBA7P03dHroJdeR5l1KQsWMh59cUx48DmNGr6T43okgn+Z vUcnYwzgqzsErw6AhWyq4lUiMfs6wCRHSwu/dU2PWCk3Of4dvjWFi95rKsroidqF 4a/Wnnt8R64zQ08co+BqD7o= Received: (qmail 32333 invoked by alias); 12 Feb 2018 19:19:08 -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 32313 invoked by uid 89); 12 Feb 2018 19:19:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Hx-languages-length:2115 X-HELO: userp2120.oracle.com Received: from userp2120.oracle.com (HELO userp2120.oracle.com) (156.151.31.85) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 12 Feb 2018 19:19:07 +0000 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w1CJGwGu030885; Mon, 12 Feb 2018 19:19:03 GMT Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2g3gug026s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 12 Feb 2018 19:19:03 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w1CJJ1wJ012202 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 12 Feb 2018 19:19:03 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w1CJJ16s015402; Mon, 12 Feb 2018 19:19:01 GMT Received: from [192.168.1.4] (/79.52.198.133) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 12 Feb 2018 11:19:00 -0800 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] PR 84333 ("[6/7/8 Regression] ICE with ternary operator in template function") Message-ID: Date: Mon, 12 Feb 2018 20:18:58 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8803 signatures=668668 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1802120246 X-IsSubscribed: yes Hi, this ICE on valid happens only with checking enabled - that explains why we didn't notice it so far - but I think points to a minor but substantive correctness issue. In short, we ICE when build_conditional_expr calls save_expr, which in turn calls contain_placeholder_p, which doesn't handle correctly the sizeof(int), and tries to use TREE_CONSTANT on the INTEGER_TYPE. I think that in general we simply have to explicitly handle both kinds of sizeof in contains_placeholder_p: even for a type as simple as INTEGER_TYPE the result may not be trivial, ie, type_contains_placeholder_1 checks the bounds:    case INTEGER_TYPE:     case REAL_TYPE:     case FIXED_POINT_TYPE:       /* Here we just check the bounds.  */       return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type))           || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type))); I'm finishing testing the below on x86_64-linux, all good so far. Thanks, Paolo. ////////////////// 2018-02-12 Paolo Carlini PR c++/84333 * tree.c (contains_placeholder_p): Explicitly handle both kinds of SIZEOF_EXPR, ie, type and expr operand. /testsuite 2018-02-12 Paolo Carlini PR c++/84333 * g++.dg/template/sizeof16.C: New. Index: testsuite/g++.dg/template/sizeof16.C =================================================================== --- testsuite/g++.dg/template/sizeof16.C (nonexistent) +++ testsuite/g++.dg/template/sizeof16.C (working copy) @@ -0,0 +1,6 @@ +// PR c++/84333 + +template int foo() +{ + return sizeof(int) > 1 ? : 1; +} Index: tree.c =================================================================== --- tree.c (revision 257588) +++ tree.c (working copy) @@ -3733,6 +3733,12 @@ contains_placeholder_p (const_tree exp) a PLACEHOLDER_EXPR. */ return 0; + case SIZEOF_EXPR: + if (TYPE_P (TREE_OPERAND (exp, 0))) + return type_contains_placeholder_p (TREE_OPERAND (exp, 0)); + else + return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0)); + default: break; }