================
@@ -740,16 +764,182 @@ Interpreter::Visit(const BooleanLiteralNode *node) {
   return ValueObject::CreateValueObjectFromBool(m_target, value, "result");
 }
 
+llvm::Expected<CastKind>
+Interpreter::VerifyCastType(lldb::ValueObjectSP operand, CompilerType op_type,
+                            CompilerType target_type, int location) {
+
+  if (target_type.IsScalarType()) {
+    if (op_type.IsPointerType() || op_type.IsNullPtrType()) {
+      // Cast from pointer to float/double is not allowed.
+      if (target_type.IsFloat()) {
+        std::string errMsg = llvm::formatv(
+            "Cast from {0} to {1} is not allowed", op_type.TypeDescription(),
+            target_type.TypeDescription());
+        return llvm::make_error<DILDiagnosticError>(
+            m_expr, std::move(errMsg), location,
+            op_type.TypeDescription().length());
+      }
+      // Casting pointer to bool is valid. Otherwise check if the result type
+      // is at least as big as the pointer size.
----------------
Michael137 wrote:

I would have an early return here:
```
if (target_type.IsBoolean())
  return CastKind::eArithmetic;
```

Makes the logic easier to read imo

https://github.com/llvm/llvm-project/pull/170332
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to