diff options
author | Ayke van Laethem <[email protected]> | 2019-08-02 16:58:42 +0200 |
---|---|---|
committer | Ron Evans <[email protected]> | 2019-08-05 14:44:30 +0200 |
commit | 33dc4b5121e570d17d045bd35d5dac5b521d8a7c (patch) | |
tree | f86c33fa7248e96b319e5daaafabce9d33bdd196 /compiler/func.go | |
parent | a04db67ea9d882eed9164321bcb503f76a65d2f1 (diff) | |
download | tinygo-33dc4b5121e570d17d045bd35d5dac5b521d8a7c.tar.gz tinygo-33dc4b5121e570d17d045bd35d5dac5b521d8a7c.zip |
compiler: fix crash with linked lists in interfaces
This commit fixes the following issue:
https://github.com/tinygo-org/tinygo/issues/309
Also, it prepares for some other reflect-related changes that should
make it easier to add support for named types (etc.) in the future.
Diffstat (limited to 'compiler/func.go')
-rw-r--r-- | compiler/func.go | 20 |
1 files changed, 2 insertions, 18 deletions
diff --git a/compiler/func.go b/compiler/func.go index c4806a09d..d9879d748 100644 --- a/compiler/func.go +++ b/compiler/func.go @@ -48,7 +48,7 @@ func (c *Compiler) createFuncValue(funcPtr, context llvm.Value, sig *types.Signa // Closure is: {context, function pointer} funcValueScalar = funcPtr case funcValueSwitch: - sigGlobal := c.getFuncSignature(sig) + sigGlobal := c.getTypeCode(sig) funcValueWithSignatureGlobalName := funcPtr.Name() + "$withSignature" funcValueWithSignatureGlobal := c.mod.NamedGlobal(funcValueWithSignatureGlobalName) if funcValueWithSignatureGlobal.IsNil() { @@ -73,22 +73,6 @@ func (c *Compiler) createFuncValue(funcPtr, context llvm.Value, sig *types.Signa return funcValue } -// getFuncSignature returns a global for identification of a particular function -// signature. It is used in runtime.funcValueWithSignature and in calls to -// getFuncPtr. -func (c *Compiler) getFuncSignature(sig *types.Signature) llvm.Value { - typeCodeName := getTypeCodeName(sig) - sigGlobalName := "reflect/types.type:" + typeCodeName - sigGlobal := c.mod.NamedGlobal(sigGlobalName) - if sigGlobal.IsNil() { - sigGlobal = llvm.AddGlobal(c.mod, c.ctx.Int8Type(), sigGlobalName) - sigGlobal.SetInitializer(llvm.Undef(c.ctx.Int8Type())) - sigGlobal.SetGlobalConstant(true) - sigGlobal.SetLinkage(llvm.InternalLinkage) - } - return sigGlobal -} - // extractFuncScalar returns some scalar that can be used in comparisons. It is // a cheap operation. func (c *Compiler) extractFuncScalar(funcValue llvm.Value) llvm.Value { @@ -110,7 +94,7 @@ func (c *Compiler) decodeFuncValue(funcValue llvm.Value, sig *types.Signature) ( funcPtr = c.builder.CreateExtractValue(funcValue, 1, "") case funcValueSwitch: llvmSig := c.getRawFuncType(sig) - sigGlobal := c.getFuncSignature(sig) + sigGlobal := c.getTypeCode(sig) funcPtr = c.createRuntimeCall("getFuncPtr", []llvm.Value{funcValue, sigGlobal}, "") funcPtr = c.builder.CreateIntToPtr(funcPtr, llvmSig, "") default: |