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

invalid llvm code gen on missing try/catch on assignment to struct member #3269

Closed
slaide opened this issue Sep 20, 2019 · 0 comments
Closed
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@slaide
Copy link

slaide commented Sep 20, 2019

const std = @import("std");

const A=struct{
  memb: []i32,
};
const B=struct{
  memb: i32,
};

fn myAlloc(arg: bool) !i32{
  if(arg){
    return error.TestFailure;
  }else{
    return 2;
  }
}

pub fn main() anyerror!void {
  
  
  //#1
  
  var hi: []i32=std.heap.direct_allocator.alloc(i32,2);
  
  
  //#2
  
  //var res: A=undefined;
  //res.memb=std.heap.direct_allocator.alloc(i32,2);
  
  
  //#3
  
  //var perr: anyerror!i32=error.Failed;
  //var perr: error{OutOfMemory}!i32=error.OutOfMemory;
  //var btest:B=undefined;
  //btest.memb=perr;
  
  
  //#4
  
  //var res: B=undefined;
  //res.memb=myAlloc(true);
}

case 1 is how the code should behave, which is correct. it produces an error that the types are invalid.

case 2 is the minimal working example for this error. this should fail to compile, but it does not. instead this is shown:

Call parameter type does not match function signature!
  %12 = getelementptr inbounds %A, %A* %res, i32 0, i32 0, !dbg !14122
 { %"[]i32", i16 }*  call fastcc void @std.mem.Allocator.alloc.154(%"[]i32"* sret %12, %builtin.StackTrace* %0, %std.mem.Allocator* @direct_allocator_state, i64 2), !dbg !14123
LLVM ERROR: Broken module found, compilation aborted!

case 3 also behaves correctly though. does not compile, because of differing types. (both error-type-unions behave the same way. i dont know if this may be specific to the errors-unions specified by the alloc function)

case 4 also behaves the way it should. does not compile due to type incompatibility.

zig version: 0.4.0+cf4bccf7 (from snap package) on linux x86_64.

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

Successfully merging a pull request may close this issue.

2 participants