[Lldb-commits] [lldb] [LLDB] Add assignment to DIL. (PR #190223)

via lldb-commits lldb-commits at lists.llvm.org
Thu Apr 23 08:19:47 PDT 2026


================
@@ -812,6 +814,79 @@ llvm::Expected<lldb::ValueObjectSP> Interpreter::EvaluateBinaryRemainder(
   return EvaluateScalarOp(BinaryOpKind::Rem, lhs, rhs, result_type, location);
 }
 
+static bool HasFloatingRepresentation(CompilerType ct) {
+  return ct.GetTypeInfo() & lldb::eTypeIsFloat;
+}
+
+static std::string VerifyAssignmentTypes(CompilerType lhs_type,
+                                         CompilerType rhs_type) {
+  // Make sure lhs is a legal type for DIL assignment.
+  if (!lhs_type.IsInteger() && !lhs_type.IsUnscopedEnumerationType() &&
+      !HasFloatingRepresentation(lhs_type) && !lhs_type.IsPointerType() &&
+      !lhs_type.IsScalarType())
+    return "Illegal type for lhs of assignment (not scalar numeric type)";
+
+  // Make sure rhs is a legal type for DIL assignment.
+  if (!rhs_type.IsInteger() && !rhs_type.IsUnscopedEnumerationType() &&
+      !HasFloatingRepresentation(rhs_type) && !rhs_type.IsPointerType())
+    return "Illegal type for rhs of assignment (not scalar numeric type)";
+
+  // Only allow assigning pointers to pointers.
+  if ((lhs_type.IsPointerType() && !rhs_type.IsPointerType()) ||
+      (!lhs_type.IsPointerType() && rhs_type.IsPointerType()))
+    return "Invalid assignment: Can only assign pointers to pointers";
+
+  // For "real numbers", the types must match exactly.
+  if ((HasFloatingRepresentation(rhs_type) ||
+       HasFloatingRepresentation(lhs_type)) &&
+      lhs_type != rhs_type)
+    return "Invalid assignment: lhs and rhs have incompatible types";
+
+  return "all ok";
+}
+
+llvm::Expected<lldb::ValueObjectSP>
+Interpreter::EvaluateAssignment(lldb::ValueObjectSP lhs,
+                                lldb::ValueObjectSP rhs, uint32_t location) {
+
+  std::string err_msg =
+      VerifyAssignmentTypes(lhs->GetCompilerType(), rhs->GetCompilerType());
+  if (err_msg != "all ok")
+    return llvm::make_error<DILDiagnosticError>(m_expr, std::move(err_msg),
+                                                location);
+
+  Status status;
+  lhs->SetValueFromInteger(rhs, status, m_allow_var_updates);
+  if (status.Success())
+    return lhs;
+
+  err_msg = std::string(status.AsCString());
+  return llvm::make_error<DILDiagnosticError>(m_expr, std::move(err_msg),
+                                              location);
+}
+
+llvm::Expected<lldb::ValueObjectSP> Interpreter::EvaluateBinaryAddAssign(
+    lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location) {
+
+  auto ret_or_err = EvaluateBinaryAddition(lhs, rhs, location);
+  if (!ret_or_err)
+    return ret_or_err;
+
+  lldb::ValueObjectSP sum = *ret_or_err;
+  return EvaluateAssignment(lhs, sum, location);
+}
----------------
cmtice wrote:

Will do.

https://github.com/llvm/llvm-project/pull/190223


More information about the lldb-commits mailing list