[llvm-dev] multi-entry function (debug info)
Jacob Lifshay via llvm-dev
llvm-dev at lists.llvm.org
Tue Oct 23 15:13:20 PDT 2018
>
> Regarding multi-entry functions, I'm aware of two cases where this occurs
> in a source language. One is when you have optional parameters in C++,
> which effectively creates one or more overloads for the function; the other
> is PL/I which allows defining an entry label within the body of the
> function. For the C++ case, I'd expect the front-end to create stubs that
> fill in the defaulted parameters and then tail-call the main function; in
> this case, each stub would have its own debug-info entry and be treated as
> its own independent function for debug-info purposes.
>
C++ doesn't work that way, parameters with default values are defined to
evaluate the default values in the calling function then call with the
results rather than creating a set of trampolines that evaluate the default
values inside them.
>From https://en.cppreference.com/w/cpp/language/default_arguments :
"The names used in the default arguments are looked up, checked for
accessibility, and bound at the point of declaration, but are executed at
the point of the function call"
Note that a function with default arguments can't be cast to a function
pointer that doesn't have those defaulted arguments. So, if there is a
function:
void f(int = 0);
then the following cast won't compile:
static_cast<void(*)()>(f);
Note that the defined semantics for source_location::current() wouldn't
work if default arguments worked as you described:
source_location::current() is defined to return the location of the
call-site when it is used in a default argument.
In the following example, the assertion in f doesn't fail:
void f(int line, source_location loc = source_location::current())
{
assert(line == loc.line());
}
void g()
{
f(__LINE__);
}
void h()
{
f(__LINE__);
}
int main()
{
g();
h();
}
See https://en.cppreference.com/w/cpp/experimental/source_location
Jacob Lifshay
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20181023/aa7ded1a/attachment-0001.html>
More information about the llvm-dev
mailing list