Skip to content

Commit

Permalink
asm: convert type of null callee to pointer to function type
Browse files Browse the repository at this point in the history
Note sure when you'd want to call a null function, but since its
valid LLVM IR we should ensure that the null constant has the correct
type, which is pointer to function type for all callees.

An old but related issue #33.
  • Loading branch information
mewmew committed Dec 5, 2019
1 parent 9880b94 commit 9637c11
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions asm/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,13 @@ func (gen *generator) irFloatConst(t types.Type, old *ast.FloatConst) (*constant
// irNullConst translates the AST null pointer constant into an equivalent IR
// null pointer constant.
func (gen *generator) irNullConst(t types.Type, old *ast.NullConst) (*constant.Null, error) {
typ, ok := t.(*types.PointerType)
if !ok {
var typ *types.PointerType
switch t := t.(type) {
case *types.PointerType:
typ = t
case *types.FuncType:
typ = types.NewPointer(t)
default:
return nil, errors.Errorf("invalid type of null pointer constant; expected *types.PointerType, got %T", t)
}
return constant.NewNull(typ), nil
Expand Down

1 comment on commit 9637c11

@mewmew
Copy link
Member Author

@mewmew mewmew commented on 9637c11 Dec 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible we may wish to revert this commit and rethink how callee types are computed.

A lot of the constant expression type mismatches are also related to func type vs pointer to func type mismatches (e.g. constant expression type mismatch; expected "void (void ()*, void ()*)*", got "void (void ()*, void ()*)".

We need to figure out a consistent way to handle the types of callees, the underlying value of which may be either constant.Expression (e.b. bitcast, select), *ir.Func, *ir.InlineAsm or *ir.Alias.

Edit: reversing for now.

Please sign in to comment.