From patchwork Sun Sep 19 23:32:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 45167 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9793A385840E for ; Sun, 19 Sep 2021 23:33:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9793A385840E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1632094411; bh=eGHYzll2sUvoagpMpNhfvV9gO6EAPPVOosHSX9yY0vw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=WrzPaGOp5CII7UNT/5LHy5cGWMV3/uVqCNBdk5xriZzPOpXecD4FPDi3AcdYhZlfh o/sqknExNk8gCdEq1U/55xAPce21VJBDOi136Btc7uvTwLPLwmO/UQnQBGImn8pfyF PcaxbJVf/al8NFOVMaSlYP9PLuKghCagWynCsoDs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ot1-x32a.google.com (mail-ot1-x32a.google.com [IPv6:2607:f8b0:4864:20::32a]) by sourceware.org (Postfix) with ESMTPS id 56ACB385801D for ; Sun, 19 Sep 2021 23:32:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 56ACB385801D Received: by mail-ot1-x32a.google.com with SMTP id w64-20020a9d3646000000b0054716b40005so138696otb.4 for ; Sun, 19 Sep 2021 16:32:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=eGHYzll2sUvoagpMpNhfvV9gO6EAPPVOosHSX9yY0vw=; b=IxymwqZORTasKEpK38HH9kW0xg/ytMVpTB+qVap1bzG57d6L/INguJsVu7aOhymywt tJ3QcuthzTpEav+alAeawEbC0FIHSj0PnbXc9o/RSzNEJSvzQmYES0R+LvDYDLrIAt2R 1hJQRqt3QC+/Ij9/ZHwoidXuaviK1GfZYwUvq6mJdqxRCM0JGM9Vwkvdkjb4L8/bVKdJ wZdNfGdSVvXTZYvxb6goAeLnW/MFOnDaw026yE9o3gmljbEiwxeOp6Yj+a8jXUVWuh81 OY5ADuHe9LSqiremKx104aia6HxMr6/fCUO/YiNu0xyKhUTLe7DItBxWMx9Cv5GW/Nj1 r3XA== X-Gm-Message-State: AOAM5318LRTe60XuHD7W9/wB9GNqUxa4NstzpW/ODjNvw6fdpZMARsHG pUuRodKYhsT6wrzXTCajXLc+PELFiV4= X-Google-Smtp-Source: ABdhPJxw1SgUmQTMWCRCEQA1wH8KWbJUqy9rfitl/V6JjcUPXOq25mBWPEYcmZxAxi9dZECGAvTspg== X-Received: by 2002:a9d:5887:: with SMTP id x7mr1637021otg.331.1632094324557; Sun, 19 Sep 2021 16:32:04 -0700 (PDT) Received: from [192.168.0.41] (97-118-96-133.hlrn.qwest.net. [97.118.96.133]) by smtp.gmail.com with ESMTPSA id u12sm570218otq.20.2021.09.19.16.32.04 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 19 Sep 2021 16:32:04 -0700 (PDT) To: gcc-patches Subject: [committed] avoid assuming cfun is nonnull [PR102243] Message-ID: <6b76d2ce-9ad8-bcc4-7bef-dd191b1a9b81@gmail.com> Date: Sun, 19 Sep 2021 17:32:03 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Martin Sebor via Gcc-patches From: Martin Sebor Reply-To: Martin Sebor Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" After the front end passes control to the middle end cfun is never null (I'm pretty sure) but when a middle end helper is called from the C++ front end cfun can be null for a namespace scope initializer expression. A recent change of mine to the helper introduced an assumption to the contrary, causing an ICE. In r12-3673 I've committed the trivial fix below to correct this mistake Martin Handle null cfun [PR102243]. Resolves: PR middle-end/102243 - ICE on placement new at global scope gcc/ChangeLog: PR middle-end/102243 * tree-ssa-strlen.c (get_range): Handle null cfun. gcc/testsuite/ChangeLog: PR middle-end/102243 * g++.dg/warn/Wplacement-new-size-10.C: New test. --- gcc/testsuite/g++.dg/warn/Wplacement-new-size-10.C | 13 +++++++++++++ gcc/tree-ssa-strlen.c | 14 ++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/warn/Wplacement-new-size-10.C if (!rvals->range_of_expr (vr, val, stmt)) diff --git a/gcc/testsuite/g++.dg/warn/Wplacement-new-size-10.C b/gcc/testsuite/g++.dg/warn/Wplacement-new-size-10.C new file mode 100644 index 00000000000..6b71a832a30 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wplacement-new-size-10.C @@ -0,0 +1,13 @@ +/* PR middle-end/102243 - ICE on placement new at global scope + { dg-do compile } + { dg-options "-Wall" } */ + +void *operator new (__SIZE_TYPE__, void *); + +char a[2][sizeof (int)]; + +int *p = new (a[1]) int; + +void *operator new[] (__SIZE_TYPE__, void *p) { return p; } + +int *q = new (a[1]) int[1]; diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c index 7c93958e9ad..7c568a42d49 100644 --- a/gcc/tree-ssa-strlen.c +++ b/gcc/tree-ssa-strlen.c @@ -199,16 +199,22 @@ static bool handle_assign (gimple_stmt_iterator *, tree, bool *, /* Sets MINMAX to either the constant value or the range VAL is in and returns either the constant value or VAL on success or null - when the range couldn't be determined. Uses RVALS when nonnull - to determine the range, otherwise uses CFUN or global range info, - whichever is nonnull. */ + when the range couldn't be determined. Uses RVALS or CFUN for + range info, whichever is nonnull. */ tree get_range (tree val, gimple *stmt, wide_int minmax[2], range_query *rvals /* = NULL */) { if (!rvals) - rvals = get_range_query (cfun); + { + if (!cfun) + /* When called from front ends for global initializers CFUN + may be null. */ + return NULL_TREE; + + rvals = get_range_query (cfun); + } value_range vr;