Closed Focshole closed 1 year ago
@llvm/issue-subscribers-orcjit
HI @Focshole,
I don't think this is a bug. cantFail
is effectively an assertion: "this value will always be success". Passing a failure value to cantFail
will result in a call to llvm_unreachable
, and there's no guarantee that the error (or anything else) will be freed.
You should only use cantFail
if you are certain that the object that you are adding to the JIT will be added successfully.
In general you want to either propagate the Error or handle it:
if (auto Err = lm.add(rt,std::move(TSM)))
return Err;
or
if (auto Err =
handleErrors(
lm.add(rt, std::move(TSM)),
[](const DuplicateDefinition &DD) {
// Handle duplicates.
}))
return Err; // Return any other errors to the caller.
I don't think this is a bug.
cantFail
is effectively an assertion: "this value will always be success". Passing a failure value tocantFail
will result in a call tollvm_unreachable
, and there's no guarantee that the error (or anything else) will be freed.
Ouch,
/// Report a fatal error if Err is a failure value.
///
/// This function can be used to wrap calls to fallible functions ONLY when it
/// is known that the Error will always be a success value
You are right, I had used it improperly. I do not find a meaning in wrapping errors which are known to not happen, it looks like a fancy way to do a llvm::consumeError and ignore it except when running on debug, but it makes sense I guess. Thank you!
Hello everyone, I had found a memory leak in llvm's error handling in ORCv2, llvm 15.0.7. The original code exits only if compiled as debug due to a llvm::orc::DuplicateDefinition error.
I had triggered the issue while doing (simplified the code):
Assume orc to be properly initialized when running that piece of code.
The issue won't happen when "fixing" the code in this way
The relevant valgrind output is the following:
Probably the issue is around here:
https://github.com/llvm/llvm-project/blob/8dfdcc7b7bf66834a761bd8de445840ef68e4d1a/llvm/include/llvm/ExecutionEngine/Orc/Core.h#L1822
Or here: https://github.com/llvm/llvm-project/blob/8dfdcc7b7bf66834a761bd8de445840ef68e4d1a/llvm/lib/ExecutionEngine/Orc/Core.cpp#L1691
But I have no clue so far.