Skip to content

Commit 5c1d768

Browse files
authored
[lldb][ClangExpressionParser] Log and assert on failure to create TargetInfo (#101697)
`CreateTargetInfo` can return a `nullptr` in a couple cases. So we should log that and let the user know something is wrong (hence the `lldbassert`). I didn't actually run into this. Just stumbled upon it from reading the code.
1 parent 1fcddc0 commit 5c1d768

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -495,18 +495,24 @@ ClangExpressionParser::ClangExpressionParser(
495495
// A value of 0 means no limit for both LLDB and Clang.
496496
m_compiler->getDiagnostics().setErrorLimit(target_sp->GetExprErrorLimit());
497497

498-
auto target_info = TargetInfo::CreateTargetInfo(
499-
m_compiler->getDiagnostics(), m_compiler->getInvocation().TargetOpts);
500-
if (log) {
501-
LLDB_LOGF(log, "Target datalayout string: '%s'",
502-
target_info->getDataLayoutString());
503-
LLDB_LOGF(log, "Target ABI: '%s'", target_info->getABI().str().c_str());
504-
LLDB_LOGF(log, "Target vector alignment: %d",
505-
target_info->getMaxVectorAlign());
506-
}
507-
m_compiler->setTarget(target_info);
498+
if (auto *target_info = TargetInfo::CreateTargetInfo(
499+
m_compiler->getDiagnostics(),
500+
m_compiler->getInvocation().TargetOpts)) {
501+
if (log) {
502+
LLDB_LOGF(log, "Target datalayout string: '%s'",
503+
target_info->getDataLayoutString());
504+
LLDB_LOGF(log, "Target ABI: '%s'", target_info->getABI().str().c_str());
505+
LLDB_LOGF(log, "Target vector alignment: %d",
506+
target_info->getMaxVectorAlign());
507+
}
508+
m_compiler->setTarget(target_info);
509+
} else {
510+
if (log)
511+
LLDB_LOGF(log, "Failed to create TargetInfo for '%s'",
512+
m_compiler->getTargetOpts().Triple.c_str());
508513

509-
assert(m_compiler->hasTarget());
514+
lldbassert(false && "Failed to create TargetInfo.");
515+
}
510516

511517
// 4. Set language options.
512518
lldb::LanguageType language = expr.Language().AsLanguageType();

0 commit comments

Comments
 (0)