aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2025-06-26 14:54:20 +0200
committerGitHub <noreply@github.com>2025-06-26 14:54:20 +0200
commit88c208d1fbbaa250adb07637b3002d4df38af962 (patch)
treec892c496618cbc970cbb0c70dae9ee86ca94b02c
parent62e797b9d15d32b7db906e99e98f0943bf2aa6e3 (diff)
parent1fbc5641c0212dc30ea514f69a640a6d1fb5bd11 (diff)
Merge pull request #5408 from slowhei/master
Fix bug where compiler treats uint enums as ints
-rw-r--r--src/types.cpp3
-rw-r--r--tests/internal/test_signedness_comparisons.odin34
2 files changed, 37 insertions, 0 deletions
diff --git a/src/types.cpp b/src/types.cpp
index 19df3de9d..74da7f6aa 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -1248,6 +1248,9 @@ gb_internal bool is_type_unsigned(Type *t) {
if (t->kind == Type_Basic) {
return (t->Basic.flags & BasicFlag_Unsigned) != 0;
}
+ if (t->kind == Type_Enum) {
+ return (t->Enum.base_type->Basic.flags & BasicFlag_Unsigned) != 0;
+ }
return false;
}
gb_internal bool is_type_integer_128bit(Type *t) {
diff --git a/tests/internal/test_signedness_comparisons.odin b/tests/internal/test_signedness_comparisons.odin
new file mode 100644
index 000000000..5e7431c7a
--- /dev/null
+++ b/tests/internal/test_signedness_comparisons.odin
@@ -0,0 +1,34 @@
+package test_internal
+
+import "core:testing"
+
+@test
+test_comparisons_5408 :: proc(t: ^testing.T) {
+ // See: https://github.com/odin-lang/Odin/pull/5408
+ test_proc :: proc(lhs: $T, rhs: T) -> bool {
+ return lhs > rhs
+ }
+
+ Test_Enum :: enum u32 {
+ SMALL_VALUE = 0xFF,
+ BIG_VALUE = 0xFF00_0000, // negative if interpreted as i32
+ }
+
+ testing.expect_value(t, test_proc(Test_Enum.SMALL_VALUE, Test_Enum.BIG_VALUE), false)
+ testing.expect_value(t, test_proc(Test_Enum(0xF), Test_Enum.BIG_VALUE), false)
+ testing.expect_value(t, test_proc(Test_Enum(0xF), Test_Enum(0xF000_0000)), false)
+ testing.expect_value(t, test_proc(Test_Enum.SMALL_VALUE, max(Test_Enum)), false)
+ testing.expect_value(t, test_proc(Test_Enum(0xF), max(Test_Enum)), false)
+}
+
+test_signedness :: proc(t: ^testing.T) {
+ {
+ a, b := i16(32767), i16(0)
+ testing.expect_value(t, a > b, true)
+ }
+
+ {
+ a, b := u16(65535), u16(0)
+ testing.expect_value(t, a > b, true)
+ }
+} \ No newline at end of file