You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I encountered a really weird compilation error, I tried to simplify the code to find the root cause and this is the best I could do:
package main
funcmain() {
foo(nil)
}
typeBarstruct {
emptybool
}
func (b*Bar) Close() error {
returnnil
}
typeCloserinterface {
Close() error
}
funcfoo(bar*Bar) error {
varaint// replacing this condition with something simpler (i.e. nb > 10)// works fineif!bar.empty {
a=10// this inner branching is importantifa!=5 {
returnnil
}
}
varcCloser=bar// calling defer on an interface method + the branching above causes the bug// Replacing this line by func() { b.Close() }() works thoughdeferc.Close()
returnnil
}
This causes the following compilation error:
Instruction does not dominate all uses!
%3 = insertvalue %runtime._interface { i32 ptrtoint (%runtime.typeInInterface* @"typeInInterface:reflect/types.type:pointer:named:exp.Bar" to i32), i8* undef }, i8* %pack.ptr, 1
%invoke.typecode16 = extractvalue %runtime._interface %3, 0
Instruction does not dominate all uses!
%3 = insertvalue %runtime._interface { i32 ptrtoint (%runtime.typeInInterface* @"typeInInterface:reflect/types.type:pointer:named:exp.Bar" to i32), i8* undef }, i8* %pack.ptr, 1
%invoke.func.receiver19 = extractvalue %runtime._interface %3, 1
error: verification error after IR construction
I compiled to wasm using the 0.12.0 docker image with the following params:
So, it appears that the IR generation for defer is attempting to extract the interface type directly from the source, rather than passing it through the defer frame. This can also be problematic if the defer is in a loop, in which case it could be tricked into interpreting with the wrong type.
niaow
changed the title
Compilation error when combining branching and defer on interfaces
compiler: interface/function values are not passed through defer frames
Apr 8, 2020
niaow
changed the title
compiler: interface/function values are not passed through defer frames
compiler: interface values are not passed through defer frames
Apr 8, 2020
niaow
changed the title
compiler: interface values are not passed through defer frames
compiler: interface typecodes are not passed through defer frames
Apr 8, 2020
I encountered a really weird compilation error, I tried to simplify the code to find the root cause and this is the best I could do:
This causes the following compilation error:
I compiled to wasm using the
0.12.0
docker image with the following params:The text was updated successfully, but these errors were encountered: