[Lldb-commits] [lldb] 5c1d768 - [lldb][ClangExpressionParser] Log and assert on failure to create TargetInfo (#101697)

via lldb-commits lldb-commits at lists.llvm.org
Fri Aug 2 11:13:44 PDT 2024


Author: Michael Buch
Date: 2024-08-02T19:13:41+01:00
New Revision: 5c1d7689738d144613e7915c0b6ec850dd5c3956

URL: https://github.com/llvm/llvm-project/commit/5c1d7689738d144613e7915c0b6ec850dd5c3956
DIFF: https://github.com/llvm/llvm-project/commit/5c1d7689738d144613e7915c0b6ec850dd5c3956.diff

LOG: [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.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 2d34f657793c3..2bd58d568cc6d 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -495,18 +495,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.");
+  }
 
   // 4. Set language options.
   lldb::LanguageType language = expr.Language().AsLanguageType();


        


More information about the lldb-commits mailing list