The file tree-ssa-strlen.c causes several warnings when compiling the Go
library.  The warnings look like:

../../../gccgo2/libgo/go/http/transport.go: In function 
‘http.String.pN29_libgo_http.http.connectMethod’:
../../../gccgo2/libgo/go/http/transport.go:437:1: warning: offset outside 
bounds of constant string [enabled by default]

They are occurring because Go uses strings which are not null
terminated.  Some of those strings are zero length.  The code in
tree-ssa-srlen in strlen_enter_block calls get_stridx on the PHI
arguments.  get_stridx calls c_strlen.  c_strlen issues the above
warning.

I don't think it is possible to trigger this using C because I don't
think it is possible to have a zero-length STRING_CST in C.

Here is a Go file which will trigger the warning when compiling with
-O2.

package p
func A(b bool) string {
        s := ""
        if b {
                s = "a"
        }
        return s
}

foo.go: In function ‘p.A’:
foo.go:2:1: warning: offset outside bounds of constant string [enabled by 
default]

I'm not quite sure what get_stridx is doing here.  Perhaps the fix is as
simple as checking TREE_STRING_LENGTH before calling c_strlen.

Ian

Reply via email to