From patchwork Sat Nov 27 08:52:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 48223 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 1126B3858016 for ; Sat, 27 Nov 2021 08:52:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1126B3858016 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1638003169; bh=TUb+Ery2+S46PZ6UOORDQTPPO2NfmYR0iL1vA6Fbv3w=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=GDoxUl057fIqTtSq/zi0s84oTin/szzV+hk6xdNLFPKE5DIHZDbLUANf9qNY8YfU+ /ZZv6eQAc40c0N+RVIe/7BPskOD8R76Kwlcj9tIsUkNp09tjdSTv2tFnhjnXowRWmd jz6oqTNgjTKotZD9QF4ePD1q6yFOJhlWkDH79X40= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 0000C3858C3A for ; Sat, 27 Nov 2021 08:52:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0000C3858C3A Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-72-yyA9a9t5OgWYLRpENlGvVQ-1; Sat, 27 Nov 2021 03:52:18 -0500 X-MC-Unique: yyA9a9t5OgWYLRpENlGvVQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 764A01853026 for ; Sat, 27 Nov 2021 08:52:17 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.23]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 109C810013D6; Sat, 27 Nov 2021 08:52:15 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 1AR8qC6q1746164 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 27 Nov 2021 09:52:13 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 1AR8qChP1746163; Sat, 27 Nov 2021 09:52:12 +0100 Date: Sat, 27 Nov 2021 09:52:12 +0100 To: Jason Merrill Subject: [PATCH] c++: Small incremental tweak to source_location::current() folding Message-ID: <20211127085212.GT2646553@tucnak> References: <20211019120021.GL304296@tucnak> <20211021111742.GG304296@tucnak> <20211029152444.GB304296@tucnak> <1f3b346d-2d4e-a4f1-15ef-b536a162a7e6@redhat.com> <20211124160203.GO2646553@tucnak> <20211124180257.GP2646553@tucnak> <6b01cee0-91b2-7292-c95e-c774fc426eb4@redhat.com> <20211124224228.GV2646553@tucnak> MIME-Version: 1.0 In-Reply-To: <20211124224228.GV2646553@tucnak> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-5.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" On Wed, Nov 24, 2021 at 11:42:28PM +0100, Jakub Jelinek via Gcc-patches wrote: > > I'm surprised the source_location::current handling would be needed; why do > > calls to that function live long enough for us to walk into the ADDR_EXPR > > here? Maybe we should fold it in cp_fold instead of cp_genericize_r. I've already committed the patch, but perhaps we shouldn't do it in cp_fold where it will be folded even for warnings etc. and the locations might not be the final yet. This patch moves it to cp_fold_r so that it is done just once for each function and just once for each static initializer. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2021-11-27 Jakub Jelinek * cp-gimplify.c (cp_fold_r): Perform folding of std::source_location::current() calls here... (cp_fold): ... rather than here. Jakub --- gcc/cp/cp-gimplify.c.jj 2021-11-26 10:10:53.227121384 +0100 +++ gcc/cp/cp-gimplify.c 2021-11-26 11:51:50.945204127 +0100 @@ -930,6 +930,13 @@ cp_fold_r (tree *stmt_p, int *walk_subtr } break; + case CALL_EXPR: + if (tree fndecl = cp_get_callee_fndecl_nofold (stmt)) + if (DECL_IMMEDIATE_FUNCTION_P (fndecl) + && source_location_current_p (fndecl)) + *stmt_p = stmt = cxx_constant_value (stmt); + break; + default: break; } @@ -2672,14 +2679,6 @@ cp_fold (tree x) int sv = optimize, nw = sv; tree callee = get_callee_fndecl (x); - if (tree fndecl = cp_get_callee_fndecl_nofold (x)) - if (DECL_IMMEDIATE_FUNCTION_P (fndecl) - && source_location_current_p (fndecl)) - { - x = cxx_constant_value (x); - break; - } - /* Some built-in function calls will be evaluated at compile-time in fold (). Set optimize to 1 when folding __builtin_constant_p inside a constexpr function so that fold_builtin_1 doesn't fold it to 0. */