@@ -5345,7 +5345,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
53455345 tmp = builder->CreateNot (tmp);
53465346 }
53475347
5348- void visit_IntegerUnaryMinus (const ASR::IntegerUnaryMinus_t &x) {
5348+ template <typename T>
5349+ void handle_SU_IntegerUnaryMinus (const T& x) {
53495350 if (x.m_value ) {
53505351 this ->visit_expr_wrapper (x.m_value , true );
53515352 return ;
@@ -5356,15 +5357,12 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
53565357 tmp = builder->CreateSub (zero, tmp);
53575358 }
53585359
5360+ void visit_IntegerUnaryMinus (const ASR::IntegerUnaryMinus_t &x) {
5361+ handle_SU_IntegerUnaryMinus (x);
5362+ }
5363+
53595364 void visit_UnsignedIntegerUnaryMinus (const ASR::UnsignedIntegerUnaryMinus_t &x) {
5360- if (x.m_value ) {
5361- this ->visit_expr_wrapper (x.m_value , true );
5362- return ;
5363- }
5364- this ->visit_expr_wrapper (x.m_arg , true );
5365- int kind = ASRUtils::extract_kind_from_ttype_t (ASRUtils::expr_type (x.m_arg ));
5366- llvm::Value *one = llvm::ConstantInt::get (context, llvm::APInt (kind * 8 , 1 , true ));
5367- tmp = builder->CreateAdd (builder->CreateNot (tmp), one); // compute 2's complement
5365+ handle_SU_IntegerUnaryMinus (x);
53685366 }
53695367
53705368 void visit_RealUnaryMinus (const ASR::RealUnaryMinus_t &x) {
@@ -6025,8 +6023,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
60256023 }
60266024 break ;
60276025 }
6028- case (ASR::cast_kindType::IntegerToInteger) :
6029- case (ASR::cast_kindType::UnsignedIntegerToUnsignedInteger) : {
6026+ case (ASR::cast_kindType::IntegerToInteger) : {
60306027 int arg_kind = -1 , dest_kind = -1 ;
60316028 extract_kinds (x, arg_kind, dest_kind);
60326029 if ( arg_kind > 0 && dest_kind > 0 &&
@@ -6040,6 +6037,20 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
60406037 }
60416038 break ;
60426039 }
6040+ case (ASR::cast_kindType::UnsignedIntegerToUnsignedInteger) : {
6041+ int arg_kind = -1 , dest_kind = -1 ;
6042+ extract_kinds (x, arg_kind, dest_kind);
6043+ if ( arg_kind > 0 && dest_kind > 0 &&
6044+ arg_kind != dest_kind )
6045+ {
6046+ if (dest_kind > arg_kind) {
6047+ tmp = builder->CreateZExt (tmp, llvm_utils->getIntType (dest_kind));
6048+ } else {
6049+ tmp = builder->CreateTrunc (tmp, llvm_utils->getIntType (dest_kind));
6050+ }
6051+ }
6052+ break ;
6053+ }
60436054 case (ASR::cast_kindType::IntegerToUnsignedInteger) : {
60446055 int arg_kind = -1 , dest_kind = -1 ;
60456056 extract_kinds (x, arg_kind, dest_kind);
0 commit comments