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

Compiler Bug: Vector Store #3937

Closed
cshenton opened this issue Dec 18, 2019 · 2 comments
Closed

Compiler Bug: Vector Store #3937

cshenton opened this issue Dec 18, 2019 · 2 comments
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@cshenton
Copy link
Contributor

Ran into a compiler bug while trying to do some SIMD stuff.

Minimal repro, fails on master, macOS:

// bug.zig
pub fn main() void {
    var src : [8]f32 = .{0, 0, 0, 0, 0, 0, 0, 0};
    var vec : @Vector(4, f32) = [4]f32{ src[0..4] };
}

Results in the following LLVM error propagated through zig.

$ zig build-exe src/bug.zig
broken LLVM module found: Stored value type does not match pointer operand type!
  store float* %4, float* %3, !dbg !1064
 floatStored value type does not match pointer operand type!
  store i64 4, float* %5, !dbg !1064
 float
This is a bug in the Zig compiler.
Unable to dump stack trace: debug info stripped
Abort trap: 6
@fengb
Copy link
Contributor

fengb commented Dec 19, 2019

[4]f32{ src[0..4] } — this is trying to make an array where arr[0] = src[0..4]. The compiler should really be catching this failed coercion.

#863 has the accepted proposal for converting slices back to arrays.

In the meantime here's some alternatives:

var vec: @Vector(4, f32) = [4]f32{ src[0], src[1], src[2], src[3] };

// This is so kludgy -- probably should wrap in a function
var array = @ptrCast(*const [4]f32, src[0..4].ptr);
var vec2: @Vector(4, f32) = array.*;

@daurnimator daurnimator added bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend. labels Dec 19, 2019
@andrewrk andrewrk added this to the 0.6.0 milestone Dec 31, 2019
@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Mar 4, 2020
@fengb
Copy link
Contributor

fengb commented May 16, 2020

Compiler now spits out a usable error:

./testa.zig:3:42: error: expected type 'f32', found '*[4]f32'

And #863 is now done so this has a much more natural syntax:

var vec: @Vector(4, f32) = src[0..4].*;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

No branches or pull requests

5 participants