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

src/llvm_backend_const.cpp(412): Assertion Failure: sz >= max_count max_count: 7, sz: 4, written: 0, type int #3856

Closed
laytan opened this issue Jul 2, 2024 · 1 comment · Fixed by #4072
Labels
32-bit Bug occurs on 32-bit targets bug

Comments

@laytan
Copy link
Sponsor Collaborator

laytan commented Jul 2, 2024

On 32 bit targets (wasm32, arm32) the following code raises the assertion failure in the title of this issue:

package main

import "core:math"

main :: proc() {
	x := math.round_f64(1)
}
@laytan
Copy link
Sponsor Collaborator Author

laytan commented Aug 12, 2024

Looks like the constant math is acting as if the destination is int, which the value doesn't fit in on 32 bit so it asserts there
Doing this "fixes" it:

diff --git a/core/math/math.odin b/core/math/math.odin
index 3d0ab3c4e..1a76d5244 100644
--- a/core/math/math.odin
+++ b/core/math/math.odin
@@ -805,8 +805,8 @@ round_f64 :: proc "contextless" (x: f64) -> f64 {
             bits |= transmute(u64)f64(1)
         }
     } else if e < bias + shift {
-        half     :: 1 << (shift - 1)
-        mantissa :: (1 << shift) - 1
+        half     :: u64(1) << (shift - u64(1))
+        mantissa :: (u64(1) << shift) - u64(1)
         e -= bias
         bits += half >> e
         bits &~= mantissa >> e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
32-bit Bug occurs on 32-bit targets bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant