From: Jakub Jelinek <jakub@redhat.com>
To: Jason Merrill <jason@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: [PATCH] c++: Small incremental tweak to source_location::current() folding
Date: Sat, 27 Nov 2021 09:52:12 +0100 [thread overview]
Message-ID: <20211127085212.GT2646553@tucnak> (raw)
In-Reply-To: <20211124224228.GV2646553@tucnak>
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 <jakub@redhat.com>
* cp-gimplify.c (cp_fold_r): Perform folding of
std::source_location::current() calls here...
(cp_fold): ... rather than here.
--- 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. */
Jakub
next prev parent reply other threads:[~2021-11-27 8:52 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-18 8:12 [PATCH] c++: Diagnose taking address of an immediate member function [PR102753] Jakub Jelinek
2021-10-18 16:42 ` Jason Merrill
2021-10-19 12:00 ` [PATCH, v2] " Jakub Jelinek
2021-10-19 13:24 ` [PATCH] c++: Reject addresses of immediate functions in constexpr vars inside of immediate functions or consteval if [PR102753] Jakub Jelinek
2021-10-20 23:26 ` Jason Merrill
2021-10-20 23:16 ` [PATCH, v2] c++: Diagnose taking address of an immediate member function [PR102753] Jason Merrill
2021-10-21 11:17 ` Jakub Jelinek
2021-10-26 20:58 ` Jason Merrill
2021-10-29 15:24 ` Jakub Jelinek
2021-11-23 20:45 ` Jason Merrill
2021-11-24 16:02 ` Jakub Jelinek
2021-11-24 18:02 ` [PATCH] c++: Fix up diagnostics about " Jakub Jelinek
2021-11-24 22:15 ` Jason Merrill
2021-11-24 22:42 ` [PATCH] c++, v2: " Jakub Jelinek
2021-11-25 2:07 ` Jason Merrill
2021-11-25 14:38 ` [PATCH] c++, v3: " Jakub Jelinek
2021-11-25 15:49 ` Jason Merrill
2021-11-27 8:52 ` Jakub Jelinek [this message]
2021-11-29 22:45 ` [PATCH] c++: Small incremental tweak to source_location::current() folding Jason Merrill
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211127085212.GT2646553@tucnak \
--to=jakub@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).