Commit d72f832b1e

Andrew Kelley <andrew@ziglang.org>
2022-02-11 07:03:13
LLVM backend: call constPtrToInt instead of constBitCast
when appropriate. Avoids tripping an LLVM assertion.
1 parent 335c680
Changed files (1)
src
codegen
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 {