diff --git a/ssa/decl.go b/ssa/decl.go index 1e82a74b..165b5094 100644 --- a/ssa/decl.go +++ b/ssa/decl.go @@ -34,6 +34,15 @@ func VArg() *types.Var { return types.NewParam(0, nil, NameValist, types.NewSlice(tyAny)) } +func hasNameValist(sig *types.Signature) bool { + if sig.Variadic() { + if params := sig.Params(); params.At(params.Len()-1).Name() == NameValist { + return true + } + } + return false +} + // ----------------------------------------------------------------------------- type aNamedConst struct { @@ -228,7 +237,7 @@ func newParams(fn Type, prog Program) (params []Type, hasVArg bool) { sig := fn.raw.Type.(*types.Signature) in := sig.Params() if n := in.Len(); n > 0 { - if hasVArg = sig.Variadic(); hasVArg { + if hasVArg = hasNameValist(sig); hasVArg { n-- } params = make([]Type, n) diff --git a/ssa/type.go b/ssa/type.go index 11391f39..8e3f9703 100644 --- a/ssa/type.go +++ b/ssa/type.go @@ -452,7 +452,7 @@ func (p Program) toLLVMTypes(t *types.Tuple, n int) (ret []llvm.Type) { func (p Program) toLLVMFunc(sig *types.Signature) llvm.Type { tParams := sig.Params() n := tParams.Len() - hasVArg := sig.Variadic() + hasVArg := hasNameValist(sig) if hasVArg { n-- } diff --git a/ssa/type_cvt.go b/ssa/type_cvt.go index df54d0b8..1f7a5141 100644 --- a/ssa/type_cvt.go +++ b/ssa/type_cvt.go @@ -189,9 +189,8 @@ func (p goTypes) cvtFunc(sig *types.Signature, recv *types.Var) (raw *types.Sign } params, cvt1 := p.cvtTuple(sig.Params()) results, cvt2 := p.cvtTuple(sig.Results()) - if cvt1 || cvt2 || sig.Variadic() { - // variadic always is false in raw type for Go function - return types.NewSignatureType(nil, nil, nil, params, results, false) + if cvt1 || cvt2 { + return types.NewSignatureType(nil, nil, nil, params, results, sig.Variadic()) } return sig }