Skip to content

Internal Compiler Panic in left-shift by Max.Uint in arithmetic shift expression #1725

@lmaltsis

Description

@lmaltsis
$ llgo build .
panic: unsupported Const: 18446744073709551615, int

goroutine 1 [running]:
github.com/goplus/llgo/ssa.(*aBuilder).Const(0xc000a3a000, {0x103a5f0, 0xc00050e0e0}, 0xc0015097e0)
        /home/user/software/llgo/ssa/expr.go:265 +0x69b
github.com/goplus/llgo/cl.(*context).compileValue(0xc000368b00, 0xc000a3a000, {0x103c5e8?, 0xc0012c5e40})
        /home/user/software/llgo/cl/compile.go:1092 +0x24a
github.com/goplus/llgo/cl.(*context).compileInstrOrValue(0xc000368b00, 0xc000a3a000, {0x103ec40, 0xc0012f1e30}, 0x0?)
        /home/user/software/llgo/cl/compile.go:777 +0x7ab
github.com/goplus/llgo/cl.(*context).compileInstr(0xc000368b00, 0xc000a3a000, {0x103c7e0, 0xc0012f1e30})
        /home/user/software/llgo/cl/compile.go:952 +0x876
github.com/goplus/llgo/cl.(*context).compileBlock(0xc000368b00, 0xc000a3a000, 0xc0012df6b0, 0x51d92b?, 0x0)
        /home/user/software/llgo/cl/compile.go:562 +0xbaa
github.com/goplus/llgo/cl.(*context).compileFuncDecl.func1()
        /home/user/software/llgo/cl/compile.go:404 +0x6ec
github.com/goplus/llgo/cl.newPackageEx(0xc000372388, 0xc000fabef0, 0x0, 0xc0012e1480, {0xc00088b470, 0x1, 0x1}, 0xc001a22e88)
        /home/user/software/llgo/cl/compile.go:1242 +0x942
github.com/goplus/llgo/cl.NewPackageExWithEmbed(...)
        /home/user/software/llgo/cl/compile.go:1171
github.com/goplus/llgo/internal/build.buildPkg(0xc00035a848, 0xc0009b8b40, 0x0)
        /home/user/software/llgo/internal/build/build.go:1213 +0x408
github.com/goplus/llgo/internal/build.buildAllPkgs.func1(0xc0009b8b40)
        /home/user/software/llgo/internal/build/build.go:691 +0x539
github.com/goplus/llgo/internal/build.buildAllPkgs(0xc00035a848, {0xc0002f7720, 0x14, 0x14}, 0x0)
        /home/user/software/llgo/internal/build/build.go:711 +0x4dc
github.com/goplus/llgo/internal/build.Do({0xc00003e810, 0x1, 0x1}, 0xc00032eb40)
        /home/user/software/llgo/internal/build/build.go:381 +0x15f7
github.com/goplus/llgo/cmd/internal/build.runCmd(0xc00003e840?, {0xc00003e810?, 0x1?, 0x10?})
        /home/user/software/llgo/cmd/internal/build/build.go:62 +0xaf
main.(*Cmd_build).Main.func1({0xc00003e810?, 0xc00035c600?, 0xc00035c600?})
        cmd/llgo/build_cmd.gox:27 +0x2f
main.(*Cmd_build).Main.(*Command).Run__1.func2(0xc00035c600?, {0xc00003e810?, 0x4?, 0xc31b3f?})
        /home/user/go/pkg/mod/github.com/goplus/cobra@v1.9.12/xcmd/classfile.go:87 +0x25
github.com/goplus/cobra.(*Command).execute(0xc000374308, {0xc00003e810, 0x1, 0x1})
        /home/user/go/pkg/mod/github.com/goplus/cobra@v1.9.12/command.go:1019 +0xae7
github.com/goplus/cobra.(*Command).ExecuteC(0xc000374008)
        /home/user/go/pkg/mod/github.com/goplus/cobra@v1.9.12/command.go:1148 +0x465
github.com/goplus/cobra.(*Command).Execute(...)
        /home/user/go/pkg/mod/github.com/goplus/cobra@v1.9.12/command.go:1071
github.com/goplus/cobra/xcmd.Gopt_App_Main({0x1034960, 0xc000374008}, {0xc000349e90, 0x9, 0x9})
        /home/user/go/pkg/mod/github.com/goplus/cobra@v1.9.12/xcmd/classfile.go:133 +0x2ac
main.(*App).Main(0xc000374008)
        cmd/llgo/main_app.gox:13 +0x3a5
main.main()
        cmd/llgo/version_cmd.gox:34 +0x1f

$ cat main.go
package main

import (
    "math"
)

func main() {
    var x = 1
    _ = x<<(math.MaxUint<<0)
}

Expected:

Get accepted and evaluated as 0, as seen in for example:

package main

import (
    "math"
)

func f(x int) {
}

func main() {
    var x = 1
    f(x<<(math.MaxUint))
}

Which ends up getting turned into the following intermediate llvm code:

[...]
define void @project.main() {
_llgo_0:
  call void @project.f(i64 0)
  ret void
}

Commit: 1398fa6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions