================
@@ -465,18 +465,24 @@ ClangExpressionParser::ClangExpressionParser(
// A value of 0 means no limit for both LLDB and Clang.
m_compiler->getDiagnostics().setErrorLimit(target_sp->GetExprErrorLimit());
- auto target_info = TargetInfo::CreateTargetInfo(
- m_compiler->getDiagnostics(), m_compiler->getInvocation().TargetOpts);
- if (log) {
- LLDB_LOGF(log, "Target datalayout string: '%s'",
- target_info->getDataLayoutString());
- LLDB_LOGF(log, "Target ABI: '%s'", target_info->getABI().str().c_str());
- LLDB_LOGF(log, "Target vector alignment: %d",
- target_info->getMaxVectorAlign());
- }
- m_compiler->setTarget(target_info);
+ if (auto *target_info = TargetInfo::CreateTargetInfo(
+ m_compiler->getDiagnostics(),
+ m_compiler->getInvocation().TargetOpts)) {
+ if (log) {
+ LLDB_LOGF(log, "Target datalayout string: '%s'",
+ target_info->getDataLayoutString());
+ LLDB_LOGF(log, "Target ABI: '%s'", target_info->getABI().str().c_str());
+ LLDB_LOGF(log, "Target vector alignment: %d",
+ target_info->getMaxVectorAlign());
+ }
+ m_compiler->setTarget(target_info);
+ } else {
+ if (log)
+ LLDB_LOGF(log, "Failed to create TargetInfo for '%s'",
+ m_compiler->getTargetOpts().Triple.c_str());
- assert(m_compiler->hasTarget());
+ lldbassert(false && "Failed to create TargetInfo.");
----------------
Michael137 wrote:
It's a bit awkward because this all happens in the constructor. And stopping
the construction half-way probably won't buy us much. I think this is one of
those unusual circumstance where we want to assert at runtime. I guess we could
have a separate `Init` method for the `ClangExpressionParser`. Which returns
`Expected`. Then update all the users to check the return of that.
But that's a larger refactor that we can do at some later point.
What used to happen in release builds (tbh I'm not sure if this ever really
gets exercised in practice), is that `target_info` was a `nullptr`. And we just
happily continued with the construction of the object.
https://github.com/llvm/llvm-project/pull/101697
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits