<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - MS ABI: wrong ABI for returning struct with explicitly defaulted default constructor"
href="https://bugs.llvm.org/show_bug.cgi?id=47346">47346</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>MS ABI: wrong ABI for returning struct with explicitly defaulted default constructor
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>10.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>mizvekov@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>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: <a href="https://godbolt.org/z/q3194d">https://godbolt.org/z/q3194d</a>
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
<a class="bz_bug_link
bz_status_NEW "
title="NEW - Failure to optimize tail call to jump when a pointer to a variable that dies before the tail call is passed to an external function"
href="show_bug.cgi?id=46126">https://bugs.llvm.org/show_bug.cgi?id=46126</a>
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: <a href="https://godbolt.org/z/r3qPsc">https://godbolt.org/z/r3qPsc</a>
And there you can see test1 is suppressed from tail-calling into bar, but not
test2.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>