Skip to content

Commit 768cb11

Browse files
committed
LLVM: Implement UnsignedIntegerToInteger cast
1 parent 7d532ac commit 768cb11

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/libasr/codegen/asr_to_llvm.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6764,6 +6764,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
67646764
case (ASR::cast_kindType::IntegerToUnsignedInteger) : {
67656765
int arg_kind = -1, dest_kind = -1;
67666766
extract_kinds(x, arg_kind, dest_kind);
6767+
LCOMPILERS_ASSERT(arg_kind != -1 && dest_kind != -1)
67676768
if( arg_kind > 0 && dest_kind > 0 &&
67686769
arg_kind != dest_kind )
67696770
{
@@ -6776,7 +6777,18 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
67766777
break;
67776778
}
67786779
case (ASR::cast_kindType::UnsignedIntegerToInteger) : {
6779-
// tmp = tmp
6780+
int arg_kind = -1, dest_kind = -1;
6781+
extract_kinds(x, arg_kind, dest_kind);
6782+
LCOMPILERS_ASSERT(arg_kind != -1 && dest_kind != -1)
6783+
if( arg_kind > 0 && dest_kind > 0 &&
6784+
arg_kind != dest_kind )
6785+
{
6786+
if (dest_kind > arg_kind) {
6787+
tmp = builder->CreateSExt(tmp, getIntType(dest_kind));
6788+
} else {
6789+
tmp = builder->CreateTrunc(tmp, getIntType(dest_kind));
6790+
}
6791+
}
67806792
break;
67816793
}
67826794
case (ASR::cast_kindType::CPtrToUnsignedInteger) : {

0 commit comments

Comments
 (0)