[Lldb-commits] [lldb] [LLDB] Add assignment to DIL. (PR #190223)
via lldb-commits
lldb-commits at lists.llvm.org
Wed Apr 22 10:49:14 PDT 2026
================
@@ -817,41 +817,201 @@ 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 AssignConvertType 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 AssignConvertType::UnrecognizedType;
+
+ // Make sure rhs is a legal type for DIL assignment.
+ if (!rhs_type.IsInteger() && !rhs_type.IsUnscopedEnumerationType() &&
+ !HasFloatingRepresentation(rhs_type) && !rhs_type.IsPointerType())
+ return AssignConvertType::UnrecognizedType;
+
+ // Only allow assigning pointers to pointers.
+ if ((lhs_type.IsPointerType() && !rhs_type.IsPointerType()) ||
+ (!lhs_type.IsPointerType() && rhs_type.IsPointerType()))
+ return AssignConvertType::UnrecognizedType;
+
+ // Only allow assigning floats or doubles to floats, doubles or ints.
+ if (HasFloatingRepresentation(rhs_type) &&
+ !HasFloatingRepresentation(lhs_type) && !lhs_type.IsInteger())
+ return AssignConvertType::UnrecognizedType;
+
+ // Check for int-float-double conversions (the only kind we do for
+ // assignments. Note: For assignments we only ever convert the RHS,
+ // never the LHS.
+ if (lhs_type == rhs_type)
+ return AssignConvertType::None;
+
+ if (HasFloatingRepresentation(lhs_type) ||
+ HasFloatingRepresentation(rhs_type)) {
+ if (rhs_type.IsInteger() || rhs_type.IsUnscopedEnumerationType()) {
+ if (lhs_type.GetTypeName(false) == "float")
+ return AssignConvertType::IntToFloat;
+ else if (lhs_type.GetTypeName(false) == "double")
+ return AssignConvertType::IntToDouble;
+ else
+ return AssignConvertType::UnrecognizedType;
+ } else if (rhs_type.GetTypeName(false) == "float") {
+ if (lhs_type.IsInteger())
+ return AssignConvertType::FloatToInt;
+ if (lhs_type.GetTypeName(false) == "double")
+ return AssignConvertType::FloatToDouble;
+ ;
+ } else if (rhs_type.GetTypeName(false) == "double") {
+ if (lhs_type.IsInteger())
+ return AssignConvertType::DoubleToInt;
+ else if (lhs_type.GetTypeName(false) == "float")
+ return AssignConvertType::DoubleToFloat;
+ } else
+ return AssignConvertType::UnrecognizedType;
+ }
+
+ return AssignConvertType::None;
+}
+
+static llvm::APFloat GetAPFloat(lldb::ValueObjectSP rhs,
+ AssignConvertType conversion) {
+ switch (conversion) {
+ case AssignConvertType::IntToFloat: {
+ // float = int. lhs is float, rhs is int.
+ auto value_or_err = rhs->GetValueAsAPSInt();
+ if (value_or_err) {
+ float f_val = float(value_or_err->roundToDouble());
+ llvm::APFloat ap_float(f_val);
+ return ap_float;
+ }
+ } break;
+ case AssignConvertType::IntToDouble: {
+ // double = int. lhs is double, rhs is int.
+ auto value_or_err = rhs->GetValueAsAPSInt();
+ if (value_or_err) {
+ double d_val = value_or_err->roundToDouble();
+ llvm::APFloat ap_float(d_val);
+ return ap_float;
+ }
+ } break;
+ case AssignConvertType::DoubleToFloat: {
+ // float = double. lhs is float, rhs is double.
+ auto value_or_err = rhs->GetValueAsAPFloat();
+ if (value_or_err) {
+ double d_val = value_or_err->convertToDouble();
+ float f_val = static_cast<float>(d_val);
----------------
cmtice wrote:
Not really; but we've decided to remove these conversions anyway (they're not legal/accepted in all languages). If a user wants to assign a type that needs a conversion, they'll need to do an explicit cast.
https://github.com/llvm/llvm-project/pull/190223
More information about the lldb-commits
mailing list