[llvm-dev] multi-entry function (debug info)

via llvm-dev llvm-dev at lists.llvm.org
Wed Oct 24 08:45:25 PDT 2018


Interesting, that's not what I remember from 20 years ago, but then C++ is pretty malleable. That tactic makes it a bit harder to maintain old APIs, you have to do it with explicit overloads rather than defaulting parameters. In which case of course the explicit overload is its own function with its own debug info.
--paulr

From: Jacob Lifshay [mailto:programmerjake at gmail.com]
Sent: Tuesday, October 23, 2018 6:13 PM
To: Robinson, Paul
Cc: jiangmuhui at gmail.com; llvm-dev at lists.llvm.org
Subject: Re: [llvm-dev] multi-entry function (debug info)

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/20181024/1513b695/attachment.html>


More information about the llvm-dev mailing list