Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLVM: Support Unsigned Int in visit_Variable #2171

Merged
merged 2 commits into from
Jul 17, 2023

Conversation

Smit-create
Copy link
Collaborator

Fixes #2170

Copy link
Contributor

@certik certik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, but after merging let's add tests for all unsigned kinds as well as checking that the value is present in the variable correctly.

What exactly was the problem --- that this is using global variables?

@certik certik marked this pull request as ready for review July 17, 2023 14:58
@certik certik enabled auto-merge July 17, 2023 14:59
@certik certik merged commit ea9715b into lcompilers:main Jul 17, 2023
9 checks passed
@Shaikh-Ubaid
Copy link
Collaborator

Please see #2170 (comment). I think the else if condition added in this PR would never be executed since the first if in the visit_Variable() would be executed for Integers as well as UnsingedIntegers. Thus, it seems the else if condition is more like a dead code.

if (x.m_type->type == ASR::ttypeType::Integer
|| x.m_type->type == ASR::ttypeType::UnsignedInteger) {
int a_kind = ASRUtils::extract_kind_from_ttype_t(x.m_type);
llvm::Type *type;
int init_value_bits = 8*a_kind;
type = llvm_utils->getIntType(a_kind);
llvm::Constant *ptr = module->getOrInsertGlobal(x.m_name,
type);
if (!external) {
if (ASRUtils::is_array(x.m_type)) {
throw CodeGenError("Arrays are not supported by visit_Variable");
}
if (init_value) {
module->getNamedGlobal(x.m_name)->setInitializer(
init_value);
} else {
module->getNamedGlobal(x.m_name)->setInitializer(
llvm::ConstantInt::get(context,
llvm::APInt(init_value_bits, 0)));
}
}
llvm_symtab[h] = ptr;
} else if (x.m_type->type == ASR::ttypeType::UnsignedInteger) {

@Shaikh-Ubaid
Copy link
Collaborator

This is fine, but after merging let's add tests for all unsigned kinds as well as checking that the value is present in the variable correctly.

Yes, I tested different unsigned kinds in https://github.com/lcompilers/lpython/pull/2164/files#diff-b6a08444f0697e1ea781c919bcdf3b29eba7b542bddef56ce0125f3c2997c973.

x : i32

for i in range(i32(u)):
x = i * 2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If in case we update the changes in this PR, I suggest we add an assert in this test case (and also possibly a print statement before the assert).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

type casting between u16 and i32 needed
3 participants