public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* tree-ssa-strlen vs. zero-length strings
@ 2011-10-27  8:40 Ian Lance Taylor
  0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2011-10-27  8:40 UTC (permalink / raw)
  To: jakub; +Cc: gcc

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-10-27  5:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-27  8:40 tree-ssa-strlen vs. zero-length strings Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).