@@ -862,7 +862,7 @@ func (c *compilerContext) createPackage(irbuilder llvm.Builder, pkg *ssa.Package
862862 if files , ok := c .embedGlobals [member .Name ()]; ok {
863863 c .createEmbedGlobal (member , global , files )
864864 } else if ! info .extern {
865- global .SetInitializer (llvm .ConstNull (global .Type (). ElementType ()))
865+ global .SetInitializer (llvm .ConstNull (global .GlobalValueType ()))
866866 global .SetVisibility (llvm .HiddenVisibility )
867867 if info .section != "" {
868868 global .SetSection (info .section )
@@ -1405,7 +1405,7 @@ func (b *builder) createInstruction(instr ssa.Instruction) {
14051405 b .CreateRet (b .getValue (instr .Results [0 ]))
14061406 } else {
14071407 // Multiple return values. Put them all in a struct.
1408- retVal := llvm .ConstNull (b .llvmFn .Type (). ElementType ().ReturnType ())
1408+ retVal := llvm .ConstNull (b .llvmFn .GlobalValueType ().ReturnType ())
14091409 for i , result := range instr .Results {
14101410 val := b .getValue (result )
14111411 retVal = b .CreateInsertValue (retVal , val , i , "" )
@@ -1444,7 +1444,7 @@ func (b *builder) createBuiltin(argTypes []types.Type, argValues []llvm.Value, c
14441444 elemsBuf := b .CreateExtractValue (elems , 0 , "append.elemsBuf" )
14451445 elemsPtr := b .CreateBitCast (elemsBuf , b .i8ptrType , "append.srcPtr" )
14461446 elemsLen := b .CreateExtractValue (elems , 1 , "append.elemsLen" )
1447- elemType := srcBuf . Type (). ElementType ( )
1447+ elemType := b . getLLVMType ( argTypes [ 0 ]. Underlying ().( * types. Slice ). Elem () )
14481448 elemSize := llvm .ConstInt (b .uintptrType , b .targetData .TypeAllocSize (elemType ), false )
14491449 result := b .createRuntimeCall ("sliceAppend" , []llvm.Value {srcPtr , elemsPtr , srcLen , srcCap , elemsLen , elemSize }, "append.new" )
14501450 newPtr := b .CreateExtractValue (result , 0 , "append.newPtr" )
@@ -1497,7 +1497,7 @@ func (b *builder) createBuiltin(argTypes []types.Type, argValues []llvm.Value, c
14971497 srcLen := b .CreateExtractValue (src , 1 , "copy.srcLen" )
14981498 dstBuf := b .CreateExtractValue (dst , 0 , "copy.dstArray" )
14991499 srcBuf := b .CreateExtractValue (src , 0 , "copy.srcArray" )
1500- elemType := dstBuf . Type (). ElementType ( )
1500+ elemType := b . getLLVMType ( argTypes [ 0 ]. Underlying ().( * types. Slice ). Elem () )
15011501 dstBuf = b .CreateBitCast (dstBuf , b .i8ptrType , "copy.dstPtr" )
15021502 srcBuf = b .CreateBitCast (srcBuf , b .i8ptrType , "copy.srcPtr" )
15031503 elemSize := llvm .ConstInt (b .uintptrType , b .targetData .TypeAllocSize (elemType ), false )
@@ -1637,7 +1637,8 @@ func (b *builder) createBuiltin(argTypes []types.Type, argValues []llvm.Value, c
16371637 b .uintptrType ,
16381638 b .uintptrType ,
16391639 }, false ))
1640- b .createUnsafeSliceCheck (ptr , len , argTypes [1 ].Underlying ().(* types.Basic ))
1640+ elementType := b .getLLVMType (argTypes [0 ].Underlying ().(* types.Pointer ).Elem ())
1641+ b .createUnsafeSliceCheck (ptr , len , elementType , argTypes [1 ].Underlying ().(* types.Basic ))
16411642 if len .Type ().IntTypeWidth () < b .uintptrType .IntTypeWidth () {
16421643 // Too small, zero-extend len.
16431644 len = b .CreateZExt (len , b .uintptrType , "" )
@@ -1712,7 +1713,7 @@ func (b *builder) createFunctionCall(instr *ssa.CallCommon) (llvm.Value, error)
17121713 // Eventually we might be able to eliminate this special case
17131714 // entirely. For details, see:
17141715 // https://discourse.llvm.org/t/rfc-enabling-wstrict-prototypes-by-default-in-c/60521
1715- calleeType = llvm .FunctionType (callee .Type (). ElementType ().ReturnType (), nil , false )
1716+ calleeType = llvm .FunctionType (callee .GlobalValueType ().ReturnType (), nil , false )
17161717 callee = llvm .ConstBitCast (callee , llvm .PointerType (calleeType , b .funcPtrAddrSpace ))
17171718 }
17181719 case * ssa.MakeClosure :
@@ -3095,7 +3096,7 @@ func (b *builder) createUnOp(unop *ssa.UnOp) (llvm.Value, error) {
30953096 }
30963097 case token .MUL : // *x, dereference pointer
30973098 valueType := b .getLLVMType (unop .X .Type ().Underlying ().(* types.Pointer ).Elem ())
3098- if b .targetData .TypeAllocSize (x . Type (). ElementType () ) == 0 {
3099+ if b .targetData .TypeAllocSize (valueType ) == 0 {
30993100 // zero-length data
31003101 return llvm .ConstNull (valueType ), nil
31013102 } else if strings .HasSuffix (unop .X .String (), "$funcaddr" ) {
0 commit comments