From 9d16839420c674fd7dff0b28b3efcc9a7953ed74 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 28 May 2019 16:11:09 -0400 Subject: [PATCH] fix invalid LLVM IR generated for ?*void const casts closes #2578 --- src/codegen.cpp | 2 +- test/stage1/behavior.zig | 1 + test/stage1/behavior/bugs/2578.zig | 12 ++++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 test/stage1/behavior/bugs/2578.zig diff --git a/src/codegen.cpp b/src/codegen.cpp index c5fd875987f3..e00ec1261555 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -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 { diff --git a/test/stage1/behavior.zig b/test/stage1/behavior.zig index e9ff84c03586..f477bb64edc7 100644 --- a/test/stage1/behavior.zig +++ b/test/stage1/behavior.zig @@ -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"); diff --git a/test/stage1/behavior/bugs/2578.zig b/test/stage1/behavior/bugs/2578.zig new file mode 100644 index 000000000000..cf7d941562ae --- /dev/null +++ b/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); +}