Skip to content

Commit

Permalink
fix invalid LLVM IR generated for ?*void const casts
Browse files Browse the repository at this point in the history
closes #2578
  • Loading branch information
andrewrk committed May 28, 2019
1 parent 508fdfe commit 9d16839
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/codegen.cpp
Expand Up @@ -2002,7 +2002,7 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {
render_const_val_global(g, &instruction->value, "");
ZigType *ptr_type = get_pointer_to_type(g, instruction->value.type, true);
instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value.global_refs->llvm_global, get_llvm_type(g, ptr_type), "");
} else if (instruction->value.type->id == ZigTypeIdPointer) {
} else if (get_codegen_ptr_type(instruction->value.type) != nullptr) {
instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value.global_refs->llvm_value,
get_llvm_type(g, instruction->value.type), "");
} else {
Expand Down
1 change: 1 addition & 0 deletions test/stage1/behavior.zig
Expand Up @@ -26,6 +26,7 @@ comptime {
_ = @import("behavior/bugs/2006.zig");
_ = @import("behavior/bugs/2114.zig");
_ = @import("behavior/bugs/2346.zig");
_ = @import("behavior/bugs/2578.zig");
_ = @import("behavior/bugs/394.zig");
_ = @import("behavior/bugs/421.zig");
_ = @import("behavior/bugs/529.zig");
Expand Down
12 changes: 12 additions & 0 deletions test/stage1/behavior/bugs/2578.zig
@@ -0,0 +1,12 @@
const Foo = struct {
y: u8,
};

var foo: Foo = undefined;
const t = &foo;

fn bar(pointer: ?*c_void) void {}

test "fixed" {
bar(t);
}

0 comments on commit 9d16839

Please sign in to comment.