This commit is contained in:
parent
ba2314db4a
commit
b77d876ebb
11 changed files with 36 additions and 37 deletions
|
@ -2,14 +2,21 @@ package core
|
|||
|
||||
import (
|
||||
"git.urbach.dev/cli/q/src/errors"
|
||||
"git.urbach.dev/cli/q/src/ssa"
|
||||
)
|
||||
|
||||
// CheckDeadCode checks for dead values.
|
||||
func (f *Function) CheckDeadCode() error {
|
||||
for instr := range f.Values {
|
||||
if instr.IsConst() && instr.CountUsers() == 0 {
|
||||
return errors.New(&UnusedValue{Value: instr.String()}, f.File, instr.Start())
|
||||
if !instr.IsConst() {
|
||||
continue
|
||||
}
|
||||
|
||||
if len(instr.(ssa.HasLiveness).Users()) > 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
return errors.New(&UnusedValue{Value: instr.String()}, f.File, instr.(ssa.HasSource).Start())
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue