-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang] NRVO used in C mode #100902
Comments
@llvm/issue-subscribers-c Author: Ted Lyngmo (TedLyngmo)
This C program exits with `1` even though it should exit with `0`. To the best of my knowledge, NRVO is not allowed in C:
```c
typedef struct {
int i, j;
double a, b;
} S;
int result; S test(S* q) { int main(void)
|
@llvm/issue-subscribers-clang-frontend Author: Ted Lyngmo (TedLyngmo)
This C program exits with `1` even though it should exit with `0`. To the best of my knowledge, NRVO is not allowed in C:
```c
typedef struct {
int i, j;
double a, b;
} S;
int result; S test(S* q) { int main(void)
|
Agreed that this is not a valid optimization in C; Clang is marking the local variable as being available for NRVO: https://godbolt.org/z/PhdKhqPPc
|
Applying NRVO changes the observable behavior of the abstract machine, which makes it an invalid optimization to apply in C. This disables the functionality in C. This is the only code path where we set the NRVO state for a local variable in C (the other code paths are in coroutines and template instantiation, neither of which are available in C). Fixes llvm#100902
Note GCC has the opposite issue dealing with C++ where it optimizes away the comparison too early even with language mandatory NVRO, see https://cplusplus.github.io/CWG/issues/2868.html and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84414 . Note the optimizing away the comparison is how GCC handles this case here even though it does NVRO; though the NVRO is done iff the struct return has no address taken on it (after many optmizations). Here is a replacement function where GCC does not do NVRO and the comparison is still kept around (but still does
|
This C program exits with
1
even though it should exit with0
. To the best of my knowledge, NRVO is not allowed in C:The text was updated successfully, but these errors were encountered: