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

LLVM error when array returned by function is stored in wrong-typed var #3688

Closed
ghost opened this issue Nov 14, 2019 · 3 comments
Closed

LLVM error when array returned by function is stored in wrong-typed var #3688

ghost opened this issue Nov 14, 2019 · 3 comments
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@ghost
Copy link

ghost commented Nov 14, 2019

pub fn main() void {
    var arr: [4]f32 = undefined; // happens with any array type other than [16]f32
    arr = concat();
}
fn concat() [16]f32 {
    return [1]f32{0}**16;
}

Output:

Code Generation [129/453] std.debug.getLineNumberInfoDwarf...broken LLVM module found: Call parameter type does not match function signature!
  %arr = alloca [4 x float], align 4
 [16 x float]*  call fastcc void @concat([4 x float]* sret %arr), !dbg !14628

Above should be a compile error.


But this should probably work (assigning to compatible slice type):

pub fn main() void {
    var arr: []const f32 = undefined;
    arr = concat();
}   
fn concat() [16]f32 {
    return [1]f32{0}**16;
}   

But this one just outputs:

Code Generation [129/453] std.debug.getLineNumberInfoDwarf...Segmentation fault at address 0x0

Actually, that was a bit hackneyed. Here is a more realistic use case (which should work but also segfaults).

const Params = struct {
    slice: []const f32,
};
pub fn main() void {
    eatSlice(Params {
        .slice = concat(),
    });
}
fn eatSlice(params: Params) void {
}
fn concat() [16]f32 {
    return [1]f32{0}**16;
}
@Vexu
Copy link
Member

Vexu commented Nov 14, 2019

This is caused by the compiler not adding an implicit cast for the function's return type Same thing happens with #3422, #3646, #3224 and #3327.

@Vexu

This comment has been minimized.

@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label Nov 27, 2019
@andrewrk andrewrk added this to the 0.6.0 milestone Nov 27, 2019
@Vexu
Copy link
Member

Vexu commented Feb 10, 2020

Fixed by 5ea79bf

./build/a.zig:24:17: error: expected type '[4]f32', found '[16]f32'
    arr = concat();
                ^

The two other cases work if you take the address of the array.

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
Projects
None yet
Development

No branches or pull requests

3 participants