[clang] [C] Disable use of NRVO (PR #101038)
John McCall via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 29 11:47:16 PDT 2024
rjmccall wrote:
Note that we're forced to override that ABI rule in C++ sometimes — I believe we're now required (since C++11?) to elide a copy/move when initializing a normal object with a return value, and even if we weren't, it'd clearly be unreasonable compiler behavior to do an extra non-trivial operation here. I don't think the psABI intends that rule to have that effect anyway.
This does raise a language interoperation question, though, related to the tractability note I made about (2) above:
- You can call a function to initialize a global variable in C++.
- That function can be implemented in C, in which case it will expect the aliasing rule to still apply to its return value slot.
- We cannot do any sort of local analysis on a global variable to prove that the variable is not accessed during its initializer.
C++ does have some restrictions on accessing objects that are being initialized through other names. It's possible that they're strong enough to satisfy the ABI rule here through a sort of reverse of the normal analysis: basically, any program that would violate the ABI rule is actually incorrect because of the semantic restriction. If not, I think we may need to force copies of trivial return types in the caller in C++. We can consider that separately, though.
https://github.com/llvm/llvm-project/pull/101038
More information about the cfe-commits
mailing list