From d72f832b1ebab0db106e64bc9f59eba90c414311 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 10 Feb 2022 23:03:13 -0700 Subject: [PATCH] LLVM backend: call constPtrToInt instead of constBitCast when appropriate. Avoids tripping an LLVM assertion. --- src/codegen/llvm.zig | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index ec0ead94e4..85cb808996 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -1858,7 +1858,11 @@ pub const DeclGen = struct { try self.resolveGlobalDecl(decl); const llvm_type = try self.llvmType(tv.ty); - return llvm_val.constBitCast(llvm_type); + if (tv.ty.zigTypeTag() == .Int) { + return llvm_val.constPtrToInt(llvm_type); + } else { + return llvm_val.constBitCast(llvm_type); + } } fn lowerPtrToVoid(dg: *DeclGen, ptr_ty: Type) !*const llvm.Value {