* How to get the default values for parameters?
@ 2024-04-03 13:34 Hanke Zhang
2024-04-03 15:15 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Hanke Zhang @ 2024-04-03 13:34 UTC (permalink / raw)
To: GCC Development
Hi,
I'm trying to get the default values for parameters of some functions
in my GIMPLE-PASS. The example code is here:
enum {
edefault1 = 1,
edefault2 = 2,
edefault3 = 3
}
void func(int p0, int p1 = edefault1, int p2 = edefault2, int p3 = edefault3) {
// do other things
}
I want to get the value of `p1` here. But I didn't find a way to get it.
And I noticed that the marco `DECL_INITIAL` cannot be applied on
PARM_DECL. And the comments say that the default values for parameters
are encoded in the type of the function. But I can't find it.
If you know how to get the value, I'll be so grateful! :)
Thanks
Hanke Zhang
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: How to get the default values for parameters?
2024-04-03 13:34 How to get the default values for parameters? Hanke Zhang
@ 2024-04-03 15:15 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2024-04-03 15:15 UTC (permalink / raw)
To: Hanke Zhang; +Cc: GCC Development
On Wed, Apr 3, 2024 at 9:35 AM Hanke Zhang via Gcc <gcc@gcc.gnu.org> wrote:
>
> Hi,
> I'm trying to get the default values for parameters of some functions
> in my GIMPLE-PASS. The example code is here:
>
> enum {
> edefault1 = 1,
> edefault2 = 2,
> edefault3 = 3
> }
>
> void func(int p0, int p1 = edefault1, int p2 = edefault2, int p3 = edefault3) {
> // do other things
> }
>
> I want to get the value of `p1` here. But I didn't find a way to get it.
>
> And I noticed that the marco `DECL_INITIAL` cannot be applied on
> PARM_DECL. And the comments say that the default values for parameters
> are encoded in the type of the function. But I can't find it.
The TYPE_ARG_TYPES of a FUNCTION_TYPE is a TREE_LIST where the
TREE_PURPOSE is the default argument.
Jason
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-04-03 15:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-03 13:34 How to get the default values for parameters? Hanke Zhang
2024-04-03 15:15 ` Jason Merrill
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).