Skip to content

Commit

Permalink
ir: allow callee of function type in NewCall
Browse files Browse the repository at this point in the history
Prior to this commit, the callee had to be of pointer
to function type (as is the type of functions declared
in the global scope of the module).

However, to allow inline asm values to have function
type instead of pointer to function type, the type
checking of NewCall is relaxed.

Fixes llir#33.
  • Loading branch information
mewmew committed Mar 2, 2019
1 parent f20e2cd commit db5ffbf
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions ir/inst_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,19 @@ func (inst *InstCall) String() string {
func (inst *InstCall) Type() types.Type {
// Cache type if not present.
if inst.Typ == nil {
t, ok := inst.Callee.Type().(*types.PointerType)
if !ok {
panic(fmt.Errorf("invalid callee type; expected *types.PointerType, got %T", inst.Callee.Type()))
}
sig, ok := t.ElemType.(*types.FuncType)
if !ok {
panic(fmt.Errorf("invalid callee type; expected *types.FuncType, got %T", t.ElemType))
var sig *types.FuncType
switch t := inst.Callee.Type().(type) {
case *types.PointerType:
elem, ok := t.ElemType.(*types.FuncType)
if !ok {
panic(fmt.Errorf("invalid callee type; expected *types.FuncType, got %T", t.ElemType))
}
sig = elem
case *types.FuncType:
// used by inline asm values.
sig = t
default:
panic(fmt.Errorf("invalid callee type; expected *types.PointerType or *types.FuncType, got %T", inst.Callee.Type()))
}
if sig.Variadic {
inst.Typ = sig
Expand Down

0 comments on commit db5ffbf

Please sign in to comment.