From patchwork Fri Feb 16 08:28:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 874338 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-473395-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="ap44jy9g"; 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 3zjSzk4Z9Pz9t5R for ; Fri, 16 Feb 2018 20:49:54 +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=h810V/lfg54KGqQFQqvtG87AfORWV 0BSYAPPJMsDdgueOp+CUwNY2FZLzB1cMHXF0rFfyzHXucyKjoPjq/CGSZeJmASwX lUFzj7sKK11nCAkav9d8cJK2oMkGFJ3X0eAVKWYlDVHi+GgQYqRRRe4x7S1ydBQH Jsn9IZu9fzia1I= 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=SLAN2kNCNc/KFiXR7R2PD38q+0w=; b=ap4 4jy9gbyeDpvT0teIFjGx4s2+80jNdTFJZWLtCUQRA7c3VjyxFA28E3wEVDjpwife FSPpf6P3BnNXU/5njwPFdvIt7Q7WidMi0odEmmQKXMlXqACjCUGMp5U3Wj+uWwxk gzUIO+ZWy1980gxH5h9t4MmbcJDDk4apMPssfzo4= Received: (qmail 125155 invoked by alias); 16 Feb 2018 09:49:37 -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 125123 invoked by uid 89); 16 Feb 2018 09:49:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-12.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 16 Feb 2018 09:49:35 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2DBEAEAEA4 for ; Fri, 16 Feb 2018 09:49:30 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-204-85.brq.redhat.com [10.40.204.85]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E074B1007D90 for ; Fri, 16 Feb 2018 09:49:29 +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 w1G8SG8G031568; Fri, 16 Feb 2018 09:28:16 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id w1G8SFpa031567; Fri, 16 Feb 2018 09:28:15 +0100 Date: Fri, 16 Feb 2018 09:28:14 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Fix ICE with return in statement expression in constexpr.c (PR c++/84192) Message-ID: <20180216082814.GM5867@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.1 (2017-09-22) X-IsSubscribed: yes Hi! pop_stmt_list, if there is just a single stmt inside statement expression moves the stmt out of the STATEMENT_LIST (and I think cp_fold does too). We only initialize jump_target to non-NULL in cxx_eval_statement_list or for calls, so before we have a chance to diagnose the error of using an expression with void type, we ICE trying to dereference NULL jump_target. This can't happen with BREAK_STMT nor CONTINUE_STMT, because they are not potential constant expressions, and I think can only happen when ctx->quiet is true, otherwise it should have been diagnosed already before. If a RETURN_EXPR (or in theory break/continue) appears in a (potential) constant expression we want to evaluate, not doing anything with jump_target if we aren't inside a statement list makes sense to me, there is no following statement to bypass. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2018-02-16 Marek Polacek Jakub Jelinek PR c++/84192 * constexpr.c (cxx_eval_constant_expression) : Don't set *jump_target to anything if jump_target is NULL. * g++.dg/cpp1y/constexpr-84192.C: New test. Jakub --- gcc/cp/constexpr.c.jj 2018-02-12 19:17:37.937216029 +0100 +++ gcc/cp/constexpr.c 2018-02-15 16:10:56.630572360 +0100 @@ -4254,7 +4254,13 @@ cxx_eval_constant_expression (const cons r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0), lval, non_constant_p, overflow_p); - *jump_target = t; + if (jump_target) + *jump_target = t; + else + /* Can happen with ({ return true; }) && false; passed to + maybe_constant_value. There is nothing to jump over in this + case, and the bug will be diagnosed later. */ + gcc_assert (ctx->quiet); break; case SAVE_EXPR: --- gcc/testsuite/g++.dg/cpp1y/constexpr-84192.C.jj 2018-02-15 16:00:58.242588914 +0100 +++ gcc/testsuite/g++.dg/cpp1y/constexpr-84192.C 2018-02-15 16:01:30.219585291 +0100 @@ -0,0 +1,41 @@ +// PR c++/84192 +// { dg-do compile { target c++14 } } +// { dg-options "" } + +bool +f1 () +{ + return ({ return true; }) && false; // { dg-error "could not convert" } +} + +void +f2 () +{ + for (;;) + constexpr bool b = ({ break; false; }) && false; // { dg-error "statement is not a constant expression" } +} + +constexpr bool +f3 (int n) +{ + bool b = false; + for (int i = 0; i < n; i++) + b = ({ break; }); // { dg-error "void value not ignored as it ought to be" } + return b; +} + +constexpr bool b = f3 (4); + +bool +f4 () +{ + constexpr bool b = ({ return true; }) && false; // { dg-error "could not convert" } + return false; +} + +constexpr bool +f5 (int x) +{ + constexpr bool b = ({ switch (x) case 0: true; }) && false; // { dg-error "could not convert" } + return false; +}