<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/118753>118753</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[LogicalView] - Crash when loading a library
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
aurelien35
</td>
</tr>
</table>
<pre>
In the file [https://github.com/llvm/llvm-project/blob/main/llvm/lib/DebugInfo/LogicalView/LVReaderHandler.cpp](https://github.com/llvm/llvm-project/blob/main/llvm/lib/DebugInfo/LogicalView/LVReaderHandler.cpp)
There is the "LVReaderHandler::handleArchive" method (around line 73) which is used to load debug informations from libraries.
The first statement create a local "Error" variable:
```
Error LVReaderHandler::handleArchive(LVReaders &Readers, StringRef Filename,
Archive &Arch) {
// HERE
Error Err = Error::success();
for (const Archive::Child &Child : Arch.children(Err)) {
Expected<MemoryBufferRef> BuffOrErr = Child.getMemoryBufferRef();
if (Error Err = BuffOrErr.takeError())
return createStringError(errorToErrorCode(std::move(Err)), "%s",
Filename.str().c_str());
Expected<StringRef> NameOrErr = Child.getName();
if (Error Err = NameOrErr.takeError())
return createStringError(errorToErrorCode(std::move(Err)), "%s",
Filename.str().c_str());
std::string Name = (Filename + "(" + NameOrErr.get() + ")").str();
if (Error Err = handleBuffer(Readers, Name, BuffOrErr.get()))
return createStringError(errorToErrorCode(std::move(Err)), "%s",
Filename.str().c_str());
}
return Error::success();
}
```
But this error is never checked or returned.
So the variable is destroyed when it goes out of scope, which leads to an exception since the error checking is now mandatory before its deletoin, even if tis a success.
I've tried a simple fix which seems to to the job, but I don't know if it's the best way to fix this issue:
```
Error LVReaderHandler::handleArchive(LVReaders &Readers, StringRef Filename,
Archive &Arch) {
Error Err = Error::success();
for (const Archive::Child &Child : Arch.children(Err)) {
Expected<MemoryBufferRef> BuffOrErr = Child.getMemoryBufferRef();
if (Error Err = BuffOrErr.takeError())
return createStringError(errorToErrorCode(std::move(Err)), "%s",
Filename.str().c_str());
Expected<StringRef> NameOrErr = Child.getName();
if (Error Err = NameOrErr.takeError())
return createStringError(errorToErrorCode(std::move(Err)), "%s",
Filename.str().c_str());
std::string Name = (Filename + "(" + NameOrErr.get() + ")").str();
if (Error Err = handleBuffer(Readers, Name, BuffOrErr.get()))
return createStringError(errorToErrorCode(std::move(Err)), "%s",
Filename.str().c_str());
}
// FIX HERE : the variable is always checked
if (Err)
{
return Error::success();
}
return Err;
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsV1ur4zYQ_jXKy7DBke3EechDruyBdgtnl6VvRbbGsXZlKUhysvn3ZWQ7SQ9lL4Wyp9DDIbaSuXwz4_nGI7xXR4O4YvmG5buJ6EJj3Up0DrVCk-aT0srr6slAaBBqpRFYvmlCOHmWrhk_MH44qtB05bSyLeMHrc_j5c3J2U9YBcYPpbYl44dWKPMgo-i7HZbd8cnUlvHDL_aoKqE_KrzQ6eMzConurTBSo5tWpxPLd4wXP889X7JkzZL1hwYdgvIxK4zzF7KELV038bB2VaPOyDiHFkNjJTBeCGc7I0Erg7BIGV_CpVFVQxY7jxKCBW2FBEnoQJnaulYEZY2H2tkWtCqdcAr99IYHauV8AB9EwBZNgMqhCAgCtK2EJpR756wjIGfhlCg1Es6oz-bJ8J-soxR8T0TFKOSB8flwy_gW3genzPEZazgojUa0yPiWJWsYVEmcbilwttjQL9B_xIrC2_3zPp57LHvngKW7_tQj8V1VofeMF1STdDOEQTq1dZTiyhofRoe90rZRmtI_H27SHtC0oqNDw3ixd44MPuAC2H85YRVQsnT7K7bWXTddXaN7xpqle6DDb26EGC1PjxheSj4AJZuqht7bQ3g3S9MgPuNQrKKHQ2oOQ-fMUNc-xaMQ0vWDjcetlVQbH2QfdWtjrW6RUYEY54znPl5iYcY6TX0YnE6rP273f4H-kI5bnSkR70SLf5OId7H6347-pv66o78Z9hFChB3xM16MZoDxTe-koG6j0z26I4be7F1q2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