@@ -249,6 +249,7 @@ func (tm *llvmTypeMap) expandType(argTypes []llvm.Type, argAttrs []llvm.Attribut
249249
250250 switch bt := bt .(type ) {
251251 case * structBType , * arrayBType :
252+ noneAttr := tm .ctx .CreateEnumAttribute (0 , 0 )
252253 bo := tm .getBackendOffsets (bt )
253254 sp := 0
254255 for sp != len (bo ) && bo [sp ].offset < 8 {
@@ -258,21 +259,23 @@ func (tm *llvmTypeMap) expandType(argTypes []llvm.Type, argAttrs []llvm.Attribut
258259 eb2 := bo [sp :]
259260 if len (eb2 ) > 0 {
260261 argTypes = append (argTypes , tm .classifyEightbyte (eb1 , & numInt , & numSSE ), tm .classifyEightbyte (eb2 , & numInt , & numSSE ))
261- argAttrs = append (argAttrs , 0 , 0 )
262+ argAttrs = append (argAttrs , noneAttr , noneAttr )
262263 } else {
263264 argTypes = append (argTypes , tm .classifyEightbyte (eb1 , & numInt , & numSSE ))
264- argAttrs = append (argAttrs , 0 )
265+ argAttrs = append (argAttrs , noneAttr )
265266 }
266267
267268 return argTypes , argAttrs , numInt , numSSE
268269
269270 case * intBType :
270271 if bt .width < 4 {
272+ var argAttrKind uint
271273 if bt .signed {
272- argAttr = llvm .SExtAttribute
274+ argAttrKind = llvm .AttributeKindID ( "signext" )
273275 } else {
274- argAttr = llvm .ZExtAttribute
276+ argAttrKind = llvm .AttributeKindID ( "zeroext" )
275277 }
278+ argAttr = tm .ctx .CreateEnumAttribute (argAttrKind , 0 )
276279 }
277280 }
278281
@@ -516,10 +519,12 @@ type functionTypeInfo struct {
516519
517520func (fi * functionTypeInfo ) declare (m llvm.Module , name string ) llvm.Value {
518521 fn := llvm .AddFunction (m , name , fi .functionType )
519- fn .AddFunctionAttr (fi .retAttr )
522+ if fi .retAttr .GetEnumKind () != 0 {
523+ fn .AddAttributeAtIndex (0 , fi .retAttr )
524+ }
520525 for i , a := range fi .argAttrs {
521- if a != 0 {
522- fn .Param ( i ). AddAttribute ( a )
526+ if a . GetEnumKind () != 0 {
527+ fn .AddAttributeAtIndex ( i + 1 , a )
523528 }
524529 }
525530 return fn
@@ -537,9 +542,13 @@ func (fi *functionTypeInfo) call(ctx llvm.Context, allocaBuilder llvm.Builder, b
537542 fi .retInf .prepare (ctx , allocaBuilder , callArgs )
538543 typedCallee := builder .CreateBitCast (callee , llvm .PointerType (fi .functionType , 0 ), "" )
539544 call := builder .CreateCall (typedCallee , callArgs , "" )
540- call .AddInstrAttribute (0 , fi .retAttr )
545+ if fi .retAttr .GetEnumKind () != 0 {
546+ call .AddCallSiteAttribute (0 , fi .retAttr )
547+ }
541548 for i , a := range fi .argAttrs {
542- call .AddInstrAttribute (i + 1 , a )
549+ if a .GetEnumKind () != 0 {
550+ call .AddCallSiteAttribute (i + 1 , a )
551+ }
543552 }
544553 return fi .retInf .decode (ctx , allocaBuilder , builder , call )
545554}
@@ -556,9 +565,13 @@ func (fi *functionTypeInfo) invoke(ctx llvm.Context, allocaBuilder llvm.Builder,
556565 fi .retInf .prepare (ctx , allocaBuilder , callArgs )
557566 typedCallee := builder .CreateBitCast (callee , llvm .PointerType (fi .functionType , 0 ), "" )
558567 call := builder .CreateInvoke (typedCallee , callArgs , cont , lpad , "" )
559- call .AddInstrAttribute (0 , fi .retAttr )
568+ if fi .retAttr .GetEnumKind () != 0 {
569+ call .AddCallSiteAttribute (0 , fi .retAttr )
570+ }
560571 for i , a := range fi .argAttrs {
561- call .AddInstrAttribute (i + 1 , a )
572+ if a .GetEnumKind () != 0 {
573+ call .AddCallSiteAttribute (i + 1 , a )
574+ }
562575 }
563576 builder .SetInsertPointAtEnd (cont )
564577 return fi .retInf .decode (ctx , allocaBuilder , builder , call )
@@ -567,6 +580,7 @@ func (fi *functionTypeInfo) invoke(ctx llvm.Context, allocaBuilder llvm.Builder,
567580func (tm * llvmTypeMap ) getFunctionTypeInfo (args []types.Type , results []types.Type ) (fi functionTypeInfo ) {
568581 var returnType llvm.Type
569582 var argTypes []llvm.Type
583+ var argAttrKind uint
570584 if len (results ) == 0 {
571585 returnType = llvm .VoidType ()
572586 fi .retInf = & directRetInfo {}
@@ -609,15 +623,17 @@ func (tm *llvmTypeMap) getFunctionTypeInfo(args []types.Type, results []types.Ty
609623 case AIK_Indirect :
610624 returnType = llvm .VoidType ()
611625 argTypes = []llvm.Type {llvm .PointerType (resultsType , 0 )}
612- fi .argAttrs = []llvm.Attribute {llvm .StructRetAttribute }
626+ argAttrKind = llvm .AttributeKindID ("sret" )
627+ fi .argAttrs = []llvm.Attribute {tm .ctx .CreateEnumAttribute (argAttrKind , 0 )}
613628 fi .retInf = & indirectRetInfo {numResults : len (results ), resultsType : resultsType }
614629 }
615630 }
616631
617632 // Allocate an argument for the call chain.
618633 fi .chainIndex = len (argTypes )
619634 argTypes = append (argTypes , llvm .PointerType (tm .ctx .Int8Type (), 0 ))
620- fi .argAttrs = append (fi .argAttrs , llvm .NestAttribute )
635+ argAttrKind = llvm .AttributeKindID ("nest" )
636+ fi .argAttrs = append (fi .argAttrs , tm .ctx .CreateEnumAttribute (argAttrKind , 0 ))
621637
622638 // Keep track of the number of INTEGER/SSE class registers remaining.
623639 remainingInt := 6
@@ -651,7 +667,8 @@ func (tm *llvmTypeMap) getFunctionTypeInfo(args []types.Type, results []types.Ty
651667 if ! isDirect {
652668 fi .argInfos = append (fi .argInfos , & indirectArgInfo {len (argTypes )})
653669 argTypes = append (argTypes , llvm .PointerType (tm .ToLLVM (arg ), 0 ))
654- fi .argAttrs = append (fi .argAttrs , llvm .ByValAttribute )
670+ argAttrKind = llvm .AttributeKindID ("byval" )
671+ fi .argAttrs = append (fi .argAttrs , tm .ctx .CreateEnumAttribute (argAttrKind , 0 ))
655672 }
656673 }
657674
0 commit comments