mirror of
https://github.com/odin-lang/Odin.git
synced 2026-08-26 06:51:34 +00:00
big endian bool cmp
This commit is contained in:
@@ -2407,6 +2407,13 @@ gb_internal lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t) {
|
||||
// boolean -> boolean/integer
|
||||
if (is_type_boolean(src) && (is_type_boolean(dst) || is_type_integer(dst))) {
|
||||
LLVMValueRef b = LLVMBuildICmp(p->builder, LLVMIntNE, value.value, LLVMConstNull(lb_type(m, value.type)), "");
|
||||
if (type_size_of(default_type(dst)) > 1 && is_type_different_to_arch_endianness(dst)) {
|
||||
Type *platform_dst_type = integer_endian_type_to_platform_type(dst);
|
||||
lbValue res = {};
|
||||
res.value = LLVMBuildIntCast2(p->builder, b, lb_type(m, platform_dst_type), false, "");
|
||||
res.type = t;
|
||||
return lb_emit_byte_swap(p, res, t);
|
||||
}
|
||||
lbValue res = {};
|
||||
res.value = LLVMBuildIntCast2(p->builder, b, lb_type(m, t), false, "");
|
||||
res.type = t;
|
||||
|
||||
@@ -43,6 +43,7 @@ set COMMON=-define:ODIN_TEST_FANCY=false -file -vet -strict-style -ignore-unused
|
||||
..\..\..\odin test ..\test_issue_7008.odin %COMMON% || exit /b
|
||||
..\..\..\odin check ..\test_issue_7012.odin -no-entry-point %COMMON% || exit /b
|
||||
..\..\..\odin check ..\test_issue_7260.odin -no-entry-point %COMMON% || exit /b
|
||||
..\..\..\odin test ..\test_issue_bool_to_be_conversion.odin %COMMON% || exit /b
|
||||
..\..\..\odin check ..\test_issue_asm_named_register_slot.odin -no-entry-point %COMMON% 2>&1 | find /c "Error:" | findstr /x "8" || exit /b
|
||||
..\..\..\odin check ..\test_issue_ellipsis_type_call.odin -no-entry-point %COMMON% 2>&1 | find /c "Error:" | findstr /x "10" || exit /b
|
||||
..\..\..\odin check ..\test_issue_foreign_redeclaration.odin -no-entry-point %COMMON% || exit /b
|
||||
|
||||
@@ -95,6 +95,7 @@ $ODIN test ../test_issue_7356.odin $COMMON
|
||||
$ODIN build ../test_issue_7167.odin $COMMON
|
||||
$ODIN build ../test_issue_7188.odin $COMMON
|
||||
$ODIN check ../test_issue_7260.odin -no-entry-point $COMMON_CHECK
|
||||
$ODIN test ../test_issue_bool_to_be_conversion.odin $COMMON
|
||||
|
||||
# `asm` templates are amd64-only, so this file is empty on every other architecture
|
||||
if [[ "$(uname -m)" == "x86_64" || "$(uname -m)" == "amd64" ]]; then
|
||||
|
||||
37
tests/issues/test_issue_bool_to_be_conversion.odin
Normal file
37
tests/issues/test_issue_bool_to_be_conversion.odin
Normal file
@@ -0,0 +1,37 @@
|
||||
package test_issues
|
||||
|
||||
import "core:testing"
|
||||
|
||||
// Converting a boolean to a big-endian integer skipped the endian fixup that the integer source
|
||||
// path performs, so the result carried a native bit pattern labelled big-endian. The checker
|
||||
// folded the same conversion to the right value, so only the runtime disagreed.
|
||||
|
||||
@(test)
|
||||
bool_to_big_endian :: proc(t: ^testing.T) {
|
||||
b: bool = true
|
||||
f: bool = false
|
||||
b8v: b8 = true
|
||||
b16v: b16 = true
|
||||
b32v: b32 = true
|
||||
b64v: b64 = true
|
||||
i: int = 1
|
||||
|
||||
testing.expect_value(t, int(i16be(b)), 1)
|
||||
testing.expect_value(t, int(u32be(b)), 1)
|
||||
testing.expect_value(t, int(u64be(b)), 1)
|
||||
testing.expect_value(t, int(u128be(b)), 1)
|
||||
testing.expect_value(t, int(i16be(f)), 0)
|
||||
|
||||
testing.expect_value(t, int(i16be(b8v)), 1)
|
||||
testing.expect_value(t, int(i16be(b16v)), 1)
|
||||
testing.expect_value(t, int(i16be(b32v)), 1)
|
||||
testing.expect_value(t, int(i16be(b64v)), 1)
|
||||
|
||||
// the little-endian target and the integer source were already correct
|
||||
testing.expect_value(t, int(i16le(b)), 1)
|
||||
testing.expect_value(t, int(i16be(i)), 1)
|
||||
|
||||
// the bytes have to actually be big-endian, not a native pattern relabelled
|
||||
testing.expect_value(t, transmute([4]u8)u32be(b), transmute([4]u8)u32be(i))
|
||||
testing.expect_value(t, transmute([4]u8)u32be(b), [4]u8{0, 0, 0, 1})
|
||||
}
|
||||
Reference in New Issue
Block a user