This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Pointer wraparound warning
- From: "Udo A. Steinberg" <us15 at os dot inf dot tu-dresden dot de>
- To: Ian Lance Taylor <iant at google dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Sun, 4 May 2008 19:39:38 +0200
- Subject: Re: Pointer wraparound warning
- References: <20080428182402.0755fd72@laptop.hypervisor.org> <m363twyzv6.fsf@google.com>
On Fri, 02 May 2008 17:50:53 -0700 Ian Lance Taylor (ILT) wrote:
ILT> "Udo A. Steinberg" <us15@os.inf.tu-dresden.de> writes:
ILT>
ILT> > gcc now complains about the following code snippet, saying...
ILT> > warning: assuming pointer wraparound does not occur when comparing
ILT> > P +- C1 with P +- C2
ILT>
ILT> Presumably only when you use -Wstrict-overflow=N where N >= 3. At
ILT> that level false positives are likely.
Actually it warns at N >= 2. I'm using gcc version 4.4.0 20080428
(experimental) via: g++ -Os -Wstrict-overflow=2 foo.cpp
ILT> > In the first snippet ptr never points outside x[], so the compiler
ILT> > shouldn't warn. What am I missing here?
ILT>
ILT> Nothing. The compiler could be smarter here. pointer_may_wrap_p in
ILT> fold-const.c could handle TREE_CODE (TREE_TYPE (base)) == ARRAY_TYPE.
That would be nice.
ILT> By the way, the compiler doesn't warn here:
[...]
ILT> because it doesn't know that putc doesn't change x, so it can't
ILT> optimize away the comparison.
Ahh ok! Thanks for the explanation.
Cheers,
- Udo