-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[Windows] Segmentation fault when returning a struct from a function or instance method #14048
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
Comments
assigned to @timurrrr |
Could you attach the assembly generated by MSVC? |
Please don't attach output generated by the MSVC compiler to the public bug tracker unless you understand all of the implications of its EULA. I don't think we need it for Timur to continue working on this. |
Currently I'm prioritized to get Clang working on Chromium and I don't think the pattern described in this bug is widespread there due to our strict code style. I might be wrong though as we have a lot of third_party/ there. So feel free to take over unless I explicitly take it myself :) |
I'll wager you one beverage of your choice that you end up having to fix this for Chromium. ;] Anyways, prioritize as is convenient for you, I just was pointing out that whomever chooses to dig into this can likely do so w/o someone posting asm. |
Indeed, Chromium's FilePath::DirName returns a FilePath by value, it's a 32-byte structure => boom it crashes. -- Actually it turns out the problem is not that the struct is "2 integers". A similar "returning a struct" scenario works fine for non-class functions or static class method. Changing the subject accordingly. |
Taking this. After some investigation, there are at least three different problems here:
I have small patches for (1) and (2), but their current versions likely break the Itanium ABI. |
A fix for everything I know except for __cdecl methods has been committed as r179681. |
(See also r178291, r178634) |
Re: cdecl - see llvm/llvm-bugzilla-archive#15768 |
mentioned in issue llvm/llvm-bugzilla-archive#15556 |
mentioned in issue llvm/llvm-bugzilla-archive#16226 |
Extended Description
As of r160851,
$ cat with_cl.cpp
struct S {
int a, b;
};
class C {
public:
S foo();
};
S C::foo() {
S ret;
ret.a = 1;
ret.b = 2;
return ret;
}
///////////////////// EOF
$ cat with_clang.cpp
struct S {
int a, b;
};
class C {
public:
S foo();
};
int main() {
C c;
S s = c.foo();
if (s.a != 1)
return 1;
if (s.b != 2)
return 2;
}
///////////////////// EOF
$ clang -Xclang -cxx-abi -Xclang microsoft -c with_clang.cpp && cl -nologo -c with_cl.cpp && link -nologo with_cl.obj with_clang.o
$ with_cl.exe
Segmentation fault
The text was updated successfully, but these errors were encountered: