Skip to content

Commit 02e9571

Browse files
committed
Remove some redundant type checks. Clean up code slightly.
1 parent 1646670 commit 02e9571

File tree

1 file changed

+4
-37
lines changed

1 file changed

+4
-37
lines changed

lldb/source/ValueObject/DILEval.cpp

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -672,10 +672,8 @@ llvm::Expected<CompilerType> Interpreter::VerifyCStyleCastType(
672672
uint64_t type_byte_size = 0;
673673
uint64_t rhs_type_byte_size = 0;
674674
if (auto temp = target_type.GetByteSize(m_exe_ctx_scope.get()))
675-
// type_byte_size = temp.value();
676675
type_byte_size = *temp;
677676
if (auto temp = op_type.GetByteSize(m_exe_ctx_scope.get()))
678-
// rhs_type_byte_size = temp.value();
679677
rhs_type_byte_size = *temp;
680678
if (!target_type.IsBoolean() && type_byte_size < rhs_type_byte_size) {
681679
std::string errMsg = llvm::formatv(
@@ -784,30 +782,15 @@ Interpreter::Visit(const CStyleCastNode *node) {
784782

785783
switch (cast_kind) {
786784
case CStyleCastKind::eEnumeration: {
787-
if (!target_type.IsEnumerationType()) {
788-
std::string errMsg = "invalid ast: target type should be an enumeration.";
789-
return llvm::make_error<DILDiagnosticError>(m_expr, std::move(errMsg),
790-
node->GetLocation());
791-
}
792-
if (op_type.IsFloat())
793-
return operand->CastToEnumType(target_type);
794-
795-
if (op_type.IsInteger() || op_type.IsEnumerationType())
785+
if (op_type.IsFloat() || op_type.IsInteger() || op_type.IsEnumerationType())
796786
return operand->CastToEnumType(target_type);
797787

798788
std::string errMsg =
799789
"invalid ast: operand is not convertible to enumeration type";
800790
return llvm::make_error<DILDiagnosticError>(m_expr, std::move(errMsg),
801791
node->GetLocation());
802-
// return error.ToError();
803792
}
804793
case CStyleCastKind::eNullptr: {
805-
if (target_type.GetCanonicalType().GetBasicTypeEnumeration() !=
806-
lldb::eBasicTypeNullPtr) {
807-
std::string errMsg = "invalid ast: target type should be a nullptr_t.";
808-
return llvm::make_error<DILDiagnosticError>(m_expr, std::move(errMsg),
809-
node->GetLocation());
810-
}
811794
return ValueObject::CreateValueObjectFromNullptr(m_target, target_type,
812795
"result");
813796
}
@@ -820,33 +803,17 @@ Interpreter::Visit(const CStyleCastNode *node) {
820803
case CStyleCastKind::eNone: {
821804
switch (promo_kind) {
822805
case CastPromoKind::eArithmetic: {
823-
if (target_type.GetCanonicalType().GetBasicTypeEnumeration() ==
824-
lldb::eBasicTypeInvalid) {
825-
std::string errMsg = "invalid ast: target type should be a basic type.";
826-
return llvm::make_error<DILDiagnosticError>(m_expr, std::move(errMsg),
827-
node->GetLocation());
828-
}
829-
// Pick an appropriate cast.
830-
if (op_type.IsPointerType() || op_type.IsNullPtrType()) {
831-
return operand->CastToBasicType(target_type);
832-
}
833-
if (op_type.IsScalarType()) {
834-
return operand->CastToBasicType(target_type);
835-
}
836-
if (op_type.IsEnumerationType()) {
806+
if (op_type.IsPointerType() || op_type.IsNullPtrType() ||
807+
op_type.IsScalarType() || op_type.IsEnumerationType()) {
837808
return operand->CastToBasicType(target_type);
838809
}
810+
839811
std::string errMsg =
840812
"invalid ast: operand is not convertible to arithmetic type";
841813
return llvm::make_error<DILDiagnosticError>(m_expr, std::move(errMsg),
842814
node->GetLocation());
843815
}
844816
case CastPromoKind::ePointer: {
845-
if (!target_type.IsPointerType()) {
846-
std::string errMsg = "invalid ast: target type should be a pointer";
847-
return llvm::make_error<DILDiagnosticError>(m_expr, std::move(errMsg),
848-
node->GetLocation());
849-
}
850817
uint64_t addr =
851818
op_type.IsArrayType()
852819
? operand->GetLoadAddress()

0 commit comments

Comments
 (0)