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

Creating bit field using non-constant variables breaking code gen #3556

Closed
jockus opened this issue May 8, 2024 · 1 comment
Closed

Creating bit field using non-constant variables breaking code gen #3556

jockus opened this issue May 8, 2024 · 1 comment

Comments

@jockus
Copy link
Contributor

jockus commented May 8, 2024

Context

Creating bit field using non-constant variables causing a code gen failure.

package main

Foo :: bit_field u32 {
	val : int | 10,
}

main :: proc() {
	foo : Foo

	foo = Foo{val = 1}

	a :: 5
	foo = Foo{val = a}

	b := 5
	foo = Foo{val = b} // code gen failure
}

  • Operating System & Odin Version:
    Odin: dev-2024-05
    OS: Windows 10 Enterprise
    Backend: LLVM 17.0.1

Expected Behavior

No code gen failure.

Current Behavior

Code gen failure

Failure Information (for bugs)

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. Compile above code
  2. See code gen failure

Failure Logs

|| [build.bat]
|| LLVM CODE GEN FAILED FOR PROCEDURE: main.main
|| define internal void @main.main(ptr noalias nocapture nonnull %__.context_ptr) {
|| decls:
||   %foo = alloca i32, align 4
||   %0 = alloca i32, align 4
||   %1 = alloca i32, align 4
||   %b = alloca i64, align 8
||   %2 = alloca i32, align 4
||   br label %entry
|| 
|| entry:                                            ; preds = %decls
||   store i32 0, ptr %foo, align 4
||   store i32 0, ptr %0, align 4
||   store i32 1, ptr %0, align 4
||   %3 = load i32, ptr %0, align 4
||   store i32 %3, ptr %foo, align 4
||   store i32 0, ptr %1, align 4
||   store i32 5, ptr %1, align 4
||   %4 = load i32, ptr %1, align 4
||   store i32 %4, ptr %foo, align 4
||   store i64 5, ptr %b, align 8
||   store i32 0, ptr %2, align 4
||   %5 = load i64, ptr %b, align 8
||   %6 = zext i64 %5 to i32
||   %7 = and i32 %6, 1023
||   %8 = shl i32 %7, 0
||   %9 = or i32 0, %8
||   store i32 %9, ptr %2, align 4
||   %10 = load i32, ptr %2, align 4
||   store i32 %10, ptr %foo, align 4
||   ret void
|| }
|| 
|| 
|| 
|| 
|| Type too small for ZExt
||   %6 = zext i64 %5 to i32
|| [Finished in 0 seconds with code 1]

@jockus
Copy link
Contributor Author

jockus commented May 9, 2024

This seems to specifically be the case when an individual field type is larger than the bit field type. val : int | 10 to val : u32 | 10 works fine.

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

No branches or pull requests

1 participant