Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gccgo crash on shift of expression involving unsafe.Sizeof #21372

Closed
thanm opened this issue Aug 9, 2017 · 3 comments
Closed

gccgo crash on shift of expression involving unsafe.Sizeof #21372

thanm opened this issue Aug 9, 2017 · 3 comments
Milestone

Comments

@thanm
Copy link
Contributor

thanm commented Aug 9, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

gccgo tip:
go version go1.8.3 gccgo (GCC) 8.0.0 20170727 (experimental) linux/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOHOSTARCH="amd64"
GOOS="linux"

What did you do?

Compiled this fragment:

package foo
import "unsafe"
func bar() int {
	good := int(1) << (uint64(unsafe.Sizeof(0)-1) * 8)
	bad := 1 << (uint64(unsafe.Sizeof(0)-1) * 8)
	return good + bad
}

with "go build -compiler gccgo"

What did you expect to see?

successful build

What did you see instead?

crash with this stack trace

# command-line-arguments
go1: internal compiler error: in do_get_backend, at go/gofrontend/types.cc:4048
0x9bd50f Integer_type::do_get_backend(Gogo*)
	../../gcc-trunk/gcc/go/gofrontend/types.cc:4048
0x9b3ff8 Type::get_btype_without_hash(Gogo*)
	../../gcc-trunk/gcc/go/gofrontend/types.cc:965
0x9b3f35 Type::get_backend(Gogo*)
	../../gcc-trunk/gcc/go/gofrontend/types.cc:934
0x8ee92b Binary_expression::do_get_backend(Translate_context*)
	../../gcc-trunk/gcc/go/gofrontend/expressions.cc:6023
0x8e10e6 Expression::get_backend(Translate_context*)
	../../gcc-trunk/gcc/go/gofrontend/expressions.cc:402
0x8e7a79 Type_conversion_expression::do_get_backend(Translate_context*)
	../../gcc-trunk/gcc/go/gofrontend/expressions.cc:3495
0x8e10e6 Expression::get_backend(Translate_context*)
	../../gcc-trunk/gcc/go/gofrontend/expressions.cc:402
0x94efa3 Variable::get_init(Gogo*, Named_object*)
	../../gcc-trunk/gcc/go/gofrontend/gogo.cc:6703
0x99bbc3 Variable_declaration_statement::do_get_backend(Translate_context*)
	../../gcc-trunk/gcc/go/gofrontend/statements.cc:292
0x99b772 Statement::get_backend(Translate_context*)
	../../gcc-trunk/gcc/go/gofrontend/statements.cc:142
0x94d8ca Block::get_backend(Translate_context*)
	../../gcc-trunk/gcc/go/gofrontend/gogo.cc:6155
0x94c0c7 Function::build(Gogo*, Named_object*)
	../../gcc-trunk/gcc/go/gofrontend/gogo.cc:5758
0x9513d4 Named_object::get_backend(Gogo*, std::vector<Bexpression*, std::allocator<Bexpression*> >&, std::vector<Btype*, std::allocator<Btype*> >&, std::vector<Bfunction*, std::allocator<Bfunction*> >&)
	../../gcc-trunk/gcc/go/gofrontend/gogo.cc:7551
0x93ed51 Gogo::write_globals()
	../../gcc-trunk/gcc/go/gofrontend/gogo.cc:1354
0x938875 go_write_globals()
	../../gcc-trunk/gcc/go/gofrontend/go.cc:177
0x92f1d3 go_langhook_parse_file
	../../gcc-trunk/gcc/go/go-lang.c:327

From poking around in the debugger it appears that the type of the left operand of the shift is still an abstract in type, for what that's worth.

@gopherbot gopherbot added this to the Gccgo milestone Aug 9, 2017
@thanm thanm self-assigned this Aug 9, 2017
@thanm
Copy link
Contributor Author

thanm commented Aug 9, 2017

@ianlancetaylor
I'll see if I can come up with a fix for this, may need to task you for advice at some point

@gopherbot
Copy link

Change https://golang.org/cl/54370 mentions this issue: compiler: fix buglet in lshift type determination

@thanm
Copy link
Contributor Author

thanm commented Aug 9, 2017

@ianlancetaylor
Tentative fix mailed. I think this is the right solution, but not totally sure (haven't really worked on this aspect of gofrontend much).

hubot pushed a commit to gcc-mirror/gcc that referenced this issue Aug 9, 2017
    
    It's possible to construct an lshift expression using unsafe.Sizeof
    that is technically a compile-time constant but can't be evaluated
    without going through backend methods. In this case, insure that
    Type::make_non_abstract_type is called on the numeric operand of the
    shift (as opposed to leaving as abstract), to avoid an assert later on
    in the compiler flow.
    
    Fixes golang/go#21372.
    
    Reviewed-on: https://go-review.googlesource.com/54370


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@251006 138bc75d-0d04-0410-961f-82ee72b054a4
@golang golang locked and limited conversation to collaborators Aug 9, 2018
asiekierka pushed a commit to WonderfulToolchain/gcc-ia16 that referenced this issue May 16, 2022
    
    It's possible to construct an lshift expression using unsafe.Sizeof
    that is technically a compile-time constant but can't be evaluated
    without going through backend methods. In this case, insure that
    Type::make_non_abstract_type is called on the numeric operand of the
    shift (as opposed to leaving as abstract), to avoid an assert later on
    in the compiler flow.
    
    Fixes golang/go#21372.
    
    Reviewed-on: https://go-review.googlesource.com/54370

From-SVN: r251006
@rsc rsc unassigned thanm Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants