LLVM backend: call constPtrToInt instead of constBitCast

when appropriate. Avoids tripping an LLVM assertion.
This commit is contained in:
Andrew Kelley 2022-02-10 23:03:13 -07:00 committed by Jakub Konka
parent 335c680cde
commit d72f832b1e

View File

@ -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 {