From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 0631A3858402; Tue, 30 Nov 2021 08:50:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0631A3858402 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-5596] c++: Small incremental tweak to source_location::current() folding X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: c39d77f252e895306ef88c1efb3eff04e4232554 X-Git-Newrev: 2af2f55a500adad73451f3b859cfaa8974920caf Message-Id: <20211130085003.0631A3858402@sourceware.org> Date: Tue, 30 Nov 2021 08:50:03 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Nov 2021 08:50:03 -0000 https://gcc.gnu.org/g:2af2f55a500adad73451f3b859cfaa8974920caf commit r12-5596-g2af2f55a500adad73451f3b859cfaa8974920caf Author: Jakub Jelinek Date: Tue Nov 30 09:48:59 2021 +0100 c++: Small incremental tweak to source_location::current() folding 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. 2021-11-30 Jakub Jelinek * cp-gimplify.c (cp_fold_r): Perform folding of std::source_location::current() calls here... (cp_fold): ... rather than here. Diff: --- gcc/cp/cp-gimplify.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index 2fbb4236b92..0988655eeba 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -930,6 +930,13 @@ cp_fold_r (tree *stmt_p, int *walk_subtrees, void *data) } 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. */