[cfe-dev] Detecting (N)RVO
Kim Gräsman via cfe-dev
cfe-dev at lists.llvm.org
Tue Nov 3 12:49:35 PST 2015
Hi all,
I'm experimenting with a patch to let users mark functions with an attribute
[[clang::requires_rvo]]
std::string f() {
return std::string("Hello world");
}
and in the presence of this attribute, warn if (N)RVO didn't happen.
This would be useful to prevent small code changes from disabling RVO
in critical paths.
I have the attribute in place, and I've seen that I can check if it
exists with FunctionDecl::hasAttr. But finding where NRVO is actually
decided for a given function turns out to be more difficult...
SemaInit appears to do something for NRVO/copy elision more generally
when constructors are called. But it only marks the CXXConstructExpr
as elidable, as far as I can see, and I'm not sure if this is used to
effect RVO later (I found something in
CodeGenFunction::EmitCXXConstructExpr, but there seems to be more
playing into the decision of whether to construct at caller or not.
Also, I'm not sure if my terminology is right; I haven't found any
references to RVO-sans-the-N, is that refered to as copy elision? NRVO
only seems to address VarDecls and their lifetime.
Thanks for any ideas,
- Kim
More information about the cfe-dev
mailing list