<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61434>61434</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
-fuse-ld=lld: Wrong code generation ?
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
FlorianChevassu
</td>
</tr>
</table>
<pre>
Consider the following simple [example](https://github.com/llvm/llvm-project/files/10981720/example.zip):
_lib.cpp_
```cpp
#include "lib.h"
#include <stdexcept>
void test(const T_value& entry_value) {
boost::apply_visitor([](const auto& value) { test(value); },
entry_value);
}
void test(const Obj_1& ) {
throw std::runtime_error("Obj_1");
}
void test(const Obj_2& ) {
throw std::runtime_error("Obj_2");
}
```
___
_lib.h_
```cpp
#pragma once
#include <string>
#include <boost/variant.hpp>
struct Obj_1 {
std::string oid;
};
struct Obj_2 {
std::string oid;
};
using T_value = boost::make_recursive_variant<
Obj_1,
Obj_2>::type;
void test(const T_value&);
void test(const Obj_2&);
void test(const Obj_1&);
```
___
_main.cpp_
```cpp
#include "lib.h"
#include <stdexcept>
int main() {
try {
test(Obj_2{"foo"});
} catch (const std::runtime_error& e) {
}
try {
test(Obj_1{"foo"});
} catch (const std::runtime_error& e) {
}
}
```
___
When building the code using `g++` and linking with `lld`, the exception thrown by the call to `test(Obj_1{"foo"});` is never caught, and the program terminates.
Please note that the program executes successfully with the following configurations:
- compile with g++ and link with ld,
- compile with clang++ and link with lld.
- if we add a dummy function implementation at the top of `lib.cpp`
The versions of the software used are the following:
- LLVM: 15.0.7 (installed with `bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"`)
- GCC 12.2.0
A docker image with all the dependencies reproducing the issue is available in the example.
Please let me know if you need more information, or if the issue should be on the GCC side.
Best regards
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0Vk2P2zgM_TXKhYhhy_k85DBJmr100T0U22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