[llvm-bugs] [Bug 47346] New: MS ABI: wrong ABI for returning struct with explicitly defaulted default constructor
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Aug 28 12:29:12 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=47346
Bug ID: 47346
Summary: MS ABI: wrong ABI for returning struct with explicitly
defaulted default constructor
Product: clang
Version: 10.0
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: mizvekov at gmail.com
CC: blitzrakete at gmail.com, dgregor at apple.com,
erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
richard-llvm at metafoo.co.uk
Consider this example reproduction:
```
extern void bar() noexcept;
struct ret1 {
bool val;
};
struct ret2 {
ret2() = default;
bool val;
};
template<class T> extern T fooret() noexcept;
template <class T> void test() noexcept {
auto ret = fooret<T>();
if (ret.val) bar();
}
template void test<ret1>() noexcept;
template void test<ret2>() noexcept;
```
MSVC generates exactly the same code for both `test<ret1>` and `test<ret2>`,
expecting the struct to be returned by register from `fooret<>`.
clang generates different code for each, on ret1 case it expects by register,
on ret2 case it passes by implicit pointer parameter.
Workspace for convenience: https://godbolt.org/z/q3194d
Also, and sorry perhaps if this should be a separate bug, but notice on clang
the ret2 case is also suppressed from tail calling into bar.
This should not happen either way, and may be related to
https://bugs.llvm.org/show_bug.cgi?id=46126
But perhaps it's because the implicit parameter does not have the
`[[clang::noescape]]` attribute?
The following code with an explicit reference parameter shows the noescape
attribute makes a difference (even though it should not, but that is probably
related to #46126)
The following code shows this:
```
extern void bar() noexcept;
struct ret_t {
unsigned int val;
};
extern void fooret1(ret_t&) noexcept;
extern void fooret2([[clang::noescape]] ret_t &) noexcept;
void test1() noexcept {
bool val;
{
ret_t ret;
fooret1(ret);
val = ret.val;
}
if (val) bar();
}
void test2() noexcept {
bool val;
{
ret_t ret;
fooret2(ret);
val = ret.val;
}
if (val) bar();
}
```
Another workspace for convenience: https://godbolt.org/z/r3qPsc
And there you can see test1 is suppressed from tail-calling into bar, but not
test2.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200828/c33edf5a/attachment.html>
More information about the llvm-bugs
mailing list