http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59377
Bug ID: 59377 Summary: VRP produces bogus warning with -Warray-bounds Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: dnovillo at gcc dot gnu.org Host: x86_64-unknown-linux-gnu Target: x86_64-unknown-linux-gnu Build: x86_64-unknown-linux-gnu Using trunk and 4.8.x, this code produces a bogus -Warray-bounds warning: typedef decltype(sizeof(void*)) size_t; size_t strlen(const char *); int memcmp (const void *, const void *, size_t); struct StringPiece { const char *ptr_; size_t size_; StringPiece (); StringPiece (const char *p1):ptr_ (p1), size_(strlen(p1)) { } const char *data () { return ptr_; } size_t length() { return size_; } }; void operator== (StringPiece, StringPiece p2) { const char *a = p2.data (), *b = a; if (p2.length() > 8) { b += 8; memcmp (a, b, 1); } } void UtilsSplitQuotedStrings () { StringPiece c; c == ""; } $ trunk/bld/bin/g++ -std=c++11 -c -Warray-bounds -O2 a.cc a.cc: In function ‘void UtilsSplitQuotedStrings()’: a.cc:22:23: warning: array subscript is above array bounds [-Warray-bounds] memcmp (a, b, 1); $ ^ The warning disappears with -fno-tree-vrp: $ trunk/bld/bin/g++ -std=c++11 -c -Warray-bounds -O2 a.cc -fno-tree-vrp $ I've seen some similar looking bug reports, but none seemed related with VRP.