This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
tree-ssa-strlen vs. zero-length strings
- From: Ian Lance Taylor <iant at google dot com>
- To: jakub at redhat dot com
- Cc: gcc at gcc dot gnu dot org
- Date: Wed, 26 Oct 2011 22:22:21 -0700
- Subject: tree-ssa-strlen vs. zero-length strings
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