[Lldb-commits] [lldb] [lldb] Add arithmetic binary addition to DIL (PR #177208)

Michael Buch via lldb-commits lldb-commits at lists.llvm.org
Mon Feb 16 03:22:49 PST 2026


================
@@ -127,6 +127,87 @@ Interpreter::UnaryConversion(lldb::ValueObjectSP valobj, uint32_t location) {
   return valobj;
 }
 
+static size_t IntegerConversionRank(CompilerType type) {
+  switch (type.GetCanonicalType().GetBasicTypeEnumeration()) {
+  case lldb::eBasicTypeBool:
+    return 1;
+  case lldb::eBasicTypeChar:
+  case lldb::eBasicTypeSignedChar:
+  case lldb::eBasicTypeUnsignedChar:
+    return 2;
+  case lldb::eBasicTypeShort:
+  case lldb::eBasicTypeUnsignedShort:
+    return 3;
+  case lldb::eBasicTypeInt:
+  case lldb::eBasicTypeUnsignedInt:
+    return 4;
+  case lldb::eBasicTypeLong:
+  case lldb::eBasicTypeUnsignedLong:
+    return 5;
+  case lldb::eBasicTypeLongLong:
+  case lldb::eBasicTypeUnsignedLongLong:
+    return 6;
+  case lldb::eBasicTypeInt128:
+  case lldb::eBasicTypeUnsignedInt128:
+    return 7;
+  default:
+    break;
+  }
+  return 0;
+}
+
+llvm::Expected<CompilerType>
+Interpreter::ArithmeticConversion(lldb::ValueObjectSP &lhs,
+                                  lldb::ValueObjectSP &rhs, uint32_t location) {
+  // Apply unary conversion for both operands.
+  auto lhs_or_err = UnaryConversion(lhs, location);
+  if (!lhs_or_err)
+    return lhs_or_err.takeError();
+  lhs = *lhs_or_err;
+  auto rhs_or_err = UnaryConversion(rhs, location);
+  if (!rhs_or_err)
+    return rhs_or_err.takeError();
+  rhs = *rhs_or_err;
+
+  CompilerType lhs_type = lhs->GetCompilerType();
+  CompilerType rhs_type = rhs->GetCompilerType();
+
+  if (lhs_type.CompareTypes(rhs_type))
+    return lhs_type;
+
+  // If either of the operands is not arithmetic (e.g. pointer), we're done.
+  if (!lhs_type.IsScalarType() || !rhs_type.IsScalarType())
+    return CompilerType();
+
+  // Handle conversions for floating types (float, double).
+  if (lhs_type.IsRealFloatingPointType() ||
+      rhs_type.IsRealFloatingPointType()) {
+    // If both are floats, convert the smaller operand to the bigger.
+    if (lhs_type.IsRealFloatingPointType() &&
+        rhs_type.IsRealFloatingPointType()) {
+      if (lhs_type.GetBasicTypeEnumeration() >
+          rhs_type.GetBasicTypeEnumeration())
+        return lhs_type;
+      return rhs_type;
----------------
Michael137 wrote:

Should this also be based on `IntegerConversionRank`?

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


More information about the lldb-commits mailing list