Skip to content

Commit

Permalink
Fix comparing two unsigned types
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuli committed Dec 26, 2023
1 parent 075ea5c commit a01abf6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,11 @@ static void codegen_instruction(const struct State *st, const CfInstruction *ins
setdest(LLVMBuildFCmp(st->builder, LLVMRealOEQ, getop(0), getop(1), "num_eq"));
break;
case CF_NUM_LT:
if (is_integer_type(ins->operands[0]->type))
// TODO: unsigned less than
if (ins->operands[0]->type->kind == TYPE_UNSIGNED_INTEGER && ins->operands[1]->type->kind == TYPE_UNSIGNED_INTEGER)
setdest(LLVMBuildICmp(st->builder, LLVMIntULT, getop(0), getop(1), "num_lt"));
else if (is_integer_type(ins->operands[0]->type) && is_integer_type(ins->operands[1]->type))
setdest(LLVMBuildICmp(st->builder, LLVMIntSLT, getop(0), getop(1), "num_lt"));
else
// TODO: signed less than
setdest(LLVMBuildFCmp(st->builder, LLVMRealOLT, getop(0), getop(1), "num_lt"));
break;
}
Expand Down
18 changes: 18 additions & 0 deletions tests/should_succeed/compare_bytes.jou
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import "stdlib/io.jou"


def main() -> int:
a = 0 as byte
b = 100 as byte
c = 200 as byte

printf("%d %d %d\n", a < b, b < b, c < b) # Output: 1 0 0
printf("%d %d %d\n", a > b, b > b, c > b) # Output: 0 0 1

printf("%d %d %d\n", a <= b, b <= b, c <= b) # Output: 1 1 0
printf("%d %d %d\n", a >= b, b >= b, c >= b) # Output: 0 1 1

printf("%d %d %d\n", a == b, b == b, c == b) # Output: 0 1 0
printf("%d %d %d\n", a != b, b != b, c != b) # Output: 1 0 1

return 0

0 comments on commit a01abf6

Please sign in to comment.